X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Flib_8_decompiler.4th;fp=src%2Flib_7_decompiler.4th;h=90ba1096a256696d49960799a69de11643a34760;hb=90a9b8ad41a542c3ca7d150d4d1168cb8ec97b81;hp=a27442bdeb2537ae3ce3cc28593d441da84aeb48;hpb=56f581c25775f4244cd60d5943a5beb46a9ccafb;p=forth.jl.git diff --git a/src/lib_7_decompiler.4th b/src/lib_8_decompiler.4th similarity index 81% rename from src/lib_7_decompiler.4th rename to src/lib_8_decompiler.4th index a27442b..90ba109 100644 --- a/src/lib_7_decompiler.4th +++ b/src/lib_8_decompiler.4th @@ -1,30 +1,54 @@ \ Decompilation -: .NAME - DUP @ ( get the flags/length byte ) - F_LENMASK AND ( mask out the flags - just want the length ) +: VCFA>LATEST + 1+ @ +; - BEGIN - DUP 0> ( length > 0? ) - WHILE - SWAP 1+ ( addr len -- len addr+1 ) - DUP @ ( len addr -- len addr char | get the next character) - DUP 32 >= OVER 127 <= AND IF - EMIT ( len addr char -- len addr | and print it) - ELSE - BASE @ SWAP HEX - ." \x" 0 .R - BASE ! - THEN - SWAP 1- ( len addr -- addr len-1 | subtract one from length ) - REPEAT - 2DROP ( len addr -- ) +: CLOSESTLINK ( addr vcfa -- lfa ) + + vcfa>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 ; -: ?HIDDEN - 1+ ( skip over the link pointer ) - @ ( get the flags/length byte ) - F_HIDDEN AND ( mask the F_HIDDEN flag and return it (as a truth value) ) +: 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 @@ -33,10 +57,6 @@ F_IMMED AND ( mask the F_IMMED flag and return it (as a truth value) ) ; -: BODYLEN - \ **TODO** -; - : SEE BL WORD FIND ( find the dictionary entry to decompile )