FIND working again.
authorTim Vaughan <tgvaughan@gmail.com>
Wed, 1 Jun 2016 00:33:34 +0000 (12:33 +1200)
committerTim Vaughan <tgvaughan@gmail.com>
Wed, 1 Jun 2016 00:34:09 +0000 (12:34 +1200)
src/forth.jl
src/lib.4th
src/lib_10_misc.4th [moved from src/lib_9_misc.4th with 67% similarity]
src/lib_9_vocab.4th [new file with mode: 0644]

index 57fda1b..8cc7547 100644 (file)
@@ -211,7 +211,8 @@ end)
 # Dictionary entries for core built-in variables, constants
 
 H_CFA = defExistingVar("H", H)
-#LATEST_CFA = defExistingVar("LATEST", LATEST)
+FORTH_CFA = defExistingVar("FORTH", FORTH)
+CURRENT_CFA = defExistingVar("CURRENT", CURRENT)
 
 PSP0_CFA = defConst("PSP0", PSP0)
 RSP0_CFA = defConst("RSP0", RSP0)
@@ -708,7 +709,6 @@ end)
 
 TOBODY_CFA = defWord(">BODY", [INCR_CFA, EXIT_CFA])
 
-FORTH_CFA = defExistingVar("FORTH", FORTH)
 CONTEXT, CONTEXT_CFA = defNewVar("CONTEXT", zeros(Int64, 100))
 mem[CONTEXT] = FORTH_CFA
 NUMCONTEXT, NUMCONTEXT_CFA = defNewVar("#CONTEXT", 1)
@@ -720,7 +720,7 @@ FIND_CFA = defPrimWord("FIND", () -> begin
     wordLen = mem[countedAddr]
     word = lowercase(getString(wordAddr, wordLen))
 
-    context = mem[CONTEXT:(CONTEXT+mem[NUMCONTEXT])]
+    context = mem[CONTEXT:(CONTEXT+mem[NUMCONTEXT]-1)]
 
     lenAndFlags = 0
     lfa = 0
@@ -729,7 +729,8 @@ FIND_CFA = defPrimWord("FIND", () -> begin
         callPrim(mem[vocabCFA])
         lfa = popPS()
 
-        while lfa > 0
+        while (lfa = mem[lfa]) > 0
+
             lenAndFlags = mem[lfa+1]
             len = lenAndFlags & F_LENMASK
             hidden = (lenAndFlags & F_HIDDEN) == F_HIDDEN
@@ -738,14 +739,11 @@ FIND_CFA = defPrimWord("FIND", () -> begin
                 continue
             end
 
-            thisAddr = latest+2
-            thisWord = lowercase(getString(thisAddr, len))
+            thisWord = lowercase(getString(lfa+2, len))
 
-            if lowercase(thisWord) == lowercase(word)
+            if thisWord == word
                 break
             end
-
-            lfa = mem[lfa]
         end
 
         if lfa>0
index 62b826f..496e639 100644 (file)
@@ -13,5 +13,6 @@ include lib_5_strings.4th
 include lib_6_variables.4th
 include lib_7_printwords.4th
 include lib_8_decompiler.4th
+include lib_9_vocab.4th
 
-include lib_9_misc.4th
+include lib_10_misc.4th
similarity index 67%
rename from src/lib_9_misc.4th
rename to src/lib_10_misc.4th
index 57b7e75..a864cbb 100644 (file)
         then
 ;
 
-: FORGET
-        BL WORD FIND >LFA   ( find the word, gets the dictionary entry address )
-        DUP @ LATEST !      ( set LATEST to point to the previous word )
-        H !                 ( and store H with the dictionary address )
-;
-
-: HIDE
-        BL WORD FIND DROP >NAME
-        DUP @ F_HIDDEN OR SWAP !
-;
-
 : UNUSED  ( -- cells )
         MEMSIZE HERE - ;
diff --git a/src/lib_9_vocab.4th b/src/lib_9_vocab.4th
new file mode 100644 (file)
index 0000000..32d12c2
--- /dev/null
@@ -0,0 +1,12 @@
+\ Vocabulary management
+
+: FORGET
+        BL WORD FIND >LFA   ( find the word, gets the dictionary entry address )
+        DUP @ LATEST !      ( set LATEST to point to the previous word )
+        H !                 ( and store H with the dictionary address )
+;
+
+: HIDE
+        BL WORD FIND DROP >NAME
+        DUP @ F_HIDDEN OR SWAP !
+;