Skip to content

Commit

Permalink
64 bit literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Jun 18, 2024
1 parent 8bfee8f commit b812129
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 27 deletions.
8 changes: 0 additions & 8 deletions build.rs

This file was deleted.

47 changes: 33 additions & 14 deletions build/out.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,42 @@ section .text
main:
push rbp
mov rbp, rsp
mov qword [rbp-8], 0
mov qword [rbp-16], 1
mov rax, qword [rbp-16]
mov qword [rbp-40], rax
mov rax, qword [rbp-8]
mov qword [rbp-48], rax
sub rsp, 48
mov dword [rbp-8], 0xb7891800
mov dword [rbp-4], 0xffffffe8
mov rdi, __4_fstr
mov rsi, [rbp-8]
mov al, 0
sub rsp, 8
extern printf
call printf
add rsp, 8
mov dword [rbp-16], 0x00000002
mov dword [rbp-12], 0x00000000
mov rax, 60
mov rdi, [rbp-16]
syscall
mov dword [rbp-24], 0x00000000
mov dword [rbp-20], 0x00000000
mov dword [rbp-32], 0x00000001
mov dword [rbp-28], 0x00000000
mov rax, qword [rbp-32]
mov qword [rbp-56], rax
mov rax, qword [rbp-24]
mov qword [rbp-64], rax
sub rsp, 64
call _1
add rsp, 48
mov qword [rbp-40], 1
mov rax, qword [rbp-40]
add rsp, 64
mov dword [rbp-56], 0x00000001
mov dword [rbp-52], 0x00000000
mov rax, qword [rbp-56]
leave
ret


_1:
push rbp
mov rbp, rsp
mov rax, qword [rbp+16]
mov rax, qword [rbp+24]
mov qword [rbp-8], rax
mov rdi, __4_fstr
mov rsi, [rbp-8]
Expand All @@ -34,7 +51,8 @@ _1:
add rsp, 8
mov rax, qword [rbp+16]
mov qword [rbp-17], rax
mov qword [rbp-25], 233
mov dword [rbp-25], 0x01709e79
mov dword [rbp-21], 0x00000000
mov rax, qword [rbp-17]
cmp rax, qword [rbp-25]
jz __5_0
Expand All @@ -45,7 +63,8 @@ _1:
__5_1:
cmp byte [rbp-9], 0
jz _1_2
mov qword [rbp-33], 10
mov dword [rbp-33], 0x0000000a
mov dword [rbp-29], 0x00000000
mov rax, 60
mov rdi, [rbp-33]
syscall
Expand Down Expand Up @@ -73,4 +92,4 @@ _1:


section .data_readonly
__4_fstr db `Integer: %d\n`,0
__4_fstr db `Integer: %ld\n`,0
Binary file modified build/out.o
Binary file not shown.
Binary file modified build/out.out
Binary file not shown.
8 changes: 6 additions & 2 deletions main.why
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn fib(a: int, b: int) {
printi(a);
printi(b);

if (a == 233) {
if (a == 24157817) {
exit(10);
}

Expand All @@ -12,7 +12,11 @@ fn fib(a: int, b: int) {
}

fn main() -> int {
printi(-100000000000);
exit(2);

fib(0, 1);


return 1;
}
2 changes: 1 addition & 1 deletion src/root/builtin/types/bool/printb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl BuiltinInlineFunction for PrintB {
|args: &[LocalAddress], _, gt, sz| -> String {
let id = format!("{}_fstr", Self::id().string_id());

let data = format!("{id} db `Boolean: %d\\n`,0");
let data = format!("{id} db `Boolean: %ld\\n`,0");

gt.add_readonly_data(&id, &data);

Expand Down
5 changes: 4 additions & 1 deletion src/root/builtin/types/int/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod p_sub;
mod printi;
mod eq;

use std::fmt::format;
use b_box::b;
use unique_type_id::UniqueTypeId;
use crate::root::builtin::t_id;
Expand Down Expand Up @@ -59,7 +60,9 @@ impl Type for IntType {
}
}
LiteralTokens::Int(value) => {
format!(" mov qword {location}, {value}\n")
let full_hex = format!("{:016x}", value);
format!(" mov dword {location}, 0x{}
mov dword {}, 0x{}\n", &full_hex[8..], *location + LocalAddress(4), &full_hex[..8])
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/root/builtin/types/int/printi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl BuiltinInlineFunction for PrintI {
|args: &[LocalAddress], _, gt, sz| -> String {
let id = format!("{}_fstr", Self::id().string_id());

let data = format!("{id} db `Integer: %d\\n`,0");
let data = format!("{id} db `Integer: %ld\\n`,0");

gt.add_readonly_data(&id, &data);

Expand Down

0 comments on commit b812129

Please sign in to comment.