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