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) )
37 BL WORD FIND ( find the dictionary entry to decompile )
42 ." Word '" COUNT TYPE ." ' not found in dictionary."
48 ( Now we search again, looking for the next word in the dictionary. This gives us
49 the length of the word that we will be decompiling. (Well, mostly it does). )
50 HERE ( address of the end of the last compiled word )
51 LATEST @ ( word last curr )
53 2 PICK ( word last curr word )
54 OVER ( word last curr word curr )
55 <> ( word last curr word<>curr? )
56 WHILE ( word last curr )
58 DUP @ ( word curr prev (which becomes: word last curr) )
61 DROP ( at this point, the stack is: start-of-word end-of-word )
62 SWAP ( end-of-word start-of-word )
67 [CHAR] : EMIT SPACE DUP 1+ .NAME SPACE
68 DUP ?IMMEDIATE IF ." IMMEDIATE " THEN CR
72 ." Variable " DUP 1+ .NAME CR
77 ." Constant " DUP 1+ .NAME CR
82 ." Primitive or word with unrecognized codeword." CR
88 LINK> >BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
90 ( now we start decompiling until we hit the end of the word )
94 DUP @ ( end start codeword )
97 ['] LIT OF ( is it LIT ? )
98 1+ DUP @ ( get next word which is the integer constant )
101 ['] LITSTRING OF ( is it LITSTRING ? )
102 [CHAR] S EMIT [CHAR] " EMIT SPACE ( print S"<space> )
103 1+ DUP @ ( get the length word )
104 SWAP 1+ SWAP ( end start+1 length )
105 2DUP TYPE ( print the string )
106 [CHAR] " EMIT SPACE ( finish the string with a final quote )
107 + ( end start+1+len, aligned )
108 1- ( because we're about to add 4 below )
110 ['] 0BRANCH OF ( is it 0BRANCH ? )
112 1+ DUP @ ( print the offset )
116 ['] BRANCH OF ( is it BRANCH ? )
118 1+ DUP @ ( print the offset )
122 ['] ['] OF ( is it ['] ? )
124 1+ DUP @ ( get the next codeword )
125 >NAME ( and force it to be printed as a dictionary entry )
128 ['] EXIT OF ( is it EXIT? )
129 ( We expect the last word to be EXIT, and if it is then we don't print it
130 because EXIT is normally implied by ;. EXIT can also appear in the middle
131 of words, and then it needs to be printed. )
132 2DUP ( end start end start )
133 1+ ( end start end start+1 )
134 <> IF ( end start | we're not at the end )
139 DUP ( in the default case we always need to DUP before using )
140 >NAME ( look up the codeword to get the dictionary entry )
141 .NAME SPACE ( and print it )
149 2DROP ( restore stack )