1.0.19.33: Improved interrupt handling on darwin/x86[-64]
[sbcl/eslaughter.git] / src / pcl / macros.lisp
bloba9a657fd48ed0f23009b97eb2d3a8b8797d6e097
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 ;; 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.
35 %method-name
36 ;; These nonstandard declarations seem to be used privately
37 ;; within PCL itself to pass information around, so we can't
38 ;; just delete them.
39 %class
40 %method-lambda-list
41 ;; This declaration may also be used within PCL to pass
42 ;; information around, I'm not sure. -- WHN 2000-12-30
43 %variable-rebinding))
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.))
62 (progn ,@body))))
64 (/show "pcl/macros.lisp 101")
66 (defmacro dolist-carefully ((var list improper-list-handler) &body body)
67 `(let ((,var nil)
68 (.dolist-carefully. ,list))
69 (loop (when (null .dolist-carefully.) (return nil))
70 (if (consp .dolist-carefully.)
71 (progn
72 (setq ,var (pop .dolist-carefully.))
73 ,@body)
74 (,improper-list-handler)))))
76 ;;;; FIND-CLASS
77 ;;;;
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)
84 (symbolp x))
86 (defvar *create-classes-from-internal-structure-definitions-p* t)
88 (defun find-class-from-cell (symbol cell &optional (errorp t))
89 (or (when cell
90 (or (classoid-cell-pcl-class cell)
91 (when *create-classes-from-internal-structure-definitions-p*
92 (let ((classoid (classoid-cell-classoid cell)))
93 (when (and classoid
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)
107 errorp))
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)))
125 (constantp errorp)
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)
131 ,(if errorp
132 `(find-class-from-cell ',symbol ,cell t)
133 `(when (classoid-cell-classoid ,cell)
134 (find-class-from-cell ',symbol ,cell nil))))))
135 form))
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 ~
146 (SETF FIND-CLASS)"))
147 (let ((cell (find-classoid-cell name :create new-value)))
148 (cond (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))))
154 (cell
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))
159 new-value))
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)
174 `(setf ,name))
176 (defsetf slot-value set-slot-value)
178 (/show "finished with pcl/macros.lisp")