-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtools.fs
169 lines (134 loc) · 3.53 KB
/
tools.fs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
\ tools.fs --
\ Copyright 2011 (C) David Vazquez
\ This file is part of Eulex.
\ Eulex is free software: you can redistribute it and/or modify
\ it under the terms of the GNU General Public License as published by
\ the Free Software Foundation, either version 3 of the License, or
\ (at your option) any later version.
\ Eulex is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\ You should have received a copy of the GNU General Public License
\ along with Eulex. If not, see <http://www.gnu.org/licenses/>.
: addr-column
attr gray swap print-hex-number [char] : emit space attr! ;
\ Dump n bytes of the memory from ADDR, in a readable way.
: dump ( addr n -- )
0 ?do
i 16 mod 0= if
cr dup i + addr-column
then
dup i + c@ print-hex-byte space
loop drop
cr
;
: map-nt ( xt -- )
>r
context @ dowords
dup r@ execute
endwords
r> drop ;
: words ['] id. map-nt ;
: room-count ( -- n )
0 context @ dowords swap 1+ swap endwords ;
: room
CR
." Words in the context: " room-count . CR
." Dictionary space allocated: " dp dp-base - . ." bytes" cr ;
\ Display the content of the variable ADDR.
: ? ( addr -- )
@ . ;
\ Display the data stack
: .s
." <" depth print-number ." > "
sp-limit
begin
cell -
dup sp cell + > while
dup @ .
repeat
drop ;
: unfind-in-wordlist ( xt wordlist -- addr c )
dowords
2dup nt>xt = if
nip nt>name
exit
then
endwords
drop
0 0 ;
\ Find the first avalaible word whose CFA is XT, pushing the name to
\ the stack or two zeros if it is not found.
: unfind ( xt -- addr u )
get-order dup 1+ roll
( widn ... wid1 n xt )
begin
over 0<> while
swap 1- swap rot
over swap unfind-in-wordlist
dup 0= if
2drop
else
>r >r
drop 0 ?do drop loop
r> r>
exit
then
repeat
2drop
0 0
;
\ Backtrace!
: upper@ ( addr -- x|0)
dup mem-upper-size u< if @ else drop 0 endif ;
: retaddr>xt ( x -- )
dup cell - upper@ + ;
: backtrace-frame ( addr -- flag )
retaddr>xt unfind dup 0<> if
2 spaces type cr true
else
type false
endif ;
\ Display the current backtrace.
variable backtrace-limit
10 backtrace-limit !
: backtrace
." Backtrace: " cr
backtrace-limit @
rsp
begin over 0<> over rsp-limit <= and while
dup @ backtrace-frame if swap 1- swap endif
cell +
repeat
drop ;
( Display the list of vocabularies in the system and the search order stack )
: .wid ( wid -- )
wid>name ?dup if type space else ." ??? " drop then ;
: vocs
last-wid @
begin ?dup while
dup .wid
wid-previous @
repeat ;
: order
get-order 0 ?do .wid loop 4 spaces current @ .wid ;
Root definitions
' order alias order
' words alias words
previous definitions
( Disassembler. SEE )
require @disassem.fs
\ Dynamic memory management debugging
: .chunk ( chunk -- )
." Base: " dup chunk>addr print-hex-number 5 SPACES
." End: " dup chunk>end print-hex-number 5 SPACES
." Size: " chunk>size print-hex-number CR ;
: meminfo
CR first-chunk
begin dup null-chunk? not while
dup .chunk
next-chunk
repeat
drop ;
\ tools.fs ends here