From: Tim Vaughan Date: Sun, 17 Apr 2016 11:38:18 +0000 (+1200) Subject: Added NUMBER X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=d19298c246ea568bcd40a7d72d2dfc0383a00756;p=forth.jl.git Added NUMBER --- diff --git a/src/forth.jl b/src/forth.jl index a115e48..2790f84 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -414,7 +414,7 @@ WORD = defPrim("WORD", () -> begin callPrim(KEY) c = Char(popPS()) - if c == ' ' || c == '\t' + if c == ' ' || c == '\t' || c == '\n' break end end @@ -426,12 +426,24 @@ WORD = defPrim("WORD", () -> begin return NEXT end) -# -#NUMBER = defPrim("NUMBER", (reg) -> begin -# -# return NEXT -#end) -# + +NUMBER = defPrim("NUMBER", () -> begin + + wordLen = popPS() + wordAddr = popPS() + + s = ASCIIString([Char(c) for c in mem[wordAddr:(wordAddr+wordLen-1)]]) + + try + pushPS(parse(Int64, s, mem[BASE])) + pushPS(0) + catch + pushPS(1) # Error indication + end + + return NEXT +end) + #### VM loop #### #function runVM(reg::Reg) # jmp = NEXT