forth: LSHIFT/RSHIFT + 32-bit arith truncation + early binding (Hayes 174→268)
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:
@@ -30,12 +30,37 @@
|
||||
(forth-compile-lit state n)
|
||||
(forth-error state (str tok " ?"))))))))
|
||||
|
||||
;; Resolve the word NOW (early binding) so that `: X X ;` compiles a call
|
||||
;; to the prior X — matching standard Forth redefinition semantics.
|
||||
;; RECURSE is the one exception: it stays late-bound against the not-yet-
|
||||
;; installed current definition.
|
||||
(define
|
||||
forth-compile-call
|
||||
(fn
|
||||
(state name)
|
||||
(let
|
||||
((op (fn (s) (let ((w (forth-lookup s name))) (if (nil? w) (forth-error s (str name " ? (compiled)")) (forth-execute-word s w))))))
|
||||
((w (forth-lookup state name)))
|
||||
(if
|
||||
(nil? w)
|
||||
(forth-error state (str name " ?"))
|
||||
(let
|
||||
((op (fn (s) (forth-execute-word s w))))
|
||||
(forth-def-append! state op))))))
|
||||
|
||||
(define
|
||||
forth-compile-recurse
|
||||
(fn
|
||||
(state name)
|
||||
(let
|
||||
((op
|
||||
(fn
|
||||
(s)
|
||||
(let
|
||||
((w (forth-lookup s name)))
|
||||
(if
|
||||
(nil? w)
|
||||
(forth-error s (str "RECURSE: " name " not yet installed"))
|
||||
(forth-execute-word s w))))))
|
||||
(forth-def-append! state op))))
|
||||
|
||||
(define
|
||||
@@ -287,7 +312,7 @@
|
||||
(forth-error s "RECURSE only in definition"))
|
||||
(let
|
||||
((name (get (get s "current-def") "name")))
|
||||
(forth-compile-call s name))))
|
||||
(forth-compile-recurse s name))))
|
||||
(forth-def-prim-imm!
|
||||
state
|
||||
"IF"
|
||||
|
||||
Reference in New Issue
Block a user