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.
80 (/show "pcl/macros.lisp 119")
82 (defvar *find-class* (make-hash-table :test 'eq))
84 (defmacro find-class-cell-class (cell)
87 (defmacro find-class-cell-predicate (cell)
90 (defmacro make-find-class-cell (class-name)
91 (declare (ignore class-name))
92 '(list* nil #'constantly-nil nil))
94 (defun find-class-cell (symbol &optional dont-create-p)
95 (or (gethash symbol *find-class*)
97 (unless (legal-class-name-p symbol)
98 (error "~S is not a legal class name." symbol))
99 (setf (gethash symbol *find-class*) (make-find-class-cell symbol)))))
101 (/show "pcl/macros.lisp 157")
103 (defvar *create-classes-from-internal-structure-definitions-p* t)
105 (defun find-class-from-cell (symbol cell &optional (errorp t))
106 (or (find-class-cell-class cell)
107 (and *create-classes-from-internal-structure-definitions-p*
108 (or (structure-type-p symbol) (condition-type-p symbol))
109 (ensure-non-standard-class symbol))
110 (cond ((null errorp) nil)
111 ((legal-class-name-p symbol)
112 (error "There is no class named ~S." symbol))
114 (error "~S is not a legal class name." symbol)))))
116 (defun legal-class-name-p (x)
119 (defun find-class (symbol &optional (errorp t) environment)
120 (declare (ignore environment))
121 (find-class-from-cell symbol
122 (find-class-cell symbol errorp)
126 ;;; This DEFVAR was originally in defs.lisp, now moved here.
128 ;;; Possible values are NIL, EARLY, BRAID, or COMPLETE.
130 ;;; KLUDGE: This should probably become
131 ;;; (DECLAIM (TYPE (MEMBER NIL :EARLY :BRAID :COMPLETE) *BOOT-STATE*))
132 (defvar *boot-state* nil)
134 (/show "pcl/macros.lisp 187")
136 (define-compiler-macro find-class (&whole form
137 symbol &optional (errorp t) environment)
138 (declare (ignore environment))
139 (if (and (constantp symbol)
140 (legal-class-name-p (eval symbol))
142 (member *boot-state* '(braid complete)))
143 (let ((symbol (eval symbol))
144 (errorp (not (null (eval errorp))))
145 (class-cell (make-symbol "CLASS-CELL")))
146 `(let ((,class-cell (load-time-value (find-class-cell ',symbol))))
147 (or (find-class-cell-class ,class-cell)
149 `(find-class-from-cell ',symbol ,class-cell t)
150 `(and (classoid-cell-classoid
151 ',(find-classoid-cell symbol))
152 (find-class-from-cell ',symbol ,class-cell nil))))))
155 (defun (setf find-class) (new-value name &optional errorp environment)
156 (declare (ignore errorp environment))
157 (cond ((legal-class-name-p name)
158 (with-single-package-locked-error
159 (:symbol name "using ~A as the class-name argument in ~
161 (let ((cell (find-class-cell name)))
162 (setf (find-class-cell-class cell) new-value)
163 (when (and (eq *boot-state* 'complete) (null new-value))
164 (setf (find-classoid name) nil))
165 (when (or (eq *boot-state* 'complete)
166 (eq *boot-state* 'braid))
167 (update-ctors 'setf-find-class :class new-value :name name))
170 (error "~S is not a legal class name." name))))
172 (/show "pcl/macros.lisp 230")
174 (defun find-wrapper (symbol)
175 (class-wrapper (find-class symbol)))
177 (/show "pcl/macros.lisp 241")
179 (defmacro function-funcall (form &rest args)
180 `(funcall (the function ,form) ,@args))
182 (defmacro function-apply (form &rest args)
183 `(apply (the function ,form) ,@args))
185 (/show "pcl/macros.lisp 249")
187 (defun get-setf-fun-name (name)
190 (defsetf slot-value set-slot-value)
192 (/show "finished with pcl/macros.lisp")