a = popPS()
b = popPS()
c = popPS()
+ pushPS(b)
pushPS(a)
pushPS(c)
- pushPS(b)
return NEXT
end)
a = popPS()
b = popPS()
c = popPS()
- pushPS(b)
pushPS(a)
pushPS(c)
+ pushPS(b)
return NEXT
end)
+
TWODROP = defPrimWord("2DROP", () -> begin
popPS()
popPS()
return mem[reg.W]
end)
+type ParseError <: Exception
+ wordName::ASCIIString
+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])
isImmediate = (mem[wordAddr+1] & F_IMMED) != 0
callPrim(mem[TOCFA])
- callPrim(mem[ROT]) # get rid of extra copy of word string details
+ callPrim(mem[NROT]) # get rid of extra copy of word string details
popPS()
popPS()
callPrim(mem[NUMBER])
if popPS() != 0
- println("Parse error at word: '$wordName'")
- return NEXT
+ throw(ParseError(wordName))
end
if mem[STATE] == 0
global initialized, initFileName
if !initialized && initialize
if initFileName != nothing
- print("Including definitions from $initFileName.")
+ print("Including definitions from $initFileName...")
push!(sources, open(initFileName, "r"))
initialized = true
else
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
showerror(STDOUT, ex)
println()
+ while !isempty(sources) && currentSource() != STDIN
+ close(pop!(sources))
+ end
+
+ mem[STATE] = 0
mem[NUMTIB] = 0
+ reg.PSP = mem[PSP0]
+ reg.RSP = mem[RSP0]
reg.IP = QUIT + 1
jmp = NEXT
end