-
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.
Started adding support for inline functions
- Loading branch information
Robert-M-Lucas
committed
Jun 6, 2024
1 parent
2a22044
commit aad9441
Showing
13 changed files
with
184 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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 IntAdd {} | ||
|
||
impl BuiltinInlineFunction for IntAdd { | ||
fn id(&self) -> FunctionID { | ||
FunctionID(-(IntAdd::unique_type_id().0 as isize) - 1) | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"add" | ||
} | ||
|
||
fn signature(&self) -> FunctionSignature { | ||
FunctionSignature::new_inline_builtin( | ||
&[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())], | ||
Some(IntType::id().immediate()) | ||
) | ||
} | ||
|
||
fn inline(&self) -> InlineFunctionGenerator { | ||
|args: &[LocalAddress], return_addr: Option<LocalAddress>| -> Result<String, WErr> { | ||
todo!() | ||
} | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
pub mod int; | ||
|
||
use crate::root::builtin::int::IntType; | ||
use crate::root::builtin::int::{IntType, register_int}; | ||
use crate::root::errors::WErr; | ||
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable}; | ||
use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; | ||
use crate::root::shared::common::{FunctionID, LocalAddress, TypeID}; | ||
use crate::root::shared::types::Type; | ||
|
||
pub fn register_builtin(global_table: &mut GlobalDefinitionTable) { | ||
let types: [(String, Box<dyn Type>); 1] = [ | ||
("int".to_string(), Box::new(IntType{})) | ||
]; | ||
|
||
for (n, t) in types { | ||
global_table.register_builtin_type(n, t); | ||
} | ||
register_int(global_table); | ||
} | ||
|
||
pub type InlineFunctionGenerator = fn(&[LocalAddress], Option<LocalAddress>) -> Result<String, WErr>; | ||
|
||
pub trait BuiltinInlineFunction { | ||
fn id(&self) -> FunctionID; | ||
fn name(&self) -> &'static str; | ||
fn signature(&self) -> FunctionSignature; | ||
fn inline(&self) -> InlineFunctionGenerator; | ||
fn parent_type(&self) -> Option<TypeID>; | ||
} |
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,6 @@ | ||
use crate::root::errors::WErr; | ||
use crate::root::shared::common::{FunctionID, LocalAddress}; | ||
|
||
pub fn call_function(fid: FunctionID, arguments: &[LocalAddress], return_address: Option<LocalAddress>) -> Result<String, WErr> { | ||
todo!() | ||
} |
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
IntType=0 | ||
IntAdd=1 |