New interpreter working.
authorTim Vaughan <tgvaughan@gmail.com>
Sat, 7 May 2016 02:05:41 +0000 (14:05 +1200)
committerTim Vaughan <tgvaughan@gmail.com>
Sat, 7 May 2016 02:05:41 +0000 (14:05 +1200)
src/forth.jl

index 7c0fea8..1679115 100644 (file)
@@ -805,13 +805,13 @@ INTERPRET = defWord("INTERPRET",
             NUMBER, BTICK, LIT, COMMA, BRANCH, -39,
         
        # Interpreting
             NUMBER, BTICK, LIT, COMMA, BRANCH, -39,
         
        # Interpreting
-        DUP, FIND, ZBRANCH, 5,
+        DUP, FIND, QDUP, ZBRANCH, 7,
 
             # Found word. Execute!
 
             # Found word. Execute!
-            TOCFA, EXECUTE, BRANCH, -47,
+            SWAP, DROP, TOCFA, EXECUTE, BRANCH, -50,
 
             # No word found, parse number and leave on stack
 
             # No word found, parse number and leave on stack
-            NUMBER, BRANCH, -50,
+            NUMBER, BRANCH, -53,
     EXIT]
 )
 
     EXIT]
 )
 
@@ -830,6 +830,7 @@ QUIT = defWord("QUIT",
     BRANCH,-4])
 
 BYE = defPrimWord("BYE", () -> begin
     BRANCH,-4])
 
 BYE = defPrimWord("BYE", () -> begin
+    println("Bye!")
     return 0
 end)
 
     return 0
 end)
 
@@ -938,25 +939,25 @@ function run(;initialize=false)
     # Everyting else is simply a consequence of this loop!
     jmp = NEXT
     while jmp != 0
     # Everyting else is simply a consequence of this loop!
     jmp = NEXT
     while jmp != 0
-#        try
-            println("Entering prim $(getPrimName(jmp))")
+        try
+            #println("Entering prim $(getPrimName(jmp))")
             jmp = callPrim(jmp)
 
             jmp = callPrim(jmp)
 
-#        catch ex
-#            showerror(STDOUT, ex)
-#            println()
-#
-#            while !isempty(sources) && currentSource() != STDIN
-#                close(pop!(sources))
-#            end
-#
-#            mem[STATE] = 0
-#            mem[NUMTIB] = 0
-#            reg.PSP = mem[PSP0]
-#            reg.RSP = mem[RSP0]
-#            reg.IP = QUIT + 1
-#            jmp = NEXT
-#        end
+        catch ex
+            showerror(STDOUT, ex)
+            println()
+
+            while !isempty(sources) && currentSource() != STDIN
+                close(pop!(sources))
+            end
+
+            mem[STATE] = 0
+            mem[NUMTIB] = 0
+            reg.PSP = mem[PSP0]
+            reg.RSP = mem[RSP0]
+            reg.IP = QUIT + 1
+            jmp = NEXT
+        end
     end
 end
 
     end
 end