Skip to content

Commit 3c69dc0

Browse files
author
Attila Magyar
committed
decompiler: arrows indicate src and dst addresses
1 parent be9914d commit 3c69dc0

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

generic/forth/decompiler.forth

+9-11
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ MAX 4 * 1+ constant: LEN
1919
LEN buffer: arrow
2020
variable: rownum
2121
variable: idx
22-
: sort ( n n -- n n ) 2dup > if swap then ;
23-
: pack ( n n -- n ) sort 16 lshift or ;
22+
: pack ( n n -- n ) 16 lshift or ;
2423
: unpack ( n -- n n ) dup 16rFFFF and swap 16 rshift ;
25-
: at ( i -- n n ) jumps @ unpack ;
26-
: add ( row1 row2 -- ) idx @ MAX < if pack idx @ jumps ! idx ++ else 2drop then ;
24+
: at ( i -- dst-row src-row ) jumps @ unpack ;
25+
: add ( dst-row src-row -- ) idx @ MAX < if pack idx @ jumps ! idx ++ else 2drop then ;
2726
: jump? ( addr -- bool ) @ dup ['] branch0 = swap ['] branch = or ;
28-
: positions ( branch-addr -- row1 row2 ) cell + @ cell / rownum @ 1+ + rownum @ ;
27+
: positions ( branch-addr -- dst-row src-row ) cell + @ cell / rownum @ 1+ + rownum @ ;
2928

3029
: collect-jumps ( xt -- )
3130
0 idx ! 1 rownum !
@@ -36,15 +35,14 @@ variable: idx
3635
until
3736
1 rownum ! drop ;
3837

39-
: head? ( n n -- bool ) rownum @ = swap rownum @ = or ; \ arrow head
4038
: head ( -- )
4139
idx @ 0 ?do
42-
i at head? if
43-
$< i 1+ 4 * 3 - arrow + c!
44-
$- i 1+ 4 * 2 - arrow + c!
45-
then
40+
i at ( dst-row src-row )
41+
rownum @ = if $- i 1+ 4 * 3 - arrow + c! $> i 1+ 4 * 2 - arrow + c! then
42+
rownum @ = if $< i 1+ 4 * 3 - arrow + c! $- i 1+ 4 * 2 - arrow + c! then
4643
loop ;
47-
: body? ( n n -- bool ) rownum @ > swap rownum @ < and ;
44+
: sort ( n n -- n n ) 2dup > if swap then ;
45+
: body? ( n n -- bool ) sort rownum @ > swap rownum @ < and ;
4846
: body ( -- ) idx @ 0 ?do i at body? if $| i 1+ 4 * 1- arrow + c! then loop ; \ arrow body
4947
: clear ( -- ) LEN 0 do 32 i arrow + c! loop ;
5048
: .arrow ( -- ) clear body head arrow LEN type-counted cr ;

0 commit comments

Comments
 (0)