From 1d001ad64380f6812e7cdbf542d2e04e99db1e74 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Sat, 16 Apr 2016 14:02:49 +1200 Subject: [PATCH] Getting messy. --- src/forth.jl | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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 -- 2.20.1