projects
/
rrq
/
jonasforth.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
24d3a49
)
Define IF and THEN
author
Jonas Hvid
<mail@johv.dk>
Tue, 10 Dec 2019 15:26:36 +0000
(16:26 +0100)
committer
Jonas Hvid
<mail@johv.dk>
Tue, 10 Dec 2019 15:26:36 +0000
(16:26 +0100)
main.asm
patch
|
blob
|
history
sys.f
patch
|
blob
|
history
diff --git
a/main.asm
b/main.asm
index e6b0ac280cfc359bbad93881900df086e3e0379e..086d1dc243dcfa4d8641d2eba627eedd804c1138 100644
(file)
--- a/
main.asm
+++ b/
main.asm
@@
-288,18
+288,19
@@
forth INTERPRET, 'INTERPRET'
;; Stack is (word length word length).
dq FIND ; Try to find word
dq DUP_
;; Stack is (word length word length).
dq FIND ; Try to find word
dq DUP_
- dq ZBRANCH, 8 * 2
0
; Check if word is found
+ dq ZBRANCH, 8 * 2
2
; Check if word is found
;; - Word is found -
;; - Word is found -
- dq STATE, GET, ZBRANCH, 8 *
9
; Check whether we are in compilation or immediate mode
+ dq STATE, GET, ZBRANCH, 8 *
11
; Check whether we are in compilation or immediate mode
;; (Word found, compilation mode)
;; (Word found, compilation mode)
- dq DUP_, IS_IMMEDIATE, NOT_, ZBRANCH, 8 *
4
; If the word is immediate, continue as we would in immediate mode
+ dq DUP_, IS_IMMEDIATE, NOT_, ZBRANCH, 8 *
6
; If the word is immediate, continue as we would in immediate mode
;; Otherwise, we want to compile this word
dq TCFA
dq COMMA
;; Otherwise, we want to compile this word
dq TCFA
dq COMMA
+ dq DROP, DROP
dq EXIT
;; (Word found, immediate mode)
dq EXIT
;; (Word found, immediate mode)
@@
-557,6
+558,11
@@
forth OUTOF_IMMEDIATE, ']'
dq LIT, 1, STATE, PUT_BYTE
dq EXIT
dq LIT, 1, STATE, PUT_BYTE
dq EXIT
+forth_asm TICK, "'"
+ lodsq
+ push rax
+ next
+
forth MAIN, 'MAIN'
dq HELLO
dq INTERPRET
forth MAIN, 'MAIN'
dq HELLO
dq INTERPRET
@@
-591,7
+597,7
@@
DOTU.printed_length dq ?
;; Reserve space for compiled words, accessed through HERE.
here dq here_top
;; Reserve space for compiled words, accessed through HERE.
here dq here_top
-here_top rq $
2
000
+here_top rq $
4
000
;; Return stack
rq $2000
;; Return stack
rq $2000
diff --git
a/sys.f
b/sys.f
index 23fed8781df27e3ee98bfff9a2bd8b12375d1968..df2d231a8266511b8dcfe5cc251f1be28bd4055f 100644
(file)
--- a/
sys.f
+++ b/
sys.f
@@
-13,3
+13,16
@@
EXIT [
: / /MOD DROP ;
: MOD /MOD SWAP DROP ;
: NEG 0 SWAP - ;
: / /MOD DROP ;
: MOD /MOD SWAP DROP ;
: NEG 0 SWAP - ;
+
+: IF IMMEDIATE
+ ' 0BRANCH ,
+ HERE @
+ 0 ,
+;
+
+: THEN IMMEDIATE
+ DUP
+ HERE @ SWAP -
+ SWAP !
+;
+