Skip to content

Commit

Permalink
Added referencing
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Jun 18, 2024
1 parent 1bbf537 commit 41ef12b
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 79 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ nom-supreme = "0.8.0"
substring = "1.4.5"
derive-getters = "0.4.0"
derive_more = "0.99.17"
pinned-init = "0.0.7"
arr_macro = "0.2.1"

[profile.release]
opt-level = 3
Expand Down
64 changes: 30 additions & 34 deletions build/out.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,46 @@ main:
push rbp
mov rbp, rsp
mov qword [rbp-8], 0
mov qword [rbp-16], 0
main_0:
mov rax, qword [rbp-8]
mov qword [rbp-25], rax
mov qword [rbp-33], 0
mov rax, qword [rbp-25]
cmp rax, qword [rbp-33]
jz __5_2
mov byte [rbp-17], 0
jmp __5_3
__5_2:
mov byte [rbp-17], 1
__5_3:
cmp byte [rbp-17], 0
mov byte [rbp-9], 1
cmp byte [rbp-9], 0
jz main_1
mov rax, rbp
add rax, -8
mov qword [rbp-17], rax
mov qword [rbp-25], 1
mov rax, qword [rbp-17]
mov rdx, qword [rbp-25]
add qword [rax], rdx
mov rax, qword [rbp-8]
mov qword [rbp-41], rax
mov qword [rbp-33], rax
mov rdi, __4_fstr
mov rsi, [rbp-41]
mov rsi, [rbp-33]
mov al, 0
sub rsp, 41
sub rsp, 33
extern printf
call printf
add rsp, 41
mov rax, qword [rbp-16]
mov qword [rbp-50], rax
mov qword [rbp-58], 0
mov rax, qword [rbp-50]
cmp rax, qword [rbp-58]
jz __5_4
mov byte [rbp-42], 0
jmp __5_5
__5_4:
mov byte [rbp-42], 1
__5_5:
cmp byte [rbp-42], 0
jz main_6
add rsp, 33
mov rax, qword [rbp-8]
mov qword [rbp-42], rax
mov qword [rbp-50], 12
mov rax, qword [rbp-42]
cmp rax, qword [rbp-50]
jz __5_2
mov byte [rbp-34], 0
jmp __5_3
__5_2:
mov byte [rbp-34], 1
__5_3:
cmp byte [rbp-34], 0
jz main_4
jmp main_1
main_7:
main_6:
main_5:
main_4:
jmp main_0
main_1:
mov qword [rbp-41], 2
mov rax, qword [rbp-41]
mov qword [rbp-17], 2
mov rax, qword [rbp-17]
leave
ret

Expand Down
Binary file modified build/out.o
Binary file not shown.
6 changes: 3 additions & 3 deletions main.why
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
fn main() -> int {
let a: int = 0;
let b: int = 0;

while (a == 0) {
while (true) {
&a += 1;
printi(a);

if (b == 0) {
if (a == 12) {
break;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
use std::mem::MaybeUninit;
use std::hint::black_box;
use arr_macro::arr;
use pinned_init::{pin_data, pin_init};
use std::mem;

mod root;

#[pin_data]
struct Large {
#[pin]
inner: [u8; 10_000]
}

fn main() {
root::main();
}
1 change: 1 addition & 0 deletions src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub mod shared;
pub mod compiler;
pub mod assembler;
pub mod errors;
mod ob;

pub const POINTER_SIZE: ByteSize = ByteSize(8);

Expand Down
37 changes: 37 additions & 0 deletions src/root/builtin/types/int/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,40 @@ impl BuiltinInlineFunction for IntAdd {
Some(IntType::id())
}
}

#[derive(UniqueTypeId)]
#[UniqueTypeIdType = "u16"]
pub struct IntAsAdd;

impl BuiltinInlineFunction for IntAsAdd {
fn id(&self) -> FunctionID {
f_id(IntAsAdd::unique_type_id().0)
}

fn name(&self) -> &'static str {
"as_add"
}

fn signature(&self) -> FunctionSignature {
FunctionSignature::new_inline_builtin(
true,
&[("lhs", IntType::id().with_indirection(1)), ("rhs", IntType::id().immediate())],
None
)
}

fn inline(&self) -> InlineFunctionGenerator {
|args: &[LocalAddress], return_into: Option<LocalAddress>, _, _| -> String {
let lhs = args[0];
let rhs = args[1];
format!(
" mov rax, qword {lhs}
mov rdx, qword {rhs}
add qword [rax], rdx\n")
}
}

fn parent_type(&self) -> Option<TypeID> {
Some(IntType::id())
}
}
3 changes: 2 additions & 1 deletion src/root/builtin/types/int/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::format;
use b_box::b;
use unique_type_id::UniqueTypeId;
use crate::root::builtin::t_id;
use crate::root::builtin::types::int::add::IntAdd;
use crate::root::builtin::types::int::add::{IntAdd, IntAsAdd};
use crate::root::builtin::types::int::eq::IntEq;
use crate::root::builtin::types::int::p_sub::IntPSub;
use crate::root::builtin::types::int::printi::PrintI;
Expand All @@ -22,6 +22,7 @@ use crate::root::shared::types::Type;
pub fn register_int(global_table: &mut GlobalDefinitionTable) {
global_table.register_builtin_type(b!(IntType));
global_table.register_inline_function(&IntAdd);
global_table.register_inline_function(&IntAsAdd);
global_table.register_inline_function(&IntSub);
global_table.register_inline_function(&IntPSub);
global_table.register_inline_function(&IntEq);
Expand Down
Loading

0 comments on commit 41ef12b

Please sign in to comment.