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