forth: IF/ELSE/THEN + PC-driven body runner (+18)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 17:03:41 +00:00
parent 30d76537d1
commit b2939c1922
4 changed files with 238 additions and 3 deletions

View File

@@ -20,8 +20,27 @@
(dict-set! s "current-def" nil)
(dict-set! s "base" 10)
(dict-set! s "vars" (dict))
(dict-set! s "cstack" (list))
s)))
(define
forth-cpush
(fn (state v) (dict-set! state "cstack" (cons v (get state "cstack")))))
(define
forth-cpop
(fn
(state)
(let
((cs (get state "cstack")))
(if
(= (len cs) 0)
(forth-error state "control stack underflow")
(let
((top (first cs)))
(dict-set! state "cstack" (rest cs))
top)))))
(define
forth-error
(fn (state msg) (dict-set! state "error" msg) (raise msg)))
@@ -416,7 +435,7 @@
(forth-def-prim!
state
"EMIT"
(fn (s) (forth-emit-str s (code-char (forth-pop s)))))
(fn (s) (forth-emit-str s (char-from-code (forth-pop s)))))
(forth-def-prim! state "CR" (fn (s) (forth-emit-str s "\n")))
(forth-def-prim! state "SPACE" (fn (s) (forth-emit-str s " ")))
(forth-def-prim!