From: Tim Vaughan Date: Sat, 16 Apr 2016 02:02:49 +0000 (+1200) Subject: Getting messy. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=forth.jl.git;a=commitdiff_plain;h=1d001ad64380f6812e7cdbf542d2e04e99db1e74 Getting messy. --- diff --git a/src/forth.jl b/src/forth.jl index 5bcd583..39d5e69 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -23,6 +23,8 @@ latest = 0 # no previous definition # The following array constitutes the memory of the VM. It has the following geography: # # memory = +-----------------------+ +# | System Variables | +# +-----------------------+ # | Return Stack | # +-----------------------+ # | Parameter Stack | @@ -43,6 +45,7 @@ memory = Array{Int64,1}(size_memory) primitives = Array{Function,1}() + # Stack manipulation functions function pushRS(val::Int64) @@ -90,7 +93,7 @@ end callPrim(addr::Int64) = primitives[-addr]() -function defVar(name::AbstractString, val::Int64) +function defSysVar(name::AbstractString, varAddr::Int64) global latest, here memory[here] = latest @@ -100,14 +103,18 @@ function defVar(name::AbstractString, val::Int64) 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 @@ -184,10 +191,6 @@ end) # Built-in variables -defVar("STATE", :state) -defVar("HERE", :here) -defVar("LATEST", :latest) -defVar("BASE", :base) # Constants