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!CONDITIONS")
18 ;;;; the CONDITION class
20 (eval-when (:compile-toplevel :load-toplevel :execute)
22 (def!struct (condition-class (:include slot-class)
23 (:constructor bare-make-condition-class))
24 ;; list of CONDITION-SLOT structures for the direct slots of this
26 (slots nil :type list)
27 ;; list of CONDITION-SLOT structures for all of the effective class
28 ;; slots of this class
29 (class-slots nil :type list)
30 ;; report function or NIL
31 (report nil :type (or function null))
32 ;; list of alternating initargs and initforms
33 (default-initargs () :type list)
34 ;; class precedence list as a list of class objects, with all
35 ;; non-condition classes removed
37 ;; a list of all the effective instance allocation slots of this
38 ;; class that have a non-constant initform or default-initarg.
39 ;; Values for these slots must be computed in the dynamic
40 ;; environment of MAKE-CONDITION.
41 (hairy-slots nil :type list))
43 (defun make-condition-class (&rest rest)
44 (apply #'bare-make-condition-class
45 (rename-keyword-args '((:name :%name)) rest)))
50 (:constructor make-condition-object (actual-initargs))
51 (:alternate-metaclass instance
57 ;; actual initargs supplied to MAKE-CONDITION
58 (actual-initargs (required-argument) :type list)
59 ;; plist mapping slot names to any values that were assigned or
60 ;; defaulted after creation
61 (assigned-slots () :type list))
63 (defstruct condition-slot
64 (name (required-argument) :type symbol)
65 ;; list of all applicable initargs
66 (initargs (required-argument) :type list)
67 ;; names of reader and writer functions
68 (readers (required-argument) :type list)
69 (writers (required-argument) :type list)
70 ;; true if :INITFORM was specified
71 (initform-p (required-argument) :type (member t nil))
72 ;; If this is a function, call it with no args. Otherwise, it's the
74 (initform (required-argument) :type t)
75 ;; allocation of this slot, or NIL until defaulted
76 (allocation nil :type (member :instance :class nil))
77 ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value.
78 (cell nil :type (or cons null)))
80 (eval-when (#-sb-xc :compile-toplevel :load-toplevel :execute)
81 ;; the appropriate initialization value for the CPL slot of a CONDITION,
82 ;; calculated by looking at the INHERITS information in the LAYOUT
84 (defun condition-class-cpl-from-layout (condition)
85 (declare (type condition condition))
86 (let* ((class (sb!xc:find-class condition))
87 (layout (class-layout class))
88 (superset (map 'list #'identity (layout-inherits layout))))
89 (delete-if (lambda (superclass)
90 (not (typep superclass 'condition-class)))
93 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
94 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
95 ;;; have themselves listed in their CPLs. This behavior is inherited
96 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
97 ;;; figured out whether it's right. -- WHN 19990612
98 (eval-when (:compile-toplevel :load-toplevel :execute)
99 (let ((condition-class (locally
100 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for
101 ;; constant class names which creates fast but
102 ;; non-cold-loadable, non-compact code. In this
103 ;; context, we'd rather have compact, cold-loadable
104 ;; code. -- WHN 19990928
105 (declare (notinline sb!xc:find-class))
106 (sb!xc:find-class 'condition))))
107 (setf (condition-class-cpl condition-class)
108 (list condition-class))))
110 (setf (condition-class-report (locally
111 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM
112 ;; for constant class names which creates fast
113 ;; but non-cold-loadable, non-compact code. In
114 ;; this context, we'd rather have compact,
115 ;; cold-loadable code. -- WHN 19990928
116 (declare (notinline sb!xc:find-class))
117 (find-class 'condition)))
118 #'(lambda (cond stream)
119 (format stream "Condition ~S was signalled." (type-of cond))))
121 (eval-when (:compile-toplevel :load-toplevel :execute)
123 (defun find-condition-layout (name parent-types)
124 (let* ((cpl (remove-duplicates
127 (mapcar #'(lambda (x)
129 (sb!xc:find-class x)))
131 (cond-layout (info :type :compiler-layout 'condition))
132 (olayout (info :type :compiler-layout name))
134 (concatenate 'simple-vector
135 (layout-inherits cond-layout)
136 (mapcar #'class-layout cpl))))
138 (not (mismatch (layout-inherits olayout) new-inherits)))
140 (make-layout :class (make-undefined-class name)
141 :inherits new-inherits
143 :length (layout-length cond-layout)))))
147 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
148 ;;; Condition reporting is mediated through the PRINT-OBJECT method
149 ;;; for the condition type in question, with *PRINT-ESCAPE* always
150 ;;; being nil. Specifying (:REPORT REPORT-NAME) in the definition of
151 ;;; a condition type C is equivalent to:
152 ;;; (defmethod print-object ((x c) stream)
153 ;;; (if *print-escape* (call-next-method) (report-name x stream)))
154 ;;; The current code doesn't seem to quite match that.
155 (def!method print-object ((x condition) stream)
157 (print-unreadable-object (x stream :type t :identity t))
158 ;; KLUDGE: A comment from CMU CL here said
159 ;; 7/13/98 BUG? CPL is not sorted and results here depend on order of
160 ;; superclasses in define-condition call!
161 (dolist (class (condition-class-cpl (sb!xc:class-of x))
162 (error "no REPORT? shouldn't happen!"))
163 (let ((report (condition-class-report class)))
165 (return (funcall report x stream)))))))
167 ;;;; slots of CONDITION objects
169 (defvar *empty-slot* '(empty))
171 (defun find-slot-default (class slot)
172 (let ((initargs (condition-slot-initargs slot))
173 (cpl (condition-class-cpl class)))
175 (let ((default-initargs (condition-class-default-initargs class)))
176 (dolist (initarg initargs)
177 (let ((val (getf default-initargs initarg *empty-slot*)))
178 (unless (eq val *empty-slot*)
179 (return-from find-slot-default
184 (if (condition-slot-initform-p slot)
185 (let ((initform (condition-slot-initform slot)))
186 (if (functionp initform)
189 (error "unbound condition slot: ~S" (condition-slot-name slot)))))
191 (defun find-slot (classes name)
192 (dolist (sclass classes nil)
193 (dolist (slot (condition-class-slots sclass))
194 (when (eq (condition-slot-name slot) name)
195 (return-from find-slot slot)))))
197 (defun condition-writer-function (condition new-value name)
198 (dolist (cslot (condition-class-class-slots
199 (layout-class (%instance-layout condition)))
200 (setf (getf (condition-assigned-slots condition) name)
202 (when (eq (condition-slot-name cslot) name)
203 (return (setf (car (condition-slot-cell cslot)) new-value)))))
205 (defun condition-reader-function (condition name)
206 (let ((class (layout-class (%instance-layout condition))))
207 (dolist (cslot (condition-class-class-slots class))
208 (when (eq (condition-slot-name cslot) name)
209 (return-from condition-reader-function
210 (car (condition-slot-cell cslot)))))
212 (let ((val (getf (condition-assigned-slots condition) name
214 (if (eq val *empty-slot*)
215 (let ((actual-initargs (condition-actual-initargs condition))
216 (slot (find-slot (condition-class-cpl class) name)))
217 (dolist (initarg (condition-slot-initargs slot))
218 (let ((val (getf actual-initargs initarg *empty-slot*)))
219 (unless (eq val *empty-slot*)
220 (return-from condition-reader-function
221 (setf (getf (condition-assigned-slots condition)
224 (setf (getf (condition-assigned-slots condition) name)
225 (find-slot-default class slot)))
230 (defun make-condition (thing &rest args)
232 "Make an instance of a condition object using the specified initargs."
233 ;; Note: ANSI specifies no exceptional situations in this function.
234 ;; signalling simple-type-error would not be wrong.
235 (let* ((thing (if (symbolp thing)
236 (sb!xc:find-class thing)
238 (class (typecase thing
239 (condition-class thing)
241 (error 'simple-type-error
243 :expected-type 'condition-class
244 :format-control "~S is not a condition class."
245 :format-arguments (list thing)))
247 (error 'simple-type-error
249 :expected-type 'condition-class
250 :format-control "bad thing for class argument:~% ~S"
251 :format-arguments (list thing)))))
252 (res (make-condition-object args)))
253 (setf (%instance-layout res) (class-layout class))
254 ;; Set any class slots with initargs present in this call.
255 (dolist (cslot (condition-class-class-slots class))
256 (dolist (initarg (condition-slot-initargs cslot))
257 (let ((val (getf args initarg *empty-slot*)))
258 (unless (eq val *empty-slot*)
259 (setf (car (condition-slot-cell cslot)) val)))))
260 ;; Default any slots with non-constant defaults now.
261 (dolist (hslot (condition-class-hairy-slots class))
262 (when (dolist (initarg (condition-slot-initargs hslot) t)
263 (unless (eq (getf args initarg *empty-slot*) *empty-slot*)
265 (setf (getf (condition-assigned-slots res) (condition-slot-name hslot))
266 (find-slot-default class hslot))))
270 ;;;; DEFINE-CONDITION
272 (eval-when (:compile-toplevel :load-toplevel :execute)
273 (defun %compiler-define-condition (name direct-supers layout)
274 (multiple-value-bind (class old-layout)
275 (insured-find-class name #'condition-class-p #'make-condition-class)
276 (setf (layout-class layout) class)
277 (setf (class-direct-superclasses class)
278 (mapcar #'sb!xc:find-class direct-supers))
279 (cond ((not old-layout)
280 (register-layout layout))
281 ((not *type-system-initialized*)
282 (setf (layout-class old-layout) class)
283 (setq layout old-layout)
284 (unless (eq (class-layout class) layout)
285 (register-layout layout)))
286 ((redefine-layout-warning "current"
289 (layout-length layout)
290 (layout-inherits layout)
291 (layout-depthoid layout))
292 (register-layout layout :invalidate t))
293 ((not (class-layout class))
294 (register-layout layout)))
296 (setf (layout-info layout)
298 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
299 ;; names which creates fast but non-cold-loadable, non-compact
300 ;; code. In this context, we'd rather have compact, cold-loadable
301 ;; code. -- WHN 19990928
302 (declare (notinline sb!xc:find-class))
303 (layout-info (class-layout (sb!xc:find-class 'condition)))))
305 (setf (sb!xc:find-class name) class)
307 ;; Initialize CPL slot from layout.
310 (let ((inherits (layout-inherits layout)))
311 (do ((i (1- (length inherits)) (1- i)))
313 (let ((super (sb!xc:find-class
315 (layout-class (svref inherits i))))))
316 (when (typep super 'condition-class)
318 (setf (condition-class-cpl class) (cpl))))
324 ;;; Compute the effective slots of class, copying inherited slots and
325 ;;; side-effecting direct slots.
326 (defun compute-effective-slots (class)
327 (collect ((res (copy-list (condition-class-slots class))))
328 (dolist (sclass (condition-class-cpl class))
329 (dolist (sslot (condition-class-slots sclass))
330 (let ((found (find (condition-slot-name sslot) (res)
333 (setf (condition-slot-initargs found)
334 (union (condition-slot-initargs found)
335 (condition-slot-initargs sslot)))
336 (unless (condition-slot-initform-p found)
337 (setf (condition-slot-initform-p found)
338 (condition-slot-initform-p sslot))
339 (setf (condition-slot-initform found)
340 (condition-slot-initform sslot)))
341 (unless (condition-slot-allocation found)
342 (setf (condition-slot-allocation found)
343 (condition-slot-allocation sslot))))
345 (res (copy-structure sslot)))))))
348 (defun %define-condition (name slots documentation report default-initargs)
349 (let ((class (sb!xc:find-class name)))
350 (setf (condition-class-slots class) slots)
351 (setf (condition-class-report class) report)
352 (setf (condition-class-default-initargs class) default-initargs)
353 (setf (fdocumentation name 'type) documentation)
357 ;; Set up reader and writer functions.
358 (let ((name (condition-slot-name slot)))
359 (dolist (reader (condition-slot-readers slot))
360 (setf (fdefinition reader)
361 #'(lambda (condition)
362 (condition-reader-function condition name))))
363 (dolist (writer (condition-slot-writers slot))
364 (setf (fdefinition writer)
365 #'(lambda (new-value condition)
366 (condition-writer-function condition new-value name))))))
368 ;; Compute effective slots and set up the class and hairy slots (subsets of
369 ;; the effective slots.)
370 (let ((eslots (compute-effective-slots class))
373 (mapcar #'condition-class-default-initargs
374 (condition-class-cpl class)))))
375 (dolist (slot eslots)
376 (ecase (condition-slot-allocation slot)
378 (unless (condition-slot-cell slot)
379 (setf (condition-slot-cell slot)
380 (list (if (condition-slot-initform-p slot)
381 (let ((initform (condition-slot-initform slot)))
382 (if (functionp initform)
386 (push slot (condition-class-class-slots class)))
388 (setf (condition-slot-allocation slot) :instance)
389 (when (or (functionp (condition-slot-initform slot))
390 (dolist (initarg (condition-slot-initargs slot) nil)
391 (when (functionp (getf e-def-initargs initarg))
393 (push slot (condition-class-hairy-slots class))))))))
396 (defmacro define-condition (name (&rest parent-types) (&rest slot-specs)
399 "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
400 Define NAME as a condition type. This new type inherits slots and its
401 report function from the specified PARENT-TYPEs. A slot spec is a list of:
402 (slot-name :reader <rname> :initarg <iname> {Option Value}*
404 The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
405 and :TYPE and the overall options :DEFAULT-INITARGS and
406 [type] :DOCUMENTATION are also allowed.
408 The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
409 a string or a two-argument lambda or function name. If a function, the
410 function is called with the condition and stream to report the condition.
411 If a string, the string is printed.
413 Condition types are classes, but (as allowed by ANSI and not as described in
414 CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
415 SLOT-VALUE may not be used on condition objects."
416 (let* ((parent-types (or parent-types '(condition)))
417 (layout (find-condition-layout name parent-types))
420 (default-initargs ()))
422 (all-readers nil append)
423 (all-writers nil append))
424 (dolist (spec slot-specs)
425 (when (keywordp spec)
426 (warn "Keyword slot name indicates probable syntax error:~% ~S"
428 (let* ((spec (if (consp spec) spec (list spec)))
429 (slot-name (first spec))
430 (allocation :instance)
436 (do ((options (rest spec) (cddr options)))
438 (unless (and (consp options) (consp (cdr options)))
439 (error "malformed condition slot spec:~% ~S." spec))
440 (let ((arg (second options)))
441 (case (first options)
442 (:reader (readers arg))
443 (:writer (writers arg))
446 (writers `(setf ,arg)))
449 (error "more than one :INITFORM in ~S" spec))
452 (:initarg (initargs arg))
454 (setq allocation arg))
457 (error "unknown slot option:~% ~S" (first options))))))
459 (all-readers (readers))
460 (all-writers (writers))
461 (slots `(make-condition-slot
463 :initargs ',(initargs)
466 :initform-p ',initform-p
468 ,(if (constantp initform)
470 `#'(lambda () ,initform)))))))
472 (dolist (option options)
473 (unless (consp option)
474 (error "bad option:~% ~S" option))
476 (:documentation (setq documentation (second option)))
478 (let ((arg (second option)))
481 `#'(lambda (condition stream)
482 (declare (ignore condition))
483 (write-string ,arg stream))
484 `#'(lambda (condition stream)
485 (funcall #',arg condition stream))))))
487 (do ((initargs (rest option) (cddr initargs)))
489 (let ((val (second initargs)))
490 (setq default-initargs
491 (list* `',(first initargs)
495 default-initargs)))))
497 (error "unknown option: ~S" (first option)))))
500 (warn "Condition slot setters probably not allowed in ANSI CL:~% ~S"
504 (eval-when (:compile-toplevel :load-toplevel :execute)
505 (%compiler-define-condition ',name ',parent-types ',layout))
507 (declaim (ftype (function (t) t) ,@(all-readers)))
508 (declaim (ftype (function (t t) t) ,@(all-writers)))
510 (%define-condition ',name
514 (list ,@default-initargs))))))
516 ;;;; DESCRIBE on CONDITIONs
518 ;;; a function to be used as the guts of DESCRIBE-OBJECT (CONDITION T)
519 ;;; eventually (once we get CLOS up and running so that we can define
521 (defun describe-condition (condition stream)
523 "~@<~S ~_is a ~S. ~_Its slot values are ~_~S.~:>"
527 (condition-actual-initargs condition)
528 (condition-assigned-slots condition))))
530 ;;;; various CONDITIONs specified by ANSI
532 (define-condition serious-condition (condition) ())
534 (define-condition error (serious-condition) ())
536 (define-condition warning (condition) ())
537 (define-condition style-warning (warning) ())
539 (defun simple-condition-printer (condition stream)
540 ;; FIXME: Why use APPLY instead of an ordinary form? To stop the optimizer
541 ;; from doing something?
542 (apply #'format stream (simple-condition-format-control condition)
543 (simple-condition-format-arguments condition)))
545 (define-condition simple-condition ()
546 ((format-control :reader simple-condition-format-control
547 :initarg :format-control)
548 (format-arguments :reader simple-condition-format-arguments
549 :initarg :format-arguments
551 (:report simple-condition-printer))
553 (define-condition simple-warning (simple-condition warning) ())
555 (defun print-simple-error (condition stream)
557 "~&~@<error in function ~S: ~3I~:_~?~:>"
558 (condition-function-name condition)
559 (simple-condition-format-control condition)
560 (simple-condition-format-arguments condition)))
562 (define-condition simple-error (simple-condition error) ()
563 ;; This is the condition type used by ERROR and CERROR when
564 ;; a format-control string is supplied as the first argument.
565 (:report print-simple-error))
567 (define-condition storage-condition (serious-condition) ())
569 ;;; FIXME: Should we really be reporting CONDITION-FUNCTION-NAME data on an
570 ;;; ad hoc basis, for some conditions and not others? Why not standardize
571 ;;; it somehow? perhaps by making the debugger report it?
573 (define-condition type-error (error)
574 ((datum :reader type-error-datum :initarg :datum)
575 (expected-type :reader type-error-expected-type :initarg :expected-type))
577 (lambda (condition stream)
579 "~@<TYPE-ERROR in ~S: ~3I~:_~S is not of type ~S~:>."
580 (condition-function-name condition)
581 (type-error-datum condition)
582 (type-error-expected-type condition)))))
584 (define-condition program-error (error) ())
585 (define-condition parse-error (error) ())
586 (define-condition control-error (error) ())
587 (define-condition stream-error (error)
588 ((stream :reader stream-error-stream :initarg :stream)))
590 (define-condition end-of-file (stream-error) ()
592 (lambda (condition stream)
595 (stream-error-stream condition)))))
597 (define-condition file-error (error)
598 ((pathname :reader file-error-pathname :initarg :pathname))
600 (lambda (condition stream)
602 "~&~@<FILE-ERROR in function ~S: ~3i~:_~?~:>"
603 (condition-function-name condition)
604 (serious-condition-format-control condition)
605 (serious-condition-format-arguments condition)))))
607 (define-condition package-error (error)
608 ((package :reader package-error-package :initarg :package)))
610 (define-condition cell-error (error)
611 ((name :reader cell-error-name :initarg :name)))
613 (define-condition unbound-variable (cell-error) ()
615 (lambda (condition stream)
617 "error in ~S: The variable ~S is unbound."
618 (condition-function-name condition)
619 (cell-error-name condition)))))
621 (define-condition undefined-function (cell-error) ()
623 (lambda (condition stream)
625 "error in ~S: The function ~S is undefined."
626 (condition-function-name condition)
627 (cell-error-name condition)))))
629 (define-condition arithmetic-error (error)
630 ((operation :reader arithmetic-error-operation
633 (operands :reader arithmetic-error-operands
635 (:report (lambda (condition stream)
637 "arithmetic error ~S signalled"
639 (when (arithmetic-error-operation condition)
641 "~%Operation was ~S, operands ~S."
642 (arithmetic-error-operation condition)
643 (arithmetic-error-operands condition))))))
645 (define-condition division-by-zero (arithmetic-error) ())
646 (define-condition floating-point-overflow (arithmetic-error) ())
647 (define-condition floating-point-underflow (arithmetic-error) ())
648 (define-condition floating-point-inexact (arithmetic-error) ())
649 (define-condition floating-point-invalid-operation (arithmetic-error) ())
651 (define-condition print-not-readable (error)
652 ((object :reader print-not-readable-object :initarg :object))
654 (lambda (condition stream)
655 (let ((obj (print-not-readable-object condition))
657 (format stream "~S cannot be printed readably." obj)))))
659 (define-condition reader-error (parse-error stream-error)
660 ;; FIXME: Do we need FORMAT-CONTROL and FORMAT-ARGUMENTS when
661 ;; we have an explicit :REPORT function? I thought we didn't..
663 :reader reader-error-format-control
664 :initarg :format-control)
666 :reader reader-error-format-arguments
667 :initarg :format-arguments
670 (lambda (condition stream)
671 (let ((error-stream (stream-error-stream condition)))
672 (format stream "READER-ERROR ~@[at ~D ~]on ~S:~%~?"
673 (file-position error-stream) error-stream
674 (reader-error-format-control condition)
675 (reader-error-format-arguments condition))))))
677 ;;;; various other (not specified by ANSI) CONDITIONs
679 ;;;; These might logically belong in other files; they're here, after
680 ;;;; setup of CONDITION machinery, only because that makes it easier to
681 ;;;; get cold init to work.
683 ;;; KLUDGE: a condition for floating point errors when we can't or
684 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
685 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
686 ;;; know how but the old code was broken by the conversion to POSIX
687 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
689 ;;; FIXME: Perhaps this should also be a base class for all
690 ;;; floating point exceptions?
691 (define-condition floating-point-exception (arithmetic-error)
692 ((flags :initarg :traps
694 :reader floating-point-exception-traps))
695 (:report (lambda (condition stream)
697 "An arithmetic error ~S was signalled.~%"
699 (let ((traps (floating-point-exception-traps condition)))
702 "Trapping conditions are: ~%~{ ~S~^~}~%"
705 "No traps are enabled? How can this be?"
708 (define-condition index-too-large-error (type-error)
711 (lambda (condition stream)
713 "error in ~S: ~S: index too large"
714 (condition-function-name condition)
715 (type-error-datum condition)))))
717 (define-condition io-timeout (stream-error)
718 ((direction :reader io-timeout-direction :initarg :direction))
720 (lambda (condition stream)
721 (declare (type stream stream))
723 "IO-TIMEOUT ~(~A~)ing ~S"
724 (io-timeout-direction condition)
725 (stream-error-stream condition)))))
727 (define-condition namestring-parse-error (parse-error)
728 ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
729 (arguments :reader namestring-parse-error-arguments :initarg :arguments
731 (namestring :reader namestring-parse-error-namestring :initarg :namestring)
732 (offset :reader namestring-parse-error-offset :initarg :offset))
733 (:report %print-namestring-parse-error))
735 (define-condition simple-package-error (simple-condition package-error) ())
737 (define-condition reader-package-error (reader-error) ())
739 (define-condition reader-eof-error (end-of-file)
740 ((context :reader reader-eof-error-context :initarg :context))
742 (lambda (condition stream)
744 "unexpected EOF on ~S ~A"
745 (stream-error-stream condition)
746 (reader-eof-error-context condition)))))
748 ;;;; restart definitions
750 (define-condition abort-failure (control-error) ()
752 "An ABORT restart was found that failed to transfer control dynamically."))
754 (defun abort (&optional condition)
756 "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
758 (invoke-restart (find-restart 'abort condition))
759 ;; ABORT signals an error in case there was a restart named ABORT that did
760 ;; not transfer control dynamically. This could happen with RESTART-BIND.
761 (error 'abort-failure))
763 (defun muffle-warning (&optional condition)
765 "Transfer control to a restart named MUFFLE-WARNING, signalling a
766 CONTROL-ERROR if none exists."
767 (invoke-restart (find-restart 'muffle-warning condition)))
769 (macrolet ((define-nil-returning-restart (name args doc)
770 #!-sb-doc (declare (ignore doc))
771 `(defun ,name (,@args &optional condition)
773 ;; FIXME: Perhaps this shared logic should be pulled out into
774 ;; FLET MAYBE-INVOKE-RESTART? See whether it shrinks code..
775 (when (find-restart ',name condition)
776 (invoke-restart ',name ,@args)))))
777 (define-nil-returning-restart continue ()
778 "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
779 (define-nil-returning-restart store-value (value)
780 "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
782 (define-nil-returning-restart use-value (value)
783 "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if