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 : signal-error. ( obj -- )
92 "Operating system signal " write third . ;
94 : array-size-error. ( obj -- )
95 "Invalid array size: " write dup third .
96 "Maximum: " write fourth 1- . ;
98 : c-string-error. ( obj -- )
99 "Cannot convert to C string: " write third . ;
101 : ffi-error. ( obj -- )
103 dup third [ write ": " write ] when*
106 : heap-scan-error. ( obj -- )
107 "Cannot do next-object outside begin/end-scan" print drop ;
109 : undefined-symbol-error. ( obj -- )
110 "The image refers to a library or symbol that was not found"
111 " at load time" append print drop ;
113 : stack-underflow. ( obj name -- )
114 write " stack underflow" print drop ;
116 : stack-overflow. ( obj name -- )
117 write " stack overflow" print drop ;
119 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
120 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
121 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
122 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
124 : memory-error. ( error -- )
125 "Memory protection fault at address " write third .h ;
127 : primitive-error. ( error -- )
128 "Unimplemented primitive" print drop ;
130 PREDICATE: kernel-error < array
132 { [ dup empty? ] [ drop f ] }
133 { [ dup first "kernel-error" = not ] [ drop f ] }
134 [ second 0 15 between? ]
137 : kernel-errors ( error -- n errors )
139 { 0 [ expired-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. ] }
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. ] }
157 M: kernel-error error. dup kernel-errors case ;
159 M: kernel-error error-help kernel-errors at first ;
162 drop "No suitable method" ;
165 "Generic word " write
167 " does not define a method for the " write
168 dup object>> class pprint
170 "Dispatching on object: " write object>> short. ;
172 M: bad-slot-value summary drop "Bad store to specialized slot" ;
174 M: no-math-method summary
175 drop "No suitable arithmetic method" ;
177 M: no-next-method summary
178 drop "Executing call-next-method from least-specific method" ;
180 M: inconsistent-next-method summary
181 drop "Executing call-next-method with inconsistent parameters" ;
183 M: check-method summary
184 drop "Invalid parameters for create-method" ;
186 M: not-a-tuple summary
189 M: bad-superclass summary
190 drop "Tuple classes can only inherit from other tuple classes" ;
192 M: no-initial-value summary
193 drop "Initial value must be provided for slots specialized to this class" ;
195 M: bad-initial-value summary
196 drop "Incompatible initial value" ;
199 drop "Fall-through in cond" ;
202 drop "Fall-through in case" ;
204 M: slice-error summary
205 drop "Cannot create slice" ;
207 M: bounds-error summary drop "Sequence index out of bounds" ;
209 M: condition error. error>> error. ;
211 M: condition summary error>> summary ;
213 M: condition error-help error>> error-help ;
215 M: assert summary drop "Assertion failed" ;
217 M: assert-sequence summary drop "Assertion failed" ;
219 M: assert-sequence error.
220 standard-table-style [
221 [ "=== Expected:" print expected>> stack. ]
222 [ "=== Got:" print got>> stack. ] bi
225 M: immutable summary drop "Sequence is immutable" ;
227 M: redefine-error error.
228 "Re-definition of " write
232 drop "Calling a deferred word before it has been defined" ;
234 M: no-compilation-unit error.
235 "Attempting to define " write
237 " outside of a compilation unit" print ;
240 drop "Vocabulary does not exist" ;
242 M: encode-error summary drop "Character encoding error" ;
244 M: decode-error summary drop "Character decoding error" ;
246 M: bad-create summary drop "Bad parameters to create" ;
248 M: attempt-all-error summary drop "Nothing to attempt" ;
250 M: already-disposed summary drop "Attempting to operate on disposed object" ;
252 M: no-current-vocab summary
253 drop "Not in a vocabulary; IN: form required" ;
255 M: no-word-error error.
256 "No word named ``" write name>> write "'' found in current vocabulary search path" print ;
258 M: staging-violation summary
260 "A parsing word cannot be used in the same file it is defined in." ;
262 M: bad-number summary
263 drop "Bad number literal" ;
265 M: duplicate-slot-names summary
266 drop "Duplicate slot names" ;
268 M: invalid-slot-name summary
269 drop "Invalid slot name" ;
271 M: not-in-a-method-error summary
272 drop "call-next-method can only be called in a method definition" ;
274 GENERIC: expected>string ( obj -- str )
276 M: f expected>string drop "end of input" ;
277 M: word expected>string name>> ;
278 M: string expected>string ;
282 dup want>> expected>string write
284 got>> expected>string print ;
286 M: lexer-error error.
287 [ lexer-dump ] [ error>> error. ] bi ;
289 M: lexer-error summary
292 M: lexer-error compute-restarts
293 error>> compute-restarts ;
295 M: lexer-error error-help
298 M: bad-effect summary
299 drop "Bad stack effect declaration" ;
301 M: bad-escape summary drop "Bad escape code" ;
303 M: bad-literal-tuple summary drop "Bad literal tuple" ;
305 M: check-mixin-class summary drop "Not a mixin class" ;
307 M: not-found-in-roots summary drop "Cannot resolve vocab: path" ;
309 M: wrong-values summary drop "Quotation called with wrong stack effect" ;