The Lambda Lab
/
projects
/
forth.jl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8c73ef0
)
Getting messy.
author
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 16 Apr 2016 02:02:49 +0000
(14:02 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 16 Apr 2016 02:02:49 +0000
(14:02 +1200)
src/forth.jl
patch
|
blob
|
history
diff --git
a/src/forth.jl
b/src/forth.jl
index
5bcd583
..
39d5e69
100644
(file)
--- 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 = +-----------------------+
# The following array constitutes the memory of the VM. It has the following geography:
#
# memory = +-----------------------+
+# | System Variables |
+# +-----------------------+
# | Return Stack |
# +-----------------------+
# | Parameter Stack |
# | Return Stack |
# +-----------------------+
# | Parameter Stack |
@@
-43,6
+45,7
@@
memory = Array{Int64,1}(size_memory)
primitives = Array{Function,1}()
primitives = Array{Function,1}()
+
# Stack manipulation functions
function pushRS(val::Int64)
# Stack manipulation functions
function pushRS(val::Int64)
@@
-90,7
+93,7
@@
end
callPrim(addr::Int64) = primitives[-addr]()
callPrim(addr::Int64) = primitives[-addr]()
-function def
Var(name::AbstractString, val
::Int64)
+function def
SysVar(name::AbstractString, varAddr
::Int64)
global latest, here
memory[here] = latest
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)
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
end
+function defConst(name
+
# Threading Primitives
NEXT = defPrim("NEXT", () -> begin
# Threading Primitives
NEXT = defPrim("NEXT", () -> begin
@@
-184,10
+191,6
@@
end)
# Built-in variables
# Built-in variables
-defVar("STATE", :state)
-defVar("HERE", :here)
-defVar("LATEST", :latest)
-defVar("BASE", :base)
# Constants
# Constants