From cca6fc55d62876b3fb0ff417c94f1ee8d2b054a8 Mon Sep 17 00:00:00 2001 From: nub31 Date: Mon, 5 May 2025 16:36:24 +0200 Subject: [PATCH] cleanup --- build.sh | 10 +++------- example/{core/c.nub => c/bindings.nub} | 0 example/core/string.nub | 2 -- example/program.nub | 2 +- std/baseline/runtime.asm | 10 ---------- std/core/itoa.asm | 23 ----------------------- std/core/str_len.asm | 13 ------------- std/{baseline => }/gc.c | 0 std/{baseline/str_cmp.asm => runtime.asm} | 15 +++++++++++++-- 9 files changed, 17 insertions(+), 58 deletions(-) rename example/{core/c.nub => c/bindings.nub} (100%) delete mode 100644 example/core/string.nub delete mode 100644 std/baseline/runtime.asm delete mode 100644 std/core/itoa.asm delete mode 100644 std/core/str_len.asm rename std/{baseline => }/gc.c (100%) rename std/{baseline/str_cmp.asm => runtime.asm} (53%) diff --git a/build.sh b/build.sh index 6396cc8..a96bd06 100755 --- a/build.sh +++ b/build.sh @@ -3,14 +3,10 @@ mkdir -p out dotnet run --project lang/Nub.Lang example out/out.qbe -gcc -c -g -fno-stack-protector -fno-builtin std/baseline/gc.c -o out/gc.o -nasm -g -felf64 std/baseline/str_cmp.asm -o out/str_cmp.o -nasm -g -felf64 std/baseline/runtime.asm -o out/runtime.o - -nasm -g -felf64 std/core/str_len.asm -o out/str_len.o -nasm -g -felf64 std/core/itoa.asm -o out/itoa.o +gcc -c -g -fno-stack-protector -fno-builtin std/gc.c -o out/gc.o +nasm -g -felf64 std/runtime.asm -o out/runtime.o qbe out/out.qbe > out/out.s gcc -c -g out/out.s -o out/out.o -gcc -no-pie -nostartfiles -o out/program out/gc.o out/str_cmp.o out/str_len.o out/itoa.o out/runtime.o out/out.o +gcc -no-pie -nostartfiles -o out/program out/gc.o out/runtime.o out/out.o diff --git a/example/core/c.nub b/example/c/bindings.nub similarity index 100% rename from example/core/c.nub rename to example/c/bindings.nub diff --git a/example/core/string.nub b/example/core/string.nub deleted file mode 100644 index 45b1051..0000000 --- a/example/core/string.nub +++ /dev/null @@ -1,2 +0,0 @@ -extern func str_len(msg: string): int64; -extern func itoa(value: int64): string; diff --git a/example/program.nub b/example/program.nub index 8dae7c2..5ef2046 100644 --- a/example/program.nub +++ b/example/program.nub @@ -1,4 +1,4 @@ -import "core"; +import "c"; global func main() { let x = "test"; diff --git a/std/baseline/runtime.asm b/std/baseline/runtime.asm deleted file mode 100644 index 90e0941..0000000 --- a/std/baseline/runtime.asm +++ /dev/null @@ -1,10 +0,0 @@ -global _start -extern main, gc_init - -section .text -_start: - call gc_init - call main - mov rax, 60 - mov rdi, 0 - syscall \ No newline at end of file diff --git a/std/core/itoa.asm b/std/core/itoa.asm deleted file mode 100644 index 51f0d9e..0000000 --- a/std/core/itoa.asm +++ /dev/null @@ -1,23 +0,0 @@ -section .bss - buffer resb 20 - -section .text - global itoa - -itoa: - mov rax, rdi - mov rsi, buffer + 19 - mov byte [rsi], 0 - dec rsi -.loop: - xor rdx, rdx - mov rcx, 10 - div rcx - add dl, '0' - mov [rsi], dl - dec rsi - test rax, rax - jnz .loop - inc rsi - mov rax, rsi - ret diff --git a/std/core/str_len.asm b/std/core/str_len.asm deleted file mode 100644 index ea7fc00..0000000 --- a/std/core/str_len.asm +++ /dev/null @@ -1,13 +0,0 @@ -global str_len - -section .text -str_len: - xor rax, rax -.loop: - cmp byte [rdi], 0 - jz .done - inc rax - inc rdi - jmp .loop -.done: - ret \ No newline at end of file diff --git a/std/baseline/gc.c b/std/gc.c similarity index 100% rename from std/baseline/gc.c rename to std/gc.c diff --git a/std/baseline/str_cmp.asm b/std/runtime.asm similarity index 53% rename from std/baseline/str_cmp.asm rename to std/runtime.asm index 4da1302..f4c6102 100644 --- a/std/baseline/str_cmp.asm +++ b/std/runtime.asm @@ -1,7 +1,18 @@ -global str_cmp +global _start +extern main, gc_init section .text -str_cmp: +_start: + call gc_init + call main + mov rax, 60 + mov rdi, 0 + syscall + +global base_str_cmp + +section .text +base_str_cmp: xor rdx, rdx .loop: mov al, [rsi + rdx]