-
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
1 parent
69475ab
commit b21f378
Showing
9 changed files
with
522 additions
and
94 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file was deleted.
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 |
---|---|---|
@@ -1,10 +1,22 @@ | ||
use linked_list; | ||
use std/linked_list; | ||
|
||
|
||
fn main() -> int { | ||
let x: LL = LL::new(); | ||
x.add(12); | ||
x.push(12); | ||
x.push(7); | ||
x.push(8); | ||
x.print(); | ||
printnl(); | ||
|
||
printi(x.get(1)); | ||
printnl(); | ||
|
||
printi(x.pop()); | ||
printnl(); | ||
|
||
x.print(); | ||
|
||
return 8; | ||
} | ||
|
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,8 +1,11 @@ | ||
mod exit; | ||
mod printnl; | ||
|
||
use crate::root::builtin::functions::exit::ExitFunction; | ||
use crate::root::builtin::functions::printnl::PrintNL; | ||
use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; | ||
|
||
pub fn register_functions(global_table: &mut GlobalDefinitionTable) { | ||
global_table.register_inline_function(&ExitFunction); | ||
global_table.register_inline_function(&PrintNL); | ||
} |
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,56 @@ | ||
use crate::root::builtin::types::int::IntType; | ||
use crate::root::builtin::{f_id, BuiltinInlineFunction, InlineFunctionGenerator}; | ||
use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; | ||
use crate::root::parser::parse_parameters::SelfType; | ||
use crate::root::shared::common::{FunctionID, LocalAddress, TypeID}; | ||
use unique_type_id::UniqueTypeId; | ||
|
||
#[derive(UniqueTypeId)] | ||
#[UniqueTypeIdType = "u16"] | ||
pub struct PrintNL; | ||
|
||
impl PrintNL { | ||
pub const fn id() -> FunctionID { | ||
f_id(PrintNL::unique_type_id().0) | ||
} | ||
} | ||
|
||
impl BuiltinInlineFunction for PrintNL { | ||
fn id(&self) -> FunctionID { | ||
Self::id() | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"printnl" | ||
} | ||
|
||
fn signature(&self) -> FunctionSignature { | ||
FunctionSignature::new_inline_builtin( | ||
SelfType::None, | ||
&[], | ||
None, | ||
) | ||
} | ||
|
||
fn inline(&self) -> InlineFunctionGenerator { | ||
|_, _, gt, sz| -> String { | ||
let id = format!("{}_fstr", Self::id().string_id()); | ||
let data = format!("{id} db `\\n`,0"); | ||
gt.add_readonly_data(&id, &data); | ||
|
||
format!( | ||
" mov rdi, {id} | ||
mov al, 0 | ||
sub rsp, {sz} | ||
extern printf | ||
call printf | ||
add rsp, {sz} | ||
" | ||
) | ||
} | ||
} | ||
|
||
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,88 @@ | ||
struct LL { | ||
first: &Node | ||
} | ||
|
||
impl LL { | ||
fn new() -> LL { | ||
return LL { | ||
first: Node::null() | ||
}; | ||
} | ||
|
||
fn push(&self, val: int) { | ||
if (Node::is_null(*self.first)) { | ||
self.first = Node::new(val); | ||
} else { | ||
self.first.push(val); | ||
}; | ||
} | ||
|
||
fn get(&self, idx: int) -> int { | ||
return self.first.get(idx); | ||
} | ||
|
||
fn pop(&self) -> int { | ||
if (Node::is_null(*(*self.first).next)) { | ||
let val: int = *(*self.first).val; | ||
Node::free(*self.first); | ||
self.first = Node::null(); | ||
return val; | ||
} | ||
|
||
return self.first.pop(); | ||
} | ||
|
||
fn print(&self) { | ||
if (!Node::is_null(*self.first)) { | ||
self.first.print(); | ||
}; | ||
} | ||
} | ||
|
||
struct Node { | ||
val: int, | ||
next: &Node | ||
} | ||
|
||
impl Node { | ||
fn new(val: int) -> &Node { | ||
return new Node { | ||
val: val, | ||
next: Node::null() | ||
}; | ||
} | ||
|
||
fn push(&self, val: int) { | ||
if (Node::is_null(*self.next)) { | ||
self.next = Node::new(val); | ||
} else { | ||
self.next.push(val); | ||
}; | ||
} | ||
|
||
fn get(&self, idx: int) -> int { | ||
if (idx == 0) { | ||
return *self.val; | ||
} | ||
|
||
return self.next.get(idx - 1); | ||
} | ||
|
||
fn pop(&self) -> int { | ||
if (Node::is_null(*(*self.next).next)) { | ||
let val: int = *(*self.next).val; | ||
Node::free(*self.next); | ||
self.next = Node::null(); | ||
return val; | ||
} | ||
|
||
return self.next.pop(); | ||
} | ||
|
||
fn print(&self) { | ||
printi(*self.val); | ||
if (!Node::is_null(*self.next)) { | ||
self.next.print(); | ||
}; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -34,3 +34,9 @@ BoolEq=32 | |
BoolNE=33 | ||
IntType=34 | ||
IsNullFunction=35 | ||
P=36 | ||
Pr=37 | ||
Pri=38 | ||
Prin=39 | ||
Print=40 | ||
PrintNL=41 |