3 RS = Array{Int64, 1}(1024)
6 PS = Array{Int64, 1}(1024)
15 primitives = Array{Expr,1}()
16 memory = Array{Int64,1}(64*1024)
31 tib = length(memory) - tib_size
35 # Stack manipulation functions
37 function pushRS(val::Int64)
49 function pushPS(val::Int64)
61 # Primitive creation and calling functions
63 function defPrim(name::AbstractString, expr::Expr)
70 memory[HERE] = length(name); HERE += 1
71 memory[HERE:(HERE+length(name)-1)] = [Int(c) for c in name]; HERE += length(name)
73 push!(primitives, expr)
74 memory[HERE] = -length(primitives)
77 return -length(primitives)
80 defVar(name::AbstractString, var::Symbol) = defPrim(name, quote
85 defConst(name::AbstractString, val::Int64) = defPrim(name, quote
90 callPrim(addr::Int64) = eval(primitives[-addr])
92 # Threading Primitives
94 NEXT = defPrim("NEXT", quote
101 DOCOL = defPrim("DOCOL", quote
107 EXIT = defPrim("EXIT", quote
113 # Basic forth primitives
115 DROP = defPrim("DROP", quote
120 SWAP = defPrim("SWAP", quote
121 PS[PSP], PS[PSP-1] = PS[PSP-1], PS[PS]
125 DUP = defPrim("DUP", quote
130 LIT = defPrim("LIT", quote
138 STORE = defPrim("!", quote
145 FETCH = defPrim("@", quote
151 ADDSTORE = defPrim("+!", quote
154 memory[addr] += toAdd
158 SUBSTORE = defPrim("-!", quote
161 memory[addr] -= toSub
168 defVar("STATE", :state)
169 defVar("HERE", :here)
170 defVar("LATEST", :latest)
171 defVar("BASE", :base)
175 defConst("VERSION", 1)
176 defConst("DOCOL", DOCOL)
180 TOR = defPrim(">R", quote
185 FROMR = defPrim("R>", quote
189 RSPFETCH = defPrim("RSP@", quote
194 RSPSTORE = defPrim("RSP!", quote
199 RDROP = defPrim("RDROP", quote
206 PSPFETCH = defPrim("PSP@", quote
211 PSPSTORE = defPrim("PSP!", quote
219 defVar("#TIB", :numtib)
222 KEY = defPrim("KEY", quote
230 EMIT = defPrim("EMIT", quote
235 WORD = defPrim("WORD", quote
240 NUMBER = defPrim("NUMBER", quote