From: Tim Vaughan Date: Wed, 1 Jun 2016 09:05:36 +0000 (+1200) Subject: Using standard field conversion words. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=3c35d5caec5303e84c5de9dde74759f38280a3d3;p=forth.jl.git Using standard field conversion words. --- diff --git a/src/forth.jl b/src/forth.jl index da7321b..c5c7175 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -698,7 +698,7 @@ end) # Dictionary searches -LFATOCFA_CFA = defPrimWord("LFA>CFA", () -> begin +FROMLINK_CFA = defPrimWord("LINK>", () -> begin addr = popPS() lenAndFlags = mem[addr+1] @@ -709,8 +709,6 @@ LFATOCFA_CFA = defPrimWord("LFA>CFA", () -> begin return NEXT end) -TOBODY_CFA = defWord(">BODY", [INCR_CFA, EXIT_CFA]) - CONTEXT, CONTEXT_CFA = defNewVar("CONTEXT", zeros(Int64, 100)) mem[CONTEXT] = FORTH_CFA NUMCONTEXT, NUMCONTEXT_CFA = defNewVar("#CONTEXT", 1) @@ -755,7 +753,7 @@ FIND_CFA = defPrimWord("FIND", () -> begin if lfa > 0 pushPS(lfa) - callPrim(mem[LFATOCFA_CFA]) + callPrim(mem[FROMLINK_CFA]) if (lenAndFlags & F_IMMED) == F_IMMED pushPS(1) else @@ -890,7 +888,7 @@ end, name="DODOES") DOES_HELPER_CFA = defPrimWord("(DOES>)", () -> begin pushPS(mem[mem[CURRENT]]) - callPrim(mem[LFATOCFA_CFA]) + callPrim(mem[FROMLINK_CFA]) cfa = popPS() runtimeAddr = popPS() diff --git a/src/lib_1_basic.4th b/src/lib_1_basic.4th index dc8c584..00b200d 100644 --- a/src/lib_1_basic.4th +++ b/src/lib_1_basic.4th @@ -36,17 +36,22 @@ : C@ @ ; : C, , ; +\ Retrieve stack depth : DEPTH PSP@ PSP0 - ; +\ Words for whitespace : '\n' 10 ; : BL 32 ; : CR '\n' emit ; : SPACE BL emit ; +\ CFA retrieval : ' BL WORD FIND DROP ; : ['] IMMEDIATE LIT LIT , ' , ; +\ Compilation + : [COMPILE] IMMEDIATE ' , ; : COMPILE IMMEDIATE LIT LIT , ' , LIT , , ; @@ -59,12 +64,14 @@ ['] LIT , , ; +\ LFA of most recent definition : LATEST CURRENT @ ; +\ Compile in recursive call to current word : RECURSE IMMEDIATE LATEST @ \ LATEST points to the word being compiled at the moment - LFA>CFA \ get the codeword + LINK> \ get the codeword , \ compile it ; diff --git a/src/lib_6_variables.4th b/src/lib_6_variables.4th index 6829c9c..a7aea70 100644 --- a/src/lib_6_variables.4th +++ b/src/lib_6_variables.4th @@ -1,3 +1,20 @@ +\ Remaining field address conversion words + +: >NAME + BEGIN + 1- DUP @ + NFA_MARK AND + NFA_MARK = UNTIL +; + +: NAME> 1- LINK> ; + +: >LINK >NAME 1- ; + +: >BODY 1+ ; + +: BODY> 1- ; + \ Constants and Variables : CONSTANT diff --git a/src/lib_8_decompiler.4th b/src/lib_8_decompiler.4th index 5daa501..e1470f3 100644 --- a/src/lib_8_decompiler.4th +++ b/src/lib_8_decompiler.4th @@ -1,14 +1,5 @@ \ Decompilation -: >NAME - BEGIN - 1- DUP @ - NFA_MARK AND - NFA_MARK = UNTIL -; - -: >LFA >NAME 1- ; - : SEE BL WORD FIND ( find the dictionary entry to decompile ) @@ -19,7 +10,7 @@ EXIT THEN - >LFA + >LINK ( Now we search again, looking for the next word in the dictionary. This gives us the length of the word that we will be decompiling. (Well, mostly it does). ) @@ -37,7 +28,7 @@ DROP ( at this point, the stack is: start-of-word end-of-word ) SWAP ( end-of-word start-of-word ) - DUP LFA>CFA @ CASE + DUP LINK> @ CASE DOCOL OF \ Colon definition [CHAR] : EMIT SPACE DUP 1+ .NAME SPACE @@ -61,7 +52,7 @@ 4 SPACES - LFA>CFA >BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data ) + LINK> >BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data ) ( now we start decompiling until we hit the end of the word ) BEGIN ( end start ) diff --git a/src/lib_9_vocab.4th b/src/lib_9_vocab.4th index 32d12c2..2b10730 100644 --- a/src/lib_9_vocab.4th +++ b/src/lib_9_vocab.4th @@ -1,7 +1,7 @@ \ Vocabulary management : FORGET - BL WORD FIND >LFA ( find the word, gets the dictionary entry address ) + BL WORD FIND >LINK ( 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 ) ;