-
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 8, 2024
1 parent
b573fba
commit ad80498
Showing
17 changed files
with
180 additions
and
94 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,14 +1,11 @@ | ||
impl int { | ||
fn sub(lhs: int, rhs: int) -> int { | ||
return lhs == rhs; | ||
} | ||
|
||
fn eq(lhs: int, rhs: int) -> int { | ||
return (lhs + rhs) + 1; | ||
fn p_sub(self) -> Self { | ||
return 0 - self; | ||
} | ||
} | ||
|
||
fn main() -> int { | ||
return 3 - 2; | ||
let x: int = -12; | ||
return -x; | ||
} | ||
|
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,46 @@ | ||
use unique_type_id::UniqueTypeId; | ||
use crate::root::builtin::{BuiltinInlineFunction, InlineFunctionGenerator}; | ||
use crate::root::builtin::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 IntSub; | ||
|
||
impl BuiltinInlineFunction for IntSub { | ||
fn id(&self) -> FunctionID { | ||
FunctionID(-(IntSub::unique_type_id().0 as isize) - 1) | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"sub" | ||
} | ||
|
||
fn signature(&self) -> FunctionSignature { | ||
FunctionSignature::new_inline_builtin( | ||
true, | ||
&[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())], | ||
Some(IntType::id().immediate()) | ||
) | ||
} | ||
|
||
fn inline(&self) -> InlineFunctionGenerator { | ||
|args: &[LocalAddress], return_into: Option<LocalAddress>| -> String { | ||
let lhs = args[0]; | ||
let rhs = args[1]; | ||
let return_into = return_into.unwrap(); | ||
format!( | ||
" mov rax, qword {lhs} | ||
sub rax, qword {rhs} | ||
mov qword {return_into}, rax") | ||
} | ||
} | ||
|
||
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
Oops, something went wrong.