From: Tim Vaughan Date: Wed, 1 Jun 2016 00:33:34 +0000 (+1200) Subject: FIND working again. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=forth.jl.git;a=commitdiff_plain;h=fba53adbaa70e296388c421aa182ff7bad090b17 FIND working again. --- diff --git a/src/forth.jl b/src/forth.jl index 57fda1b..8cc7547 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -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 diff --git a/src/lib.4th b/src/lib.4th index 62b826f..496e639 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -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 diff --git a/src/lib_9_misc.4th b/src/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 --- a/src/lib_9_misc.4th +++ b/src/lib_10_misc.4th @@ -32,16 +32,5 @@ 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 index 0000000..32d12c2 --- /dev/null +++ b/src/lib_9_vocab.4th @@ -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 ! +;