Changeset 2909
- Timestamp:
- Mar 21, 2012 11:14:01 PM (15 months ago)
- File:
-
- 1 edited
-
forth/lib/decomp.fth (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
forth/lib/decomp.fth
r2904 r2909 55 55 56 56 hidden definitions 57 d# 200 2* /n* constant /positions57 d# 300 2* /n* constant /positions 58 58 /positions buffer: positions 59 59 0 value end-positions … … 71 71 drop true ( true ) 72 72 ; 73 0 value the-ip73 0 value decompiler-ip 74 74 : add-position ( ip -- ) 75 the-ip find-position if( )75 decompiler-ip find-position if ( ) 76 76 end-positions positions /positions + >= ( flag ) 77 77 abort" Decompiler position table overflow" ( ) 78 78 end-positions dup 2 na+ is end-positions ( adr ) 79 79 then ( adr ) 80 #out @ #line @ wljoin the-ip rot 2!( )80 #out @ #line @ wljoin decompiler-ip rot 2! ( ) 81 81 ; 82 82 : ip>position ( ip -- true | #out #line false ) … … 92 92 ; 93 93 94 headers 95 defer indent 96 : (indent) ( -- ) lmargin @ #out @ - 0 max spaces ; 97 ' (indent) is indent 98 headerless 99 100 : +indent ( -- ) 3 lmargin +! cr ; 101 : -indent ( -- ) ??cr -3 lmargin +! ; 102 \ : <indent ( -- ) ??cr -3 lmargin +! indent 3 lmargin +! ; 103 94 104 headerless 95 105 \ Like ." but goes to a new line if needed. 96 106 : cr". ( adr len -- ) 97 dup ?line ( adr len )107 dup ?line indent ( adr len ) 98 108 add-position ( adr len ) 99 109 magenta-letters type cancel ( ) … … 199 209 200 210 ; 201 headers202 defer indent203 : (indent) ( -- )204 #out @ lmargin @ > if cr then205 lmargin @ #out @ - spaces206 ;207 ' (indent) is indent208 headerless209 210 : +indent ( -- ) 3 lmargin +! indent ;211 : -indent ( -- ) -3 lmargin +! indent ;212 : <indent ( -- ) -3 lmargin +! indent 3 lmargin +! ;213 211 214 212 : .begin ( -- ) .." begin " +indent ; 215 : .then ( -- ) -indent .." then ";213 : .then ( -- ) -indent .." then" cr ; 216 214 217 215 \ Extent holds the largest known extent of the current word, as determined … … 221 219 : +extent ( possible-new-extent -- ) extent @ umax extent ! ; 222 220 : +branch ( ip-of-branch -- next-ip ) ta1+ /branch + ; 223 : .endof ( ip -- ip' ) .." endof" indent+branch ;224 : .endcase ( ip -- ip' ) indent .." endcase" indentta1+ ;225 : .$endof ( ip -- ip' ) .." $endof" indent+branch ;226 : .$endcase ( ip -- ip' ) indent .." $endcase" indentta1+ ;221 : .endof ( ip -- ip' ) .." endof" cr +branch ; 222 : .endcase ( ip -- ip' ) .." endcase" cr ta1+ ; 223 : .$endof ( ip -- ip' ) .." $endof" cr +branch ; 224 : .$endcase ( ip -- ip' ) .." $endcase" cr ta1+ ; 227 225 228 226 : add-break ( break-address break-type -- ) … … 284 282 : .;code (s ip -- ip' ) 285 283 does-ip? if 286 cr lmargin @ spaces." does> "284 ??cr .." does> " 287 285 else 288 0 lmargin ! indent.." ;code " cr disassemble 0286 ??cr 0 lmargin ! .." ;code " cr disassemble 0 289 287 then 290 288 ; 291 289 : .branch ( ip -- ip' ) 292 290 dup forward-branch? if 293 <indent .." else"indent291 -indent .." else" +indent 294 292 else 295 -indent .." repeat "293 -indent .." repeat" cr 296 294 then 297 295 +branch … … 300 298 dup forward-branch? if 301 299 dup while? if 302 <indent .." while"indent300 -indent .." while" +indent 303 301 else 304 .." if " +indent302 .." if" +indent 305 303 then 306 304 else 307 -indent .." until " 305 -indent .." until " cr 308 306 then 309 307 +branch … … 312 310 : .do ( ip -- ip' ) .." do " +indent +branch ; 313 311 : .?do ( ip -- ip' ) .." ?do " +indent +branch ; 314 : .loop ( ip -- ip' ) -indent .." loop "+branch ;315 : .+loop ( ip -- ip' ) -indent .." +loop " +branch ;312 : .loop ( ip -- ip' ) .." loop " cr +branch ; 313 : .+loop ( ip -- ip' ) -indent .." +loop " cr +branch ; 316 314 : .of ( ip -- ip' ) .." of " +branch ; 317 315 : .$of ( ip -- ip' ) .." $of " +branch ; … … 344 342 : pretty-. ( n -- ) 345 343 base @ d# 10 = if (.) else (u.) then ( adr len ) 346 dup ?line add-position 347 green-letters type cancel space 344 dup 3 + ?line indent add-position 345 green-letters 346 base @ case 347 d# 10 of ." d# " endof 348 d# 16 of ." h# " endof 349 d# 8 of ." o# " endof 350 d# 2 of ." b# " endof 351 endcase 352 type cancel space 348 353 ; 349 354 … … 355 360 ; 356 361 : .word ( ip -- ip' ) 362 indent 357 363 dup token@ check-[compile] ( ip xt ) 358 364 >name name>string ( ip adr len ) … … 379 385 : skip-(') ( ip -- ip' ) ta1+ ta1+ ; 380 386 headerless 381 : .is ( ip -- ip' ) .." to " ta1+ dup token@ .name ta1+ ;387 : .is ( ip -- ip' ) .." to " ta1+ dup token@ .name ta1+ ; 382 388 : .string ( ip -- ip' ) cword-name .string-tail +str ; 383 389 : .nstring ( ip -- ip' ) ta1+ dup ncount " n""" .string-tail +nstr ; … … 388 394 : .unnest ( ip -- ip' ) 389 395 dup extent @ u>= if 390 0 lmargin ! indent .." ;" drop 0396 ??cr 0 lmargin ! .." ;" drop 0 391 397 else 392 398 .." exit " ta1+ … … 499 505 dup scan-pf next-break 3 lmargin ! indent ( apf ) 500 506 begin ( adr ) 501 dup is the-ip ( adr ) 502 ?cr break-addr @ over = if ( adr ) 507 dup is decompiler-ip ( adr ) 508 ?cr ( adr ) 509 break-addr @ over = if ( adr ) 503 510 begin ( adr ) 504 511 break-type @ execute ( adr ) … … 526 533 ; 527 534 \ Display category of word 528 : .: ( acf definer -- ) .definer space space>body .pf ;535 : .: ( acf definer -- ) .definer cr ( space space ) >body .pf ; 529 536 : debug-see ( apf -- ) 530 537 page-mode? >r no-page
Note: See TracChangeset
for help on using the changeset viewer.
