1 ;;;; Condition support in target lisp
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB-KERNEL")
14 (fmakunbound 'install-condition-slot-reader)
15 (fmakunbound 'install-condition-slot-writer)
17 (defmacro standard-method-function (lambda &environment env)
18 (let ((proto-gf (load-time-value
19 (ensure-generic-function (gensym)))))
20 (multiple-value-bind (lambda initargs)
21 (sb-mop:make-method-lambda
23 (sb-mop:class-prototype (sb-mop:generic-function-method-class proto-gf))
26 `(values #',lambda ',initargs))))
28 (defun install-condition-slot-reader (name condition slot-name)
29 (let ((gf (if (fboundp name)
30 (ensure-generic-function name)
31 (ensure-generic-function name :lambda-list '(condition)))))
32 (if (and (eq (class-of gf) (find-class 'standard-generic-function))
33 (eq (sb-mop:generic-function-method-class gf)
34 (find-class 'standard-method)))
35 (multiple-value-bind (method-fun initargs)
36 (standard-method-function
38 (condition-reader-function condition slot-name)))
40 (apply #'make-instance
42 :specializers (list (find-class condition))
43 :lambda-list '(condition)
46 (eval `(defmethod ,name ((condition ,condition))
47 (condition-reader-function condition ',slot-name))))))
49 (defun install-condition-slot-writer (name condition slot-name)
50 (let ((gf (if (fboundp name)
51 (ensure-generic-function name)
52 (ensure-generic-function name :lambda-list '(new-value condition)))))
53 (if (and (eq (class-of gf) (find-class 'standard-generic-function))
54 (eq (sb-mop:generic-function-method-class gf)
55 (find-class 'standard-method)))
56 (multiple-value-bind (method-fun initargs)
57 (standard-method-function
58 (lambda (new-value condition)
59 (condition-writer-function condition new-value slot-name)))
61 (apply #'make-instance
63 :specializers (list (find-class t)
64 (find-class condition))
65 :lambda-list '(new-value condition)
68 (eval `(defmethod ,name (new-value (condition ,condition))
69 (condition-writer-function condition new-value ',slot-name))))))