X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Fforth.jl;h=3e043f8b0eabab2a45d234d3c8151d4a09e02d60;hb=43cd7e6d8968a85ee9250033080268caafef5a47;hp=4c81dc35b59f305078a7a2a08f4e95927b640b8b;hpb=2de79279a0f7157a41c0f32674ba96f56cb1b02f;p=forth.jl.git diff --git a/src/forth.jl b/src/forth.jl index 4c81dc3..3e043f8 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -1,6 +1,6 @@ module forth -import Base.REPLCompletions, Base.invokelatest +import REPL.REPLCompletions, Base.invokelatest # VM mem size size_mem = 1000000 # 1 mega-int @@ -34,7 +34,7 @@ mem[CURRENT] = FORTH_LATEST-1 # Compile words to system dict initially DICT = mem[H] # Save bottom of dictionary as constant # VM registers -type Reg +mutable struct Reg RSP::Int64 # Return stack pointer PSP::Int64 # Parameter/data stack pointer IP::Int64 # Instruction pointer @@ -114,7 +114,7 @@ stringAsInts(str::AbstractString) = [Int(c) for c in collect(str)] function defPrim(f::Function; name="nameless") push!(primitives, f) - push!(primNames, replace(name, "\004", "EOF")) + push!(primNames, replace(name, "\004" => "EOF")) return -length(primitives) end @@ -677,6 +677,10 @@ READ_LINE_CFA = defPrimWord("READ-LINE", () -> begin maxSize = popPS() addr = popPS() + if !(fid in keys(openFiles)) + error(string("Invalid FID ", fid, ".")) + end + fh = openFiles[fid] line = readline(fh, chomp=false) @@ -718,7 +722,7 @@ EMIT_CFA = defPrimWord("EMIT", () -> begin end) function raw_mode!(mode::Bool) - if ccall(:jl_tty_set_mode, Int32, (Ptr{Void}, Int32), STDIN.handle, mode) != 0 + if ccall(:jl_tty_set_mode, Int32, (Ptr{Nothing}, Int32), STDIN.handle, mode) != 0 throw("FATAL: Terminal unable to enter raw mode.") end end @@ -1336,7 +1340,8 @@ function run(fileName=nothing; initialize=true) jmp = callPrim(jmp) catch ex - showerror(STDOUT, ex) + println(string("Error in primitive '", getPrimName(jmp), "' at address ", jmp)) + showerror(stdout, ex) println() # QUIT