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:
a8d6c9e
)
Getting somewhere.
author
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 9 Apr 2016 13:19:05 +0000
(
01:19
+1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 9 Apr 2016 13:19:05 +0000
(
01:19
+1200)
src/forth.jl
patch
|
blob
|
history
diff --git
a/src/forth.jl
b/src/forth.jl
index
0aa33d7
..
67dd77d
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-1,20
+1,47
@@
module forth
module forth
-RS = Array{Int64, 1}()
-DS = Array{Int64, 1}()
+RS = Array{Int, 1}()
+DS = Array{Int, 1}()
+
+IP = 0
+W = 0
+X = 0
+jmp = nothing
primitives = Array{Expr,1}()
primitives = Array{Expr,1}()
-memory = Array{Int,1}()
-headers = Array{Tuple{AbstractString, Int
},1}
+memory = Array{Int
64
,1}()
+headers = Array{Tuple{AbstractString, Int
64},1}()
function addPrim(name::AbstractString, expr::Expr)
push!(primitives, expr)
push!(memory, -length(primitives))
function addPrim(name::AbstractString, expr::Expr)
push!(primitives, expr)
push!(memory, -length(primitives))
- push!(headers, length(memory))
+ push!(headers, (name, length(memory)))
+
+ return expr
end
end
-addPrim("docol", :(begin
+NEXT = addPrim("next", :(begin
+ W = memory[IP]
+ IP += 1
+ X = memory[W]
+ jmp = primitives[-X]
+end))
+DOCOL = addPrim("docol", :(begin
+ push!(RS, IP)
+ IP = W + 1
+ jmp = NEXT
end))
end))
+EXIT = addPrim("exit", :(begin
+ IP = pop!(RS)
+ jmp = NEXT
+end))
+
+# VM loop
+#jmp = NEXT
+#while true
+# eval(jmp)
+#end
+
end
end