3 RS = Array{Int64, 1}(1024)
6 PS = Array{Int64, 1}(1024)
15 primitives = Array{Expr,1}()
16 memory = Array{Int64,1}(64*1024)
28 # Stack manipulation macros
30 function pushRS(val::Int64)
42 function pushPS(val::Int64)
54 # Primitive creation functions
56 function defPrim(name::AbstractString, expr::Expr)
63 memory[HERE] = length(name); HERE += 1
64 memory[HERE:(HERE+length(name)-1)] = [Int(c) for c in name]; HERE += length(name)
66 push!(primitives, expr)
67 memory[HERE] = -length(primitives)
70 return -length(primitives)
73 defVar(name::AbstractString, var::Symbol) = defPrim(name, quote
78 defConst(name::AbstractString, val::Int64) = defPrim(name, quote
83 # Threading Primitives
85 NEXT = defPrim("NEXT", quote
92 DOCOL = defPrim("DOCOL", quote
98 EXIT = defPrim("EXIT", quote
104 # Basic forth primitives
106 DROP = defPrim("DROP", quote
111 SWAP = defPrim("SWAP", quote
112 PS[PSP], PS[PSP-1] = PS[PSP-1], PS[PS]
116 DUP = defPrim("DUP", quote
121 LIT = defPrim("LIT", quote
129 STORE = defPrim("!", quote
136 FETCH = defPrim("@", quote
142 ADDSTORE = defPrim("+!", quote
145 memory[addr] += toAdd
149 SUBSTORE = defPrim("-!", quote
152 memory[addr] -= toSub
159 defVar("STATE", :STATE)
160 defVar("HERE", :HERE)
161 defVar("LATEST", :LATEST)
162 defVAR("BASE", :BASE)
166 defConst("VERSION", 1)
167 defConst("DOCOL", DOCOL)
171 TOR = defPrim(">R", quote
176 FROMR = defPrim("R>", quote
180 RSPFETCH = defPrim("RSP@", quote
185 RSPSTORE = defPrim("RSP!", quote
190 RDROP = defPrim("RDROP", quote
197 PSPFETCH = defPrim("PSP@", quote
202 PSPSTORE = defPrim("PSP!", quote
209 KEY = defPrim("KEY", quote
217 eval(primitives[-jmp])