forth: BEGIN/UNTIL/WHILE/REPEAT/AGAIN (+9)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user