4 BL WORD FIND ( find the dictionary entry to decompile )
9 ." Word '" COUNT TYPE ." ' not found in dictionary."
15 ( Now we search again, looking for the next word in the dictionary. This gives us
16 the length of the word that we will be decompiling. (Well, mostly it does). )
17 HERE ( address of the end of the last compiled word )
18 LATEST @ ( word last curr )
20 2 PICK ( word last curr word )
21 OVER ( word last curr word curr )
22 <> ( word last curr word<>curr? )
23 WHILE ( word last curr )
25 DUP @ ( word curr prev (which becomes: word last curr) )
28 DROP ( at this point, the stack is: start-of-word end-of-word )
29 SWAP ( end-of-word start-of-word )
34 [CHAR] : EMIT SPACE DUP 1+ .NAME SPACE
35 DUP ?IMMEDIATE IF ." IMMEDIATE " THEN CR
39 ." Variable " DUP 1+ .NAME CR
44 ." Constant " DUP 1+ .NAME CR
49 ." Primitive or word with unrecognized codeword." CR
55 LINK> >BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
57 ( now we start decompiling until we hit the end of the word )
61 DUP @ ( end start codeword )
64 ['] LIT OF ( is it LIT ? )
65 1+ DUP @ ( get next word which is the integer constant )
68 ['] LITSTRING OF ( is it LITSTRING ? )
69 [CHAR] S EMIT [CHAR] " EMIT SPACE ( print S"<space> )
70 1+ DUP @ ( get the length word )
71 SWAP 1+ SWAP ( end start+1 length )
72 2DUP TYPE ( print the string )
73 [CHAR] " EMIT SPACE ( finish the string with a final quote )
74 + ( end start+1+len, aligned )
75 1- ( because we're about to add 4 below )
77 ['] 0BRANCH OF ( is it 0BRANCH ? )
79 1+ DUP @ ( print the offset )
83 ['] BRANCH OF ( is it BRANCH ? )
85 1+ DUP @ ( print the offset )
89 ['] ['] OF ( is it ['] ? )
91 1+ DUP @ ( get the next codeword )
92 >NAME ( and force it to be printed as a dictionary entry )
95 ['] EXIT OF ( is it EXIT? )
96 ( We expect the last word to be EXIT, and if it is then we don't print it
97 because EXIT is normally implied by ;. EXIT can also appear in the middle
98 of words, and then it needs to be printed. )
99 2DUP ( end start end start )
100 1+ ( end start end start+1 )
101 <> IF ( end start | we're not at the end )
106 DUP ( in the default case we always need to DUP before using )
107 >NAME ( look up the codeword to get the dictionary entry )
108 .NAME SPACE ( and print it )
116 2DROP ( restore stack )