X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Flib_8_decompiler.4th;h=412d7f1e4b0f8d0929fe8290a63e9f3f7012011e;hb=b3d4b64d4ededd05309089235561731e65e6be6e;hp=e1470f31b6c6fe0f633213e1137d00581b11068d;hpb=3c35d5caec5303e84c5de9dde74759f38280a3d3;p=forth.jl.git diff --git a/src/lib_8_decompiler.4th b/src/lib_8_decompiler.4th index e1470f3..412d7f1 100644 --- a/src/lib_8_decompiler.4th +++ b/src/lib_8_decompiler.4th @@ -1,5 +1,59 @@ \ Decompilation + +: CLOSESTLINK ( addr vcfa -- lfa ) + + vocab>latest dup ( addr link link ) + rot dup -rot ( link addr link addr ) + < if + 2drop + 0 exit + then + + swap ( addr link ) + 0 -rot ( 0 addr link ) + + begin + rot drop ( addr link ) + dup -rot @ ( link addr nextlink ) + 2dup ( link addr nextlink addr nextlink) + > until + + 2drop +; + +: MIN ( n m -- max ) + 2dup - 0> if + swap drop + else + drop + then +; + +: BODYLEN ( cfa -- len ) + + here swap ( clink addr ) + context dup #context @ + swap + do + dup i @ + + closestlink ( clink addr clink' ) + + ?dup 0> if + rot min + swap + then + loop + + - +; + +: ?IMMEDIATE + 1+ ( skip over the link pointer ) + @ ( get the flags/length byte ) + F_IMMED AND ( mask the F_IMMED flag and return it (as a truth value) ) +; + : SEE BL WORD FIND ( find the dictionary entry to decompile ) @@ -7,26 +61,10 @@ 0= IF ." Word '" COUNT TYPE ." ' not found in dictionary." - EXIT + CR ABORT THEN - >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). ) - HERE ( address of the end of the last compiled word ) - LATEST @ ( word last curr ) - BEGIN - 2 PICK ( word last curr word ) - OVER ( word last curr word curr ) - <> ( word last curr word<>curr? ) - WHILE ( word last curr ) - NIP ( word curr ) - DUP @ ( word curr prev (which becomes: word last curr) ) - REPEAT - - DROP ( at this point, the stack is: start-of-word end-of-word ) - SWAP ( end-of-word start-of-word ) + DUP DUP BODYLEN + SWAP >LINK DUP LINK> @ CASE DOCOL OF