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 functions
30 function pushRS(val::Int64)
42 function pushPS(val::Int64)
54 # Primitive creation and calling 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 callPrim(addr::Int64) = eval(primitives[-addr])
85 # Threading Primitives
87 NEXT = defPrim("NEXT", quote
94 DOCOL = defPrim("DOCOL", quote
100 EXIT = defPrim("EXIT", quote
106 # Basic forth primitives
108 DROP = defPrim("DROP", quote
113 SWAP = defPrim("SWAP", quote
114 PS[PSP], PS[PSP-1] = PS[PSP-1], PS[PS]
118 DUP = defPrim("DUP", quote
123 LIT = defPrim("LIT", quote
131 STORE = defPrim("!", quote
138 FETCH = defPrim("@", quote
144 ADDSTORE = defPrim("+!", quote
147 memory[addr] += toAdd
151 SUBSTORE = defPrim("-!", quote
154 memory[addr] -= toSub
161 defVar("STATE", :STATE)
162 defVar("HERE", :HERE)
163 defVar("LATEST", :LATEST)
164 defVAR("BASE", :BASE)
168 defConst("VERSION", 1)
169 defConst("DOCOL", DOCOL)
173 TOR = defPrim(">R", quote
178 FROMR = defPrim("R>", quote
182 RSPFETCH = defPrim("RSP@", quote
187 RSPSTORE = defPrim("RSP!", quote
192 RDROP = defPrim("RDROP", quote
199 PSPFETCH = defPrim("PSP@", quote
204 PSPSTORE = defPrim("PSP!", quote
211 KEY = defPrim("KEY", quote
216 EMIT = defPrim("EMIT", quote
221 WORD = defPrim("WORD", quote
226 NUMBER = defPrim("NUMBER", quote