4 DUP @ ( get the flags/length byte )
5 F_LENMASK AND ( mask out the flags - just want the length )
10 SWAP 1+ ( addr len -- len addr+1 )
11 DUP @ ( len addr -- len addr char | get the next character)
12 DUP 32 >= OVER 127 <= AND IF
13 EMIT ( len addr char -- len addr | and print it)
19 SWAP 1- ( len addr -- addr len-1 | subtract one from length )
25 1+ ( skip over the link pointer )
26 @ ( get the flags/length byte )
27 F_HIDDEN AND ( mask the F_HIDDEN flag and return it (as a truth value) )
31 1+ ( skip over the link pointer )
32 @ ( get the flags/length byte )
33 F_IMMED AND ( mask the F_IMMED flag and return it (as a truth value) )
41 BL WORD FIND ( find the dictionary entry to decompile )
46 ." Word '" COUNT TYPE ." ' not found in dictionary."
50 DUP DUP BODYLEN + SWAP >LINK
55 [CHAR] : EMIT SPACE DUP 1+ .NAME SPACE
56 DUP ?IMMEDIATE IF ." IMMEDIATE " THEN CR
60 ." Variable " DUP 1+ .NAME CR
65 ." Constant " DUP 1+ .NAME CR
70 ." Primitive or word with unrecognized codeword." CR
76 LINK> >BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
78 ( now we start decompiling until we hit the end of the word )
82 DUP @ ( end start codeword )
85 ['] LIT OF ( is it LIT ? )
86 1+ DUP @ ( get next word which is the integer constant )
89 ['] LITSTRING OF ( is it LITSTRING ? )
90 [CHAR] S EMIT [CHAR] " EMIT SPACE ( print S"<space> )
91 1+ DUP @ ( get the length word )
92 SWAP 1+ SWAP ( end start+1 length )
93 2DUP TYPE ( print the string )
94 [CHAR] " EMIT SPACE ( finish the string with a final quote )
95 + ( end start+1+len, aligned )
96 1- ( because we're about to add 4 below )
98 ['] 0BRANCH OF ( is it 0BRANCH ? )
100 1+ DUP @ ( print the offset )
104 ['] BRANCH OF ( is it BRANCH ? )
106 1+ DUP @ ( print the offset )
110 ['] ['] OF ( is it ['] ? )
112 1+ DUP @ ( get the next codeword )
113 >NAME ( and force it to be printed as a dictionary entry )
116 ['] EXIT OF ( is it EXIT? )
117 ( We expect the last word to be EXIT, and if it is then we don't print it
118 because EXIT is normally implied by ;. EXIT can also appear in the middle
119 of words, and then it needs to be printed. )
120 2DUP ( end start end start )
121 1+ ( end start end start+1 )
122 <> IF ( end start | we're not at the end )
127 DUP ( in the default case we always need to DUP before using )
128 >NAME ( look up the codeword to get the dictionary entry )
129 .NAME SPACE ( and print it )
137 2DROP ( restore stack )