forth: BEGIN/UNTIL/WHILE/REPEAT/AGAIN (+9)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 17:33:25 +00:00
parent b2939c1922
commit bb16477fd4
3 changed files with 127 additions and 1 deletions

View File

@@ -219,6 +219,72 @@
(let
((target (forth-cpop s)))
(dict-set! target "v" (forth-def-length s)))))
(forth-def-prim-imm!
state
"BEGIN"
(fn
(s)
(when
(not (get s "compiling"))
(forth-error s "BEGIN outside definition"))
(forth-cpush s (forth-def-length s))))
(forth-def-prim-imm!
state
"UNTIL"
(fn
(s)
(when
(not (get s "compiling"))
(forth-error s "UNTIL outside definition"))
(let
((back-pc (forth-cpop s)))
(let
((target (forth-make-target)))
(dict-set! target "v" back-pc)
(forth-def-append! s (forth-make-branch "bif" target))))))
(forth-def-prim-imm!
state
"AGAIN"
(fn
(s)
(when
(not (get s "compiling"))
(forth-error s "AGAIN outside definition"))
(let
((back-pc (forth-cpop s)))
(let
((target (forth-make-target)))
(dict-set! target "v" back-pc)
(forth-def-append! s (forth-make-branch "branch" target))))))
(forth-def-prim-imm!
state
"WHILE"
(fn
(s)
(when
(not (get s "compiling"))
(forth-error s "WHILE outside definition"))
(let
((target (forth-make-target)))
(forth-def-append! s (forth-make-branch "bif" target))
(forth-cpush s target))))
(forth-def-prim-imm!
state
"REPEAT"
(fn
(s)
(when
(not (get s "compiling"))
(forth-error s "REPEAT outside definition"))
(let
((while-target (forth-cpop s)))
(let
((back-pc (forth-cpop s)))
(let
((b-target (forth-make-target)))
(dict-set! b-target "v" back-pc)
(forth-def-append! s (forth-make-branch "branch" b-target))
(dict-set! while-target "v" (forth-def-length s)))))))
(forth-def-prim!
state
"VARIABLE"