primitives = Array{Function,1}()
primNames = Array{ASCIIString,1}()
-# Built-in variables
+# Memory geography and built-in variables
nextVarAddr = 1
H = nextVarAddr; nextVarAddr += 1 # Next free memory address
mem[addr:(addr+length(str)-1)] = [Int64(c) for c in str]
end
+stringAsInts(str::ASCIIString) = [Int(c) for c in collect(str)]
+
# Primitive creation and calling functions
function defPrim(f::Function; name="nameless")
sources = Array{Any,1}()
currentSource() = sources[length(sources)]
+CLOSEFILES_CFA = defPrimWord("CLOSEFILES", () -> begin
+ while currentSource() != STDIN
+ close(pop!(sources))
+ end
+
+ return NEXT
+end)
+
EOF_CFA = defPrimWord("\x04", () -> begin
if currentSource() != STDIN
close(pop!(sources))
EXIT_CFA])
PROMPT_CFA = defPrimWord("PROMPT", () -> begin
- if (mem[STATE] == 0 && currentSource() == STDIN)
- println(" ok")
+ if currentSource() == STDIN
+ if mem[STATE] == 0
+ print(" ok")
+ end
+ println()
end
return NEXT
BRANCH_CFA,-4])
ABORT_CFA = defWord("ABORT",
- [PSP0_CFA, PSPSTORE_CFA, QUIT_CFA])
+ [CLOSEFILES_CFA, PSP0_CFA, PSPSTORE_CFA, QUIT_CFA])
BYE_CFA = defPrimWord("BYE", () -> begin
println("\nBye!")