Declare COERCE and two helpers as EXPLICIT-CHECK.
[sbcl.git] / src / pcl / macros.lisp
bloba7bfd58a7f7195032c7674170507cd1932525eff
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
5 ;;;; more information.
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
11 ;;;; information.
13 ;;;; copyright information from original PCL sources:
14 ;;;;
15 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
16 ;;;; All rights reserved.
17 ;;;;
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
21 ;;;; control laws.
22 ;;;;
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
25 ;;;; specification.
27 (in-package "SB-PCL")
29 (/show "starting pcl/macros.lisp")
31 (declaim (declaration
32 ;; These nonstandard declarations seem to be used privately
33 ;; within PCL itself to pass information around, so we can't
34 ;; just delete them.
35 %class
36 ;; This declaration may also be used within PCL to pass
37 ;; information around, I'm not sure. -- WHN 2000-12-30
38 %variable-rebinding))
40 (/show "done with DECLAIM DECLARATION")
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))))))
48 (/show "pcl/macros.lisp 85")
50 (/show "pcl/macros.lisp 101")
52 (defmacro dolist-carefully ((var list improper-list-handler) &body body)
53 `(let ((,var nil)
54 (.dolist-carefully. ,list))
55 (loop (when (null .dolist-carefully.) (return nil))
56 (if (consp .dolist-carefully.)
57 (progn
58 (setq ,var (pop .dolist-carefully.))
59 ,@body)
60 (,improper-list-handler)))))
62 ;;;; FIND-CLASS
63 ;;;;
64 ;;;; This is documented in the CLOS specification.
66 (/show "pcl/macros.lisp 119")
68 (declaim (inline legal-class-name-p))
69 (defun legal-class-name-p (x)
70 (symbolp x))
72 (defvar *create-classes-from-internal-structure-definitions-p* t)
74 (declaim (ftype function ensure-non-standard-class))
75 (defun find-class-from-cell (symbol cell &optional (errorp t))
76 (or (when cell
77 (or (classoid-cell-pcl-class cell)
78 (when *create-classes-from-internal-structure-definitions-p*
79 (let ((classoid (classoid-cell-classoid cell)))
80 (when (and classoid
81 (or (condition-classoid-p classoid)
82 (defstruct-classoid-p classoid)))
83 (ensure-non-standard-class symbol classoid))))))
84 (cond ((null errorp) nil)
85 ((legal-class-name-p symbol)
86 (error "There is no class named ~
87 ~/sb-impl::print-symbol-with-prefix/." symbol))
89 (error "~S is not a legal class name." symbol)))))
91 (defun find-class (symbol &optional (errorp t) environment)
92 (declare (ignore environment))
93 (find-class-from-cell symbol
94 (find-classoid-cell symbol)
95 errorp))
98 ;;; This DEFVAR was originally in defs.lisp, now moved here.
99 ;;;
100 ;;; Possible values are NIL, EARLY, BRAID, or COMPLETE.
101 (declaim (type (member nil early braid complete) **boot-state**))
102 (defglobal **boot-state** nil)
104 (/show "pcl/macros.lisp 187")
106 (define-compiler-macro find-class (&whole form
107 symbol &optional (errorp t) environment)
108 (declare (ignore environment))
109 (if (and (constantp symbol)
110 (legal-class-name-p (setf symbol (constant-form-value symbol)))
111 (constantp errorp)
112 (member **boot-state** '(braid complete)))
113 (let ((errorp (not (null (constant-form-value errorp))))
114 (cell (make-symbol "CLASSOID-CELL")))
115 `(let ((,cell (load-time-value (find-classoid-cell ',symbol :create t))))
116 (or (classoid-cell-pcl-class ,cell)
117 ,(if errorp
118 `(find-class-from-cell ',symbol ,cell t)
119 `(when (classoid-cell-classoid ,cell)
120 (find-class-from-cell ',symbol ,cell nil))))))
121 form))
123 (declaim (ftype function class-wrapper))
124 (declaim (inline class-classoid))
125 (defun class-classoid (class)
126 (layout-classoid (class-wrapper class)))
128 (declaim (ftype function %set-class-type-translation update-ctors))
129 (defun (setf find-class) (new-value name &optional errorp environment)
130 (declare (ignore errorp environment))
131 (cond ((legal-class-name-p name)
132 (with-single-package-locked-error
133 (:symbol name "Using ~A as the class-name argument in ~
134 (SETF FIND-CLASS)"))
135 (with-world-lock ()
136 (let ((cell (find-classoid-cell name :create new-value)))
137 (cond (new-value
138 (setf (classoid-cell-pcl-class cell) new-value)
139 (when (eq **boot-state** 'complete)
140 (let ((classoid (class-classoid new-value)))
141 (setf (find-classoid name) classoid)
142 (%set-class-type-translation new-value classoid))))
143 (cell
144 (%clear-classoid name cell)))
145 (when (or (eq **boot-state** 'complete)
146 (eq **boot-state** 'braid))
147 (update-ctors 'setf-find-class :class new-value :name name))
148 new-value)))
150 (error "~S is not a legal class name." name))))
152 (/show "pcl/macros.lisp 241")
154 (defmacro function-funcall (form &rest args)
155 `(funcall (the function ,form) ,@args))
157 (defmacro function-apply (form &rest args)
158 `(apply (the function ,form) ,@args))
160 (/show "pcl/macros.lisp 249")
162 (defun get-setf-fun-name (name)
163 `(setf ,name))
165 (defsetf slot-value set-slot-value)
167 (/show "finished with pcl/macros.lisp")