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 (/show "starting pcl/macros.lisp")
32 ;; As of sbcl-0.7.0.6, SBCL actively uses this declaration
33 ;; to propagate information needed to set up nice debug
34 ;; names (as seen e.g. in BACKTRACE) for method functions.
36 ;; These nonstandard declarations seem to be used privately
37 ;; within PCL itself to pass information around, so we can't
41 ;; This declaration may also be used within PCL to pass
42 ;; information around, I'm not sure. -- WHN 2000-12-30
45 (/show "done with DECLAIM DECLARATION")
47 (defun get-declaration (name declarations &optional default)
48 (dolist (d declarations default)
49 (dolist (form (cdr d))
50 (when (and (consp form) (eq (car form) name))
51 (return-from get-declaration (cdr form))))))
53 (/show "pcl/macros.lisp 85")
55 (defmacro doplist ((key val) plist &body body)
56 `(let ((.plist-tail. ,plist) ,key ,val)
57 (loop (when (null .plist-tail.) (return nil))
58 (setq ,key (pop .plist-tail.))
59 (when (null .plist-tail.)
60 (error "malformed plist, odd number of elements"))
61 (setq ,val (pop .plist-tail.))
64 (/show "pcl/macros.lisp 101")
66 (defmacro dolist-carefully ((var list improper-list-handler) &body body)
68 (.dolist-carefully. ,list))
69 (loop (when (null .dolist-carefully.) (return nil))
70 (if (consp .dolist-carefully.)
72 (setq ,var (pop .dolist-carefully.))
74 (,improper-list-handler)))))
78 ;;;; This is documented in the CLOS specification. FIXME: Except that
79 ;;;; SBCL deviates from the spec by having CL:FIND-CLASS distinct from
80 ;;;; PCL:FIND-CLASS, alas.
82 (/show "pcl/macros.lisp 119")
84 (defvar *find-class* (make-hash-table :test 'eq))
86 (defmacro find-class-cell-class (cell)
89 (defmacro find-class-cell-predicate (cell)
92 (defmacro find-class-cell-make-instance-function-keys (cell)
95 (defmacro make-find-class-cell (class-name)
96 (declare (ignore class-name))
97 '(list* nil #'constantly-nil nil))
99 (defun find-class-cell (symbol &optional dont-create-p)
100 (or (gethash symbol *find-class*)
101 (unless dont-create-p
102 (unless (legal-class-name-p symbol)
103 (error "~S is not a legal class name." symbol))
104 (setf (gethash symbol *find-class*) (make-find-class-cell symbol)))))
106 (/show "pcl/macros.lisp 157")
108 (defvar *create-classes-from-internal-structure-definitions-p* t)
110 (defun find-class-from-cell (symbol cell &optional (errorp t))
111 (or (find-class-cell-class cell)
112 (and *create-classes-from-internal-structure-definitions-p*
113 (structure-type-p symbol)
114 (find-structure-class symbol))
115 (cond ((null errorp) nil)
116 ((legal-class-name-p symbol)
117 (error "There is no class named ~S." symbol))
119 (error "~S is not a legal class name." symbol)))))
121 (defun find-class-predicate-from-cell (symbol cell &optional (errorp t))
122 (unless (find-class-cell-class cell)
123 (find-class-from-cell symbol cell errorp))
124 (find-class-cell-predicate cell))
126 (defun legal-class-name-p (x)
130 (defun find-class (symbol &optional (errorp t) environment)
131 (declare (ignore environment))
132 (find-class-from-cell symbol
133 (find-class-cell symbol errorp)
136 (defun find-class-predicate (symbol &optional (errorp t) environment)
137 (declare (ignore environment))
138 (find-class-predicate-from-cell symbol
139 (find-class-cell symbol errorp)
142 ;;; This DEFVAR was originally in defs.lisp, now moved here.
144 ;;; Possible values are NIL, EARLY, BRAID, or COMPLETE.
146 ;;; KLUDGE: This should probably become
147 ;;; (DECLAIM (TYPE (MEMBER NIL :EARLY :BRAID :COMPLETE) *BOOT-STATE*))
148 (defvar *boot-state* nil)
150 (/show "pcl/macros.lisp 187")
152 ;;; Note that in SBCL as in CMU CL,
153 ;;; COMMON-LISP:FIND-CLASS /= SB-PCL:FIND-CLASS.
154 ;;; (Yes, this is a KLUDGE!)
155 (define-compiler-macro find-class (&whole form
156 symbol &optional (errorp t) environment)
157 (declare (ignore environment))
158 (if (and (constantp symbol)
159 (legal-class-name-p (eval symbol))
161 (member *boot-state* '(braid complete)))
162 (let ((symbol (eval symbol))
163 (errorp (not (null (eval errorp))))
164 (class-cell (make-symbol "CLASS-CELL")))
165 `(let ((,class-cell (load-time-value (find-class-cell ',symbol))))
166 (or (find-class-cell-class ,class-cell)
168 `(find-class-from-cell ',symbol ,class-cell t)
169 `(and (sb-kernel:class-cell-class
170 ',(sb-kernel:find-class-cell symbol))
171 (find-class-from-cell ',symbol ,class-cell nil))))))
174 (defun (setf find-class) (new-value symbol)
175 (if (legal-class-name-p symbol)
176 (let ((cell (find-class-cell symbol)))
177 (setf (find-class-cell-class cell) new-value)
178 (when (or (eq *boot-state* 'complete)
179 (eq *boot-state* 'braid))
180 (when (and new-value (class-wrapper new-value))
181 (setf (find-class-cell-predicate cell)
182 (fdefinition (class-predicate-name new-value))))
183 (when (and new-value (not (forward-referenced-class-p new-value)))
185 (dolist (keys+aok (find-class-cell-make-instance-function-keys
187 (update-initialize-info-internal
188 (initialize-info new-value (car keys+aok) nil (cdr keys+aok))
189 'make-instance-function))))
191 (error "~S is not a legal class name." symbol)))
193 (/show "pcl/macros.lisp 230")
195 (defun (setf find-class-predicate)
197 (if (legal-class-name-p symbol)
198 (setf (find-class-cell-predicate (find-class-cell symbol)) new-value)
199 (error "~S is not a legal class name." symbol)))
201 (defun find-wrapper (symbol)
202 (class-wrapper (find-class symbol)))
204 (/show "pcl/macros.lisp 241")
206 (defmacro function-funcall (form &rest args)
207 `(funcall (the function ,form) ,@args))
209 (defmacro function-apply (form &rest args)
210 `(apply (the function ,form) ,@args))
212 (/show "pcl/macros.lisp 249")
214 (defun get-setf-fun-name (name)
217 (defsetf slot-value set-slot-value)
219 (/show "finished with pcl/macros.lisp")