1 ;; ////////////////////////////////////////////////////////////////////////// //
2 0 VALUE ZX
-TRACER
-SAVED
-DP
3 0 VALUE ZX
-TRACER
-WORD
-START
;; always ZX address
4 0 VALUE ZX
-TRACER
-WORD
-END ;; always ZX address
13 ;; bit
6: unconditional branch
17 ;; ////////////////////////////////////////////////////////////////////////// //
18 : (ZX
-WRITE-#HEX4
) ( n
-- )
20 <# # # # #
[CHAR
] # HOLD #
> TYPE
25 : (ZX
-WRITE-HEX4
) ( n
-- )
32 ;; ////////////////////////////////////////////////////////////////////////// //
33 : ZX
-LABELS
-COUNT
( -- addr
)
37 : ZX
-LABELS
-START
-ADDR
( -- addr
)
41 : ZX
-LABELS
-END-ADDR
( -- addr
)
42 ZX
-LABELS
-START
-ADDR ZX
-LABELS
-COUNT
+
45 : ZX
-HAS
-LABEL
-AT
( addr
-- flag
)
46 ZX
-LABELS
-COUNT IFNOT DROP
0 EXIT
ENDIF
48 ZX
-LABELS
-END-ADDR ZX
-LABELS
-START
-ADDR
50 DUP I @
= IF DROP RDROP RDROP
1 EXIT
ENDIF
55 : ZX
-HAS
-LABEL
-AFTER
( addr
-- flag
)
56 ZX
-LABELS
-COUNT IFNOT DROP
0 EXIT
ENDIF
58 ZX
-LABELS
-END-ADDR ZX
-LABELS
-START
-ADDR
60 DUP I @ U
< IF DROP RDROP RDROP
1 EXIT
ENDIF
65 : ZX
-APPEND
-LABEL
( addr
-- )
66 \ DUP
." checking label: #" HEX U
. DECIMAL ZX
-TRACER
-SAVED
-DP @
." (labels:" 0 .R
." )\n"
67 DUP ZX
-HAS
-LABEL
-AT
IF
68 \ DUP
." duplicate label: #" HEX U
. DECIMAL CR
71 \ DUP
." new label: #" HEX U
. DECIMAL CR
72 ZX
-TRACER
-SAVED
-DP
1+!
78 ;; ////////////////////////////////////////////////////////////////////////// //
79 : ZX
-TRACE
-SKIP
-INSTR
( pfa
-- nextpfa
)
80 DUP @ UR
-ZX
-WORD
-FLAGS
-BY
-CFA SWAP
2+
82 OVER FWF
-CODEBLOCK AND
IF 5 + SWAP DROP
0 SWAP
ENDIF
83 OVER FWF
-BRANCH FWF
-NUMLIT OR FWF
-COMPILE OR AND
IF 2+ ENDIF
84 OVER FWF
-STRLIT AND
IF ZX
-BCOUNT
+ ENDIF
89 : ZX
-PRINT
-INSTR
-ARGS
( pfa
-- )
90 DUP @ UR
-ZX
-WORD
-FLAGS
-BY
-CFA SWAP
2+
93 OVER FWF
-CODEBLOCK AND
IF
94 ;; codeblock is followed by jump destination
, then cfa
, then threaded code
95 ." L" @
(ZX
-WRITE-HEX4
)
99 OVER FWF
-BRANCH AND
IF
100 ." L" @
(ZX
-WRITE-HEX4
)
104 OVER FWF
-NUMLIT AND
IF
109 OVER FWF
-STRLIT AND
IF
110 ZX
-BCOUNT
." ~" XTYPE
." ~"
114 OVER FWF
-COMPILE AND
IF
115 @ UR
-ZX
-WORD
-NAME
-BY
-CFA
IF SPACE XTYPE
ELSE ." ???" ENDIF
122 ;; ////////////////////////////////////////////////////////////////////////// //
123 : ZX
-TRACE
-LABELS
( pfa
-- )
124 DUP
TO ZX
-TRACER
-WORD
-START
129 UR
-ZX
-WORD
-FLAGS
-BY
-CFA
130 SWAP
2+ ;; move
to the next word
133 OVER FWF
-CODEBLOCK AND
IF
134 ;; codeblock is followed by jump destination
, then cfa
, then threaded code
135 ;; it is guaranteed
to jump forward
, so take a shortcut here
136 DUP @ ZX
-APPEND
-LABEL
;; append label
137 4+ ;; skip branch and CFA
; we want
to continue tracing inside a codeblock anyway
138 ;; no need
to anaylze it further
142 OVER FWF
-BRANCH AND
IF
143 DUP @ ZX
-APPEND
-LABEL
144 2+ ;; skip branch destination
145 ;; check
if this is backward unconditional branch
146 OVER FWF
-UNCONDITIONAL AND
IF
147 ;; check
if this is backward branch
149 DUP
2- @ TOZX
;; ( flags pfa dest
)
150 OVER TOZX
;; ( flags pfa dest pfa
)
151 ;; ( flags pfa dest pfa
)
153 ;; check
if we should
stop here
155 DUP ZX
-HAS
-LABEL
-AFTER
158 TO ZX
-TRACER
-WORD
-END
163 SWAP FWF
-NORETURN BITNOT AND SWAP
166 OVER FWF
-NUMLIT AND
IF
170 OVER FWF
-STRLIT AND
IF
174 OVER FWF
-COMPILE AND
IF
178 OVER FWF
-NORETURN AND
IF
180 ;; check
if we have any label after this word
181 DUP
2- ZX
-HAS
-LABEL
-AFTER
183 TO ZX
-TRACER
-WORD
-END
187 SWAP DROP
;; drop flags
192 ;; ////////////////////////////////////////////////////////////////////////// //
193 ;; labels must be already traced
194 : (ZX
-DECOMP
) ( pfa
-- )
195 DUP
3- UR
-ZX
-WORD
-NAME
-BY
-CFA IFNOT
" WTF??!" UFE
-FATAL
ENDIF ." === " TYPE
." ===\n"
197 DUP ZX
-TRACER
-WORD
-END U
<
200 DUP
(ZX
-WRITE-#HEX4
) ." :"
202 DUP ZX
-HAS
-LABEL
-AT
IF
203 ." L" DUP
(ZX
-WRITE-HEX4
) CR
204 DUP
(ZX
-WRITE-#HEX4
) ." : "
209 DUP @ UR
-ZX
-WORD
-NAME
-BY
-CFA IFNOT
" WTF?!" UFE
-FATAL
ENDIF XTYPE
211 DUP ZX
-PRINT
-INSTR
-ARGS