# The following array constitutes the memory of the VM. It has the following geography:
#
# memory = +-----------------------+
+# | System Variables |
+# +-----------------------+
# | Return Stack |
# +-----------------------+
# | Parameter Stack |
primitives = Array{Function,1}()
+
# Stack manipulation functions
function pushRS(val::Int64)
callPrim(addr::Int64) = primitives[-addr]()
-function defVar(name::AbstractString, val::Int64)
+function defSysVar(name::AbstractString, varAddr::Int64)
global latest, here
memory[here] = latest
memory[here] = length(name); here += 1
memory[here:(here+length(name)-1)] = [Int(c) for c in name]; here += length(name)
- push!(primitives, () -> begin
-
- end)
+ push!(primitives, eval(:(() -> begin
+ pushPS($(varAddr))
+ return NEXT
+ end)))
+ memory[here] = -length(primitives)
+ here += 1
- pushPS($var)
- jmp = NEXT
+ return varAddr
end
+function defConst(name
+
# Threading Primitives
NEXT = defPrim("NEXT", () -> begin
# Built-in variables
-defVar("STATE", :state)
-defVar("HERE", :here)
-defVar("LATEST", :latest)
-defVar("BASE", :base)
# Constants