0.9.0.30: towards callbacks: static-vectors
[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 (define-condition simple-storage-condition (storage-condition simple-condition) ())
779
780 ;;; a condition for use in stubs for operations which aren't supported
781 ;;; on some platforms
782 ;;;
783 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
784 ;;;   #-(or freebsd linux)
785 ;;;   (defun load-foreign (&rest rest)
786 ;;;     (error 'unsupported-operator :name 'load-foreign))
787 ;;;   #+(or freebsd linux)
788 ;;;   (defun load-foreign ... actual definition ...)
789 ;;; By signalling a standard condition in this case, we make it
790 ;;; possible for test code to distinguish between (1) intentionally
791 ;;; unimplemented and (2) unintentionally just screwed up somehow.
792 ;;; (Before this condition was defined, test code tried to deal with 
793 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
794 ;;; sbcl-0.7.0, a a package screwup left the definition of
795 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
796 ;;; architectures where it was supposed to be supported, and the
797 ;;; regression tests cheerfully passed because they assumed that
798 ;;; unFBOUNDPness meant they were running on an system which didn't
799 ;;; support the extension.)
800 (define-condition unsupported-operator (simple-error) ())
801
802 \f
803 ;;; (:ansi-cl :function remove)
804 ;;; (:ansi-cl :section (a b c))
805 ;;; (:ansi-cl :glossary "similar")
806 ;;;
807 ;;; (:sbcl :node "...")
808 ;;; (:sbcl :variable *ed-functions*)
809 ;;;
810 ;;; FIXME: this is not the right place for this.
811 (defun print-reference (reference stream)
812   (ecase (car reference)
813     (:amop
814      (format stream "AMOP")
815      (format stream ", ")
816      (destructuring-bind (type data) (cdr reference)
817        (ecase type
818          (:generic-function (format stream "Generic Function ~S" data))
819          (:section (format stream "Section ~{~D~^.~}" data)))))
820     (:ansi-cl
821      (format stream "The ANSI Standard")
822      (format stream ", ")
823      (destructuring-bind (type data) (cdr reference)
824        (ecase type
825          (:function (format stream "Function ~S" data))
826          (:special-operator (format stream "Special Operator ~S" data))
827          (:macro (format stream "Macro ~S" data))
828          (:section (format stream "Section ~{~D~^.~}" data))
829          (:glossary (format stream "Glossary entry for ~S" data))
830          (:issue (format stream "writeup for Issue ~A" data)))))
831     (:sbcl
832      (format stream "The SBCL Manual")
833      (format stream ", ")
834      (destructuring-bind (type data) (cdr reference)
835        (ecase type
836          (:node (format stream "Node ~S" data))
837          (:variable (format stream "Variable ~S" data))
838          (:function (format stream "Function ~S" data)))))
839     ;; FIXME: other documents (e.g. CLIM, Franz documentation :-)
840     ))
841 (define-condition reference-condition ()
842   ((references :initarg :references :reader reference-condition-references)))
843 (defvar *print-condition-references* t)
844 (def!method print-object :around ((o reference-condition) s)
845   (call-next-method)
846   (unless (or *print-escape* *print-readably*)
847     (when (and *print-condition-references*
848                (reference-condition-references o))
849       (format s "~&See also:~%")
850       (pprint-logical-block (s nil :per-line-prefix "  ")
851         (do* ((rs (reference-condition-references o) (cdr rs))
852               (r (car rs) (car rs)))
853              ((null rs))
854           (print-reference r s)
855           (unless (null (cdr rs))
856             (terpri s)))))))
857
858 (define-condition duplicate-definition (reference-condition warning)
859   ((name :initarg :name :reader duplicate-definition-name))
860   (:report (lambda (c s)
861              (format s "~@<Duplicate definition for ~S found in ~
862                         one file.~@:>"
863                      (duplicate-definition-name c))))
864   (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
865
866 (define-condition package-at-variance (reference-condition simple-warning) 
867   ()
868   (:default-initargs :references (list '(:ansi-cl :macro defpackage))))
869
870 (define-condition defconstant-uneql (reference-condition error)
871   ((name :initarg :name :reader defconstant-uneql-name)
872    (old-value :initarg :old-value :reader defconstant-uneql-old-value)
873    (new-value :initarg :new-value :reader defconstant-uneql-new-value))
874   (:report
875    (lambda (condition stream)
876      (format stream
877              "~@<The constant ~S is being redefined (from ~S to ~S)~@:>"
878              (defconstant-uneql-name condition)
879              (defconstant-uneql-old-value condition)
880              (defconstant-uneql-new-value condition))))
881   (:default-initargs :references (list '(:ansi-cl :macro defconstant)
882                                        '(:sbcl :node "Idiosyncrasies"))))
883
884 (define-condition array-initial-element-mismatch 
885     (reference-condition simple-warning)
886   ()
887   (:default-initargs 
888       :references (list 
889                    '(:ansi-cl :function make-array) 
890                    '(:ansi-cl :function sb!xc:upgraded-array-element-type))))
891
892 (define-condition displaced-to-array-too-small-error
893     (reference-condition simple-error)
894   ()
895   (:default-initargs
896       :references (list '(:ansi-cl :function adjust-array))))
897
898 (define-condition type-warning (reference-condition simple-warning)
899   ()
900   (:default-initargs :references (list '(:sbcl :node "Handling of Types"))))
901
902 (define-condition local-argument-mismatch (reference-condition simple-warning)
903   ()
904   (:default-initargs :references (list '(:ansi-cl :section (3 2 2 3)))))
905
906 (define-condition format-args-mismatch (reference-condition)
907   ()
908   (:default-initargs :references (list '(:ansi-cl :section (22 3 10 2)))))
909
910 (define-condition format-too-few-args-warning 
911     (format-args-mismatch simple-warning)
912   ())
913 (define-condition format-too-many-args-warning
914     (format-args-mismatch simple-style-warning)
915   ())
916
917 (define-condition extension-failure (reference-condition simple-error)
918   ())
919
920 (define-condition structure-initarg-not-keyword
921     (reference-condition simple-style-warning)
922   ()
923   (:default-initargs :references (list '(:ansi-cl :section (2 4 8 13)))))
924
925 #!+sb-package-locks
926 (progn
927
928 (define-condition package-lock-violation (reference-condition package-error)
929   ((format-control :initform nil :initarg :format-control 
930                    :reader package-error-format-control)
931    (format-arguments :initform nil :initarg :format-arguments
932                      :reader package-error-format-arguments))
933   (:report 
934    (lambda (condition stream)
935      (let ((control (package-error-format-control condition)))
936        (if control
937            (apply #'format stream
938                   (format nil "~~@<Lock on package ~A violated when ~A.~~:@>"
939                           (package-name (package-error-package condition))
940                           control)
941                   (package-error-format-arguments condition))
942            (format stream "~@<Lock on package ~A violated.~:@>"
943                    (package-name (package-error-package condition)))))))
944   ;; no :default-initargs -- reference-stuff provided by the
945   ;; signalling form in target-package.lisp
946   #!+sb-doc
947   (:documentation
948    "Subtype of CL:PACKAGE-ERROR. A subtype of this error is signalled
949 when a package-lock is violated."))
950
951 (define-condition package-locked-error (package-lock-violation) ()
952   #!+sb-doc
953   (:documentation
954    "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
955 signalled when an operation on a package violates a package lock."))
956
957 (define-condition symbol-package-locked-error (package-lock-violation)
958   ((symbol :initarg :symbol :reader package-locked-error-symbol))
959   #!+sb-doc
960   (:documentation
961    "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
962 signalled when an operation on a symbol violates a package lock. The
963 symbol that caused the violation is accessed by the function
964 SB-EXT:PACKAGE-LOCKED-ERROR-SYMBOL."))
965
966 ) ; progn
967
968 (define-condition undefined-alien-error (error) ())
969
970 (define-condition undefined-alien-variable-error (undefined-alien-error) ()
971   (:report
972    (lambda (condition stream)
973      (declare (ignore condition))
974      (format stream "Attempt to access an undefined alien variable."))))
975
976 (define-condition undefined-alien-function-error (undefined-alien-error) ()
977   (:report
978    (lambda (condition stream)
979      (declare (ignore condition))
980      (format stream "Attempt to call an undefined alien function."))))
981
982 \f
983 ;;;; various other (not specified by ANSI) CONDITIONs
984 ;;;;
985 ;;;; These might logically belong in other files; they're here, after
986 ;;;; setup of CONDITION machinery, only because that makes it easier to
987 ;;;; get cold init to work.
988
989 ;;; OAOOM warning: see cross-condition.lisp
990 (define-condition encapsulated-condition (condition)
991   ((condition :initarg :condition :reader encapsulated-condition)))
992
993 (define-condition values-type-error (type-error)
994   ()
995   (:report
996    (lambda (condition stream)
997      (format stream
998              "~@<The values set ~2I~:_[~{~S~^ ~}] ~I~_is not of type ~2I~_~S.~:>"
999              (type-error-datum condition)
1000              (type-error-expected-type condition)))))
1001
1002 ;;; KLUDGE: a condition for floating point errors when we can't or
1003 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
1004 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
1005 ;;; know how but the old code was broken by the conversion to POSIX
1006 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
1007 ;;;
1008 ;;; FIXME: Perhaps this should also be a base class for all
1009 ;;; floating point exceptions?
1010 (define-condition floating-point-exception (arithmetic-error)
1011   ((flags :initarg :traps
1012           :initform nil
1013           :reader floating-point-exception-traps))
1014   (:report (lambda (condition stream)
1015              (format stream
1016                      "An arithmetic error ~S was signalled.~%"
1017                      (type-of condition))
1018              (let ((traps (floating-point-exception-traps condition)))
1019                (if traps
1020                    (format stream
1021                            "Trapping conditions are: ~%~{ ~S~^~}~%"
1022                            traps)
1023                    (write-line
1024                     "No traps are enabled? How can this be?"
1025                     stream))))))
1026
1027 (define-condition index-too-large-error (type-error)
1028   ()
1029   (:report
1030    (lambda (condition stream)
1031      (format stream
1032              "The index ~S is too large."
1033              (type-error-datum condition)))))
1034
1035 (define-condition bounding-indices-bad-error (reference-condition type-error)
1036   ((object :reader bounding-indices-bad-object :initarg :object))
1037   (:report
1038    (lambda (condition stream)
1039      (let* ((datum (type-error-datum condition))
1040             (start (car datum))
1041             (end (cdr datum))
1042             (object (bounding-indices-bad-object condition)))
1043        (etypecase object
1044          (sequence
1045           (format stream
1046                   "The bounding indices ~S and ~S are bad ~
1047                    for a sequence of length ~S."
1048                   start end (length object)))
1049          (array
1050           ;; from WITH-ARRAY-DATA
1051           (format stream
1052                   "The START and END parameters ~S and ~S are ~
1053                    bad for an array of total size ~S."
1054                   start end (array-total-size object)))))))
1055   (:default-initargs 
1056       :references 
1057       (list '(:ansi-cl :glossary "bounding index designator")
1058             '(:ansi-cl :issue "SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR"))))
1059
1060 (define-condition nil-array-accessed-error (reference-condition type-error)
1061   ()
1062   (:report (lambda (condition stream)
1063              (declare (ignore condition))
1064              (format stream
1065                      "An attempt to access an array of element-type ~
1066                       NIL was made.  Congratulations!")))
1067   (:default-initargs
1068       :references (list '(:ansi-cl :function sb!xc:upgraded-array-element-type)
1069                         '(:ansi-cl :section (15 1 2 1))
1070                         '(:ansi-cl :section (15 1 2 2)))))
1071
1072 (define-condition io-timeout (stream-error)
1073   ((direction :reader io-timeout-direction :initarg :direction))
1074   (:report
1075    (lambda (condition stream)
1076      (declare (type stream stream))
1077      (format stream
1078              "I/O timeout ~(~A~)ing ~S"
1079              (io-timeout-direction condition)
1080              (stream-error-stream condition)))))
1081
1082 (define-condition namestring-parse-error (parse-error)
1083   ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
1084    (args :reader namestring-parse-error-args :initarg :args :initform nil)
1085    (namestring :reader namestring-parse-error-namestring :initarg :namestring)
1086    (offset :reader namestring-parse-error-offset :initarg :offset))
1087   (:report
1088    (lambda (condition stream)
1089      (format stream
1090              "parse error in namestring: ~?~%  ~A~%  ~V@T^"
1091              (namestring-parse-error-complaint condition)
1092              (namestring-parse-error-args condition)
1093              (namestring-parse-error-namestring condition)
1094              (namestring-parse-error-offset condition)))))
1095
1096 (define-condition simple-package-error (simple-condition package-error) ())
1097
1098 (define-condition reader-package-error (reader-error) ())
1099
1100 (define-condition reader-eof-error (end-of-file)
1101   ((context :reader reader-eof-error-context :initarg :context))
1102   (:report
1103    (lambda (condition stream)
1104      (format stream
1105              "unexpected end of file on ~S ~A"
1106              (stream-error-stream condition)
1107              (reader-eof-error-context condition)))))
1108
1109 (define-condition reader-impossible-number-error (reader-error)
1110   ((error :reader reader-impossible-number-error-error :initarg :error))
1111   (:report
1112    (lambda (condition stream)
1113      (let ((error-stream (stream-error-stream condition)))
1114        (format stream "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
1115                (file-position-or-nil-for-error error-stream) error-stream
1116                (reader-error-format-control condition)
1117                (reader-error-format-arguments condition)
1118                (reader-impossible-number-error-error condition))))))
1119
1120 (define-condition timeout (serious-condition) ())
1121
1122 ;;; Single stepping conditions
1123
1124 (define-condition step-condition ()
1125   ((form :initarg :form :reader step-condition-form))
1126   #!+sb-doc
1127   (:documentation "Common base class of single-stepping conditions.
1128 STEP-CONDITION-FORM holds a string representation of the form being
1129 stepped."))
1130
1131 #!+sb-doc
1132 (setf (fdocumentation 'step-condition-form 'function)
1133       "Form associated with the STEP-CONDITION.")
1134
1135 (define-condition step-form-condition (step-condition)
1136   ((source-path :initarg :source-path :reader step-condition-source-path)
1137    (pathname :initarg :pathname :reader step-condition-pathname))
1138   #!+sb-doc
1139   (:documentation "Condition signalled by code compiled with
1140 single-stepping information when about to execute a form.
1141 STEP-CONDITION-FORM holds the form, STEP-CONDITION-PATHNAME holds the
1142 pathname of the original file or NIL, and STEP-CONDITION-SOURCE-PATH
1143 holds the source-path to the original form within that file or NIL.
1144 Associated with this condition are always the restarts STEP-INTO,
1145 STEP-NEXT, and STEP-CONTINUE."))
1146
1147 #!+sb-doc
1148 (setf (fdocumentation 'step-condition-source-path 'function)
1149       "Source-path of the original form associated with the
1150 STEP-FORM-CONDITION or NIL."
1151       (fdocumentation 'step-condition-pathname 'function)
1152       "Pathname of the original source-file associated with the
1153 STEP-FORM-CONDITION or NIL.")
1154
1155 (define-condition step-result-condition (step-condition)
1156   ((result :initarg :result :reader step-condition-result)))
1157
1158 #!+sb-doc
1159 (setf (fdocumentation 'step-condition-result 'function)
1160       "Return values associated with STEP-VALUES-CONDITION as a list,
1161 or the variable value associated with STEP-VARIABLE-CONDITION.")
1162
1163 (define-condition step-values-condition (step-result-condition)
1164   ()
1165   #!+sb-doc
1166   (:documentation "Condition signalled by code compiled with
1167 single-stepping information after executing a form.
1168 STEP-CONDITION-FORM holds the form, and STEP-CONDITION-RESULT holds
1169 the values returned by the form as a list. No associated restarts."))
1170
1171 (define-condition step-variable-condition (step-result-condition)
1172   ()
1173   #!+sb-doc
1174   (:documentation "Condition signalled by code compiled with
1175 single-stepping information when referencing a variable.
1176 STEP-CONDITION-FORM hold the symbol, and STEP-CONDITION-RESULT holds
1177 the value of the variable. No associated restarts."))
1178
1179 \f
1180 ;;;; restart definitions
1181
1182 (define-condition abort-failure (control-error) ()
1183   (:report
1184    "An ABORT restart was found that failed to transfer control dynamically."))
1185
1186 (defun abort (&optional condition)
1187   #!+sb-doc
1188   "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
1189    none exists."
1190   (invoke-restart (find-restart-or-control-error 'abort condition))
1191   ;; ABORT signals an error in case there was a restart named ABORT
1192   ;; that did not transfer control dynamically. This could happen with
1193   ;; RESTART-BIND.
1194   (error 'abort-failure))
1195
1196 (defun muffle-warning (&optional condition)
1197   #!+sb-doc
1198   "Transfer control to a restart named MUFFLE-WARNING, signalling a
1199    CONTROL-ERROR if none exists."
1200   (invoke-restart (find-restart-or-control-error 'muffle-warning condition)))
1201
1202 (macrolet ((define-nil-returning-restart (name args doc)
1203              #!-sb-doc (declare (ignore doc))
1204              `(defun ,name (,@args &optional condition)
1205                 #!+sb-doc ,doc
1206                 ;; FIXME: Perhaps this shared logic should be pulled out into
1207                 ;; FLET MAYBE-INVOKE-RESTART? See whether it shrinks code..
1208                 (let ((restart (find-restart ',name condition)))
1209                   (when restart
1210                     (invoke-restart restart ,@args))))))
1211   (define-nil-returning-restart continue ()
1212     "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
1213   (define-nil-returning-restart store-value (value)
1214     "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
1215    none exists.")
1216   (define-nil-returning-restart use-value (value)
1217     "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if
1218    none exists."))
1219
1220 ;;; single-stepping restarts
1221
1222 (macrolet ((def (name doc)
1223                #!-sb-doc (declare (ignore doc))
1224                `(defun ,name (condition)
1225                  #!+sb-doc ,doc
1226                  (invoke-restart (find-restart-or-control-error ',name condition)))))
1227   (def step-continue
1228       "Transfers control to the STEP-CONTINUE restart associated with
1229 the condition, continuing execution without stepping. Signals a
1230 CONTROL-ERROR if the restart does not exist.")
1231   (def step-next
1232       "Transfers control to the STEP-NEXT restart associated with the
1233 condition, executing the current form without stepping and continuing
1234 stepping with the next form. Signals CONTROL-ERROR is the restart does
1235 not exists.")
1236   (def step-into
1237       "Transfers control to the STEP-INTO restart associated with the
1238 condition, stepping into the current form. Signals a CONTROL-ERROR is
1239 the restart does not exist."))
1240
1241 (/show0 "condition.lisp end of file")
1242