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)'.")
+
INTERPRET = defPrimWord("INTERPRET", () -> begin
callPrim(mem[WORD])
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
showerror(STDOUT, ex)
println()
+ while !isempty(sources) && currentSource() != STDIN
+ close(pop!(sources))
+ end
+
+ mem[STATE] = 0
mem[NUMTIB] = 0
reg.IP = QUIT + 1
jmp = NEXT
: MOD /MOD DROP ;
: */ * / ;
-: '\n' 10 ;
-: BL 32 ;
-
-: CR '\n' emit ;
-: SPACE BL emit ;
-
-: NEGATE 0 swap - ;
+: NEGATE 0 SWAP - ;
: TRUE -1 ;
: FALSE 0 ;
: DEPTH PSP@ PSP0 @ - ;
+: '\n' 10 ;
+: BL 32 ;
+
: LITERAL IMMEDIATE ' LIT , , ;
: ':' [ CHAR : ] LITERAL ;
: '-' [ CHAR - ] LITERAL ;
: '.' [ CHAR . ] LITERAL ;
+: CR '\n' emit ;
+: SPACE BL emit ;
+
: [COMPILE] IMMEDIATE
WORD \ get the next word
FIND \ find it in the dictionary
: HEX ( -- ) 16 BASE ! ;
( Compute absolute value. )
-: ABS ( n -- m)
+: ABS ( n -- |n| )
dup 0< if
negate
then
;
+: MAX ( n m -- max )
+ 2dup - 0< if
+ swap drop
+ else
+ drop
+ then
+;
+
+: MIN ( n m -- max )
+ 2dup - 0> if
+ swap drop
+ else
+ drop
+ then
+;
+
( PRINTING NUMBERS ---------------------------------------------------------------------- )
( This is the underlying recursive definition of U. )