1 ;;;; macros, global variable definitions, and other miscellaneous support stuff
2 ;;;; used by the rest of the PCL subsystem
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from software originally released by Xerox
8 ;;;; Corporation. Copyright and release statements follow. Later modifications
9 ;;;; to the software are in the public domain and are provided with
10 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
13 ;;;; copyright information from original PCL sources:
15 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
16 ;;;; All rights reserved.
18 ;;;; Use and copying of this software and preparation of derivative works based
19 ;;;; upon this software are permitted. Any distribution of this software or
20 ;;;; derivative works must comply with all applicable United States export
23 ;;;; This software is made available AS IS, and Xerox Corporation makes no
24 ;;;; warranty about the software, its performance or its conformity to any
29 (defglobal *optimize-speed
*
30 '(optimize (speed 3) (safety 0) (sb-ext:inhibit-warnings
3) (debug 0)))
33 ;; These nonstandard declarations seem to be used privately
34 ;; within PCL itself to pass information around, so we can't
38 ;; This declaration may also be used within PCL to pass
39 ;; information around, I'm not sure. -- WHN 2000-12-30
42 (defun get-declaration (name declarations
&optional default
)
43 (dolist (d declarations default
)
44 (dolist (form (cdr d
))
45 (when (and (consp form
) (eq (car form
) name
))
46 (return-from get-declaration
(cdr form
))))))
50 ;;;; This is documented in the CLOS specification.
52 (define-condition class-not-found-error
(sb-kernel::cell-error
)
53 ((sb-kernel::name
:type
(satisfies legal-class-name-p
)))
54 (:report
(lambda (condition stream
)
55 (format stream
"~@<There is no class named ~
56 ~/sb-ext:print-symbol-with-prefix/.~@:>"
57 (sb-kernel::cell-error-name condition
)))))
59 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
60 (defvar *create-classes-from-internal-structure-definitions-p
* t
))
61 (declaim (always-bound *create-classes-from-internal-structure-definitions-p
*))
63 (declaim (ftype function ensure-non-standard-class
))
64 (defun find-class-from-cell (symbol cell
&optional
(errorp t
))
66 (or (classoid-cell-pcl-class cell
)
67 (when *create-classes-from-internal-structure-definitions-p
*
68 (let ((classoid (classoid-cell-classoid cell
)))
70 (or (condition-classoid-p classoid
)
71 (defstruct-classoid-p classoid
)))
72 (ensure-non-standard-class symbol classoid
))))))
74 (check-class-name symbol
)
75 (error 'class-not-found-error
:name symbol
))))
77 (defun find-class (symbol &optional
(errorp t
) environment
)
78 (declare (ignore environment
) (explicit-check))
79 (find-class-from-cell symbol
80 (find-classoid-cell symbol
)
84 (define-compiler-macro find-class
(&whole form
85 symbol
&optional
(errorp t
) environment
)
86 (declare (ignore environment
))
87 (if (and (constantp symbol
)
88 (legal-class-name-p (setf symbol
(constant-form-value symbol
)))
90 (member **boot-state
** '(braid complete
)))
91 (let ((errorp (not (null (constant-form-value errorp
))))
92 (cell (make-symbol "CLASSOID-CELL")))
93 `(let ((,cell
,(find-classoid-cell symbol
:create t
)))
94 (or (classoid-cell-pcl-class ,cell
)
96 `(find-class-from-cell ',symbol
,cell
)
97 `(when (classoid-cell-classoid ,cell
)
98 (find-class-from-cell ',symbol
,cell nil
))))))
101 (declaim (ftype function update-ctors
))
102 (defun (setf find-class
) (new-value name
&optional errorp environment
)
103 (declare (ignore errorp environment
))
104 (check-class-name name
)
105 (with-single-package-locked-error
106 (:symbol name
"Using ~A as the class-name argument in ~
109 (let ((cell (find-classoid-cell name
:create new-value
)))
111 (setf (classoid-cell-pcl-class cell
) new-value
)
112 (when (eq **boot-state
** 'complete
)
113 (let ((classoid (class-classoid new-value
)))
114 (setf (find-classoid name
) classoid
))))
116 (%clear-classoid name cell
)))
117 (when (or (eq **boot-state
** 'complete
)
118 (eq **boot-state
** 'braid
))
119 (update-ctors 'setf-find-class
:class new-value
:name name
))
122 (flet ((call-gf (gf-nameize object slot-name env
&optional newval
)
123 (aver (constantp slot-name env
))
124 `(funcall #',(funcall gf-nameize
(constant-form-value slot-name env
))
126 (defmacro accessor-slot-boundp
(object slot-name
&environment env
)
127 (call-gf 'slot-boundp-name object slot-name env
))
129 (defmacro accessor-slot-makunbound
(object slot-name
&environment env
)
130 (call-gf 'slot-makunbound-name object slot-name env
))
132 (defmacro accessor-slot-value
(object slot-name
&environment env
)
133 `(truly-the (values t
&optional
)
134 ,(call-gf 'slot-reader-name object slot-name env
)))
136 (defmacro accessor-set-slot-value
(object slot-name new-value
&environment env
)
137 ;; Expand NEW-VALUE before deciding not to bind a temp var for OBJECT,
138 ;; which should be eval'd first. We skip the binding if either new-value
139 ;; is constant or a plain variable. This is still subtly wrong if NEW-VALUE
140 ;; is a special, because we'll read it more than once.
141 (setq new-value
(%macroexpand new-value env
))
142 (let ((bind-object (unless (or (constantp new-value env
) (atom new-value
))
143 (let* ((object-var (gensym))
144 (bind `((,object-var
,object
))))
145 (setf object object-var
)
147 (form (call-gf 'slot-writer-name object slot-name env
(list new-value
))))
149 `(let ,bind-object
,form
)