-
Notifications
You must be signed in to change notification settings - Fork 45
/
diagnostics.frt
113 lines (92 loc) · 2.39 KB
/
diagnostics.frt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
( diagnostics words: decompilation, exception handling )
: info dup 9 + prints ." : " cfa . cr ;
: dump last_word @
repeat
dup info @
dup not until ;
: word_foreach >r last_word @
repeat
dup r@ execute @
dup not until r> ;
: word_any >r last_word @
repeat
dup r@ execute
if dup
else @ dup not
then
until r> drop ;
: is-word >r last_word @
repeat
dup cfa r@ =
if dup
else @ dup not
then
until r> drop ;
: word-predecessor ( wa - wa )
>r last_word @
repeat
dup @ dup if cfa r@ = if 1
else @ 0
then
else drop drop 0 1
then
until r> drop ;
: word-size ( xt - sz )
dup word-predecessor dup not if drop here then
swap -
;
: word-contains-addr ( w a -- 0/1 )
swap dup dup word-size + in-range ;
: ? " decompile" find cfa execute ;
: decompile >r last_word
repeat
@ dup if
dup r@ word-contains-addr if
." <" dup 9 + prints
r@ swap cfa - dup if ." +" . else drop then ." >" 1
else 0 then
else r@ . drop 1 then
until r> drop ;
64 constant OFF_r11
72 constant OFF_r12
80 constant OFF_r13
88 constant OFF_r14
96 constant OFF_r15
160 constant OFF_rsp
168 constant OFF_rip
OFF_r15 constant OFF_PC
OFF_r14 constant OFF_W
OFF_r13 constant OFF_rstack
( stackbase context - )
: trap >r drop
." Exception. Here is some useful information: " cr
." PC = " r@ OFF_PC + @ dup . ." " ? cr
." W = " r@ OFF_W + @ dup . ." " ? cr
." program : " cr
r@ OFF_PC + @
." " 2 cells - dup ? ." " dup @ ? cr
." " cell% + dup ? ." " dup @ ? cr
." pc=> " cell% + dup ? ." " dup @ ? cr
." " cell% + dup ? ." " dup @ ? cr
." " cell% + dup ? ." " dup @ ? cr
." " cell% + dup ? ." " dup @ ? cr
." " cell% + dup ? ." " dup @ ? cr
." Stack : " cr
r@ OFF_rsp + @
." " 2 cells - dup @ ? cr
." " cell% + dup @ ? cr
." sp=>" cell% + dup @ ? cr
." " cell% + dup @ ? cr
." " cell% + dup @ ? cr
." " cell% + dup @ ? cr
." " cell% + dup @ ? cr
." Return stack : " cr
r@ OFF_rstack + @ 2 cells -
." " cell% + dup @ ." " ? cr
." =>" cell% + dup @ ." " ? cr
." " cell% + dup @ ." " ? cr
." " cell% + dup @ ." " ? cr
." " cell% + dup @ ." " ? cr
( dump )
( cr ." dictionary " cr dump ) ( TODO: Add dump to file )
r> drop ;