summaryrefslogtreecommitdiff
path: root/sanctuary.s
diff options
context:
space:
mode:
Diffstat (limited to 'sanctuary.s')
-rw-r--r--sanctuary.s43
1 files changed, 40 insertions, 3 deletions
diff --git a/sanctuary.s b/sanctuary.s
index 0d35337..53749cc 100644
--- a/sanctuary.s
+++ b/sanctuary.s
@@ -1,15 +1,26 @@
; sanctuary
; macros {{{
-; TODO: error handling (once i add that)
+; the error handling feels slow but i dont know a better way
+; todo at some point make these use actual error codes
%macro pspush 1
lea r15, [r15-8]
mov qword [r15], %1
+
+ cmp r15, wstk_b
+ jge %%ok
+ call abort
+ %%ok:
%endmacro
%macro pspop 1
mov %1, qword [r15]
lea r15, [r15+8]
+
+ cmp r15, wstk
+ jle %%ok
+ call abort
+ %%ok:
%endmacro
%define s_latest 0
@@ -58,8 +69,8 @@
%assign init_brk 0x9c400
section .bss
-resq 4091
-wstk: resq 1
+wstk_b: resq 4091
+wstk: resq 1
section .text
global _start
@@ -502,6 +513,16 @@ defcode "char", char, 0
pspush r11
ret
+defcode "(execute)", do_execute, 0
+ pspop r11
+ call r11
+ ret
+
+defcode "execute", execute, 0
+ call to_body
+ call do_execute
+ ret
+
; number {{{
defcode "number", number, 0 ; ( c-addr u -- ?n flag )
pspop r11 ; u
@@ -965,6 +986,21 @@ defcode "?branch", q_branch, 0
mov qword [here], r12
ret
+; error handling {{{
+; default error handler, because we don't have QUIT yet
+; it just Exits with exit code 1
+defcode "(0handler)", do_0handler, 0
+ mov rdi, 1
+ mov rax, __NR_exit
+ syscall
+ ret
+
+defcode "abort", abort, 0
+ mov r11, qword [handler]
+ call r11
+ ret
+; }}}
+
; TEMPORARY WONKY DEBUGGING FUNCTIONS {{{
; .s {{{
defcode ".s", dots, 0
@@ -1024,6 +1060,7 @@ defvar "dp$", dp$, 0, 0
defvar "tib", tib, 0, initfile
defvar "#tib", n_tib, 0, initlen
defvar ">in", to_in, 0, 0
+defvar "handler", handler, 0, do_0handler
defvar "latest", latest, 0, lfa_latest
initfile: incbin "sanctuary.fs"