forth: add "VARIABLE"

This commit is contained in:
Virgil Dupras 2020-03-07 22:23:08 -05:00
parent 989d8bbabf
commit 5cadde557c
2 changed files with 14 additions and 2 deletions

View File

@ -430,11 +430,22 @@ ALLOT:
.dw STOREINC+CODELINK_OFFSET
.dw EXIT+CODELINK_OFFSET
; CREATE 2 ALLOT
VARIABLE:
.db "VARIABLE"
.dw ALLOT
.dw compiledWord
.dw CREATE+CODELINK_OFFSET
.dw NUMBER
.dw 2
.dw ALLOT+CODELINK_OFFSET
.dw EXIT+CODELINK_OFFSET
; ( n -- )
; CREATE HERE @ ! DOES> @
CONSTANT:
.db "CONSTANT"
.dw ALLOT
.dw VARIABLE
.dw compiledWord
.dw CREATE+CODELINK_OFFSET
.dw HERE_+CODELINK_OFFSET

View File

@ -25,7 +25,7 @@ DOES>: Used inside a colon definition that itself uses CREATE, DOES> transforms
- a b -- c a - b -> c
* a b -- c a * b -> c
/ a b -- c a / b -> c
CREATE x -- Create cell named x
CREATE x -- Create cell named x. Doesn't allocate a PF.
DOES> -- See description at top of file
DUP a -- a a
EMIT c -- Spit char c to stdout
@ -45,3 +45,4 @@ SWAP a b -- b a
+! n a -- Increase value of addr a by n
ALLOT n -- Move HERE by n bytes
CONSTANT x n -- Creates cell x that when called pushes its value
VARIABLE c -- Creates cell x with 2 bytes allocation.