summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-02-24 19:11:46 +1100
committerkitty <nepeta@canaglie.net>2026-02-24 19:11:46 +1100
commit7f577ebad6f135e2169c25deb8f3ca7bf91a9e50 (patch)
tree01e5f91292ae23ee6ab3aded3240b57b4cdc5918
parentcb16fdb58dbe98c49831a596d332defc2740c051 (diff)
error handling?
-rw-r--r--jefs.fs9
-rw-r--r--jefs.s29
-rw-r--r--readme.md13
3 files changed, 44 insertions, 7 deletions
diff --git a/jefs.fs b/jefs.fs
index 9677229..e056cf7 100644
--- a/jefs.fs
+++ b/jefs.fs
@@ -165,11 +165,12 @@ variable hld
\ : .free bytes-free u. ." of " bytes-allocated u. ." bytes free (used " bytes-used (.) say ." )" cr ; \ segfaults
: >nfa ( lfa -- nfa ) 9 + ;
-: (words) ( lfa -- ) >nfa dup w@ swap 1+ 1+ swap say 2 spaces ; \ TODO works? maybe? idk
-: words latest @ begin ?dup 0<> while dup (words) @ ( todo ->NEXT ) repeat cr ;
+: >ffa ( lfa -- ffa ) 8 + ;
+: (words) ( lfa -- ) >nfa dup w@ swap 2 + swap say 2 spaces ;
+: words latest @ begin ?dup 0<> while dup (words) @ repeat cr ;
\ .free bye
-\ : t s" eue eu eo o eu" drop .s say s" eue " ;
+\ : t s" eue eu eo o eu" ; \ s" eue " [ HEREDUMP ] ;
-words
+\ words
bye
diff --git a/jefs.s b/jefs.s
index 3d9fa1c..f3900f8 100644
--- a/jefs.s
+++ b/jefs.s
@@ -6,9 +6,18 @@
mov qword [r14], %1
%endmacro
+; this feels like Too much code and probably Too slow to have for every pspop.
+; we'll see
+; clobbers r8 (which isn't actually used anywhere here)
%macro pspop 1
mov %1, qword [r14]
lea r14, [r14+8]
+ cmp r14, wstack
+ jle %%ok
+ mov qword [error], 1
+ mov r8, qword [handler]
+ call r8
+ %%ok:
%endmacro
;;; dictionary macros {{{
@@ -62,7 +71,7 @@
section .bss exec
wstack_b: resq 2047
-wstack: resq 1
+wstack: resq 2
umem: resb 0x9c400
umem_e:
@@ -174,11 +183,13 @@ defword "c,", c_comma, 0
ret
defword "cmove", _cmove, 0 ; ( a1 a2 u -- )
+ call heredump
pspop rcx
pspop rdi
pspop rsi
rep movsb
+ call heredump
ret
defword "cmove,", _cmove_comma, 0 ; ( c-addr u -- )
@@ -242,6 +253,8 @@ defword "parse", parse, 0
pspush r11 ; u
ret
+; segfault issue is in here i think?
+; on second go around only one value is returned?
defword "cparse", cparse, 0
pspop r15 ; c
mov r13, qword [to_in]
@@ -1023,6 +1036,18 @@ defword "0branch", zerobranch, 0
mov qword [here], r12
ret
+; rudimentary error handler
+; this word may be called when the stack is fucked,
+; so instead we take the error from a variable called error.
+; this word is intended to be called as an xt from the HANDLER variable,
+; so better error handling can be given from forth.
+defword "(handler)", brac_handler, 0
+ mov r11, [error]
+ mov rdi, r11
+ mov rax, __NR_exit
+ syscall
+ ret
+
; TEMPORARY HORRIBLE DEBUGGING BULLSHIT {{{
; debugging word; outputs raw bytes so needs to be piped through `x(x)d`
; terrible and awful
@@ -1100,6 +1125,8 @@ defvar "s0", s0, 0, wstack
defvar "h0", h0, 0, umem ; beginning of user memory area
defvar "hend", hend, 0, umem_e ; ending of user memory area
defvar "base", base, 0, 10
+defvar "error", error, 0, 0
+defvar "handler", handler, 0, brac_handler
defvar "latest", latest, 0, lfa_latest
initfile:
diff --git a/readme.md b/readme.md
index 7f34a62..e7c84be 100644
--- a/readme.md
+++ b/readme.md
@@ -69,8 +69,17 @@ maybe this sucks shit but my idea is that i compile in a relative jmp with
### PNO
'pictured numeric output'. its forth's numeric output functionality.
-this is me trying to describe it so i can figure it out and implement it.
note that this forth doesn't have double numbers
(i don't think it's necessary, since cells are 64 bit)
so PNO works on single cell values.
-PNO is started by `<#` and ended by `#>`.
+
+### error codes
+in order to have Good Error Handling anywhere, the error handler's xt
+is stored in the `handler` variable and is then called by loading its value
+and `execute`ing it. the actual description of the error comes from the
+`error` variable (in case the stack is fucked)
+
+the error codes are:
+
+- 0: nothing.
+- 1: stack underflow