return NEXT
end)
-ROT = defPrimWord("ROT", () -> begin
+NROT = defPrimWord("-ROT", () -> begin
a = popPS()
b = popPS()
c = popPS()
+ pushPS(b)
pushPS(a)
pushPS(c)
- pushPS(b)
return NEXT
end)
-NROT = defPrimWord("-ROT", () -> begin
+ROT = defPrimWord("ROT", () -> begin
a = popPS()
b = popPS()
c = popPS()
- pushPS(b)
pushPS(a)
pushPS(c)
+ pushPS(b)
return NEXT
end)
+
TWODROP = defPrimWord("2DROP", () -> begin
popPS()
popPS()
end
Base.showerror(io::IO, ex::ParseError) = print(io, "Parse error at word: '$(ex.wordName)'.")
+DEBUG, DEBUG_CFA = defNewVar("DEBUG", 0)
+
INTERPRET = defPrimWord("INTERPRET", () -> begin
callPrim(mem[WORD])
wordName = getString(mem[reg.PSP-1], mem[reg.PSP])
- #println("... ", replace(replace(wordName, "\004", "EOF"), "\n", "\\n"), " ...")
+ if mem[DEBUG] != 0
+ println("... ", replace(replace(wordName, "\004", "EOF"), "\n", "\\n"), " ...")
+ end
callPrim(mem[TWODUP])
callPrim(mem[FIND])
jmp = NEXT
while jmp != 0
try
- #println("Evaluating prim ", jmp," ", primNames[-jmp])
+ if mem[DEBUG] != 0
+ println("Evaluating prim ", jmp," ", primNames[-jmp])
+ end
+
jmp = callPrim(jmp)
catch ex
, \ compile it
;
+: DEBUGON TRUE DEBUG ! ;
+: DEBUGOFF FALSE DEBUG ! ;
+
\ CONTROL STRUCTURES ----------------------------------------------------------------------
: IF IMMEDIATE
: DO IMMEDIATE
' >R , ' >R ,
+ ' LIT , HERE @ 0 , ' >R ,
HERE @
;
-: I RSP@ 2- @ ;
+: I RSP@ 3 - @ ;
-: LOOP+ IMMEDIATE
- ' R> , ' R> , ' -ROT , ' + , ' 2DUP , ' - ,
- ' SWAP , ' >R , ' SWAP , ' >R ,
- ' 0<= , ' 0BRANCH ,
- HERE @ - ,
- ' RDROP , ' RDROP ,
+: LEAVE IMMEDIATE
+ ' R> , ' RDROP , ' RDROP ,
+ ' LIT , HERE @ 7 + , ' DUP , ' ROT , ' - , ' SWAP , ' ! ,
+ ' BRANCH ,
+ 0 ,
;
: LOOP IMMEDIATE
- ' LIT , 1 ,
- [COMPILE] LOOP+
+ ' R> , ' R> , ' R> , ' 1+ , ' 2DUP , ' - ,
+ ' SWAP , ' >R , ' SWAP , ' >R , ' SWAP , ' >R ,
+ ' 0<= , ' 0BRANCH ,
+ HERE @ - ,
+ ' RDROP , ' RDROP , ' RDROP ,
+ HERE @ SWAP !
;
+: lt 10 0 do leave loop ;
+
\ COMMENTS ----------------------------------------------------------------------