13 BL WORD FIND ( find the dictionary entry to decompile )
18 ." Word '" COUNT TYPE ." ' not found in dictionary."
24 ( Now we search again, looking for the next word in the dictionary. This gives us
25 the length of the word that we will be decompiling. (Well, mostly it does). )
26 HERE ( address of the end of the last compiled word )
27 LATEST @ ( word last curr )
29 2 PICK ( word last curr word )
30 OVER ( word last curr word curr )
31 <> ( word last curr word<>curr? )
32 WHILE ( word last curr )
34 DUP @ ( word curr prev (which becomes: word last curr) )
37 DROP ( at this point, the stack is: start-of-word end-of-word )
38 SWAP ( end-of-word start-of-word )
43 [CHAR] : EMIT SPACE DUP 1+ .NAME SPACE
44 DUP ?IMMEDIATE IF ." IMMEDIATE " THEN CR
48 ." Variable " DUP 1+ .NAME CR
53 ." Constant " DUP 1+ .NAME CR
58 ." Primitive or word with unrecognized codeword." CR
64 >CFA >BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
66 ( now we start decompiling until we hit the end of the word )
70 DUP @ ( end start codeword )
73 ['] LIT OF ( is it LIT ? )
74 1+ DUP @ ( get next word which is the integer constant )
77 ['] LITSTRING OF ( is it LITSTRING ? )
78 [CHAR] S EMIT [CHAR] " EMIT SPACE ( print S"<space> )
79 1+ DUP @ ( get the length word )
80 SWAP 1+ SWAP ( end start+1 length )
81 2DUP TYPE ( print the string )
82 [CHAR] " EMIT SPACE ( finish the string with a final quote )
83 + ( end start+1+len, aligned )
84 1- ( because we're about to add 4 below )
86 ['] 0BRANCH OF ( is it 0BRANCH ? )
88 1+ DUP @ ( print the offset )
92 ['] BRANCH OF ( is it BRANCH ? )
94 1+ DUP @ ( print the offset )
98 ['] ['] OF ( is it ['] ? )
100 1+ DUP @ ( get the next codeword )
101 >NAME ( and force it to be printed as a dictionary entry )
104 ['] EXIT OF ( is it EXIT? )
105 ( We expect the last word to be EXIT, and if it is then we don't print it
106 because EXIT is normally implied by ;. EXIT can also appear in the middle
107 of words, and then it needs to be printed. )
108 2DUP ( end start end start )
109 1+ ( end start end start+1 )
110 <> IF ( end start | we're not at the end )
115 DUP ( in the default case we always need to DUP before using )
116 >NAME ( look up the codeword to get the dictionary entry )
117 .NAME SPACE ( and print it )
125 2DROP ( restore stack )