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