The Lambda Lab
/
projects
/
forth.jl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
dc5ec6f
)
New interpreter working.
author
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 7 May 2016 02:05:41 +0000
(14:05 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 7 May 2016 02:05:41 +0000
(14:05 +1200)
src/forth.jl
patch
|
blob
|
history
diff --git
a/src/forth.jl
b/src/forth.jl
index
7c0fea8
..
1679115
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-805,13
+805,13
@@
INTERPRET = defWord("INTERPRET",
NUMBER, BTICK, LIT, COMMA, BRANCH, -39,
# Interpreting
NUMBER, BTICK, LIT, COMMA, BRANCH, -39,
# Interpreting
- DUP, FIND,
ZBRANCH, 5
,
+ DUP, FIND,
QDUP, ZBRANCH, 7
,
# Found word. Execute!
# Found word. Execute!
-
TOCFA, EXECUTE, BRANCH, -47
,
+
SWAP, DROP, TOCFA, EXECUTE, BRANCH, -50
,
# No word found, parse number and leave on stack
# No word found, parse number and leave on stack
- NUMBER, BRANCH, -5
0
,
+ NUMBER, BRANCH, -5
3
,
EXIT]
)
EXIT]
)
@@
-830,6
+830,7
@@
QUIT = defWord("QUIT",
BRANCH,-4])
BYE = defPrimWord("BYE", () -> begin
BRANCH,-4])
BYE = defPrimWord("BYE", () -> begin
+ println("Bye!")
return 0
end)
return 0
end)
@@
-938,25
+939,25
@@
function run(;initialize=false)
# Everyting else is simply a consequence of this loop!
jmp = NEXT
while jmp != 0
# Everyting else is simply a consequence of this loop!
jmp = NEXT
while jmp != 0
-
#
try
- println("Entering prim $(getPrimName(jmp))")
+ try
+
#
println("Entering prim $(getPrimName(jmp))")
jmp = callPrim(jmp)
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
+ 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
end
end
end
end