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 (declaim (inline legal-class-name-p))
83 (defun legal-class-name-p (x)
86 (defvar *create-classes-from-internal-structure-definitions-p* t)
88 (defun find-class-from-cell (symbol cell &optional (errorp t))
90 (or (classoid-cell-pcl-class cell)
91 (when *create-classes-from-internal-structure-definitions-p*
92 (let ((classoid (classoid-cell-classoid cell)))
94 (or (condition-classoid-p classoid)
95 (defstruct-classoid-p classoid)))
96 (ensure-non-standard-class symbol classoid))))))
97 (cond ((null errorp) nil)
98 ((legal-class-name-p symbol)
99 (error "There is no class named ~S." symbol))
101 (error "~S is not a legal class name." symbol)))))
103 (defun find-class (symbol &optional (errorp t) environment)
104 (declare (ignore environment))
105 (find-class-from-cell symbol
106 (find-classoid-cell symbol)
110 ;;; This DEFVAR was originally in defs.lisp, now moved here.
112 ;;; Possible values are NIL, EARLY, BRAID, or COMPLETE.
114 ;;; KLUDGE: This should probably become
115 ;;; (DECLAIM (TYPE (MEMBER NIL :EARLY :BRAID :COMPLETE) *BOOT-STATE*))
116 (defvar *boot-state* nil)
118 (/show "pcl/macros.lisp 187")
120 (define-compiler-macro find-class (&whole form
121 symbol &optional (errorp t) environment)
122 (declare (ignore environment))
123 (if (and (constantp symbol)
124 (legal-class-name-p (setf symbol (constant-form-value symbol)))
126 (member *boot-state* '(braid complete)))
127 (let ((errorp (not (null (constant-form-value errorp))))
128 (cell (make-symbol "CLASSOID-CELL")))
129 `(let ((,cell (load-time-value (find-classoid-cell ',symbol :create t))))
130 (or (classoid-cell-pcl-class ,cell)
132 `(find-class-from-cell ',symbol ,cell t)
133 `(when (classoid-cell-classoid ,cell)
134 (find-class-from-cell ',symbol ,cell nil))))))
137 (declaim (inline class-classoid))
138 (defun class-classoid (class)
139 (layout-classoid (class-wrapper class)))
141 (defun (setf find-class) (new-value name &optional errorp environment)
142 (declare (ignore errorp environment))
143 (cond ((legal-class-name-p name)
144 (with-single-package-locked-error
145 (:symbol name "Using ~A as the class-name argument in ~
147 (let ((cell (find-classoid-cell name :create new-value)))
149 (setf (classoid-cell-pcl-class cell) new-value)
150 (when (eq *boot-state* 'complete)
151 (let ((classoid (class-classoid new-value)))
152 (setf (find-classoid name) classoid)
153 (set-class-type-translation new-value classoid))))
155 (clear-classoid name cell)))
156 (when (or (eq *boot-state* 'complete)
157 (eq *boot-state* 'braid))
158 (update-ctors 'setf-find-class :class new-value :name name))
161 (error "~S is not a legal class name." name))))
163 (/show "pcl/macros.lisp 241")
165 (defmacro function-funcall (form &rest args)
166 `(funcall (the function ,form) ,@args))
168 (defmacro function-apply (form &rest args)
169 `(apply (the function ,form) ,@args))
171 (/show "pcl/macros.lisp 249")
173 (defun get-setf-fun-name (name)
176 (defsetf slot-value set-slot-value)
178 (/show "finished with pcl/macros.lisp")