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
4 kernel math namespaces make prettyprint prettyprint.config
5 sequences assocs sequences.private strings io.styles
6 io.pathnames vectors words system splitting math.parser
7 classes.mixin classes.tuple continuations continuations.private
8 combinators generic.math classes.builtin classes compiler.units
9 generic.standard vocabs init kernel.private io.encodings
10 accessors math.order destructors source-files parser
11 classes.tuple.parser effects.parser lexer
12 generic.parser strings.parser vocabs.loader vocabs.parser see
16 GENERIC: error. ( error -- )
17 GENERIC: error-help ( error -- topic )
20 M: object error-help drop f ;
22 M: tuple error-help class ;
24 M: string error. print ;
27 error-continuation get data>> stack. ;
30 error-continuation get retain>> stack. ;
33 error-continuation get call>> callstack. ;
35 : :get ( variable -- value )
36 error-continuation get name>> assoc-stack ;
39 1- restarts get-global nth f restarts set-global restart ;
41 : :1 ( -- * ) 1 :res ;
42 : :2 ( -- * ) 2 :res ;
43 : :3 ( -- * ) 3 :res ;
45 : restart. ( restart n -- )
47 1+ dup 3 <= [ ":" % # " " % ] [ # " :res " % ] if
54 "The following restarts are available:" print
56 [ restart. ] each-index
59 : print-error ( error -- )
60 [ error. flush ] curry
61 [ global [ "Error in print-error!" print drop ] bind ]
65 error get print-error ;
67 : print-error-and-restarts ( error -- )
71 "Type :help for debugging help." print flush ;
74 [ print-error-and-restarts ] recover ; inline
76 : expired-error. ( obj -- )
77 "Object did not survive image save/load: " write third . ;
79 : io-error. ( error -- )
80 "I/O error: " write third print ;
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 . ;
88 : divide-by-zero-error. ( obj -- )
89 "Division by zero" print drop ;
91 HOOK: signal-error. os ( obj -- )
93 : array-size-error. ( obj -- )
94 "Invalid array size: " write dup third .
95 "Maximum: " write fourth 1- . ;
97 : c-string-error. ( obj -- )
98 "Cannot convert to C string: " write third . ;
100 : ffi-error. ( obj -- )
102 dup third [ write ": " write ] when*
105 : heap-scan-error. ( obj -- )
106 "Cannot do next-object outside begin/end-scan" print drop ;
108 : undefined-symbol-error. ( obj -- )
109 "The image refers to a library or symbol that was not found"
110 " at load time" append print drop ;
112 : stack-underflow. ( obj name -- )
113 write " stack underflow" print drop ;
115 : stack-overflow. ( obj name -- )
116 write " stack overflow" print drop ;
118 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
119 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
120 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
121 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
123 : memory-error. ( error -- )
124 "Memory protection fault at address " write third .h ;
126 : primitive-error. ( error -- )
127 "Unimplemented primitive" print drop ;
129 PREDICATE: vm-error < array
131 { [ dup empty? ] [ drop f ] }
132 { [ dup first "kernel-error" = not ] [ drop f ] }
133 [ second 0 15 between? ]
136 : vm-errors ( error -- n errors )
138 { 0 [ expired-error. ] }
140 { 2 [ primitive-error. ] }
141 { 3 [ type-check-error. ] }
142 { 4 [ divide-by-zero-error. ] }
143 { 5 [ signal-error. ] }
144 { 6 [ array-size-error. ] }
145 { 7 [ c-string-error. ] }
147 { 9 [ heap-scan-error. ] }
148 { 10 [ undefined-symbol-error. ] }
149 { 11 [ datastack-underflow. ] }
150 { 12 [ datastack-overflow. ] }
151 { 13 [ retainstack-underflow. ] }
152 { 14 [ retainstack-overflow. ] }
153 { 15 [ memory-error. ] }
156 M: vm-error summary drop "VM error" ;
158 M: vm-error error. dup vm-errors case ;
160 M: vm-error error-help vm-errors at first ;
163 drop "No suitable method" ;
166 "Generic word " write
168 " does not define a method for the " write
169 dup object>> class pprint
171 "Dispatching on object: " write object>> short. ;
173 M: bad-slot-value summary drop "Bad store to specialized slot" ;
175 M: no-math-method summary
176 drop "No suitable arithmetic method" ;
178 M: no-next-method summary
179 drop "Executing call-next-method from least-specific method" ;
181 M: inconsistent-next-method summary
182 drop "Executing call-next-method with inconsistent parameters" ;
184 M: check-method summary
185 drop "Invalid parameters for create-method" ;
187 M: not-a-tuple summary
190 M: bad-superclass summary
191 drop "Tuple classes can only inherit from other tuple classes" ;
193 M: no-initial-value summary
194 drop "Initial value must be provided for slots specialized to this class" ;
196 M: bad-initial-value summary
197 drop "Incompatible initial value" ;
200 drop "Fall-through in cond" ;
203 drop "Fall-through in case" ;
205 M: slice-error summary
206 drop "Cannot create slice" ;
208 M: bounds-error summary drop "Sequence index out of bounds" ;
210 M: condition error. error>> error. ;
212 M: condition summary error>> summary ;
214 M: condition error-help error>> error-help ;
216 M: assert summary drop "Assertion failed" ;
218 M: assert-sequence summary drop "Assertion failed" ;
220 M: assert-sequence error.
221 standard-table-style [
222 [ "=== Expected:" print expected>> stack. ]
223 [ "=== Got:" print got>> stack. ] bi
226 M: immutable summary drop "Sequence is immutable" ;
228 M: redefine-error error.
229 "Re-definition of " write
233 drop "Calling a deferred word before it has been defined" ;
235 M: no-compilation-unit error.
236 "Attempting to define " write
238 " outside of a compilation unit" print ;
241 drop "Vocabulary does not exist" ;
243 M: encode-error summary drop "Character encoding error" ;
245 M: decode-error summary drop "Character decoding error" ;
247 M: bad-create summary drop "Bad parameters to create" ;
249 M: attempt-all-error summary drop "Nothing to attempt" ;
251 M: already-disposed summary drop "Attempting to operate on disposed object" ;
253 M: no-current-vocab summary
254 drop "Not in a vocabulary; IN: form required" ;
256 M: no-word-error error.
257 "No word named ``" write name>> write "'' found in current vocabulary search path" print ;
259 M: staging-violation summary
261 "A parsing word cannot be used in the same file it is defined in." ;
263 M: bad-number summary
264 drop "Bad number literal" ;
266 M: duplicate-slot-names summary
267 drop "Duplicate slot names" ;
269 M: invalid-slot-name summary
270 drop "Invalid slot name" ;
272 M: not-in-a-method-error summary
273 drop "call-next-method can only be called in a method definition" ;
275 GENERIC: expected>string ( obj -- str )
277 M: f expected>string drop "end of input" ;
278 M: word expected>string name>> ;
279 M: string expected>string ;
283 dup want>> expected>string write
285 got>> expected>string print ;
287 M: lexer-error error.
288 [ lexer-dump ] [ error>> error. ] bi ;
290 M: lexer-error summary
293 M: lexer-error compute-restarts
294 error>> compute-restarts ;
296 M: lexer-error error-help
299 M: bad-effect summary
300 drop "Bad stack effect declaration" ;
302 M: bad-escape summary drop "Bad escape code" ;
304 M: bad-literal-tuple summary drop "Bad literal tuple" ;
306 M: check-mixin-class summary drop "Not a mixin class" ;
308 M: not-found-in-roots summary drop "Cannot resolve vocab: path" ;
310 M: wrong-values summary drop "Quotation called with wrong stack effect" ;
313 { [ os windows? ] [ "debugger.windows" require ] }
314 { [ os unix? ] [ "debugger.unix" require ] }