The Lambda Lab
/
projects
/
forth.jl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Working on vocabularies.
[forth.jl.git]
/
src
/
forth.jl
diff --git
a/src/forth.jl
b/src/forth.jl
index
9439dea
..
89c4c0d
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-16,13
+16,13
@@
primNames = Array{ASCIIString,1}()
# Built-in variables
nextVarAddr = 1
# Built-in variables
nextVarAddr = 1
-H = nextVarAddr; nextVarAddr += 1
-LATEST = nextVarAddr; nextVarAddr += 1
+H = nextVarAddr; nextVarAddr += 1
# Next free memory address
+LATEST = nextVarAddr; nextVarAddr += 1
# LFA of latest word in systetm dict
RSP0 = nextVarAddr # bottom of RS
PSP0 = RSP0 + size_RS # bottom of PS
TIB = PSP0 + size_PS # address of terminal input buffer
RSP0 = nextVarAddr # bottom of RS
PSP0 = RSP0 + size_RS # bottom of PS
TIB = PSP0 + size_PS # address of terminal input buffer
-mem[H] = TIB + size_TIB # location of bottom of dictionary
+mem[H] = TIB + size_TIB
# location of bottom of dictionary
mem[LATEST] = 0 # no previous definition
DICT = mem[H] # Save bottom of dictionary as constant
mem[LATEST] = 0 # no previous definition
DICT = mem[H] # Save bottom of dictionary as constant
@@
-151,18
+151,21
@@
function defExistingVar(name::AbstractString, varAddr::Int64; flags::Int64=0)
end)))
end
end)))
end
-function defNewVar(name::AbstractString, initial::
Int64
; flags::Int64=0)
+function defNewVar(name::AbstractString, initial::
Array{Int64,1}
; flags::Int64=0)
createHeader(name, flags)
codeWordAddr = mem[H]
varAddr = mem[H] + 1
mem[mem[H]] = DOVAR; mem[H] += 1
createHeader(name, flags)
codeWordAddr = mem[H]
varAddr = mem[H] + 1
mem[mem[H]] = DOVAR; mem[H] += 1
- mem[mem[H]
] = initial; mem[H] += 1
+ mem[mem[H]
:(mem[H]+length(initial)-1)] = initial; mem[H] += length(initial)
return varAddr, codeWordAddr
end
return varAddr, codeWordAddr
end
+defNewVar(name::AbstractString, initial::Int64; flags::Int64=0) =
+ defNewVar(name, [initial]; flags=flags)
+
function defConst(name::AbstractString, val::Int64; flags::Int64=0)
createHeader(name, flags)
function defConst(name::AbstractString, val::Int64; flags::Int64=0)
createHeader(name, flags)
@@
-994,7
+997,14
@@
INCLUDE_CFA = defPrimWord("INCLUDE", () -> begin
wordLen = mem[wordAddr-1]
word = getString(wordAddr, wordLen)
wordLen = mem[wordAddr-1]
word = getString(wordAddr, wordLen)
- push!(sources, open(word, "r"))
+ fname = word
+ if !isfile(fname)
+ fname = Pkg.dir("forth","src",word)
+ if !isfile(fname)
+ error("No file named $word found in current directory or package source directory.")
+ end
+ end
+ push!(sources, open(fname, "r"))
# Clear input buffer
mem[NUMTIB] = 0
# Clear input buffer
mem[NUMTIB] = 0
@@
-1009,8
+1019,8
@@
initialized = false
initFileName = nothing
if isfile("lib.4th")
initFileName = "lib.4th"
initFileName = nothing
if isfile("lib.4th")
initFileName = "lib.4th"
-elseif isfile(Pkg.dir("forth
/src/
lib.4th"))
- initFileName = Pkg.dir("forth
/src/
lib.4th")
+elseif isfile(Pkg.dir("forth
","src", "
lib.4th"))
+ initFileName = Pkg.dir("forth
","src","
lib.4th")
end
function run(;initialize=true)
end
function run(;initialize=true)