1 ;;;; stuff originally from CMU CL's error.lisp which can or should
2 ;;;; come late (mostly related to the CONDITION class itself)
4 ;;;; FIXME: should perhaps be called condition.lisp, or moved into
7 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; This software is derived from the CMU CL system, which was
11 ;;;; written at Carnegie Mellon University and released into the
12 ;;;; public domain. The software is in the public domain and is
13 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
14 ;;;; files for more information.
16 (in-package "SB!KERNEL")
18 ;;;; the CONDITION class
20 (/show0 "condition.lisp 20")
22 (eval-when (:compile-toplevel :load-toplevel :execute)
24 (/show0 "condition.lisp 24")
26 (def!struct (condition-class (:include slot-class)
27 (:constructor bare-make-condition-class))
28 ;; list of CONDITION-SLOT structures for the direct slots of this
30 (slots nil :type list)
31 ;; list of CONDITION-SLOT structures for all of the effective class
32 ;; slots of this class
33 (class-slots nil :type list)
34 ;; report function or NIL
35 (report nil :type (or function null))
36 ;; list of alternating initargs and initforms
37 (default-initargs () :type list)
38 ;; class precedence list as a list of CLASS objects, with all
39 ;; non-CONDITION classes removed
41 ;; a list of all the effective instance allocation slots of this
42 ;; class that have a non-constant initform or default-initarg.
43 ;; Values for these slots must be computed in the dynamic
44 ;; environment of MAKE-CONDITION.
45 (hairy-slots nil :type list))
47 (/show0 "condition.lisp 49")
49 (defun make-condition-class (&rest rest)
50 (apply #'bare-make-condition-class
51 (rename-key-args '((:name :%name)) rest)))
53 (/show0 "condition.lisp 53")
57 (!defstruct-with-alternate-metaclass condition
58 :slot-names (actual-initargs assigned-slots)
59 :boa-constructor %make-condition-object
60 :superclass-name instance
61 :metaclass-name condition-class
62 :metaclass-constructor make-condition-class
65 (defun make-condition-object (actual-initargs)
66 (%make-condition-object actual-initargs nil))
68 (defstruct (condition-slot (:copier nil))
69 (name (missing-arg) :type symbol)
70 ;; list of all applicable initargs
71 (initargs (missing-arg) :type list)
72 ;; names of reader and writer functions
73 (readers (missing-arg) :type list)
74 (writers (missing-arg) :type list)
75 ;; true if :INITFORM was specified
76 (initform-p (missing-arg) :type (member t nil))
77 ;; If this is a function, call it with no args. Otherwise, it's the
79 (initform (missing-arg) :type t)
80 ;; allocation of this slot, or NIL until defaulted
81 (allocation nil :type (member :instance :class nil))
82 ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value.
83 (cell nil :type (or cons null)))
85 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
86 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
87 ;;; have themselves listed in their CPLs. This behavior is inherited
88 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
89 ;;; figured out whether it's right. -- WHN 19990612
90 (eval-when (:compile-toplevel :load-toplevel :execute)
91 (/show0 "condition.lisp 103")
92 (let ((condition-class (locally
93 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for
94 ;; constant class names which creates fast but
95 ;; non-cold-loadable, non-compact code. In this
96 ;; context, we'd rather have compact, cold-loadable
97 ;; code. -- WHN 19990928
98 (declare (notinline sb!xc:find-class))
99 (sb!xc:find-class 'condition))))
100 (setf (condition-class-cpl condition-class)
101 (list condition-class)))
102 (/show0 "condition.lisp 103"))
104 (setf (condition-class-report (locally
105 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM
106 ;; for constant class names which creates fast
107 ;; but non-cold-loadable, non-compact code. In
108 ;; this context, we'd rather have compact,
109 ;; cold-loadable code. -- WHN 19990928
110 (declare (notinline sb!xc:find-class))
111 (find-class 'condition)))
112 #'(lambda (cond stream)
113 (format stream "Condition ~S was signalled." (type-of cond))))
115 (eval-when (:compile-toplevel :load-toplevel :execute)
117 (defun find-condition-layout (name parent-types)
118 (let* ((cpl (remove-duplicates
121 (mapcar #'(lambda (x)
123 (sb!xc:find-class x)))
125 (cond-layout (info :type :compiler-layout 'condition))
126 (olayout (info :type :compiler-layout name))
127 ;; FIXME: Does this do the right thing in case of multiple
128 ;; inheritance? A quick look at DEFINE-CONDITION didn't make
129 ;; it obvious what ANSI intends to be done in the case of
130 ;; multiple inheritance, so it's not actually clear what the
133 (order-layout-inherits (concatenate 'simple-vector
134 (layout-inherits cond-layout)
135 (mapcar #'class-layout cpl)))))
137 (not (mismatch (layout-inherits olayout) new-inherits)))
139 (make-layout :class (make-undefined-class name)
140 :inherits new-inherits
142 :length (layout-length cond-layout)))))
146 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
147 ;;; Condition reporting is mediated through the PRINT-OBJECT method
148 ;;; for the condition type in question, with *PRINT-ESCAPE* always
149 ;;; being nil. Specifying (:REPORT REPORT-NAME) in the definition of
150 ;;; a condition type C is equivalent to:
151 ;;; (defmethod print-object ((x c) stream)
152 ;;; (if *print-escape* (call-next-method) (report-name x stream)))
153 ;;; The current code doesn't seem to quite match that.
154 (def!method print-object ((x condition) stream)
156 (print-unreadable-object (x stream :type t :identity t))
157 ;; KLUDGE: A comment from CMU CL here said
158 ;; 7/13/98 BUG? CPL is not sorted and results here depend on order of
159 ;; superclasses in define-condition call!
160 (dolist (class (condition-class-cpl (sb!xc:class-of x))
161 (error "no REPORT? shouldn't happen!"))
162 (let ((report (condition-class-report class)))
164 (return (funcall report x stream)))))))
166 ;;;; slots of CONDITION objects
168 (defvar *empty-condition-slot* '(empty))
170 (defun find-slot-default (class slot)
171 (let ((initargs (condition-slot-initargs slot))
172 (cpl (condition-class-cpl class)))
174 (let ((default-initargs (condition-class-default-initargs class)))
175 (dolist (initarg initargs)
176 (let ((val (getf default-initargs initarg *empty-condition-slot*)))
177 (unless (eq val *empty-condition-slot*)
178 (return-from find-slot-default
183 (if (condition-slot-initform-p slot)
184 (let ((initform (condition-slot-initform slot)))
185 (if (functionp initform)
188 (error "unbound condition slot: ~S" (condition-slot-name slot)))))
190 (defun find-condition-class-slot (condition-class slot-name)
192 (condition-class-cpl condition-class)
193 (error "There is no slot named ~S in ~S."
194 slot-name condition-class))
195 (dolist (slot (condition-class-slots sclass))
196 (when (eq (condition-slot-name slot) slot-name)
197 (return-from find-condition-class-slot slot)))))
199 (defun condition-writer-function (condition new-value name)
200 (dolist (cslot (condition-class-class-slots
201 (layout-class (%instance-layout condition)))
202 (setf (getf (condition-assigned-slots condition) name)
204 (when (eq (condition-slot-name cslot) name)
205 (return (setf (car (condition-slot-cell cslot)) new-value)))))
207 (defun condition-reader-function (condition name)
208 (let ((class (layout-class (%instance-layout condition))))
209 (dolist (cslot (condition-class-class-slots class))
210 (when (eq (condition-slot-name cslot) name)
211 (return-from condition-reader-function
212 (car (condition-slot-cell cslot)))))
214 (let ((val (getf (condition-assigned-slots condition) name
215 *empty-condition-slot*)))
216 (if (eq val *empty-condition-slot*)
217 (let ((actual-initargs (condition-actual-initargs condition))
218 (slot (find-condition-class-slot class name)))
220 (error "missing slot ~S of ~S" name condition))
221 (dolist (initarg (condition-slot-initargs slot))
222 (let ((val (getf actual-initargs
224 *empty-condition-slot*)))
225 (unless (eq val *empty-condition-slot*)
226 (return-from condition-reader-function
227 (setf (getf (condition-assigned-slots condition)
230 (setf (getf (condition-assigned-slots condition) name)
231 (find-slot-default class slot)))
236 (defun make-condition (thing &rest args)
238 "Make an instance of a condition object using the specified initargs."
239 ;; Note: ANSI specifies no exceptional situations in this function.
240 ;; signalling simple-type-error would not be wrong.
241 (let* ((thing (if (symbolp thing)
242 (sb!xc:find-class thing)
244 (class (typecase thing
245 (condition-class thing)
247 (error 'simple-type-error
249 :expected-type 'condition-class
250 :format-control "~S is not a condition class."
251 :format-arguments (list thing)))
253 (error 'simple-type-error
255 :expected-type 'condition-class
256 :format-control "bad thing for class argument:~% ~S"
257 :format-arguments (list thing)))))
258 (res (make-condition-object args)))
259 (setf (%instance-layout res) (class-layout class))
260 ;; Set any class slots with initargs present in this call.
261 (dolist (cslot (condition-class-class-slots class))
262 (dolist (initarg (condition-slot-initargs cslot))
263 (let ((val (getf args initarg *empty-condition-slot*)))
264 (unless (eq val *empty-condition-slot*)
265 (setf (car (condition-slot-cell cslot)) val)))))
266 ;; Default any slots with non-constant defaults now.
267 (dolist (hslot (condition-class-hairy-slots class))
268 (when (dolist (initarg (condition-slot-initargs hslot) t)
269 (unless (eq (getf args initarg *empty-condition-slot*)
270 *empty-condition-slot*)
272 (setf (getf (condition-assigned-slots res) (condition-slot-name hslot))
273 (find-slot-default class hslot))))
277 ;;;; DEFINE-CONDITION
279 (eval-when (:compile-toplevel :load-toplevel :execute)
280 (defun %compiler-define-condition (name direct-supers layout)
281 (multiple-value-bind (class old-layout)
282 (insured-find-class name #'condition-class-p #'make-condition-class)
283 (setf (layout-class layout) class)
284 (setf (class-direct-superclasses class)
285 (mapcar #'sb!xc:find-class direct-supers))
286 (cond ((not old-layout)
287 (register-layout layout))
288 ((not *type-system-initialized*)
289 (setf (layout-class old-layout) class)
290 (setq layout old-layout)
291 (unless (eq (class-layout class) layout)
292 (register-layout layout)))
293 ((redefine-layout-warning "current"
296 (layout-length layout)
297 (layout-inherits layout)
298 (layout-depthoid layout))
299 (register-layout layout :invalidate t))
300 ((not (class-layout class))
301 (register-layout layout)))
303 (setf (layout-info layout)
305 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
306 ;; names which creates fast but non-cold-loadable, non-compact
307 ;; code. In this context, we'd rather have compact, cold-loadable
308 ;; code. -- WHN 19990928
309 (declare (notinline sb!xc:find-class))
310 (layout-info (class-layout (sb!xc:find-class 'condition)))))
312 (setf (sb!xc:find-class name) class)
314 ;; Initialize CPL slot.
315 (setf (condition-class-cpl class)
316 (remove-if-not #'condition-class-p
317 (std-compute-class-precedence-list class))))
322 ;;; Compute the effective slots of CLASS, copying inherited slots and
323 ;;; destructively modifying direct slots.
325 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
326 ;;; direct slots. Presumably it follows from the semantics of
327 ;;; inheritance and redefinition of conditions, but finding the cite
328 ;;; and documenting it here would be good. (Or, if this is not in fact
329 ;;; ANSI-compliant, fixing it would also be good.:-)
330 (defun compute-effective-slots (class)
331 (collect ((res (copy-list (condition-class-slots class))))
332 (dolist (sclass (condition-class-cpl class))
333 (dolist (sslot (condition-class-slots sclass))
334 (let ((found (find (condition-slot-name sslot) (res))))
336 (setf (condition-slot-initargs found)
337 (union (condition-slot-initargs found)
338 (condition-slot-initargs sslot)))
339 (unless (condition-slot-initform-p found)
340 (setf (condition-slot-initform-p found)
341 (condition-slot-initform-p sslot))
342 (setf (condition-slot-initform found)
343 (condition-slot-initform sslot)))
344 (unless (condition-slot-allocation found)
345 (setf (condition-slot-allocation found)
346 (condition-slot-allocation sslot))))
348 (res (copy-structure sslot)))))))
351 (defun %define-condition (name slots documentation report default-initargs)
352 (let ((class (sb!xc:find-class name)))
353 (setf (condition-class-slots class) slots)
354 (setf (condition-class-report class) report)
355 (setf (condition-class-default-initargs class) default-initargs)
356 (setf (fdocumentation name 'type) documentation)
360 ;; Set up reader and writer functions.
361 (let ((name (condition-slot-name slot)))
362 (dolist (reader (condition-slot-readers slot))
363 (setf (fdefinition reader)
364 #'(lambda (condition)
365 (condition-reader-function condition name))))
366 (dolist (writer (condition-slot-writers slot))
367 (setf (fdefinition writer)
368 #'(lambda (new-value condition)
369 (condition-writer-function condition new-value name))))))
371 ;; Compute effective slots and set up the class and hairy slots
372 ;; (subsets of the effective slots.)
373 (let ((eslots (compute-effective-slots class))
376 (mapcar #'condition-class-default-initargs
377 (condition-class-cpl class)))))
378 (dolist (slot eslots)
379 (ecase (condition-slot-allocation slot)
381 (unless (condition-slot-cell slot)
382 (setf (condition-slot-cell slot)
383 (list (if (condition-slot-initform-p slot)
384 (let ((initform (condition-slot-initform slot)))
385 (if (functionp initform)
388 *empty-condition-slot*))))
389 (push slot (condition-class-class-slots class)))
391 (setf (condition-slot-allocation slot) :instance)
392 (when (or (functionp (condition-slot-initform slot))
393 (dolist (initarg (condition-slot-initargs slot) nil)
394 (when (functionp (getf e-def-initargs initarg))
396 (push slot (condition-class-hairy-slots class))))))))
399 (defmacro define-condition (name (&rest parent-types) (&rest slot-specs)
402 "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
403 Define NAME as a condition type. This new type inherits slots and its
404 report function from the specified PARENT-TYPEs. A slot spec is a list of:
405 (slot-name :reader <rname> :initarg <iname> {Option Value}*
407 The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
408 and :TYPE and the overall options :DEFAULT-INITARGS and
409 [type] :DOCUMENTATION are also allowed.
411 The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
412 a string or a two-argument lambda or function name. If a function, the
413 function is called with the condition and stream to report the condition.
414 If a string, the string is printed.
416 Condition types are classes, but (as allowed by ANSI and not as described in
417 CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
418 SLOT-VALUE may not be used on condition objects."
419 (let* ((parent-types (or parent-types '(condition)))
420 (layout (find-condition-layout name parent-types))
423 (default-initargs ()))
425 (all-readers nil append)
426 (all-writers nil append))
427 (dolist (spec slot-specs)
428 (when (keywordp spec)
429 (warn "Keyword slot name indicates probable syntax error:~% ~S"
431 (let* ((spec (if (consp spec) spec (list spec)))
432 (slot-name (first spec))
433 (allocation :instance)
439 (do ((options (rest spec) (cddr options)))
441 (unless (and (consp options) (consp (cdr options)))
442 (error "malformed condition slot spec:~% ~S." spec))
443 (let ((arg (second options)))
444 (case (first options)
445 (:reader (readers arg))
446 (:writer (writers arg))
449 (writers `(setf ,arg)))
452 (error "more than one :INITFORM in ~S" spec))
455 (:initarg (initargs arg))
457 (setq allocation arg))
460 (error "unknown slot option:~% ~S" (first options))))))
462 (all-readers (readers))
463 (all-writers (writers))
464 (slots `(make-condition-slot
466 :initargs ',(initargs)
469 :initform-p ',initform-p
471 ,(if (constantp initform)
473 `#'(lambda () ,initform)))))))
475 (dolist (option options)
476 (unless (consp option)
477 (error "bad option:~% ~S" option))
479 (:documentation (setq documentation (second option)))
481 (let ((arg (second option)))
484 `#'(lambda (condition stream)
485 (declare (ignore condition))
486 (write-string ,arg stream))
487 `#'(lambda (condition stream)
488 (funcall #',arg condition stream))))))
490 (do ((initargs (rest option) (cddr initargs)))
492 (let ((val (second initargs)))
493 (setq default-initargs
494 (list* `',(first initargs)
498 default-initargs)))))
500 (error "unknown option: ~S" (first option)))))
503 (warn "Condition slot setters probably not allowed in ANSI CL:~% ~S"
507 (eval-when (:compile-toplevel :load-toplevel :execute)
508 (%compiler-define-condition ',name ',parent-types ',layout))
510 (declaim (ftype (function (t) t) ,@(all-readers)))
511 (declaim (ftype (function (t t) t) ,@(all-writers)))
513 (%define-condition ',name
517 (list ,@default-initargs))))))
519 ;;;; DESCRIBE on CONDITIONs
521 ;;; a function to be used as the guts of DESCRIBE-OBJECT (CONDITION T)
522 ;;; eventually (once we get CLOS up and running so that we can define
524 (defun describe-condition (condition stream)
526 "~@<~S ~_is a ~S. ~_Its slot values are ~_~S.~:>"
530 (condition-actual-initargs condition)
531 (condition-assigned-slots condition))))
533 ;;;; various CONDITIONs specified by ANSI
535 (define-condition serious-condition (condition) ())
537 (define-condition error (serious-condition) ())
539 (define-condition warning (condition) ())
540 (define-condition style-warning (warning) ())
542 (defun simple-condition-printer (condition stream)
545 (simple-condition-format-control condition)
546 (simple-condition-format-arguments condition)))
548 (define-condition simple-condition ()
549 ((format-control :reader simple-condition-format-control
550 :initarg :format-control)
551 (format-arguments :reader simple-condition-format-arguments
552 :initarg :format-arguments
554 (:report simple-condition-printer))
556 (define-condition simple-warning (simple-condition warning) ())
558 (define-condition simple-error (simple-condition error) ())
560 (define-condition storage-condition (serious-condition) ())
562 (define-condition type-error (error)
563 ((datum :reader type-error-datum :initarg :datum)
564 (expected-type :reader type-error-expected-type :initarg :expected-type))
566 (lambda (condition stream)
568 "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
569 (type-error-datum condition)
570 (type-error-expected-type condition)))))
572 (define-condition simple-type-error (simple-condition type-error) ())
574 (define-condition program-error (error) ())
575 (define-condition parse-error (error) ())
576 (define-condition control-error (error) ())
577 (define-condition stream-error (error)
578 ((stream :reader stream-error-stream :initarg :stream)))
580 (define-condition end-of-file (stream-error) ()
582 (lambda (condition stream)
585 (stream-error-stream condition)))))
587 (define-condition file-error (error)
588 ((pathname :reader file-error-pathname :initarg :pathname))
590 (lambda (condition stream)
592 "~@<error on file ~_~S: ~2I~:_~?~:>"
593 (file-error-pathname condition)
594 ;; FIXME: ANSI's FILE-ERROR doesn't have FORMAT-CONTROL and
595 ;; FORMAT-ARGUMENTS, and the inheritance here doesn't seem
596 ;; to give us FORMAT-CONTROL or FORMAT-ARGUMENTS either.
597 ;; So how does this work?
598 (serious-condition-format-control condition)
599 (serious-condition-format-arguments condition)))))
601 (define-condition package-error (error)
602 ((package :reader package-error-package :initarg :package)))
604 (define-condition cell-error (error)
605 ((name :reader cell-error-name :initarg :name)))
607 (define-condition unbound-variable (cell-error) ()
609 (lambda (condition stream)
611 "The variable ~S is unbound."
612 (cell-error-name condition)))))
614 (define-condition undefined-function (cell-error) ()
616 (lambda (condition stream)
618 "The function ~S is undefined."
619 (cell-error-name condition)))))
621 (define-condition arithmetic-error (error)
622 ((operation :reader arithmetic-error-operation
625 (operands :reader arithmetic-error-operands
627 (:report (lambda (condition stream)
629 "arithmetic error ~S signalled"
631 (when (arithmetic-error-operation condition)
633 "~%Operation was ~S, operands ~S."
634 (arithmetic-error-operation condition)
635 (arithmetic-error-operands condition))))))
637 (define-condition division-by-zero (arithmetic-error) ())
638 (define-condition floating-point-overflow (arithmetic-error) ())
639 (define-condition floating-point-underflow (arithmetic-error) ())
640 (define-condition floating-point-inexact (arithmetic-error) ())
641 (define-condition floating-point-invalid-operation (arithmetic-error) ())
643 (define-condition print-not-readable (error)
644 ((object :reader print-not-readable-object :initarg :object))
646 (lambda (condition stream)
647 (let ((obj (print-not-readable-object condition))
649 (format stream "~S cannot be printed readably." obj)))))
651 (define-condition reader-error (parse-error stream-error)
653 :reader reader-error-format-control
654 :initarg :format-control)
656 :reader reader-error-format-arguments
657 :initarg :format-arguments
660 (lambda (condition stream)
661 (let ((error-stream (stream-error-stream condition)))
662 (format stream "READER-ERROR ~@[at ~D ~]on ~S:~%~?"
663 (file-position error-stream) error-stream
664 (reader-error-format-control condition)
665 (reader-error-format-arguments condition))))))
667 ;;;; various other (not specified by ANSI) CONDITIONs
669 ;;;; These might logically belong in other files; they're here, after
670 ;;;; setup of CONDITION machinery, only because that makes it easier to
671 ;;;; get cold init to work.
673 ;;; KLUDGE: a condition for floating point errors when we can't or
674 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
675 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
676 ;;; know how but the old code was broken by the conversion to POSIX
677 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
679 ;;; FIXME: Perhaps this should also be a base class for all
680 ;;; floating point exceptions?
681 (define-condition floating-point-exception (arithmetic-error)
682 ((flags :initarg :traps
684 :reader floating-point-exception-traps))
685 (:report (lambda (condition stream)
687 "An arithmetic error ~S was signalled.~%"
689 (let ((traps (floating-point-exception-traps condition)))
692 "Trapping conditions are: ~%~{ ~S~^~}~%"
695 "No traps are enabled? How can this be?"
698 (define-condition index-too-large-error (type-error)
701 (lambda (condition stream)
703 "The index ~S is too large."
704 (type-error-datum condition)))))
706 (define-condition io-timeout (stream-error)
707 ((direction :reader io-timeout-direction :initarg :direction))
709 (lambda (condition stream)
710 (declare (type stream stream))
712 "I/O timeout ~(~A~)ing ~S"
713 (io-timeout-direction condition)
714 (stream-error-stream condition)))))
716 (define-condition namestring-parse-error (parse-error)
717 ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
718 (arguments :reader namestring-parse-error-arguments :initarg :arguments
720 (namestring :reader namestring-parse-error-namestring :initarg :namestring)
721 (offset :reader namestring-parse-error-offset :initarg :offset))
723 (lambda (condition stream)
725 "parse error in namestring: ~?~% ~A~% ~V@T^"
726 (namestring-parse-error-complaint condition)
727 (namestring-parse-error-arguments condition)
728 (namestring-parse-error-namestring condition)
729 (namestring-parse-error-offset condition)))))
731 (define-condition simple-package-error (simple-condition package-error) ())
733 (define-condition reader-package-error (reader-error) ())
735 (define-condition reader-eof-error (end-of-file)
736 ((context :reader reader-eof-error-context :initarg :context))
738 (lambda (condition stream)
740 "unexpected end of file on ~S ~A"
741 (stream-error-stream condition)
742 (reader-eof-error-context condition)))))
744 ;;;; restart definitions
746 (define-condition abort-failure (control-error) ()
748 "An ABORT restart was found that failed to transfer control dynamically."))
750 (defun abort (&optional condition)
752 "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
754 (invoke-restart (find-restart 'abort condition))
755 ;; ABORT signals an error in case there was a restart named ABORT
756 ;; that did not transfer control dynamically. This could happen with
758 (error 'abort-failure))
760 (defun muffle-warning (&optional condition)
762 "Transfer control to a restart named MUFFLE-WARNING, signalling a
763 CONTROL-ERROR if none exists."
764 (invoke-restart (find-restart 'muffle-warning condition)))
766 (macrolet ((define-nil-returning-restart (name args doc)
767 #!-sb-doc (declare (ignore doc))
768 `(defun ,name (,@args &optional condition)
770 ;; FIXME: Perhaps this shared logic should be pulled out into
771 ;; FLET MAYBE-INVOKE-RESTART? See whether it shrinks code..
772 (when (find-restart ',name condition)
773 (invoke-restart ',name ,@args)))))
774 (define-nil-returning-restart continue ()
775 "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
776 (define-nil-returning-restart store-value (value)
777 "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
779 (define-nil-returning-restart use-value (value)
780 "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if
783 (/show0 "condition.lisp end of file")