From b812129f72d83750419c5f8d976d71f96571c759 Mon Sep 17 00:00:00 2001 From: Robert-M-Lucas Date: Tue, 18 Jun 2024 15:02:27 +0100 Subject: [PATCH] 64 bit literals --- build.rs | 8 ----- build/out.asm | 47 ++++++++++++++++++-------- build/out.o | Bin 1232 -> 1376 bytes build/out.out | Bin 16896 -> 16896 bytes main.why | 8 +++-- src/root/builtin/types/bool/printb.rs | 2 +- src/root/builtin/types/int/mod.rs | 5 ++- src/root/builtin/types/int/printi.rs | 2 +- 8 files changed, 45 insertions(+), 27 deletions(-) delete mode 100644 build.rs diff --git a/build.rs b/build.rs deleted file mode 100644 index 613fb5c..0000000 --- a/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::fs; -use std::path::PathBuf; - -fn main() { - if PathBuf::from("types.toml").is_file() { - fs::remove_file(PathBuf::from("types.toml")).unwrap(); - } -} \ No newline at end of file diff --git a/build/out.asm b/build/out.asm index c69b3e7..d770531 100644 --- a/build/out.asm +++ b/build/out.asm @@ -5,17 +5,34 @@ 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 @@ -23,7 +40,7 @@ main: _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] @@ -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 @@ -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 @@ -73,4 +92,4 @@ _1: section .data_readonly - __4_fstr db `Integer: %d\n`,0 \ No newline at end of file + __4_fstr db `Integer: %ld\n`,0 \ No newline at end of file diff --git a/build/out.o b/build/out.o index 8b84e4f049a14e03ef7e7f2800a7c4535e456ad0..95124a793661de32fa705b552ff5cb284a49f47b 100644 GIT binary patch delta 465 zcmcb>`G9M}0^SHl1_YSw$Ra%PfCOg(GenGU;zM)Bg2|GM_KX`QM*_(MlV>v8b26|( zq!T7TWK`xm?)rm4qI3Ik*FP`*|NlSPn@P6*xa$WdppxURUqA|X*Z>KS?%EIhtjAqn zfJBbFzJX8=K(-%ueFEZnbh|$A=yW{+q+bB(10Kz999~F(B$|&n9CtkdQF;cd^u)=- zp&p%2fr=%7ihp?Q2Z@7#M|bJu2qp>RcYO^Jb$#z)?fSfg?U?I#hSw}W zlCh!oJ41=&ao77?Ko!SbA2Upz&J-@|2=oNd#!Qed5b(?^Nli~JvQkjZN#UBz%e+`o z8Z6GpFcnNA2sxMFu iEsHXv$mE4A;*#o6ZJ;m&x$O_oNg%KoBrCBEhb#a?S%)?N delta 321 zcmaFBb%Arj0^V;7NMQ0p7U78pBsdwEA%eUUADS}?OqOJ{XAGDe2_zFH&t$acT)+a6 zHkka7QQ6t!xa$uPA4q>-1kv5DA3Qo;Zvg2ZK>C75^BaQ~LLiCeBL+Z4H=v4coID)r z(fJgpOkna{CQVkL)bp25mNz9?fq!UR?bLlxRM}aoqI-$kgMmUqC8$ z*Z>KS?%EIhtjAqnfJBbFzJX8=7{RjRHY*Aqbc1&}@fG|}OO1W2O!h{JK$ z`V$bfXP|0NoID)r(fJgpS^}v02UhpELEQsXBmh+O{0WY5@_NFpyK92n~O}?7=f;61Ihj#NhD{jAyw5dRQz)Fv_di%sCIiFf4xtL(NvsKz z6r`9_xEMCeDhTs2YHT*tV`t&i5OM(8$G~7P+0n?JQw_>f1M;L%d6Q2Vsc;)Wncs3 cvok$ooSbB<2X~~# int { + printi(-100000000000); + exit(2); + fib(0, 1); + return 1; } diff --git a/src/root/builtin/types/bool/printb.rs b/src/root/builtin/types/bool/printb.rs index c195478..ccbebcc 100644 --- a/src/root/builtin/types/bool/printb.rs +++ b/src/root/builtin/types/bool/printb.rs @@ -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); diff --git a/src/root/builtin/types/int/mod.rs b/src/root/builtin/types/int/mod.rs index 5b142cb..ab0cef6 100644 --- a/src/root/builtin/types/int/mod.rs +++ b/src/root/builtin/types/int/mod.rs @@ -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; @@ -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]) } }) } diff --git a/src/root/builtin/types/int/printi.rs b/src/root/builtin/types/int/printi.rs index 45cb4fc..6c87709 100644 --- a/src/root/builtin/types/int/printi.rs +++ b/src/root/builtin/types/int/printi.rs @@ -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);