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