The Lambda Lab
/
projects
/
forth.jl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Doing my head in!
[forth.jl.git]
/
src
/
forth.jl
diff --git
a/src/forth.jl
b/src/forth.jl
index
c6b8cba
..
aac4c2a
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-25,7
+25,7
@@
STATE = 0
BASE = 10
BASE = 10
-# Stack manipulation
macro
s
+# Stack manipulation
function
s
function pushRS(val::Int64)
global RSP
function pushRS(val::Int64)
global RSP
@@
-51,7
+51,7
@@
function popPS()
return val
end
return val
end
-# Primitive creation functions
+# Primitive creation
and calling
functions
function defPrim(name::AbstractString, expr::Expr)
global HERE, LATEST
function defPrim(name::AbstractString, expr::Expr)
global HERE, LATEST
@@
-80,6
+80,8
@@
defConst(name::AbstractString, val::Int64) = defPrim(name, quote
jmp = Next
end)
jmp = Next
end)
+callPrim(addr::Int64) = eval(primitives[-addr])
+
# Threading Primitives
NEXT = defPrim("NEXT", quote
# Threading Primitives
NEXT = defPrim("NEXT", quote
@@
-207,14
+209,30
@@
end)
# I/O
KEY = defPrim("KEY", quote
# I/O
KEY = defPrim("KEY", quote
+
+ jmp = NEXT
+end)
+
+EMIT = defPrim("EMIT", quote
+
+ jmp = NEXT
+end)
+
+WORD = defPrim("WORD", quote
+
+ jmp = NEXT
+end)
+
+NUMBER = defPrim("NUMBER", quote
+
jmp = NEXT
end)
jmp = NEXT
end)
-#
VM loop
+#
### VM loop ####
jmp = NEXT
function runVM()
while true
jmp = NEXT
function runVM()
while true
-
eval(primitives[-jmp]
)
+
callPrim(jmp
)
end
end
end
end