forth: [, ], STATE, EVALUATE (+5; Hayes 463→477, 74%)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 01:23:23 +00:00
parent 89a879799a
commit b1a7852045
5 changed files with 81 additions and 15 deletions

View File

@@ -649,10 +649,13 @@
(s)
(let
((addr (forth-pop s)))
(if
(string? addr)
(forth-push s (or (get (get s "vars") addr) 0))
(forth-push s (forth-mem-read s addr))))))
(cond
((= addr "@@state")
(forth-push s (if (get s "compiling") -1 0)))
((= addr "@@in") (forth-push s 0))
((string? addr)
(forth-push s (or (get (get s "vars") addr) 0)))
(else (forth-push s (forth-mem-read s addr)))))))
(forth-def-prim!
state
"!"
@@ -788,6 +791,31 @@
(let
((w (forth-pop s)))
(forth-push s (or (get w "body-addr") 0)))))
(forth-def-prim-imm!
state
"["
(fn (s) (dict-set! s "compiling" false)))
(forth-def-prim! state "]" (fn (s) (dict-set! s "compiling" true)))
(forth-def-prim! state "STATE" (fn (s) (forth-push s "@@state")))
(forth-def-prim!
state
"EVALUATE"
(fn
(s)
(let
((u (forth-pop s)) (addr (forth-pop s)))
(let
((src (forth-mem-read-string s addr u)))
(let
((saved-input (get s "input")))
(dict-set! s "input" (forth-tokens src))
(forth-interpret-loop s)
(dict-set! s "input" saved-input))))))
(forth-def-prim!
state
"SOURCE"
(fn (s) (forth-push s 0) (forth-push s 0)))
(forth-def-prim! state ">IN" (fn (s) (forth-push s "@@in")))
(forth-def-prim!
state
"WORD"