# Stack manipulation functions
-type StackUnderflow <: Exception end
+type ParamStackUnderflow <: Exception end
+type ReturnStackUnderflow <: Exception end
+
+Base.showerror(io::IO, ex::ParamStackUnderflow) = print(io, "Parameter stack underflow.")
+Base.showerror(io::IO, ex::ReturnStackUnderflow) = print(io, "Return stack underflow.")
getRSDepth() = reg.RSP - mem[RSP0]
getPSDepth() = reg.PSP - mem[PSP0]
function ensurePSDepth(depth::Int64)
if getPSDepth()<depth
- throw(StackUnderflow())
+ throw(ParamStackUnderflow())
end
end
function ensureRSDepth(depth::Int64)
if getRSDepth()<depth
- throw(StackUnderflow())
+ throw(ReturnStackUnderflow())
end
end
return 0
end)
+PROMPT = defPrimWord("PROMPT", () -> begin
+ println(" ok")
+end)
+
NL = defPrimWord("\n", () -> begin
if mem[STATE] == 0 && currentSource() == STDIN
- println(" ok")
+ callPrim(mem[PROMPT])
end
return NEXT
end, flags=F_IMMED)
pop!(sources)
if length(sources)>0
+ if currentSource() == STDIN
+ callPrim(mem[PROMPT])
+ end
+
return NEXT
else
return 0
jmp = callPrim(jmp)
catch ex
- if isa(ex, StackUnderflow)
- println("Stack underflow!")
+ showerror(STDOUT, ex)
+ println()
- mem[NUMTIB] = 0
- reg.IP = QUIT + 1
- jmp = NEXT
- else
- rethrow(ex)
- end
+ mem[NUMTIB] = 0
+ reg.IP = QUIT + 1
+ jmp = NEXT
end
end
end
end
end
-DOT = defPrimWord(".", () -> begin
- print(popPS())
- return NEXT
-end)
-
-#DOTS = defPrimWord(".s", () -> begin
-# printPS()
-# return NEXT
-#end)
-
DUMP = defPrimWord("DUMP", () -> begin
count = popPS()
addr = popPS()