0.9.2.43:
[sbcl.git] / src / code / condition.lisp
1 ;;;; stuff originally from CMU CL's error.lisp which can or should
2 ;;;; come late (mostly related to the CONDITION class itself)
3 ;;;;
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
13
14 (in-package "SB!KERNEL")
15 \f
16 ;;;; miscellaneous support utilities
17
18 ;;; Signalling an error when trying to print an error condition is
19 ;;; generally a PITA, so whatever the failure encountered when
20 ;;; wondering about FILE-POSITION within a condition printer, 'tis
21 ;;; better silently to give up than to try to complain.
22 (defun file-position-or-nil-for-error (stream &optional (pos nil posp))
23   ;; Arguably FILE-POSITION shouldn't be signalling errors at all; but
24   ;; "NIL if this cannot be determined" in the ANSI spec doesn't seem
25   ;; absolutely unambiguously to prohibit errors when, e.g., STREAM
26   ;; has been closed so that FILE-POSITION is a nonsense question. So
27   ;; my (WHN) impression is that the conservative approach is to
28   ;; IGNORE-ERRORS. (I encountered this failure from within a homebrew
29   ;; defsystemish operation where the ERROR-STREAM had been CL:CLOSEd,
30   ;; I think by nonlocally exiting through a WITH-OPEN-FILE, by the
31   ;; time an error was reported.)
32   (if posp
33       (ignore-errors (file-position stream pos))
34       (ignore-errors (file-position stream))))
35 \f
36 ;;;; the CONDITION class
37
38 (/show0 "condition.lisp 20")
39
40 (eval-when (:compile-toplevel :load-toplevel :execute)
41
42 (/show0 "condition.lisp 24")
43
44 (def!struct (condition-classoid (:include slot-classoid)
45                                 (:constructor make-condition-classoid))
46   ;; list of CONDITION-SLOT structures for the direct slots of this
47   ;; class
48   (slots nil :type list)
49   ;; list of CONDITION-SLOT structures for all of the effective class
50   ;; slots of this class
51   (class-slots nil :type list)
52   ;; report function or NIL
53   (report nil :type (or function null))
54   ;; list of alternating initargs and initforms
55   (default-initargs () :type list)
56   ;; class precedence list as a list of CLASS objects, with all
57   ;; non-CONDITION classes removed
58   (cpl () :type list)
59   ;; a list of all the effective instance allocation slots of this
60   ;; class that have a non-constant initform or default-initarg.
61   ;; Values for these slots must be computed in the dynamic
62   ;; environment of MAKE-CONDITION.
63   (hairy-slots nil :type list))
64
65 (/show0 "condition.lisp 49")
66
67 ) ; EVAL-WHEN
68
69 (!defstruct-with-alternate-metaclass condition
70   :slot-names (actual-initargs assigned-slots)
71   :boa-constructor %make-condition-object
72   :superclass-name instance
73   :metaclass-name condition-classoid
74   :metaclass-constructor make-condition-classoid
75   :dd-type structure)
76
77 (defun make-condition-object (actual-initargs)
78   (%make-condition-object actual-initargs nil))
79
80 (defstruct (condition-slot (:copier nil))
81   (name (missing-arg) :type symbol)
82   ;; list of all applicable initargs
83   (initargs (missing-arg) :type list)
84   ;; names of reader and writer functions
85   (readers (missing-arg) :type list)
86   (writers (missing-arg) :type list)
87   ;; true if :INITFORM was specified
88   (initform-p (missing-arg) :type (member t nil))
89   ;; If this is a function, call it with no args. Otherwise, it's the
90   ;; actual value.
91   (initform (missing-arg) :type t)
92   ;; allocation of this slot, or NIL until defaulted
93   (allocation nil :type (member :instance :class nil))
94   ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value.
95   (cell nil :type (or cons null))
96   ;; slot documentation
97   (documentation nil :type (or string null)))
98
99 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
100 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
101 ;;; have themselves listed in their CPLs. This behavior is inherited
102 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
103 ;;; figured out whether it's right. -- WHN 19990612
104 (eval-when (:compile-toplevel :load-toplevel :execute)
105   (/show0 "condition.lisp 103")
106   (let ((condition-class (locally
107                            ;; KLUDGE: There's a DEFTRANSFORM
108                            ;; FIND-CLASSOID for constant class names
109                            ;; which creates fast but
110                            ;; non-cold-loadable, non-compact code. In
111                            ;; this context, we'd rather have compact,
112                            ;; cold-loadable code. -- WHN 19990928
113                            (declare (notinline find-classoid))
114                            (find-classoid 'condition))))
115     (setf (condition-classoid-cpl condition-class)
116           (list condition-class)))
117   (/show0 "condition.lisp 103"))
118
119 (setf (condition-classoid-report (locally
120                                    ;; KLUDGE: There's a DEFTRANSFORM
121                                    ;; FIND-CLASSOID for constant class
122                                    ;; names which creates fast but
123                                    ;; non-cold-loadable, non-compact
124                                    ;; code. In this context, we'd
125                                    ;; rather have compact,
126                                    ;; cold-loadable code. -- WHN
127                                    ;; 19990928
128                                    (declare (notinline find-classoid))
129                                    (find-classoid 'condition)))
130       (lambda (cond stream)
131         (format stream "Condition ~S was signalled." (type-of cond))))
132
133 (eval-when (:compile-toplevel :load-toplevel :execute)
134
135 (defun find-condition-layout (name parent-types)
136   (let* ((cpl (remove-duplicates
137                (reverse
138                 (reduce #'append
139                         (mapcar (lambda (x)
140                                   (condition-classoid-cpl
141                                    (find-classoid x)))
142                                 parent-types)))))
143          (cond-layout (info :type :compiler-layout 'condition))
144          (olayout (info :type :compiler-layout name))
145          ;; FIXME: Does this do the right thing in case of multiple
146          ;; inheritance? A quick look at DEFINE-CONDITION didn't make
147          ;; it obvious what ANSI intends to be done in the case of
148          ;; multiple inheritance, so it's not actually clear what the
149          ;; right thing is..
150          (new-inherits
151           (order-layout-inherits (concatenate 'simple-vector
152                                               (layout-inherits cond-layout)
153                                               (mapcar #'classoid-layout cpl)))))
154     (if (and olayout
155              (not (mismatch (layout-inherits olayout) new-inherits)))
156         olayout
157         (make-layout :classoid (make-undefined-classoid name)
158                      :inherits new-inherits
159                      :depthoid -1
160                      :length (layout-length cond-layout)))))
161
162 ) ; EVAL-WHEN
163
164 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
165 ;;;   Condition reporting is mediated through the PRINT-OBJECT method
166 ;;;   for the condition type in question, with *PRINT-ESCAPE* always
167 ;;;   being nil. Specifying (:REPORT REPORT-NAME) in the definition of
168 ;;;   a condition type C is equivalent to:
169 ;;;     (defmethod print-object ((x c) stream)
170 ;;;       (if *print-escape* (call-next-method) (report-name x stream)))
171 ;;; The current code doesn't seem to quite match that.
172 (def!method print-object ((x condition) stream)
173   (if *print-escape*
174       (print-unreadable-object (x stream :type t :identity t))
175       ;; KLUDGE: A comment from CMU CL here said
176       ;;   7/13/98 BUG? CPL is not sorted and results here depend on order of
177       ;;   superclasses in define-condition call!
178       (dolist (class (condition-classoid-cpl (classoid-of x))
179                      (error "no REPORT? shouldn't happen!"))
180         (let ((report (condition-classoid-report class)))
181           (when report
182             (return (funcall report x stream)))))))
183 \f
184 ;;;; slots of CONDITION objects
185
186 (defvar *empty-condition-slot* '(empty))
187
188 (defun find-slot-default (class slot)
189   (let ((initargs (condition-slot-initargs slot))
190         (cpl (condition-classoid-cpl class)))
191     (dolist (class cpl)
192       (let ((default-initargs (condition-classoid-default-initargs class)))
193         (dolist (initarg initargs)
194           (let ((val (getf default-initargs initarg *empty-condition-slot*)))
195             (unless (eq val *empty-condition-slot*)
196               (return-from find-slot-default
197                            (if (functionp val)
198                                (funcall val)
199                                val)))))))
200
201     (if (condition-slot-initform-p slot)
202         (let ((initform (condition-slot-initform slot)))
203           (if (functionp initform)
204               (funcall initform)
205               initform))
206         (error "unbound condition slot: ~S" (condition-slot-name slot)))))
207
208 (defun find-condition-class-slot (condition-class slot-name)
209   (dolist (sclass
210            (condition-classoid-cpl condition-class)
211            (error "There is no slot named ~S in ~S."
212                   slot-name condition-class))
213     (dolist (slot (condition-classoid-slots sclass))
214       (when (eq (condition-slot-name slot) slot-name)
215         (return-from find-condition-class-slot slot)))))
216
217 (defun condition-writer-function (condition new-value name)
218   (dolist (cslot (condition-classoid-class-slots
219                   (layout-classoid (%instance-layout condition)))
220                  (setf (getf (condition-assigned-slots condition) name)
221                        new-value))
222     (when (eq (condition-slot-name cslot) name)
223       (return (setf (car (condition-slot-cell cslot)) new-value)))))
224
225 (defun condition-reader-function (condition name)
226   (let ((class (layout-classoid (%instance-layout condition))))
227     (dolist (cslot (condition-classoid-class-slots class))
228       (when (eq (condition-slot-name cslot) name)
229         (return-from condition-reader-function
230                      (car (condition-slot-cell cslot)))))
231     (let ((val (getf (condition-assigned-slots condition) name
232                      *empty-condition-slot*)))
233       (if (eq val *empty-condition-slot*)
234           (let ((actual-initargs (condition-actual-initargs condition))
235                 (slot (find-condition-class-slot class name)))
236             (unless slot
237               (error "missing slot ~S of ~S" name condition))
238             (do ((initargs actual-initargs (cddr initargs)))
239                 ((endp initargs)
240                  (setf (getf (condition-assigned-slots condition) name)
241                        (find-slot-default class slot)))
242               (when (member (car initargs) (condition-slot-initargs slot))
243                 (return-from condition-reader-function
244                   (setf (getf (condition-assigned-slots condition)
245                               name)
246                         (cadr initargs))))))
247           val))))
248 \f
249 ;;;; MAKE-CONDITION
250
251 (defun make-condition (type &rest args)
252   #!+sb-doc
253   "Make an instance of a condition object using the specified initargs."
254   ;; Note: ANSI specifies no exceptional situations in this function.
255   ;; signalling simple-type-error would not be wrong.
256   (let* ((type (or (and (symbolp type) (find-classoid type nil))
257                     type))
258          (class (typecase type
259                   (condition-classoid type)
260                   (class
261                    ;; Punt to CLOS.
262                    (return-from make-condition (apply #'make-instance type args)))
263                   (classoid
264                    (error 'simple-type-error
265                           :datum type
266                           :expected-type 'condition-class
267                           :format-control "~S is not a condition class."
268                           :format-arguments (list type)))
269                   (t
270                    (error 'simple-type-error
271                           :datum type
272                           :expected-type 'condition-class
273                           :format-control "Bad type argument:~%  ~S"
274                           :format-arguments (list type)))))
275          (res (make-condition-object args)))
276     (setf (%instance-layout res) (classoid-layout class))
277     ;; Set any class slots with initargs present in this call.
278     (dolist (cslot (condition-classoid-class-slots class))
279       (dolist (initarg (condition-slot-initargs cslot))
280         (let ((val (getf args initarg *empty-condition-slot*)))
281           (unless (eq val *empty-condition-slot*)
282             (setf (car (condition-slot-cell cslot)) val)))))
283     ;; Default any slots with non-constant defaults now.
284     (dolist (hslot (condition-classoid-hairy-slots class))
285       (when (dolist (initarg (condition-slot-initargs hslot) t)
286               (unless (eq (getf args initarg *empty-condition-slot*)
287                           *empty-condition-slot*)
288                 (return nil)))
289         (setf (getf (condition-assigned-slots res) (condition-slot-name hslot))
290               (find-slot-default class hslot))))
291     res))
292 \f
293 ;;;; DEFINE-CONDITION
294
295 (eval-when (:compile-toplevel :load-toplevel :execute)
296 (defun %compiler-define-condition (name direct-supers layout
297                                    all-readers all-writers)
298   (with-single-package-locked-error
299       (:symbol name "defining ~A as a condition")
300     (sb!xc:proclaim `(ftype (function (t) t) ,@all-readers))
301     (sb!xc:proclaim `(ftype (function (t t) t) ,@all-writers))
302     (multiple-value-bind (class old-layout)
303         (insured-find-classoid name
304                                #'condition-classoid-p
305                                #'make-condition-classoid)
306       (setf (layout-classoid layout) class)
307       (setf (classoid-direct-superclasses class)
308             (mapcar #'find-classoid direct-supers))
309       (cond ((not old-layout)
310              (register-layout layout))
311             ((not *type-system-initialized*)
312              (setf (layout-classoid old-layout) class)
313              (setq layout old-layout)
314              (unless (eq (classoid-layout class) layout)
315                (register-layout layout)))
316             ((redefine-layout-warning "current"
317                                       old-layout
318                                       "new"
319                                       (layout-length layout)
320                                       (layout-inherits layout)
321                                       (layout-depthoid layout)
322                                       (layout-n-untagged-slots layout))
323              (register-layout layout :invalidate t))
324             ((not (classoid-layout class))
325              (register-layout layout)))
326
327       (setf (layout-info layout)
328             (locally
329                 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
330                 ;; names which creates fast but non-cold-loadable, non-compact
331                 ;; code. In this context, we'd rather have compact, cold-loadable
332                 ;; code. -- WHN 19990928
333                 (declare (notinline find-classoid))
334               (layout-info (classoid-layout (find-classoid 'condition)))))
335
336       (setf (find-classoid name) class)
337
338       ;; Initialize CPL slot.
339       (setf (condition-classoid-cpl class)
340             (remove-if-not #'condition-classoid-p
341                            (std-compute-class-precedence-list class)))))
342   (values))
343 ) ; EVAL-WHEN
344
345 ;;; Compute the effective slots of CLASS, copying inherited slots and
346 ;;; destructively modifying direct slots.
347 ;;;
348 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
349 ;;; direct slots. Presumably it follows from the semantics of
350 ;;; inheritance and redefinition of conditions, but finding the cite
351 ;;; and documenting it here would be good. (Or, if this is not in fact
352 ;;; ANSI-compliant, fixing it would also be good.:-)
353 (defun compute-effective-slots (class)
354   (collect ((res (copy-list (condition-classoid-slots class))))
355     (dolist (sclass (cdr (condition-classoid-cpl class)))
356       (dolist (sslot (condition-classoid-slots sclass))
357         (let ((found (find (condition-slot-name sslot) (res)
358                            :key #'condition-slot-name)))
359           (cond (found
360                  (setf (condition-slot-initargs found)
361                        (union (condition-slot-initargs found)
362                               (condition-slot-initargs sslot)))
363                  (unless (condition-slot-initform-p found)
364                    (setf (condition-slot-initform-p found)
365                          (condition-slot-initform-p sslot))
366                    (setf (condition-slot-initform found)
367                          (condition-slot-initform sslot)))
368                  (unless (condition-slot-allocation found)
369                    (setf (condition-slot-allocation found)
370                          (condition-slot-allocation sslot))))
371                 (t
372                  (res (copy-structure sslot)))))))
373     (res)))
374
375 ;;; Early definitions of slot accessor creators.
376 ;;;
377 ;;; Slot accessors must be generic functions, but ANSI does not seem
378 ;;; to specify any of them, and we cannot support it before end of
379 ;;; warm init. So we use ordinary functions inside SBCL, and switch to
380 ;;; GFs only at the end of building.
381 (declaim (notinline install-condition-slot-reader
382                     install-condition-slot-writer))
383 (defun install-condition-slot-reader (name condition slot-name)
384   (declare (ignore condition))
385   (setf (fdefinition name)
386         (lambda (condition)
387           (condition-reader-function condition slot-name))))
388 (defun install-condition-slot-writer (name condition slot-name)
389   (declare (ignore condition))
390   (setf (fdefinition name)
391         (lambda (new-value condition)
392           (condition-writer-function condition new-value slot-name))))
393
394 (defun %define-condition (name parent-types layout slots documentation
395                           report default-initargs all-readers all-writers)
396   (with-single-package-locked-error
397       (:symbol name "defining ~A as a condition")
398     (%compiler-define-condition name parent-types layout all-readers all-writers)
399     (let ((class (find-classoid name)))
400       (setf (condition-classoid-slots class) slots)
401       (setf (condition-classoid-report class) report)
402       (setf (condition-classoid-default-initargs class) default-initargs)
403       (setf (fdocumentation name 'type) documentation)
404
405       (dolist (slot slots)
406
407         ;; Set up reader and writer functions.
408         (let ((slot-name (condition-slot-name slot)))
409           (dolist (reader (condition-slot-readers slot))
410             (install-condition-slot-reader reader name slot-name))
411           (dolist (writer (condition-slot-writers slot))
412             (install-condition-slot-writer writer name slot-name))))
413
414       ;; Compute effective slots and set up the class and hairy slots
415       ;; (subsets of the effective slots.)
416       (let ((eslots (compute-effective-slots class))
417             (e-def-initargs
418              (reduce #'append
419                      (mapcar #'condition-classoid-default-initargs
420                            (condition-classoid-cpl class)))))
421         (dolist (slot eslots)
422           (ecase (condition-slot-allocation slot)
423             (:class
424              (unless (condition-slot-cell slot)
425                (setf (condition-slot-cell slot)
426                      (list (if (condition-slot-initform-p slot)
427                                (let ((initform (condition-slot-initform slot)))
428                                  (if (functionp initform)
429                                      (funcall initform)
430                                      initform))
431                                *empty-condition-slot*))))
432              (push slot (condition-classoid-class-slots class)))
433             ((:instance nil)
434              (setf (condition-slot-allocation slot) :instance)
435              (when (or (functionp (condition-slot-initform slot))
436                        (dolist (initarg (condition-slot-initargs slot) nil)
437                          (when (functionp (getf e-def-initargs initarg))
438                            (return t))))
439                (push slot (condition-classoid-hairy-slots class))))))))
440     name))
441
442 (defmacro define-condition (name (&rest parent-types) (&rest slot-specs)
443                                  &body options)
444   #!+sb-doc
445   "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
446    Define NAME as a condition type. This new type inherits slots and its
447    report function from the specified PARENT-TYPEs. A slot spec is a list of:
448      (slot-name :reader <rname> :initarg <iname> {Option Value}*
449
450    The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
451    and :TYPE and the overall options :DEFAULT-INITARGS and
452    [type] :DOCUMENTATION are also allowed.
453
454    The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
455    a string or a two-argument lambda or function name. If a function, the
456    function is called with the condition and stream to report the condition.
457    If a string, the string is printed.
458
459    Condition types are classes, but (as allowed by ANSI and not as described in
460    CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
461    SLOT-VALUE may not be used on condition objects."
462   (let* ((parent-types (or parent-types '(condition)))
463          (layout (find-condition-layout name parent-types))
464          (documentation nil)
465          (report nil)
466          (default-initargs ()))
467     (collect ((slots)
468               (all-readers nil append)
469               (all-writers nil append))
470       (dolist (spec slot-specs)
471         (when (keywordp spec)
472           (warn "Keyword slot name indicates probable syntax error:~%  ~S"
473                 spec))
474         (let* ((spec (if (consp spec) spec (list spec)))
475                (slot-name (first spec))
476                (allocation :instance)
477                (initform-p nil)
478                documentation
479                initform)
480           (collect ((initargs)
481                     (readers)
482                     (writers))
483             (do ((options (rest spec) (cddr options)))
484                 ((null options))
485               (unless (and (consp options) (consp (cdr options)))
486                 (error "malformed condition slot spec:~%  ~S." spec))
487               (let ((arg (second options)))
488                 (case (first options)
489                   (:reader (readers arg))
490                   (:writer (writers arg))
491                   (:accessor
492                    (readers arg)
493                    (writers `(setf ,arg)))
494                   (:initform
495                    (when initform-p
496                      (error "more than one :INITFORM in ~S" spec))
497                    (setq initform-p t)
498                    (setq initform arg))
499                   (:initarg (initargs arg))
500                   (:allocation
501                    (setq allocation arg))
502                   (:documentation
503                    (when documentation
504                      (error "more than one :DOCUMENTATION in ~S" spec))
505                    (unless (stringp arg)
506                      (error "slot :DOCUMENTATION argument is not a string: ~S"
507                             arg))
508                    (setq documentation arg))
509                   (:type)
510                   (t
511                    (error "unknown slot option:~%  ~S" (first options))))))
512
513             (all-readers (readers))
514             (all-writers (writers))
515             (slots `(make-condition-slot
516                      :name ',slot-name
517                      :initargs ',(initargs)
518                      :readers ',(readers)
519                      :writers ',(writers)
520                      :initform-p ',initform-p
521                      :documentation ',documentation
522                      :initform
523                      ,(if (constantp initform)
524                           `',(eval initform)
525                           `#'(lambda () ,initform)))))))
526
527       (dolist (option options)
528         (unless (consp option)
529           (error "bad option:~%  ~S" option))
530         (case (first option)
531           (:documentation (setq documentation (second option)))
532           (:report
533            (let ((arg (second option)))
534              (setq report
535                    (if (stringp arg)
536                        `#'(lambda (condition stream)
537                           (declare (ignore condition))
538                           (write-string ,arg stream))
539                        `#'(lambda (condition stream)
540                           (funcall #',arg condition stream))))))
541           (:default-initargs
542            (do ((initargs (rest option) (cddr initargs)))
543                ((endp initargs))
544              (let ((val (second initargs)))
545                (setq default-initargs
546                      (list* `',(first initargs)
547                             (if (constantp val)
548                                 `',(eval val)
549                                 `#'(lambda () ,val))
550                             default-initargs)))))
551           (t
552            (error "unknown option: ~S" (first option)))))
553
554       `(progn
555          (eval-when (:compile-toplevel)
556            (%compiler-define-condition ',name ',parent-types ',layout
557                                        ',(all-readers) ',(all-writers)))
558          (eval-when (:load-toplevel :execute)
559            (%define-condition ',name
560                               ',parent-types
561                               ',layout
562                               (list ,@(slots))
563                               ,documentation
564                               ,report
565                               (list ,@default-initargs)
566                               ',(all-readers)
567                               ',(all-writers)))))))
568 \f
569 ;;;; DESCRIBE on CONDITIONs
570
571 ;;; a function to be used as the guts of DESCRIBE-OBJECT (CONDITION T)
572 ;;; eventually (once we get CLOS up and running so that we can define
573 ;;; methods)
574 (defun describe-condition (condition stream)
575   (format stream
576           "~&~@<~S ~_is a ~S. ~_Its slot values are ~_~S.~:>~%"
577           condition
578           (type-of condition)
579           (concatenate 'list
580                        (condition-actual-initargs condition)
581                        (condition-assigned-slots condition))))
582 \f
583 ;;;; various CONDITIONs specified by ANSI
584
585 (define-condition serious-condition (condition) ())
586
587 (define-condition error (serious-condition) ())
588
589 (define-condition warning (condition) ())
590 (define-condition style-warning (warning) ())
591
592 (defun simple-condition-printer (condition stream)
593   (apply #'format
594          stream
595          (simple-condition-format-control condition)
596          (simple-condition-format-arguments condition)))
597
598 (define-condition simple-condition ()
599   ((format-control :reader simple-condition-format-control
600                    :initarg :format-control
601                    :type format-control)
602    (format-arguments :reader simple-condition-format-arguments
603                      :initarg :format-arguments
604                      :initform '()
605                      :type list))
606   (:report simple-condition-printer))
607
608 (define-condition simple-warning (simple-condition warning) ())
609
610 (define-condition simple-error (simple-condition error) ())
611
612 ;;; not specified by ANSI, but too useful not to have around.
613 (define-condition simple-style-warning (simple-condition style-warning) ())
614
615 (define-condition storage-condition (serious-condition) ())
616
617 (define-condition type-error (error)
618   ((datum :reader type-error-datum :initarg :datum)
619    (expected-type :reader type-error-expected-type :initarg :expected-type))
620   (:report
621    (lambda (condition stream)
622      (format stream
623              "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
624              (type-error-datum condition)
625              (type-error-expected-type condition)))))
626
627 (define-condition simple-type-error (simple-condition type-error) ())
628
629 (define-condition program-error (error) ())
630 (define-condition parse-error   (error) ())
631 (define-condition control-error (error) ())
632 (define-condition stream-error  (error)
633   ((stream :reader stream-error-stream :initarg :stream)))
634
635 (define-condition end-of-file (stream-error) ()
636   (:report
637    (lambda (condition stream)
638      (format stream
639              "end of file on ~S"
640              (stream-error-stream condition)))))
641
642 (define-condition file-error (error)
643   ((pathname :reader file-error-pathname :initarg :pathname))
644   (:report
645    (lambda (condition stream)
646      (format stream "error on file ~S" (file-error-pathname condition)))))
647
648 (define-condition package-error (error)
649   ((package :reader package-error-package :initarg :package)))
650
651 (define-condition cell-error (error)
652   ((name :reader cell-error-name :initarg :name)))
653
654 (def!method print-object ((condition cell-error) stream)
655   (if (and *print-escape* (slot-boundp condition 'name))
656       (print-unreadable-object (condition stream :type t :identity t)
657         (princ (cell-error-name condition) stream))
658       (call-next-method)))
659
660 (define-condition unbound-variable (cell-error) ()
661   (:report
662    (lambda (condition stream)
663      (format stream
664              "The variable ~S is unbound."
665              (cell-error-name condition)))))
666
667 (define-condition undefined-function (cell-error) ()
668   (:report
669    (lambda (condition stream)
670      (format stream
671              "The function ~S is undefined."
672              (cell-error-name condition)))))
673
674 (define-condition special-form-function (undefined-function) ()
675   (:report
676    (lambda (condition stream)
677      (format stream
678              "Cannot FUNCALL the SYMBOL-FUNCTION of special operator ~S."
679              (cell-error-name condition)))))
680
681 (define-condition arithmetic-error (error)
682   ((operation :reader arithmetic-error-operation
683               :initarg :operation
684               :initform nil)
685    (operands :reader arithmetic-error-operands
686              :initarg :operands))
687   (:report (lambda (condition stream)
688              (format stream
689                      "arithmetic error ~S signalled"
690                      (type-of condition))
691              (when (arithmetic-error-operation condition)
692                (format stream
693                        "~%Operation was ~S, operands ~S."
694                        (arithmetic-error-operation condition)
695                        (arithmetic-error-operands condition))))))
696
697 (define-condition division-by-zero         (arithmetic-error) ())
698 (define-condition floating-point-overflow  (arithmetic-error) ())
699 (define-condition floating-point-underflow (arithmetic-error) ())
700 (define-condition floating-point-inexact   (arithmetic-error) ())
701 (define-condition floating-point-invalid-operation (arithmetic-error) ())
702
703 (define-condition print-not-readable (error)
704   ((object :reader print-not-readable-object :initarg :object))
705   (:report
706    (lambda (condition stream)
707      (let ((obj (print-not-readable-object condition))
708            (*print-array* nil))
709        (format stream "~S cannot be printed readably." obj)))))
710
711 (define-condition reader-error (parse-error stream-error)
712   ((format-control
713     :reader reader-error-format-control
714     :initarg :format-control)
715    (format-arguments
716     :reader reader-error-format-arguments
717     :initarg :format-arguments
718     :initform '()))
719   (:report
720    (lambda (condition stream)
721      (let* ((error-stream (stream-error-stream condition))
722             (pos (file-position-or-nil-for-error error-stream)))
723        (let (lineno colno)
724          (when (and pos
725                     (< pos sb!xc:array-dimension-limit)
726                     ;; KLUDGE: lseek() (which is what FILE-POSITION
727                     ;; reduces to on file-streams) is undefined on
728                     ;; "some devices", which in practice means that it
729                     ;; can claim to succeed on /dev/stdin on Darwin
730                     ;; and Solaris.  This is obviously bad news,
731                     ;; because the READ-SEQUENCE below will then
732                     ;; block, not complete, and the report will never
733                     ;; be printed.  As a workaround, we exclude
734                     ;; interactive streams from this attempt to report
735                     ;; positions.  -- CSR, 2003-08-21
736                     (not (interactive-stream-p error-stream))
737                     (file-position error-stream :start))
738            (let ((string
739                   (make-string pos
740                                :element-type (stream-element-type
741                                               error-stream))))
742              (when (= pos (read-sequence string error-stream))
743                (setq lineno (1+ (count #\Newline string))
744                      colno (- pos
745                               (or (position #\Newline string :from-end t) -1)
746                               1))))
747            (file-position-or-nil-for-error error-stream pos))
748          (format stream
749                  "READER-ERROR ~@[at ~W ~]~
750                   ~@[(line ~W~]~@[, column ~W) ~]~
751                   on ~S:~%~?"
752                  pos lineno colno error-stream
753                  (reader-error-format-control condition)
754                  (reader-error-format-arguments condition)))))))
755 \f
756 ;;;; special SBCL extension conditions
757
758 ;;; an error apparently caused by a bug in SBCL itself
759 ;;;
760 ;;; Note that we don't make any serious effort to use this condition
761 ;;; for *all* errors in SBCL itself. E.g. type errors and array
762 ;;; indexing errors can occur in functions called from SBCL code, and
763 ;;; will just end up as ordinary TYPE-ERROR or invalid index error,
764 ;;; because the signalling code has no good way to know that the
765 ;;; underlying problem is a bug in SBCL. But in the fairly common case
766 ;;; that the signalling code does know that it's found a bug in SBCL,
767 ;;; this condition is appropriate, reusing boilerplate and helping
768 ;;; users to recognize it as an SBCL bug.
769 (define-condition bug (simple-error)
770   ()
771   (:report
772    (lambda (condition stream)
773      (format stream
774              "~@<  ~? ~:@_~?~:>"
775              (simple-condition-format-control condition)
776              (simple-condition-format-arguments condition)
777              "~@<This is probably a bug in SBCL itself. (Alternatively, ~
778               SBCL might have been corrupted by bad user code, e.g. by an ~
779               undefined Lisp operation like ~S, or by stray pointers from ~
780               alien code or from unsafe Lisp code; or there might be a bug ~
781               in the OS or hardware that SBCL is running on.) If it seems to ~
782               be a bug in SBCL itself, the maintainers would like to know ~
783               about it. Bug reports are welcome on the SBCL ~
784               mailing lists, which you can find at ~
785               <http://sbcl.sourceforge.net/>.~:@>"
786              '((fmakunbound 'compile))))))
787
788 (define-condition simple-storage-condition (storage-condition simple-condition) ())
789
790 ;;; a condition for use in stubs for operations which aren't supported
791 ;;; on some platforms
792 ;;;
793 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
794 ;;;   #-(or freebsd linux)
795 ;;;   (defun load-foreign (&rest rest)
796 ;;;     (error 'unsupported-operator :name 'load-foreign))
797 ;;;   #+(or freebsd linux)
798 ;;;   (defun load-foreign ... actual definition ...)
799 ;;; By signalling a standard condition in this case, we make it
800 ;;; possible for test code to distinguish between (1) intentionally
801 ;;; unimplemented and (2) unintentionally just screwed up somehow.
802 ;;; (Before this condition was defined, test code tried to deal with
803 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
804 ;;; sbcl-0.7.0, a a package screwup left the definition of
805 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
806 ;;; architectures where it was supposed to be supported, and the
807 ;;; regression tests cheerfully passed because they assumed that
808 ;;; unFBOUNDPness meant they were running on an system which didn't
809 ;;; support the extension.)
810 (define-condition unsupported-operator (simple-error) ())
811
812 \f
813 ;;; (:ansi-cl :function remove)
814 ;;; (:ansi-cl :section (a b c))
815 ;;; (:ansi-cl :glossary "similar")
816 ;;;
817 ;;; (:sbcl :node "...")
818 ;;; (:sbcl :variable *ed-functions*)
819 ;;;
820 ;;; FIXME: this is not the right place for this.
821 (defun print-reference (reference stream)
822   (ecase (car reference)
823     (:amop
824      (format stream "AMOP")
825      (format stream ", ")
826      (destructuring-bind (type data) (cdr reference)
827        (ecase type
828          (:generic-function (format stream "Generic Function ~S" data))
829          (:section (format stream "Section ~{~D~^.~}" data)))))
830     (:ansi-cl
831      (format stream "The ANSI Standard")
832      (format stream ", ")
833      (destructuring-bind (type data) (cdr reference)
834        (ecase type
835          (:function (format stream "Function ~S" data))
836          (:special-operator (format stream "Special Operator ~S" data))
837          (:macro (format stream "Macro ~S" data))
838          (:section (format stream "Section ~{~D~^.~}" data))
839          (:glossary (format stream "Glossary entry for ~S" data))
840          (:issue (format stream "writeup for Issue ~A" data)))))
841     (:sbcl
842      (format stream "The SBCL Manual")
843      (format stream ", ")
844      (destructuring-bind (type data) (cdr reference)
845        (ecase type
846          (:node (format stream "Node ~S" data))
847          (:variable (format stream "Variable ~S" data))
848          (:function (format stream "Function ~S" data)))))
849     ;; FIXME: other documents (e.g. CLIM, Franz documentation :-)
850     ))
851 (define-condition reference-condition ()
852   ((references :initarg :references :reader reference-condition-references)))
853 (defvar *print-condition-references* t)
854 (def!method print-object :around ((o reference-condition) s)
855   (call-next-method)
856   (unless (or *print-escape* *print-readably*)
857     (when (and *print-condition-references*
858                (reference-condition-references o))
859       (format s "~&See also:~%")
860       (pprint-logical-block (s nil :per-line-prefix "  ")
861         (do* ((rs (reference-condition-references o) (cdr rs))
862               (r (car rs) (car rs)))
863              ((null rs))
864           (print-reference r s)
865           (unless (null (cdr rs))
866             (terpri s)))))))
867
868 (define-condition duplicate-definition (reference-condition warning)
869   ((name :initarg :name :reader duplicate-definition-name))
870   (:report (lambda (c s)
871              (format s "~@<Duplicate definition for ~S found in ~
872                         one file.~@:>"
873                      (duplicate-definition-name c))))
874   (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
875
876 (define-condition package-at-variance (reference-condition simple-warning)
877   ()
878   (:default-initargs :references (list '(:ansi-cl :macro defpackage))))
879
880 (define-condition defconstant-uneql (reference-condition error)
881   ((name :initarg :name :reader defconstant-uneql-name)
882    (old-value :initarg :old-value :reader defconstant-uneql-old-value)
883    (new-value :initarg :new-value :reader defconstant-uneql-new-value))
884   (:report
885    (lambda (condition stream)
886      (format stream
887              "~@<The constant ~S is being redefined (from ~S to ~S)~@:>"
888              (defconstant-uneql-name condition)
889              (defconstant-uneql-old-value condition)
890              (defconstant-uneql-new-value condition))))
891   (:default-initargs :references (list '(:ansi-cl :macro defconstant)
892                                        '(:sbcl :node "Idiosyncrasies"))))
893
894 (define-condition array-initial-element-mismatch
895     (reference-condition simple-warning)
896   ()
897   (:default-initargs
898       :references (list
899                    '(:ansi-cl :function make-array)
900                    '(:ansi-cl :function sb!xc:upgraded-array-element-type))))
901
902 (define-condition displaced-to-array-too-small-error
903     (reference-condition simple-error)
904   ()
905   (:default-initargs
906       :references (list '(:ansi-cl :function adjust-array))))
907
908 (define-condition type-warning (reference-condition simple-warning)
909   ()
910   (:default-initargs :references (list '(:sbcl :node "Handling of Types"))))
911
912 (define-condition local-argument-mismatch (reference-condition simple-warning)
913   ()
914   (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
915
916 (define-condition format-args-mismatch (reference-condition)
917   ()
918   (:default-initargs :references (list '(:ansi-cl :section (22 3 10 2)))))
919
920 (define-condition format-too-few-args-warning
921     (format-args-mismatch simple-warning)
922   ())
923 (define-condition format-too-many-args-warning
924     (format-args-mismatch simple-style-warning)
925   ())
926
927 (define-condition extension-failure (reference-condition simple-error)
928   ())
929
930 (define-condition structure-initarg-not-keyword
931     (reference-condition simple-style-warning)
932   ()
933   (:default-initargs :references (list '(:ansi-cl :section (2 4 8 13)))))
934
935 #!+sb-package-locks
936 (progn
937
938 (define-condition package-lock-violation (reference-condition package-error)
939   ((format-control :initform nil :initarg :format-control
940                    :reader package-error-format-control)
941    (format-arguments :initform nil :initarg :format-arguments
942                      :reader package-error-format-arguments))
943   (:report
944    (lambda (condition stream)
945      (let ((control (package-error-format-control condition)))
946        (if control
947            (apply #'format stream
948                   (format nil "~~@<Lock on package ~A violated when ~A.~~:@>"
949                           (package-name (package-error-package condition))
950                           control)
951                   (package-error-format-arguments condition))
952            (format stream "~@<Lock on package ~A violated.~:@>"
953                    (package-name (package-error-package condition)))))))
954   ;; no :default-initargs -- reference-stuff provided by the
955   ;; signalling form in target-package.lisp
956   #!+sb-doc
957   (:documentation
958    "Subtype of CL:PACKAGE-ERROR. A subtype of this error is signalled
959 when a package-lock is violated."))
960
961 (define-condition package-locked-error (package-lock-violation) ()
962   #!+sb-doc
963   (:documentation
964    "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
965 signalled when an operation on a package violates a package lock."))
966
967 (define-condition symbol-package-locked-error (package-lock-violation)
968   ((symbol :initarg :symbol :reader package-locked-error-symbol))
969   #!+sb-doc
970   (:documentation
971    "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
972 signalled when an operation on a symbol violates a package lock. The
973 symbol that caused the violation is accessed by the function
974 SB-EXT:PACKAGE-LOCKED-ERROR-SYMBOL."))
975
976 ) ; progn
977
978 (define-condition undefined-alien-error (cell-error) ()
979   (:report
980    (lambda (condition stream)
981      (if (slot-boundp condition 'name)
982          (format stream "Undefined alien: ~S" (cell-error-name condition))
983          (format stream "Undefined alien symbol.")))))
984
985 (define-condition undefined-alien-variable-error (undefined-alien-error) ()
986   (:report
987    (lambda (condition stream)
988      (declare (ignore condition))
989      (format stream "Attempt to access an undefined alien variable."))))
990
991 (define-condition undefined-alien-function-error (undefined-alien-error) ()
992   (:report
993    (lambda (condition stream)
994      (declare (ignore condition))
995      (format stream "Attempt to call an undefined alien function."))))
996
997 \f
998 ;;;; various other (not specified by ANSI) CONDITIONs
999 ;;;;
1000 ;;;; These might logically belong in other files; they're here, after
1001 ;;;; setup of CONDITION machinery, only because that makes it easier to
1002 ;;;; get cold init to work.
1003
1004 ;;; OAOOM warning: see cross-condition.lisp
1005 (define-condition encapsulated-condition (condition)
1006   ((condition :initarg :condition :reader encapsulated-condition)))
1007
1008 (define-condition values-type-error (type-error)
1009   ()
1010   (:report
1011    (lambda (condition stream)
1012      (format stream
1013              "~@<The values set ~2I~:_[~{~S~^ ~}] ~I~_is not of type ~2I~_~S.~:>"
1014              (type-error-datum condition)
1015              (type-error-expected-type condition)))))
1016
1017 ;;; KLUDGE: a condition for floating point errors when we can't or
1018 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
1019 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
1020 ;;; know how but the old code was broken by the conversion to POSIX
1021 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
1022 ;;;
1023 ;;; FIXME: Perhaps this should also be a base class for all
1024 ;;; floating point exceptions?
1025 (define-condition floating-point-exception (arithmetic-error)
1026   ((flags :initarg :traps
1027           :initform nil
1028           :reader floating-point-exception-traps))
1029   (:report (lambda (condition stream)
1030              (format stream
1031                      "An arithmetic error ~S was signalled.~%"
1032                      (type-of condition))
1033              (let ((traps (floating-point-exception-traps condition)))
1034                (if traps
1035                    (format stream
1036                            "Trapping conditions are: ~%~{ ~S~^~}~%"
1037                            traps)
1038                    (write-line
1039                     "No traps are enabled? How can this be?"
1040                     stream))))))
1041
1042 (define-condition index-too-large-error (type-error)
1043   ()
1044   (:report
1045    (lambda (condition stream)
1046      (format stream
1047              "The index ~S is too large."
1048              (type-error-datum condition)))))
1049
1050 (define-condition bounding-indices-bad-error (reference-condition type-error)
1051   ((object :reader bounding-indices-bad-object :initarg :object))
1052   (:report
1053    (lambda (condition stream)
1054      (let* ((datum (type-error-datum condition))
1055             (start (car datum))
1056             (end (cdr datum))
1057             (object (bounding-indices-bad-object condition)))
1058        (etypecase object
1059          (sequence
1060           (format stream
1061                   "The bounding indices ~S and ~S are bad ~
1062                    for a sequence of length ~S."
1063                   start end (length object)))
1064          (array
1065           ;; from WITH-ARRAY-DATA
1066           (format stream
1067                   "The START and END parameters ~S and ~S are ~
1068                    bad for an array of total size ~S."
1069                   start end (array-total-size object)))))))
1070   (:default-initargs
1071       :references
1072       (list '(:ansi-cl :glossary "bounding index designator")
1073             '(:ansi-cl :issue "SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR"))))
1074
1075 (define-condition nil-array-accessed-error (reference-condition type-error)
1076   ()
1077   (:report (lambda (condition stream)
1078              (declare (ignore condition))
1079              (format stream
1080                      "An attempt to access an array of element-type ~
1081                       NIL was made.  Congratulations!")))
1082   (:default-initargs
1083       :references (list '(:ansi-cl :function sb!xc:upgraded-array-element-type)
1084                         '(:ansi-cl :section (15 1 2 1))
1085                         '(:ansi-cl :section (15 1 2 2)))))
1086
1087 (define-condition io-timeout (stream-error)
1088   ((direction :reader io-timeout-direction :initarg :direction))
1089   (:report
1090    (lambda (condition stream)
1091      (declare (type stream stream))
1092      (format stream
1093              "I/O timeout ~(~A~)ing ~S"
1094              (io-timeout-direction condition)
1095              (stream-error-stream condition)))))
1096
1097 (define-condition namestring-parse-error (parse-error)
1098   ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
1099    (args :reader namestring-parse-error-args :initarg :args :initform nil)
1100    (namestring :reader namestring-parse-error-namestring :initarg :namestring)
1101    (offset :reader namestring-parse-error-offset :initarg :offset))
1102   (:report
1103    (lambda (condition stream)
1104      (format stream
1105              "parse error in namestring: ~?~%  ~A~%  ~V@T^"
1106              (namestring-parse-error-complaint condition)
1107              (namestring-parse-error-args condition)
1108              (namestring-parse-error-namestring condition)
1109              (namestring-parse-error-offset condition)))))
1110
1111 (define-condition simple-package-error (simple-condition package-error) ())
1112
1113 (define-condition reader-package-error (reader-error) ())
1114
1115 (define-condition reader-eof-error (end-of-file)
1116   ((context :reader reader-eof-error-context :initarg :context))
1117   (:report
1118    (lambda (condition stream)
1119      (format stream
1120              "unexpected end of file on ~S ~A"
1121              (stream-error-stream condition)
1122              (reader-eof-error-context condition)))))
1123
1124 (define-condition reader-impossible-number-error (reader-error)
1125   ((error :reader reader-impossible-number-error-error :initarg :error))
1126   (:report
1127    (lambda (condition stream)
1128      (let ((error-stream (stream-error-stream condition)))
1129        (format stream "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
1130                (file-position-or-nil-for-error error-stream) error-stream
1131                (reader-error-format-control condition)
1132                (reader-error-format-arguments condition)
1133                (reader-impossible-number-error-error condition))))))
1134
1135 (define-condition timeout (serious-condition) ())
1136
1137 (define-condition declaration-type-conflict-error (reference-condition
1138                                                    simple-error)
1139   ()
1140   (:default-initargs
1141       :format-control "symbol ~S cannot be both the name of a type and the name of a declaration"
1142     :references (list '(:ansi-cl :section (3 8 21)))))
1143
1144 ;;; Single stepping conditions
1145
1146 (define-condition step-condition ()
1147   ((form :initarg :form :reader step-condition-form))
1148   #!+sb-doc
1149   (:documentation "Common base class of single-stepping conditions.
1150 STEP-CONDITION-FORM holds a string representation of the form being
1151 stepped."))
1152
1153 #!+sb-doc
1154 (setf (fdocumentation 'step-condition-form 'function)
1155       "Form associated with the STEP-CONDITION.")
1156
1157 (define-condition step-form-condition (step-condition)
1158   ((source-path :initarg :source-path :reader step-condition-source-path)
1159    (pathname :initarg :pathname :reader step-condition-pathname))
1160   #!+sb-doc
1161   (:documentation "Condition signalled by code compiled with
1162 single-stepping information when about to execute a form.
1163 STEP-CONDITION-FORM holds the form, STEP-CONDITION-PATHNAME holds the
1164 pathname of the original file or NIL, and STEP-CONDITION-SOURCE-PATH
1165 holds the source-path to the original form within that file or NIL.
1166 Associated with this condition are always the restarts STEP-INTO,
1167 STEP-NEXT, and STEP-CONTINUE."))
1168
1169 #!+sb-doc
1170 (setf (fdocumentation 'step-condition-source-path 'function)
1171       "Source-path of the original form associated with the
1172 STEP-FORM-CONDITION or NIL."
1173       (fdocumentation 'step-condition-pathname 'function)
1174       "Pathname of the original source-file associated with the
1175 STEP-FORM-CONDITION or NIL.")
1176
1177 (define-condition step-result-condition (step-condition)
1178   ((result :initarg :result :reader step-condition-result)))
1179
1180 #!+sb-doc
1181 (setf (fdocumentation 'step-condition-result 'function)
1182       "Return values associated with STEP-VALUES-CONDITION as a list,
1183 or the variable value associated with STEP-VARIABLE-CONDITION.")
1184
1185 (define-condition step-values-condition (step-result-condition)
1186   ()
1187   #!+sb-doc
1188   (:documentation "Condition signalled by code compiled with
1189 single-stepping information after executing a form.
1190 STEP-CONDITION-FORM holds the form, and STEP-CONDITION-RESULT holds
1191 the values returned by the form as a list. No associated restarts."))
1192
1193 (define-condition step-variable-condition (step-result-condition)
1194   ()
1195   #!+sb-doc
1196   (:documentation "Condition signalled by code compiled with
1197 single-stepping information when referencing a variable.
1198 STEP-CONDITION-FORM hold the symbol, and STEP-CONDITION-RESULT holds
1199 the value of the variable. No associated restarts."))
1200
1201 \f
1202 ;;;; restart definitions
1203
1204 (define-condition abort-failure (control-error) ()
1205   (:report
1206    "An ABORT restart was found that failed to transfer control dynamically."))
1207
1208 (defun abort (&optional condition)
1209   #!+sb-doc
1210   "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
1211    none exists."
1212   (invoke-restart (find-restart-or-control-error 'abort condition))
1213   ;; ABORT signals an error in case there was a restart named ABORT
1214   ;; that did not transfer control dynamically. This could happen with
1215   ;; RESTART-BIND.
1216   (error 'abort-failure))
1217
1218 (defun muffle-warning (&optional condition)
1219   #!+sb-doc
1220   "Transfer control to a restart named MUFFLE-WARNING, signalling a
1221    CONTROL-ERROR if none exists."
1222   (invoke-restart (find-restart-or-control-error 'muffle-warning condition)))
1223
1224 (macrolet ((define-nil-returning-restart (name args doc)
1225              #!-sb-doc (declare (ignore doc))
1226              `(defun ,name (,@args &optional condition)
1227                 #!+sb-doc ,doc
1228                 ;; FIXME: Perhaps this shared logic should be pulled out into
1229                 ;; FLET MAYBE-INVOKE-RESTART? See whether it shrinks code..
1230                 (let ((restart (find-restart ',name condition)))
1231                   (when restart
1232                     (invoke-restart restart ,@args))))))
1233   (define-nil-returning-restart continue ()
1234     "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
1235   (define-nil-returning-restart store-value (value)
1236     "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
1237    none exists.")
1238   (define-nil-returning-restart use-value (value)
1239     "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if
1240    none exists."))
1241
1242 ;;; single-stepping restarts
1243
1244 (macrolet ((def (name doc)
1245                #!-sb-doc (declare (ignore doc))
1246                `(defun ,name (condition)
1247                  #!+sb-doc ,doc
1248                  (invoke-restart (find-restart-or-control-error ',name condition)))))
1249   (def step-continue
1250       "Transfers control to the STEP-CONTINUE restart associated with
1251 the condition, continuing execution without stepping. Signals a
1252 CONTROL-ERROR if the restart does not exist.")
1253   (def step-next
1254       "Transfers control to the STEP-NEXT restart associated with the
1255 condition, executing the current form without stepping and continuing
1256 stepping with the next form. Signals CONTROL-ERROR is the restart does
1257 not exists.")
1258   (def step-into
1259       "Transfers control to the STEP-INTO restart associated with the
1260 condition, stepping into the current form. Signals a CONTROL-ERROR is
1261 the restart does not exist."))
1262
1263 (/show0 "condition.lisp end of file")
1264