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
15 GENERIC: error. ( error -- )
16 GENERIC: error-help ( error -- topic )
19 M: object error-help drop f ;
21 M: tuple error-help class ;
23 M: string error. print ;
29 error-continuation get data>> stack. ;
32 error-continuation get retain>> stack. ;
35 error-continuation get call>> callstack. ;
37 : :get ( variable -- value )
38 error-continuation get name>> assoc-stack ;
41 1- restarts get-global nth f restarts set-global restart ;
43 : :1 ( -- * ) 1 :res ;
44 : :2 ( -- * ) 2 :res ;
45 : :3 ( -- * ) 3 :res ;
47 : restart. ( restart n -- )
49 1+ dup 3 <= [ ":" % # " " % ] [ # " :res " % ] if
56 "The following restarts are available:" print
58 [ restart. ] each-index
61 : print-error ( error -- )
62 [ error. flush ] curry
63 [ global [ "Error in print-error!" print drop ] bind ]
66 : print-error-and-restarts ( error -- )
70 "Type :help for debugging help." print flush ;
73 [ print-error-and-restarts ] recover ;
75 M: relative-underflow summary
76 drop "Too many items removed from data stack" ;
78 M: relative-overflow summary
79 drop "Superfluous items pushed to data stack" ;
81 : expired-error. ( obj -- )
82 "Object did not survive image save/load: " write third . ;
84 : io-error. ( error -- )
85 "I/O error: " write third print ;
87 : type-check-error. ( obj -- )
88 "Type check error" print
89 "Object: " write dup fourth short.
90 "Object type: " write dup fourth class .
91 "Expected type: " write third type>class . ;
93 : divide-by-zero-error. ( obj -- )
94 "Division by zero" print drop ;
96 : signal-error. ( obj -- )
97 "Operating system signal " write third . ;
99 : array-size-error. ( obj -- )
100 "Invalid array size: " write dup third .
101 "Maximum: " write fourth 1- . ;
103 : c-string-error. ( obj -- )
104 "Cannot convert to C string: " write third . ;
106 : ffi-error. ( obj -- )
108 dup third [ write ": " write ] when*
111 : heap-scan-error. ( obj -- )
112 "Cannot do next-object outside begin/end-scan" print drop ;
114 : undefined-symbol-error. ( obj -- )
115 "The image refers to a library or symbol that was not found"
116 " at load time" append print drop ;
118 : stack-underflow. ( obj name -- )
119 write " stack underflow" print drop ;
121 : stack-overflow. ( obj name -- )
122 write " stack overflow" print drop ;
124 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
125 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
126 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
127 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
129 : memory-error. ( error -- )
130 "Memory protection fault at address " write third .h ;
132 : primitive-error. ( error -- )
133 "Unimplemented primitive" print drop ;
135 PREDICATE: kernel-error < array
137 { [ dup empty? ] [ drop f ] }
138 { [ dup first "kernel-error" = not ] [ drop f ] }
139 [ second 0 15 between? ]
142 : kernel-errors ( error -- n errors )
144 { 0 [ expired-error. ] }
146 { 2 [ primitive-error. ] }
147 { 3 [ type-check-error. ] }
148 { 4 [ divide-by-zero-error. ] }
149 { 5 [ signal-error. ] }
150 { 6 [ array-size-error. ] }
151 { 7 [ c-string-error. ] }
153 { 9 [ heap-scan-error. ] }
154 { 10 [ undefined-symbol-error. ] }
155 { 11 [ datastack-underflow. ] }
156 { 12 [ datastack-overflow. ] }
157 { 13 [ retainstack-underflow. ] }
158 { 14 [ retainstack-overflow. ] }
159 { 15 [ memory-error. ] }
162 M: kernel-error error. dup kernel-errors case ;
164 M: kernel-error error-help kernel-errors at first ;
167 drop "No suitable method" ;
170 "Generic word " write
172 " does not define a method for the " write
173 dup object>> class pprint
175 "Dispatching on object: " write object>> short. ;
177 M: bad-slot-value summary drop "Bad store to specialized slot" ;
179 M: no-math-method summary
180 drop "No suitable arithmetic method" ;
182 M: no-next-method summary
183 drop "Executing call-next-method from least-specific method" ;
185 M: inconsistent-next-method summary
186 drop "Executing call-next-method with inconsistent parameters" ;
188 M: check-method summary
189 drop "Invalid parameters for create-method" ;
191 M: not-a-tuple summary
194 M: bad-superclass summary
195 drop "Tuple classes can only inherit from other tuple classes" ;
197 M: no-initial-value summary
198 drop "Initial value must be provided for slots specialized to this class" ;
200 M: bad-initial-value summary
201 drop "Incompatible initial value" ;
204 drop "Fall-through in cond" ;
207 drop "Fall-through in case" ;
209 M: slice-error error.
210 "Cannot create slice because " write
213 M: bounds-error summary drop "Sequence index out of bounds" ;
215 M: condition error. error>> error. ;
217 M: condition summary error>> summary ;
219 M: condition error-help error>> error-help ;
221 M: assert summary drop "Assertion failed" ;
224 "Assertion failed" print
225 standard-table-style [
228 [ expect>> [ [ "Expect:" write ] with-cell pprint-cell ] with-row ]
229 [ got>> [ [ "Got:" write ] with-cell pprint-cell ] with-row ] bi
232 M: immutable summary drop "Sequence is immutable" ;
234 M: redefine-error error.
235 "Re-definition of " write
239 drop "Calling a deferred word before it has been defined" ;
241 M: no-compilation-unit error.
242 "Attempting to define " write
244 " outside of a compilation unit" print ;
247 drop "Vocabulary does not exist" ;
249 M: encode-error summary drop "Character encoding error" ;
251 M: decode-error summary drop "Character decoding error" ;
253 M: bad-create summary drop "Bad parameters to create" ;
255 M: attempt-all-error summary drop "Nothing to attempt" ;
257 M: already-disposed summary drop "Attempting to operate on disposed object" ;
259 M: no-current-vocab summary
260 drop "Not in a vocabulary; IN: form required" ;
262 M: no-word-error summary
263 drop "Word not found in current vocabulary search path" ;
265 M: staging-violation summary
267 "A parsing word cannot be used in the same file it is defined in." ;
269 M: bad-number summary
270 drop "Bad number literal" ;
272 M: duplicate-slot-names summary
273 drop "Duplicate slot names" ;
275 M: invalid-slot-name summary
276 drop "Invalid slot name" ;
278 : file. ( file -- ) path>> <pathname> . ;
280 M: source-file-error error.
281 [ file>> file. ] [ error>> error. ] bi ;
283 M: source-file-error summary
286 M: source-file-error compute-restarts
287 error>> compute-restarts ;
289 M: source-file-error error-help
292 M: not-in-a-method-error summary
293 drop "call-next-method can only be called in a method definition" ;
295 GENERIC: expected>string ( obj -- str )
297 M: f expected>string drop "end of input" ;
298 M: word expected>string name>> ;
299 M: string expected>string ;
303 dup want>> expected>string write
305 got>> expected>string print ;
307 M: lexer-error error.
308 [ lexer-dump ] [ error>> error. ] bi ;
310 M: lexer-error summary
313 M: lexer-error compute-restarts
314 error>> compute-restarts ;
316 M: lexer-error error-help
319 M: object compiler-error. ( error word -- )
321 "While compiling " write pprint ": " print
325 M: bad-effect summary
326 drop "Bad stack effect declaration" ;
328 M: bad-escape summary drop "Bad escape code" ;
330 M: bad-literal-tuple summary drop "Bad literal tuple" ;