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
15 GENERIC: error. ( error -- )
16 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 . ;
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 -- )
101 "FFI error" print drop ;
103 : heap-scan-error. ( obj -- )
104 "Cannot do next-object outside begin/end-scan" print drop ;
106 : undefined-symbol-error. ( obj -- )
107 "The image refers to a library or symbol that was not found at load time"
110 : stack-underflow. ( obj name -- )
111 write " stack underflow" print drop ;
113 : stack-overflow. ( obj name -- )
114 write " stack overflow" print drop ;
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. ;
121 : memory-error. ( error -- )
122 "Memory protection fault at address " write third .h ;
124 : primitive-error. ( error -- )
125 "Unimplemented primitive" print drop ;
127 PREDICATE: vm-error < array
129 { [ dup empty? ] [ drop f ] }
130 { [ dup first "kernel-error" = not ] [ drop f ] }
131 [ second 0 15 between? ]
134 : vm-errors ( error -- n errors )
136 { 0 [ expired-error. ] }
138 { 2 [ primitive-error. ] }
139 { 3 [ type-check-error. ] }
140 { 4 [ divide-by-zero-error. ] }
141 { 5 [ signal-error. ] }
142 { 6 [ array-size-error. ] }
143 { 7 [ c-string-error. ] }
145 { 9 [ heap-scan-error. ] }
146 { 10 [ undefined-symbol-error. ] }
147 { 11 [ datastack-underflow. ] }
148 { 12 [ datastack-overflow. ] }
149 { 13 [ retainstack-underflow. ] }
150 { 14 [ retainstack-overflow. ] }
151 { 15 [ memory-error. ] }
154 M: vm-error summary drop "VM error" ;
156 M: vm-error error. dup vm-errors case ;
158 M: vm-error error-help vm-errors at first ;
161 drop "No suitable method" ;
164 "Generic word " write
166 " does not define a method for the " write
167 dup object>> class pprint
169 "Dispatching on object: " write object>> short. ;
171 M: bad-slot-value summary drop "Bad store to specialized slot" ;
173 M: no-math-method summary
174 drop "No suitable arithmetic method" ;
176 M: no-next-method summary
177 drop "Executing call-next-method from least-specific method" ;
179 M: inconsistent-next-method summary
180 drop "Executing call-next-method with inconsistent parameters" ;
182 M: check-method summary
183 drop "Invalid parameters for create-method" ;
185 M: not-a-tuple summary
188 M: bad-superclass summary
189 drop "Tuple classes can only inherit from other tuple classes" ;
191 M: no-initial-value summary
192 drop "Initial value must be provided for slots specialized to this class" ;
194 M: bad-initial-value summary
195 drop "Incompatible initial value" ;
198 drop "Fall-through in cond" ;
201 drop "Fall-through in case" ;
203 M: slice-error summary
204 drop "Cannot create slice" ;
206 M: bounds-error summary drop "Sequence index out of bounds" ;
208 M: condition error. error>> error. ;
210 M: condition summary error>> summary ;
212 M: condition error-help error>> error-help ;
214 M: assert summary drop "Assertion failed" ;
216 M: assert-sequence summary drop "Assertion failed" ;
218 M: assert-sequence error.
219 standard-table-style [
220 [ "=== Expected:" print expected>> stack. ]
221 [ "=== Got:" print got>> stack. ] bi
224 M: immutable summary drop "Sequence is immutable" ;
226 M: redefine-error error.
227 "Re-definition of " write
231 drop "Calling a deferred word before it has been defined" ;
233 M: no-compilation-unit error.
234 "Attempting to define " write
236 " outside of a compilation unit" print ;
239 drop "Vocabulary does not exist" ;
241 M: encode-error summary drop "Character encoding error" ;
243 M: decode-error summary drop "Character decoding error" ;
245 M: bad-create summary drop "Bad parameters to create" ;
247 M: attempt-all-error summary drop "Nothing to attempt" ;
249 M: already-disposed summary drop "Attempting to operate on disposed object" ;
251 M: no-current-vocab summary
252 drop "Not in a vocabulary; IN: form required" ;
254 M: no-word-error summary
257 "'' found in current vocabulary search path" surround ;
259 M: no-word-error error. summary print ;
261 M: ambiguous-use-error summary
263 "More than one vocabulary defines a word named ``" "''" surround ;
265 M: ambiguous-use-error error. summary print ;
267 M: staging-violation summary
269 "A parsing word cannot be used in the same file it is defined in." ;
271 M: bad-number summary
272 drop "Bad number literal" ;
274 M: duplicate-slot-names summary
275 drop "Duplicate slot names" ;
277 M: invalid-slot-name summary
278 drop "Invalid slot name" ;
280 M: not-in-a-method-error summary
281 drop "call-next-method can only be called in a method definition" ;
283 GENERIC: expected>string ( obj -- str )
285 M: f expected>string drop "end of input" ;
286 M: word expected>string name>> ;
287 M: string expected>string ;
291 dup want>> expected>string write
293 got>> expected>string print ;
295 M: lexer-error error.
296 [ lexer-dump ] [ error>> error. ] bi ;
298 M: lexer-error summary
301 M: lexer-error compute-restarts
302 error>> compute-restarts ;
304 M: lexer-error error-help
307 M: bad-effect summary
308 drop "Bad stack effect declaration" ;
310 M: bad-escape summary drop "Bad escape code" ;
312 M: bad-literal-tuple summary drop "Bad literal tuple" ;
314 M: check-mixin-class summary drop "Not a mixin class" ;
316 M: not-found-in-roots summary drop "Cannot resolve vocab: path" ;
318 M: wrong-values summary drop "Quotation called with wrong stack effect" ;
321 { [ os windows? ] [ "debugger.windows" require ] }
322 { [ os unix? ] [ "debugger.unix" require ] }