wordAddr = mem[HERE]
offset = 0
+ if c == '\n'
+ # Treat newline as a special word
+
+ mem[wordAddr + offset] = Int64(c)
+ pushPS(wordAddr)
+ pushPS(1)
+ return mem[NEXT]
+ end
+
while true
mem[wordAddr + offset] = Int64(c)
offset += 1
c = Char(popPS())
if c == ' ' || c == '\t' || c == '\n'
+ # Rewind KEY
+ mem[TOIN] -= 1
break
end
end
wordLen = popPS()
wordAddr = popPS()
- word = getString(wordAddr, wordLen)
+ word = lowercase(getString(wordAddr, wordLen))
latest = LATEST
end
thisAddr = latest+2
- thisWord = getString(thisAddr, len)
+ thisWord = lowercase(getString(thisAddr, len))
- if thisWord == word
+ if lowercase(thisWord) == lowercase(word)
break
end
end
# Not in dictionary, assume number
popPS()
+
+ wordName = getString(mem[reg.PSP-1], mem[reg.PSP])
+
callPrim(mem[NUMBER])
if popPS() != 0
- println("Parse error!")
+ println("Parse error at word: '$wordName'")
return mem[NEXT]
+ else
end
if mem[STATE] == 0
INTERPRET,
BRANCH,-2])
+NL = defPrim("\n", () -> begin
+ println(" ok")
+ return mem[NEXT]
+end)
+
# Odds and Ends
CHAR = defPrim("CHAR", () -> begin
return mem[popPS()]
end)
+BYE = defPrim("BYE", () -> begin
+ return 0
+end)
+
#### VM loop ####
function runVM()
# Start with IP pointing to first instruction of outer interpreter