-
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 18, 2024
1 parent
7fb49e0
commit 8bfee8f
Showing
13 changed files
with
152 additions
and
57 deletions.
There are no files selected for viewing
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,15 +1,18 @@ | ||
fn main() -> int { | ||
let i: int = 3; | ||
let j: int = 4; | ||
let x: bool = true; | ||
printb(x); | ||
|
||
if (x) { | ||
printi(i); | ||
return 13; | ||
} | ||
else { | ||
printi(j); | ||
return 12; | ||
fn fib(a: int, b: int) { | ||
printi(a); | ||
|
||
if (a == 233) { | ||
exit(10); | ||
} | ||
|
||
let c: int = b; | ||
let d: int = a + b; | ||
|
||
fib(c, d); | ||
} | ||
|
||
fn main() -> int { | ||
fib(0, 1); | ||
|
||
return 1; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use unique_type_id::UniqueTypeId; | ||
use crate::root::builtin::{BuiltinInlineFunction, InlineFunctionGenerator, f_id}; | ||
use crate::root::builtin::types::bool::BoolType; | ||
use crate::root::builtin::types::int::IntType; | ||
use crate::root::builtin::types::int::printi::PrintI; | ||
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 IntEq; | ||
|
||
impl IntEq { | ||
pub const fn id() -> FunctionID { | ||
f_id(IntEq::unique_type_id().0) | ||
} | ||
} | ||
|
||
impl BuiltinInlineFunction for IntEq { | ||
fn id(&self) -> FunctionID { | ||
IntEq::id() | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"eq" | ||
} | ||
|
||
fn signature(&self) -> FunctionSignature { | ||
FunctionSignature::new_inline_builtin( | ||
true, | ||
&[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())], | ||
Some(BoolType::id().immediate()) | ||
) | ||
} | ||
|
||
fn inline(&self) -> InlineFunctionGenerator { | ||
|args: &[LocalAddress], return_into: Option<LocalAddress>, gt, _| -> String { | ||
let lhs = args[0]; | ||
let rhs = args[1]; | ||
let return_into = return_into.unwrap(); | ||
let j = gt.get_unique_tag(IntEq::id()); | ||
let j2 = gt.get_unique_tag(IntEq::id()); | ||
|
||
format!( | ||
" mov rax, qword {lhs} | ||
cmp rax, qword {rhs} | ||
jz {j} | ||
mov byte {return_into}, 0 | ||
jmp {j2} | ||
{j}: | ||
mov byte {return_into}, 1 | ||
{j2}:\n") | ||
} | ||
} | ||
|
||
fn parent_type(&self) -> Option<TypeID> { | ||
Some(IntType::id()) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
IntAdd=0 | ||
IntSub=1 | ||
IntPSub=2 | ||
PrintI=3 | ||
IntEq=4 | ||
IntType=5 | ||
PrintB=6 | ||
BoolType=7 | ||
ExitFunction=8 |