BASE = 10
-# Stack manipulation macros
+# Stack manipulation functions
function pushRS(val::Int64)
global RSP
return val
end
-# Primitive creation functions
+# Primitive creation and calling functions
function defPrim(name::AbstractString, expr::Expr)
global HERE, LATEST
jmp = Next
end)
+callPrim(addr::Int64) = eval(primitives[-addr])
+
# Threading Primitives
NEXT = defPrim("NEXT", 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)
-# VM loop
+#### VM loop ####
jmp = NEXT
function runVM()
while true
- eval(primitives[-jmp])
+ callPrim(jmp)
end
end