summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-02-09 20:02:04 +1100
committerkitty <nepeta@canaglie.net>2026-02-09 20:02:04 +1100
commitd9ee6abfe7b13c121c7745022109685efc8807d0 (patch)
tree68f4afa85b788f9cc5253baf628c31fb67a7d026
parentbe2502fee87aa67fa155beec51ec5bc1abbe7ac6 (diff)
stackwords, number in interpreter
gonna have to enter the debugging mines soon
-rw-r--r--jefs.s87
1 files changed, 81 insertions, 6 deletions
diff --git a/jefs.s b/jefs.s
index dce66a7..bc10981 100644
--- a/jefs.s
+++ b/jefs.s
@@ -119,10 +119,9 @@ defword "c!", cstore, 0
mov [r11], r12b
ret
-; stage 1 parser. very rudimentary, does not recognise numbers,
-; only recognises newlines and spaces as whitespace.
+; stage 1 parser. very rudimentary,
; since it will only parse a little bit of the init file
-; there won't be any error checking either.
+; there won't be much error checking either.
defword "parse", parse, 0
mov r13, qword [to_in]
add r13, initfile
@@ -204,23 +203,38 @@ defword "find", find, 0
; stage 1 interpreter, just reads from initfile
defword "interpret", interpret, 0
.loop:
-; todo interact with state
call parse
+ call twodup
call find
- pspop r11 ; assume it exists its fine for now
mov r12, qword [state]
cmp r12, compiling
je .compile
.interp:
+ pspop r11 ; assume it exists its fine for now
+ cmp r11, false
+ je .interp_n
+
call to_cfa
pspop r11
call r11
+ call twodrop
jmp .loop
ret ; unreachable safety RET
+.interp_n:
+ call number
+ pspop r11
+ jmp .loop
+ ret
+
.compile:
; handle immediates
+ pspop r11 ; assume it exists its fine for now
+ cmp r11, false
+ je .comp_n
+
+ call twodrop
call dup
call immediate_q
pspop r13
@@ -233,6 +247,13 @@ defword "interpret", interpret, 0
jmp .loop
ret ; unreachable safety RET
+.comp_n:
+ call number
+ pspop r11 ; assume its a valid number for now
+ call lit
+ jmp .loop
+ ret
+
defword "immediate?", immediate_q, 0 ; ( lfa -- flag )
pspop r11
add r11, 8
@@ -316,7 +337,7 @@ defword ";", semicolon, immediate_mask
mov byte [r12], r13b
mov r11, [here]
- mov byte [r11], 0xc3
+ mov byte [r11], 0xc3 ; RET
inc r11
mov qword [here], r11
mov qword [state], interpreting
@@ -385,11 +406,65 @@ defword "lit", lit, immediate_mask ; C: ( n -- ) ( -- n )
mov qword [here], r12
ret
+; these stack wrangling words are dreadfully inefficient right now
+; i will come back and make these less terrible later
defword "dup", dup, 0
mov r11, [r14]
pspush r11
ret
+defword "2dup", twodup, 0 ; ( a b -- a b a b )
+ ; todo inefficient
+ pspop r11
+ pspop r12
+
+ pspush r12
+ pspush r11
+ pspush r12
+ pspush r11
+ ret
+
+defword "swap", swap, 0
+ pspop r11
+ pspop r12
+
+ pspush r11
+ pspush r12
+ ret
+
+defword "over", over, 0
+ ; TODO inefficient (use r14 ptr arith to only push once)
+ pspop r11
+ pspop r12
+
+ pspush r11
+ pspush r12
+ pspush r11
+ ret
+
+defword "r>", from_r, 0
+ pop r11
+ pspush r11
+ ret
+
+defword ">r", to_r, 0
+ pspop r11
+ push r11
+ ret
+
+defword "drop", drop, 0
+ pspop r11
+ ret
+
+defword "2drop", twodrop, 0
+ pspop r11
+ pspop r11
+ ret
+
+defword "rdrop", rdrop, 0
+ pop r11
+ ret
+
defvar ">in", to_in, 0, 0
defvar "state", state, 0, interpreting
defvar "here", here, 0, 0