-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert-M-Lucas
committed
Jun 17, 2024
1 parent
e572b1f
commit a671c3e
Showing
12 changed files
with
147 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
fn r(a: int) { | ||
fn fib(a: int, b: int) { | ||
printi(a); | ||
r(a + 1); | ||
let d: int = a + b; | ||
let c: int = b; | ||
exit(12); | ||
fib(c, d); | ||
} | ||
|
||
fn main() -> int { | ||
r(1); | ||
fib(0, 1); | ||
return 255; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use unique_type_id::UniqueTypeId; | ||
use crate::root::builtin::{BuiltinInlineFunction, f_id, InlineFunctionGenerator}; | ||
use crate::root::builtin::types::int::IntType; | ||
use crate::root::errors::WErr; | ||
use crate::root::name_resolver::name_resolvers::NameResult::Function; | ||
use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; | ||
|
||
use crate::root::shared::common::{FunctionID, Indirection, LocalAddress, TypeID, TypeRef}; | ||
|
||
#[derive(UniqueTypeId)] | ||
#[UniqueTypeIdType = "u16"] | ||
pub struct ExitFunction; | ||
|
||
impl ExitFunction { | ||
pub const fn id() -> FunctionID { | ||
f_id(ExitFunction::unique_type_id().0) | ||
} | ||
} | ||
|
||
impl BuiltinInlineFunction for ExitFunction { | ||
fn id(&self) -> FunctionID { | ||
Self::id() | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"exit" | ||
} | ||
|
||
fn signature(&self) -> FunctionSignature { | ||
FunctionSignature::new_inline_builtin( | ||
false, | ||
&[("lhs", IntType::id().immediate())], | ||
None | ||
) | ||
} | ||
|
||
fn inline(&self) -> InlineFunctionGenerator { | ||
|args: &[LocalAddress], _, gt, sz| -> String { | ||
let lhs = &args[0]; | ||
|
||
// 0 us exit syscall | ||
format!(" mov rax, 60 | ||
mov rdi, {lhs} | ||
syscall") | ||
} | ||
} | ||
|
||
fn parent_type(&self) -> Option<TypeID> { | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod exit; | ||
|
||
use b_box::b; | ||
use crate::root::builtin::functions::exit::ExitFunction; | ||
use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; | ||
|
||
pub fn register_functions(global_table: &mut GlobalDefinitionTable) { | ||
global_table.register_inline_function(&ExitFunction); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters