# Dictionary searches
-LFATOCFA_CFA = defPrimWord("LFA>CFA", () -> begin
+FROMLINK_CFA = defPrimWord("LINK>", () -> begin
addr = popPS()
lenAndFlags = mem[addr+1]
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)
if lfa > 0
pushPS(lfa)
- callPrim(mem[LFATOCFA_CFA])
+ callPrim(mem[FROMLINK_CFA])
if (lenAndFlags & F_IMMED) == F_IMMED
pushPS(1)
else
DOES_HELPER_CFA = defPrimWord("(DOES>)", () -> begin
pushPS(mem[mem[CURRENT]])
- callPrim(mem[LFATOCFA_CFA])
+ callPrim(mem[FROMLINK_CFA])
cfa = popPS()
runtimeAddr = popPS()
: 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 , , ;
['] 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
;
+\ 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
\ Decompilation
-: >NAME
- BEGIN
- 1- DUP @
- NFA_MARK AND
- NFA_MARK = UNTIL
-;
-
-: >LFA >NAME 1- ;
-
: SEE
BL WORD FIND ( find the dictionary entry to decompile )
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). )
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
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 )
\ 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 )
;