]> gitweb.factorcode.org Git - factor.git/blob - basis/debugger/debugger.factor
Move make to its own vocabulary, remove fry _ feature
[factor.git] / basis / debugger / debugger.factor
1 ! Copyright (C) 2004, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: slots arrays definitions generic hashtables summary io
4 kernel math namespaces make prettyprint prettyprint.config
5 sequences assocs sequences.private strings io.styles io.files
6 vectors words system splitting math.parser classes.tuple
7 continuations continuations.private combinators generic.math
8 classes.builtin classes compiler.units generic.standard vocabs
9 init kernel.private io.encodings accessors math.order
10 destructors source-files parser classes.tuple.parser
11 effects.parser lexer compiler.errors generic.parser
12 strings.parser ;
13 IN: debugger
14
15 GENERIC: error. ( error -- )
16 GENERIC: error-help ( error -- topic )
17
18 M: object error. . ;
19 M: object error-help drop f ;
20
21 M: tuple error-help class ;
22
23 M: string error. print ;
24
25 : :s ( -- )
26     error-continuation get data>> stack. ;
27
28 : :r ( -- )
29     error-continuation get retain>> stack. ;
30
31 : :c ( -- )
32     error-continuation get call>> callstack. ;
33
34 : :get ( variable -- value )
35     error-continuation get name>> assoc-stack ;
36
37 : :res ( n -- * )
38     1- restarts get-global nth f restarts set-global restart ;
39
40 : :1 ( -- * ) 1 :res ;
41 : :2 ( -- * ) 2 :res ;
42 : :3 ( -- * ) 3 :res ;
43
44 : restart. ( restart n -- )
45     [
46         1+ dup 3 <= [ ":" % # "    " % ] [ # " :res  " % ] if
47         name>> %
48     ] "" make print ;
49
50 : restarts. ( -- )
51     restarts get [
52         nl
53         "The following restarts are available:" print
54         nl
55         [ restart. ] each-index
56     ] unless-empty ;
57
58 : print-error ( error -- )
59     [ error. flush ] curry
60     [ global [ "Error in print-error!" print drop ] bind ]
61     recover ;
62
63 : print-error-and-restarts ( error -- )
64     print-error
65     restarts.
66     nl
67     "Type :help for debugging help." print flush ;
68
69 : try ( quot -- )
70     [ print-error-and-restarts ] recover ;
71
72 M: relative-underflow summary
73     drop "Too many items removed from data stack" ;
74
75 M: relative-overflow summary
76     drop "Superfluous items pushed to data stack" ;
77
78 : expired-error. ( obj -- )
79     "Object did not survive image save/load: " write third . ;
80
81 : io-error. ( error -- )
82     "I/O error: " write third print ;
83
84 : type-check-error. ( obj -- )
85     "Type check error" print
86     "Object: " write dup fourth short.
87     "Object type: " write dup fourth class .
88     "Expected type: " write third type>class . ;
89
90 : divide-by-zero-error. ( obj -- )
91     "Division by zero" print drop ;
92
93 : signal-error. ( obj -- )
94     "Operating system signal " write third . ;
95
96 : array-size-error. ( obj -- )
97     "Invalid array size: " write dup third .
98     "Maximum: " write fourth 1- . ;
99
100 : c-string-error. ( obj -- )
101     "Cannot convert to C string: " write third . ;
102
103 : ffi-error. ( obj -- )
104     "FFI: " write
105     dup third [ write ": " write ] when*
106     fourth print ;
107
108 : heap-scan-error. ( obj -- )
109     "Cannot do next-object outside begin/end-scan" print drop ;
110
111 : undefined-symbol-error. ( obj -- )
112     "The image refers to a library or symbol that was not found"
113     " at load time" append print drop ;
114
115 : stack-underflow. ( obj name -- )
116     write " stack underflow" print drop ;
117
118 : stack-overflow. ( obj name -- )
119     write " stack overflow" print drop ;
120
121 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
122 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
123 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
124 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
125
126 : memory-error. ( error -- )
127     "Memory protection fault at address " write third .h ;
128
129 : primitive-error. ( error -- ) 
130     "Unimplemented primitive" print drop ;
131
132 PREDICATE: kernel-error < array
133     {
134         { [ dup empty? ] [ drop f ] }
135         { [ dup first "kernel-error" = not ] [ drop f ] }
136         [ second 0 15 between? ]
137     } cond ;
138
139 : kernel-errors ( error -- n errors )
140     second {
141         { 0  [ expired-error.          ] }
142         { 1  [ io-error.               ] }
143         { 2  [ primitive-error.        ] }
144         { 3  [ type-check-error.       ] }
145         { 4  [ divide-by-zero-error.   ] }
146         { 5  [ signal-error.           ] }
147         { 6  [ array-size-error.       ] }
148         { 7  [ c-string-error.         ] }
149         { 8  [ ffi-error.              ] }
150         { 9  [ heap-scan-error.        ] }
151         { 10 [ undefined-symbol-error. ] }
152         { 11 [ datastack-underflow.    ] }
153         { 12 [ datastack-overflow.     ] }
154         { 13 [ retainstack-underflow.  ] }
155         { 14 [ retainstack-overflow.   ] }
156         { 15 [ memory-error.           ] }
157     } ; inline
158
159 M: kernel-error error. dup kernel-errors case ;
160
161 M: kernel-error error-help kernel-errors at first ;
162
163 M: no-method summary
164     drop "No suitable method" ;
165
166 M: no-method error.
167     "Generic word " write
168     dup generic>> pprint
169     " does not define a method for the " write
170     dup object>> class pprint
171     " class." print
172     "Dispatching on object: " write object>> short. ;
173
174 M: bad-slot-value summary drop "Bad store to specialized slot" ;
175
176 M: no-math-method summary
177     drop "No suitable arithmetic method" ;
178
179 M: no-next-method summary
180     drop "Executing call-next-method from least-specific method" ;
181
182 M: inconsistent-next-method summary
183     drop "Executing call-next-method with inconsistent parameters" ;
184
185 M: check-method summary
186     drop "Invalid parameters for create-method" ;
187
188 M: not-a-tuple summary
189     drop "Not a tuple" ;
190
191 M: bad-superclass summary
192     drop "Tuple classes can only inherit from other tuple classes" ;
193
194 M: no-initial-value summary
195     drop "Initial value must be provided for slots specialized to this class" ;
196
197 M: bad-initial-value summary
198     drop "Incompatible initial value" ;
199
200 M: no-cond summary
201     drop "Fall-through in cond" ;
202
203 M: no-case summary
204     drop "Fall-through in case" ;
205
206 M: slice-error error.
207     "Cannot create slice because " write
208     reason>> print ;
209
210 M: bounds-error summary drop "Sequence index out of bounds" ;
211
212 M: condition error. error>> error. ;
213
214 M: condition summary error>> summary ;
215
216 M: condition error-help error>> error-help ;
217
218 M: assert summary drop "Assertion failed" ;
219
220 M: assert error.
221     "Assertion failed" print
222     standard-table-style [
223         15 length-limit set
224         5 line-limit set
225         [ expect>> [ [ "Expect:" write ] with-cell pprint-cell ] with-row ]
226         [ got>> [ [ "Got:" write ] with-cell pprint-cell ] with-row ] bi
227     ] tabular-output ;
228
229 M: immutable summary drop "Sequence is immutable" ;
230
231 M: redefine-error error.
232     "Re-definition of " write
233     def>> . ;
234
235 M: undefined summary
236     drop "Calling a deferred word before it has been defined" ;
237
238 M: no-compilation-unit error.
239     "Attempting to define " write
240     definition>> pprint
241     " outside of a compilation unit" print ;
242
243 M: no-vocab summary
244     drop "Vocabulary does not exist" ;
245
246 M: encode-error summary drop "Character encoding error" ;
247
248 M: decode-error summary drop "Character decoding error" ;
249
250 M: bad-create summary drop "Bad parameters to create" ;
251
252 M: attempt-all-error summary drop "Nothing to attempt" ;
253
254 M: already-disposed summary drop "Attempting to operate on disposed object" ;
255
256 M: no-current-vocab summary
257     drop "Not in a vocabulary; IN: form required" ;
258
259 M: no-word-error summary
260     drop "Word not found in current vocabulary search path" ;
261
262 M: staging-violation summary
263     drop
264     "A parsing word cannot be used in the same file it is defined in." ;
265
266 M: bad-number summary
267     drop "Bad number literal" ;
268
269 M: duplicate-slot-names summary
270     drop "Duplicate slot names" ;
271
272 M: invalid-slot-name summary
273     drop "Invalid slot name" ;
274
275 : file. ( file -- ) path>> <pathname> . ;
276
277 M: source-file-error error.
278     [ file>> file. ] [ error>> error. ] bi ;
279
280 M: source-file-error summary
281     error>> summary ;
282
283 M: source-file-error compute-restarts
284     error>> compute-restarts ;
285
286 M: source-file-error error-help
287     error>> error-help ;
288
289 M: not-in-a-method-error summary
290     drop "call-next-method can only be called in a method definition" ;
291
292 GENERIC: expected>string ( obj -- str )
293
294 M: f expected>string drop "end of input" ;
295 M: word expected>string name>> ;
296 M: string expected>string ;
297
298 M: unexpected error.
299     "Expected " write
300     dup want>> expected>string write
301     " but got " write
302     got>> expected>string print ;
303
304 M: lexer-error error.
305     [ lexer-dump ] [ error>> error. ] bi ;
306
307 M: lexer-error summary
308     error>> summary ;
309
310 M: lexer-error compute-restarts
311     error>> compute-restarts ;
312
313 M: lexer-error error-help
314     error>> error-help ;
315
316 M: object compiler-error. ( error word -- )
317     nl
318     "While compiling " write pprint ": " print
319     nl
320     print-error ;
321
322 M: bad-effect summary
323     drop "Bad stack effect declaration" ;
324
325 M: bad-escape summary drop "Bad escape code" ;