From a3c68860a7e1223f40203960e38b16939f39e021 Mon Sep 17 00:00:00 2001 From: IgorCielniak Date: Thu, 12 Feb 2026 17:39:05 +0100 Subject: [PATCH] added get_addr and jmp --- stdlib/core.sl | 14 ++++++++++++++ tests/jmp_test.expected | 5 +++++ tests/jmp_test.sl | 18 ++++++++++++++++++ tests/jmp_test.test | 1 + 4 files changed, 38 insertions(+) create mode 100644 tests/jmp_test.expected create mode 100644 tests/jmp_test.sl create mode 100644 tests/jmp_test.test diff --git a/stdlib/core.sl b/stdlib/core.sl index 9728df0..6f8f8ca 100644 --- a/stdlib/core.sl +++ b/stdlib/core.sl @@ -1,3 +1,17 @@ +#get_addr [*] -> [* | addr] +:asm get_addr { + mov rax, [rsp] + sub r12, 8 + mov [r12], rax +}; + +#jmp [* | addr] -> [*] +:asm jmp { + mov rax, [r12] + add r12, 8 + jmp rax +}; + # Reserve 64 bytes in .bss # persistent: resb 64 # push the addr of it diff --git a/tests/jmp_test.expected b/tests/jmp_test.expected new file mode 100644 index 0000000..751e999 --- /dev/null +++ b/tests/jmp_test.expected @@ -0,0 +1,5 @@ +gg +gg +gg +gg +gg diff --git a/tests/jmp_test.sl b/tests/jmp_test.sl new file mode 100644 index 0000000..b50bad2 --- /dev/null +++ b/tests/jmp_test.sl @@ -0,0 +1,18 @@ +import stdlib.sl + +word main + 5 # loop count + get_addr # push loop target address (next instruction) + "gg" puts + + swap # bring count to top + 1 - # decrement + dup 0 > if + swap # put addr on top + dup # keep a copy for next iteration + jmp + else + drop # drop count + drop # drop addr + end +end \ No newline at end of file diff --git a/tests/jmp_test.test b/tests/jmp_test.test new file mode 100644 index 0000000..e6d145e --- /dev/null +++ b/tests/jmp_test.test @@ -0,0 +1 @@ +python main.py tests/jmp_test.sl -o ./build/jmp_test > /dev/null && ./build/jmp_test \ No newline at end of file