Delete a ton of cruft from the globaldb initialization logic.
[sbcl.git] / src / pcl / braid.lisp
blobd87ac252e2e9434b58489af1d6445eaedd972ca4
1 ;;;; bootstrapping the meta-braid
2 ;;;;
3 ;;;; The code in this file takes the early definitions that have been
4 ;;;; saved up and actually builds those class objects. This work is
5 ;;;; largely driven off of those class definitions, but the fact that
6 ;;;; STANDARD-CLASS is the class of all metaclasses in the braid is
7 ;;;; built into this code pretty deeply.
9 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; more information.
12 ;;;; This software is derived from software originally released by Xerox
13 ;;;; Corporation. Copyright and release statements follow. Later modifications
14 ;;;; to the software are in the public domain and are provided with
15 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
16 ;;;; information.
18 ;;;; copyright information from original PCL sources:
19 ;;;;
20 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
21 ;;;; All rights reserved.
22 ;;;;
23 ;;;; Use and copying of this software and preparation of derivative works based
24 ;;;; upon this software are permitted. Any distribution of this software or
25 ;;;; derivative works must comply with all applicable United States export
26 ;;;; control laws.
27 ;;;;
28 ;;;; This software is made available AS IS, and Xerox Corporation makes no
29 ;;;; warranty about the software, its performance or its conformity to any
30 ;;;; specification.
32 (in-package "SB-PCL")
34 (defun allocate-standard-instance (wrapper
35 &optional (slots-init nil slots-init-p))
36 (let ((instance (%make-standard-instance nil (get-instance-hash-code)))
37 (no-of-slots (wrapper-no-of-instance-slots wrapper)))
38 (setf (std-instance-wrapper instance) wrapper)
39 (setf (std-instance-slots instance)
40 (cond (slots-init-p
41 ;; Inline the slots vector allocation and initialization.
42 (let ((slots (make-array no-of-slots :initial-element 0)))
43 (do ((rem-slots slots-init (rest rem-slots))
44 (i 0 (1+ i)))
45 ((>= i no-of-slots)) ;endp rem-slots))
46 (declare (list rem-slots)
47 (type index i))
48 (setf (aref slots i) (first rem-slots)))
49 slots))
51 (make-array no-of-slots
52 :initial-element +slot-unbound+))))
53 instance))
55 (defmacro allocate-standard-funcallable-instance-slots
56 (wrapper &optional slots-init-p slots-init)
57 `(let ((no-of-slots (wrapper-no-of-instance-slots ,wrapper)))
58 ,(if slots-init-p
59 `(if ,slots-init-p
60 (make-array no-of-slots :initial-contents ,slots-init)
61 (make-array no-of-slots :initial-element +slot-unbound+))
62 `(make-array no-of-slots :initial-element +slot-unbound+))))
64 (define-condition unset-funcallable-instance-function
65 (reference-condition simple-error)
67 (:default-initargs
68 :references (list '(:amop :generic-function allocate-instance)
69 '(:amop :function set-funcallable-instance-function))))
71 (defun allocate-standard-funcallable-instance
72 (wrapper &optional (slots-init nil slots-init-p))
73 (let ((fin (%make-standard-funcallable-instance
74 nil nil (get-instance-hash-code))))
75 (set-funcallable-instance-function
76 fin
77 #'(lambda (&rest args)
78 (declare (ignore args))
79 (error 'unset-funcallable-instance-function
80 :format-control "~@<The function of funcallable instance ~
81 ~S has not been set.~@:>"
82 :format-arguments (list fin))))
83 (setf (fsc-instance-wrapper fin) wrapper
84 (fsc-instance-slots fin)
85 (allocate-standard-funcallable-instance-slots
86 wrapper slots-init-p slots-init))
87 fin))
89 (defun classify-slotds (slotds)
90 (let (instance-slots class-slots custom-slots bootp)
91 (dolist (slotd slotds)
92 (let ((alloc (cond ((consp slotd) ; bootstrap
93 (setf bootp t)
94 :instance)
96 (slot-definition-allocation slotd)))))
97 (case alloc
98 (:instance
99 (push slotd instance-slots))
100 (:class
101 (push slotd class-slots))
103 (push slotd custom-slots)))))
104 (values (if bootp
105 (nreverse instance-slots)
106 (when slotds
107 (sort instance-slots #'< :key #'slot-definition-location)))
108 class-slots
109 custom-slots)))
111 ;;;; BOOTSTRAP-META-BRAID
112 ;;;;
113 ;;;; This function builds the base metabraid from the early class definitions.
115 (defmacro !initial-classes-and-wrappers (&rest classes)
116 `(progn
117 ,@(mapcar (lambda (class)
118 (let ((wr (format-symbol *pcl-package* "~A-WRAPPER" class)))
119 `(setf ,wr ,(if (eq class 'standard-generic-function)
120 '*sgf-wrapper*
121 `(!boot-make-wrapper
122 (early-class-size ',class)
123 ',class))
124 ,class (allocate-standard-instance
125 ,(if (eq class 'standard-generic-function)
126 'funcallable-standard-class-wrapper
127 'standard-class-wrapper))
128 (wrapper-class ,wr) ,class
129 (find-class ',class) ,class)))
130 classes)))
132 (defun !wrapper-p (x) (and (sb-kernel::layout-p x) (layout-for-std-class-p x)))
134 (defun !bootstrap-meta-braid ()
135 (let* ((*create-classes-from-internal-structure-definitions-p* nil)
136 standard-class-wrapper standard-class
137 funcallable-standard-class-wrapper funcallable-standard-class
138 slot-class-wrapper slot-class
139 system-class-wrapper system-class
140 built-in-class-wrapper built-in-class
141 structure-class-wrapper structure-class
142 condition-class-wrapper condition-class
143 standard-direct-slot-definition-wrapper
144 standard-direct-slot-definition
145 standard-effective-slot-definition-wrapper
146 standard-effective-slot-definition
147 class-eq-specializer-wrapper class-eq-specializer
148 standard-generic-function-wrapper standard-generic-function)
149 (!initial-classes-and-wrappers
150 standard-class funcallable-standard-class
151 slot-class system-class built-in-class structure-class condition-class
152 standard-direct-slot-definition standard-effective-slot-definition
153 class-eq-specializer standard-generic-function)
154 ;; First, make a class metaobject for each of the early classes. For
155 ;; each metaobject we also set its wrapper. Except for the class T,
156 ;; the wrapper is always that of STANDARD-CLASS.
157 (dolist (definition *early-class-definitions*)
158 (let* ((name (ecd-class-name definition))
159 (meta (ecd-metaclass definition))
160 (wrapper (ecase meta
161 (slot-class slot-class-wrapper)
162 (standard-class standard-class-wrapper)
163 (funcallable-standard-class
164 funcallable-standard-class-wrapper)
165 (built-in-class built-in-class-wrapper)
166 (system-class system-class-wrapper)
167 (structure-class structure-class-wrapper)
168 (condition-class condition-class-wrapper)))
169 (class (or (find-class name nil)
170 (allocate-standard-instance wrapper))))
171 (setf (find-class name) class)))
172 (dolist (definition *early-class-definitions*)
173 (let ((name (ecd-class-name definition))
174 (meta (ecd-metaclass definition))
175 (source (ecd-source-location definition))
176 (direct-supers (ecd-superclass-names definition))
177 (direct-slots (ecd-canonical-slots definition))
178 (other-initargs (ecd-other-initargs definition)))
179 (let ((direct-default-initargs
180 (getf other-initargs :direct-default-initargs)))
181 (multiple-value-bind (slots cpl default-initargs direct-subclasses)
182 (early-collect-inheritance name)
183 (let* ((class (find-class name))
184 (wrapper (cond ((eq class slot-class)
185 slot-class-wrapper)
186 ((eq class standard-class)
187 standard-class-wrapper)
188 ((eq class funcallable-standard-class)
189 funcallable-standard-class-wrapper)
190 ((eq class standard-direct-slot-definition)
191 standard-direct-slot-definition-wrapper)
192 ((eq class
193 standard-effective-slot-definition)
194 standard-effective-slot-definition-wrapper)
195 ((eq class system-class) system-class-wrapper)
196 ((eq class built-in-class)
197 built-in-class-wrapper)
198 ((eq class structure-class)
199 structure-class-wrapper)
200 ((eq class condition-class)
201 condition-class-wrapper)
202 ((eq class class-eq-specializer)
203 class-eq-specializer-wrapper)
204 ((eq class standard-generic-function)
205 standard-generic-function-wrapper)
207 (!boot-make-wrapper (length slots) name))))
208 (proto nil))
209 (when (eq name t) (setq *the-wrapper-of-t* wrapper))
210 (set (make-class-symbol name) class)
211 (dolist (slot slots)
212 (unless (eq (getf slot :allocation :instance) :instance)
213 (error "Slot allocation ~S is not supported in bootstrap."
214 (getf slot :allocation))))
216 (when (!wrapper-p wrapper)
217 (setf (layout-slot-list wrapper) slots))
219 (setq proto (if (eq meta 'funcallable-standard-class)
220 (allocate-standard-funcallable-instance wrapper)
221 (allocate-standard-instance wrapper)))
223 (setq direct-slots
224 (!bootstrap-make-slot-definitions
225 name class direct-slots
226 standard-direct-slot-definition-wrapper nil))
227 (setq slots
228 (!bootstrap-make-slot-definitions
229 name class slots
230 standard-effective-slot-definition-wrapper t))
232 (setf (layout-slot-table wrapper) (make-slot-table class slots t))
233 (when (!wrapper-p wrapper)
234 (setf (layout-slot-list wrapper) slots))
236 (case meta
237 ((standard-class funcallable-standard-class)
238 (!bootstrap-initialize-class
239 meta
240 class name class-eq-specializer-wrapper source
241 direct-supers direct-subclasses cpl wrapper proto
242 direct-slots slots direct-default-initargs default-initargs))
243 (built-in-class ; *the-class-t*
244 (!bootstrap-initialize-class
245 meta
246 class name class-eq-specializer-wrapper source
247 direct-supers direct-subclasses cpl wrapper proto))
248 (system-class
249 (!bootstrap-initialize-class
250 meta
251 class name class-eq-specializer-wrapper source
252 direct-supers direct-subclasses cpl wrapper proto))
253 (slot-class ; *the-class-slot-object*
254 (!bootstrap-initialize-class
255 meta
256 class name class-eq-specializer-wrapper source
257 direct-supers direct-subclasses cpl wrapper proto))
258 (structure-class ; *the-class-structure-object*
259 (!bootstrap-initialize-class
260 meta
261 class name class-eq-specializer-wrapper source
262 direct-supers direct-subclasses cpl wrapper))
263 (condition-class
264 (!bootstrap-initialize-class
265 meta
266 class name class-eq-specializer-wrapper source
267 direct-supers direct-subclasses cpl wrapper))))))))
269 (setq **standard-method-classes**
270 (mapcar (lambda (name)
271 (symbol-value (make-class-symbol name)))
272 *standard-method-class-names*))
274 (let* ((smc-class (find-class 'standard-method-combination))
275 (smc-wrapper (!bootstrap-get-slot 'standard-class
276 smc-class
277 'wrapper))
278 (smc (allocate-standard-instance smc-wrapper)))
279 (flet ((set-slot (name value)
280 (!bootstrap-set-slot 'standard-method-combination
282 name
283 value)))
284 (set-slot 'source nil)
285 (set-slot 'type-name 'standard)
286 (set-slot '%documentation "The standard method combination.")
287 (set-slot 'options ()))
288 (setq *standard-method-combination* smc))))
290 ;;; Initialize a class metaobject.
291 (defun !bootstrap-initialize-class
292 (metaclass-name class name
293 class-eq-wrapper source direct-supers direct-subclasses cpl wrapper
294 &optional
295 (proto nil proto-p)
296 direct-slots slots direct-default-initargs default-initargs)
297 (flet ((classes (names) (mapcar #'find-class names))
298 (set-slot (slot-name value)
299 (!bootstrap-set-slot metaclass-name class slot-name value)))
300 (set-slot 'name name)
301 (set-slot 'finalized-p t)
302 (set-slot 'source source)
303 (set-slot 'safe-p nil)
304 (set-slot '%type (if (eq class (find-class t))
306 ;; FIXME: Could this just be CLASS instead
307 ;; of `(CLASS ,CLASS)? If not, why not?
308 ;; (See also similar expression in
309 ;; SHARED-INITIALIZE :BEFORE (CLASS).)
310 `(class ,class)))
311 (set-slot 'class-eq-specializer
312 (let ((spec (allocate-standard-instance class-eq-wrapper)))
313 (!bootstrap-set-slot 'class-eq-specializer spec '%type
314 `(class-eq ,class))
315 (!bootstrap-set-slot 'class-eq-specializer spec 'object
316 class)
317 spec))
318 (set-slot '%class-precedence-list (classes cpl))
319 (set-slot 'cpl-available-p t)
320 (set-slot 'can-precede-list (classes (cdr cpl)))
321 (set-slot 'incompatible-superclass-list nil)
322 (set-slot 'direct-superclasses (classes direct-supers))
323 (set-slot 'direct-subclasses (classes direct-subclasses))
324 (set-slot 'direct-methods (cons nil nil))
325 (set-slot 'wrapper wrapper)
326 (set-slot '%documentation nil)
327 (set-slot 'plist
328 `(,@(and direct-default-initargs
329 `(direct-default-initargs ,direct-default-initargs))
330 ,@(and default-initargs
331 `(default-initargs ,default-initargs))))
332 (when (memq metaclass-name '(standard-class funcallable-standard-class
333 structure-class condition-class
334 slot-class))
335 (set-slot 'direct-slots direct-slots)
336 (set-slot 'slots slots)
337 (setf (layout-slot-table wrapper)
338 (make-slot-table class slots
339 (member metaclass-name
340 '(standard-class funcallable-standard-class))))
341 (when (!wrapper-p wrapper)
342 (setf (layout-slot-list wrapper) slots)))
344 ;; For all direct superclasses SUPER of CLASS, make sure CLASS is
345 ;; a direct subclass of SUPER. Note that METACLASS-NAME doesn't
346 ;; matter here for the slot DIRECT-SUBCLASSES, since every class
347 ;; inherits the slot from class CLASS.
348 (dolist (super direct-supers)
349 (let* ((super (find-class super))
350 (subclasses (!bootstrap-get-slot metaclass-name super
351 'direct-subclasses)))
352 (cond ((eq +slot-unbound+ subclasses)
353 (!bootstrap-set-slot metaclass-name super 'direct-subclasses
354 (list class)))
355 ((not (memq class subclasses))
356 (!bootstrap-set-slot metaclass-name super 'direct-subclasses
357 (cons class subclasses))))))
359 (case metaclass-name
360 (structure-class
361 (let ((constructor-sym '|STRUCTURE-OBJECT class constructor|))
362 (set-slot 'defstruct-form
363 `(defstruct (structure-object (:constructor
364 ,constructor-sym)
365 (:copier nil))))
366 (set-slot 'defstruct-constructor constructor-sym)
367 (set-slot 'from-defclass-p t)
368 (set-slot 'plist nil)
369 (set-slot 'prototype (funcall constructor-sym))))
370 (condition-class
371 (set-slot 'prototype (make-condition name)))
373 (set-slot 'prototype
374 (if proto-p proto (allocate-standard-instance wrapper)))))
375 class))
377 (defun !bootstrap-make-slot-definitions (name class slots wrapper effective-p)
378 (let ((index -1))
379 (mapcar (lambda (slot)
380 (incf index)
381 (!bootstrap-make-slot-definition
382 name class slot wrapper effective-p index))
383 slots)))
385 (defun !bootstrap-make-slot-definition
386 (name class slot wrapper effective-p index)
387 (let* ((slotd-class-name (if effective-p
388 'standard-effective-slot-definition
389 'standard-direct-slot-definition))
390 (slotd (allocate-standard-instance wrapper))
391 (slot-name (getf slot :name)))
392 (flet ((get-val (name) (getf slot name))
393 (set-val (name val)
394 (!bootstrap-set-slot slotd-class-name slotd name val)))
395 (set-val 'name slot-name)
396 (set-val 'initform (get-val :initform))
397 (set-val 'initfunction (get-val :initfunction))
398 (set-val 'initargs (get-val :initargs))
399 (unless effective-p
400 (set-val 'readers (get-val :readers))
401 (set-val 'writers (get-val :writers)))
402 (set-val 'allocation :instance)
403 (set-val '%type (or (get-val :type) t))
404 (set-val '%documentation (or (get-val :documentation) ""))
405 (set-val '%class class)
406 (when effective-p
407 (set-val 'location index)
408 (set-val 'accessor-flags 7)
409 (set-val
410 'info
411 (make-slot-info
412 :reader
413 (make-optimized-std-reader-method-function nil nil slot-name index)
414 :writer
415 (make-optimized-std-writer-method-function nil nil slot-name index)
416 :boundp
417 (make-optimized-std-boundp-method-function nil nil slot-name index))))
418 (when (and (eq name 'standard-class)
419 (eq slot-name 'slots) effective-p)
420 (setq *the-eslotd-standard-class-slots* slotd))
421 (when (and (eq name 'funcallable-standard-class)
422 (eq slot-name 'slots) effective-p)
423 (setq *the-eslotd-funcallable-standard-class-slots* slotd))
424 slotd)))
426 (defun !bootstrap-accessor-definitions (early-p)
427 (let ((*early-p* early-p))
428 (dolist (definition *early-class-definitions*)
429 (let ((name (ecd-class-name definition))
430 (meta (ecd-metaclass definition)))
431 (unless (or (eq meta 'built-in-class) (eq meta 'system-class))
432 (let ((direct-slots (ecd-canonical-slots definition)))
433 (dolist (slotd direct-slots)
434 (let ((slot-name (getf slotd :name))
435 (readers (getf slotd :readers))
436 (writers (getf slotd :writers)))
437 (!bootstrap-accessor-definitions1
438 name
439 slot-name
440 readers
441 writers
443 (ecd-source-location definition))))))))))
445 (defun !bootstrap-accessor-definition (class-name accessor-name slot-name type source-location)
446 (multiple-value-bind (accessor-class make-method-function arglist specls doc)
447 (ecase type
448 (reader (values 'standard-reader-method
449 #'make-std-reader-method-function
450 (list class-name)
451 (list class-name)
452 "automatically generated reader method"))
453 (writer (values 'standard-writer-method
454 #'make-std-writer-method-function
455 (list 'new-value class-name)
456 (list t class-name)
457 "automatically generated writer method"))
458 (boundp (values 'standard-boundp-method
459 #'make-std-boundp-method-function
460 (list class-name)
461 (list class-name)
462 "automatically generated boundp method")))
463 (let ((gf (ensure-generic-function accessor-name :lambda-list arglist)))
464 (if (find specls (early-gf-methods gf)
465 :key #'early-method-specializers
466 :test 'equal)
467 (unless (assoc accessor-name *!generic-function-fixups*
468 :test #'equal)
469 (update-dfun gf))
470 (add-method gf
471 (make-a-method accessor-class
473 arglist specls
474 (funcall make-method-function
475 class-name slot-name)
477 :slot-name slot-name
478 :object-class class-name
479 :method-class-function (constantly (find-class accessor-class))
480 :definition-source source-location))))))
482 (defun !bootstrap-accessor-definitions1 (class-name
483 slot-name
484 readers
485 writers
486 boundps
487 source-location)
488 (flet ((do-reader-definition (reader)
489 (!bootstrap-accessor-definition class-name
490 reader
491 slot-name
492 'reader
493 source-location))
494 (do-writer-definition (writer)
495 (!bootstrap-accessor-definition class-name
496 writer
497 slot-name
498 'writer
499 source-location))
500 (do-boundp-definition (boundp)
501 (!bootstrap-accessor-definition class-name
502 boundp
503 slot-name
504 'boundp
505 source-location)))
506 (dolist (reader readers) (do-reader-definition reader))
507 (dolist (writer writers) (do-writer-definition writer))
508 (dolist (boundp boundps) (do-boundp-definition boundp))))
510 ;;; FIXME: find a better name.
511 (defun !bootstrap-class-predicates (early-p)
512 (let ((*early-p* early-p)
513 (source-loc (sb-c:source-location)))
514 (dolist (ecp *!early-class-predicates*)
515 (let ((class-name (car ecp))
516 (predicate-name (cadr ecp)))
517 (!make-class-predicate (find-class class-name) predicate-name
518 source-loc)))))
520 (defun !bootstrap-built-in-classes ()
522 ;; First make sure that all the supers listed in
523 ;; *BUILT-IN-CLASS-LATTICE* are themselves defined by
524 ;; *BUILT-IN-CLASS-LATTICE*. This is just to check for typos and
525 ;; other sorts of brainos. (The exceptions, T and SEQUENCE, are
526 ;; those classes which are SYSTEM-CLASSes which nevertheless have
527 ;; BUILT-IN-CLASS subclasses.)
528 (dolist (e *built-in-classes*)
529 (dolist (super (cadr e))
530 (unless (or (eq super t)
531 (eq super 'sequence)
532 (assq super *built-in-classes*))
533 (error "in *BUILT-IN-CLASSES*: ~S has ~S as a super,~%~
534 but ~S is not itself a class in *BUILT-IN-CLASSES*."
535 (car e) super super))))
537 ;; In the first pass, we create a skeletal object to be bound to the
538 ;; class name.
539 (let* ((built-in-class (find-class 'built-in-class))
540 (built-in-class-wrapper (class-wrapper built-in-class)))
541 (dolist (e *built-in-classes*)
542 (let ((class (allocate-standard-instance built-in-class-wrapper)))
543 (setf (find-class (car e)) class))))
545 ;; In the second pass, we initialize the class objects.
546 (let ((class-eq-wrapper (class-wrapper (find-class 'class-eq-specializer))))
547 (dolist (e *built-in-classes*)
548 (destructuring-bind (name supers subs cpl prototype) e
549 (let* ((class (find-class name))
550 (lclass (find-classoid name))
551 (wrapper (classoid-layout lclass)))
552 (set (get-built-in-class-symbol name) class)
553 (set (get-built-in-wrapper-symbol name) wrapper)
554 (setf (classoid-pcl-class lclass) class)
556 (!bootstrap-initialize-class 'built-in-class class
557 name class-eq-wrapper nil
558 supers subs
559 (cons name cpl)
560 wrapper prototype))))))
562 (defun class-of (x)
563 (wrapper-class* (layout-of x)))
565 (defun eval-form (form)
566 (lambda () (eval form)))
568 (defun ensure-non-standard-class (name classoid &optional existing-class)
569 (flet
570 ((ensure (metaclass slots)
571 (let ((supers (mapcar #'classoid-name (classoid-direct-superclasses classoid))))
572 (ensure-class-using-class existing-class name
573 :metaclass metaclass :name name
574 :direct-superclasses supers
575 :direct-slots slots)))
576 (slot-initargs-from-structure-slotd (slotd)
577 (let ((accessor (structure-slotd-accessor-symbol slotd)))
578 `(:name ,(structure-slotd-name slotd)
579 :defstruct-accessor-symbol ,accessor
580 :internal-reader-function ,(structure-slotd-reader-function slotd)
581 :internal-writer-function ,(structure-slotd-writer-function name slotd)
582 :type ,(or (structure-slotd-type slotd) t)
583 :initform ,(structure-slotd-init-form slotd)
584 :initfunction ,(eval-form (structure-slotd-init-form slotd)))))
585 (slot-initargs-from-condition-slot (slot)
586 `(:name ,(condition-slot-name slot)
587 :initargs ,(condition-slot-initargs slot)
588 :readers ,(condition-slot-readers slot)
589 :writers ,(condition-slot-writers slot)
590 ,@(when (condition-slot-initform-p slot)
591 (let ((initform (condition-slot-initform slot))
592 (initfun (condition-slot-initfunction slot)))
593 `(:initform ',initform :initfunction ,initfun)))
594 :allocation ,(condition-slot-allocation slot)
595 :documentation ,(condition-slot-documentation slot))))
596 (cond ((structure-type-p name)
597 (ensure 'structure-class
598 (mapcar #'slot-initargs-from-structure-slotd
599 (structure-type-slot-description-list name))))
600 ((condition-type-p name)
601 (ensure 'condition-class
602 (mapcar #'slot-initargs-from-condition-slot
603 (condition-classoid-slots classoid))))
605 (error "~@<~S is not the name of a class.~@:>" name)))))
607 (defun ensure-deffoo-class (classoid)
608 (let ((class (classoid-pcl-class classoid)))
609 (cond (class
610 (ensure-non-standard-class (class-name class) classoid class))
611 ((eq 'complete **boot-state**)
612 (ensure-non-standard-class (classoid-name classoid) classoid)))))
614 (pushnew 'ensure-deffoo-class sb-kernel::*defstruct-hooks*)
615 (pushnew 'ensure-deffoo-class sb-kernel::*define-condition-hooks*)
617 (defun !make-class-predicate (class name source-location)
618 (let* ((gf (ensure-generic-function name :lambda-list '(object)
619 :definition-source source-location))
620 (mlist (if (eq **boot-state** 'complete)
621 (early-gf-methods gf)
622 (generic-function-methods gf))))
623 (unless mlist
624 (unless (eq class *the-class-t*)
625 (let* ((default-method-function #'constantly-nil)
626 (default-method-initargs (list :function default-method-function
627 'plist '(:constant-value nil)))
628 (default-method (make-a-method
629 'standard-method
631 (list 'object)
632 (list *the-class-t*)
633 default-method-initargs
634 "class predicate default method")))
635 (add-method gf default-method)))
636 (let* ((class-method-function #'constantly-t)
637 (class-method-initargs (list :function class-method-function
638 'plist '(:constant-value t)))
639 (class-method (make-a-method 'standard-method
641 (list 'object)
642 (list class)
643 class-method-initargs
644 "class predicate class method")))
645 (add-method gf class-method)))
646 gf))
648 ;;; Set the inherits from CPL, and register the layout. This actually
649 ;;; installs the class in the Lisp type system.
650 (defun %update-lisp-class-layout (class layout)
651 ;; Protected by *world-lock* in callers.
652 (let ((classoid (layout-classoid layout)))
653 (unless (eq (classoid-layout classoid) layout)
654 (setf (layout-inherits layout)
655 (order-layout-inherits
656 (map 'simple-vector #'class-wrapper
657 (reverse (rest (class-precedence-list class))))))
658 (register-layout layout :invalidate t)
660 ;; FIXME: I don't think this should be necessary, but without it
661 ;; we are unable to compile (TYPEP foo '<class-name>) in the
662 ;; same file as the class is defined. If we had environments,
663 ;; then I think the classsoid whould only be associated with the
664 ;; name in that environment... Alternatively, fix the compiler
665 ;; so that TYPEP foo '<class-name> is slow but compileable.
666 (let ((name (class-name class)))
667 (when (and name (symbolp name) (eq name (classoid-name classoid)))
668 (setf (find-classoid name) classoid))))))
670 (defun %set-class-type-translation (class classoid)
671 (when (not (typep classoid 'classoid))
672 (setq classoid (find-classoid classoid nil)))
673 (etypecase classoid
674 (null)
675 (built-in-classoid
676 (let ((translation (built-in-classoid-translation classoid)))
677 (cond
678 (translation
679 (aver (ctype-p translation))
680 (setf (info :type :translator class)
681 (lambda (spec) (declare (ignore spec)) translation)))
683 (setf (info :type :translator class)
684 (lambda (spec) (declare (ignore spec)) classoid))))))
685 (classoid
686 (setf (info :type :translator class)
687 (lambda (spec) (declare (ignore spec)) classoid)))))
689 (!bootstrap-meta-braid)
690 (!bootstrap-accessor-definitions t)
691 (!bootstrap-class-predicates t)
692 (!bootstrap-accessor-definitions nil)
693 (!bootstrap-class-predicates nil)
694 (!bootstrap-built-in-classes)
696 (loop for (name . x)
697 in (let (classoid-cells)
698 (do-all-symbols (s classoid-cells)
699 (let ((cell (sb-int:info :type :classoid-cell s)))
700 (when cell
701 (push (cons s cell) classoid-cells)))))
703 (when (classoid-cell-pcl-class x)
704 (let* ((class (find-class-from-cell name x))
705 (layout (class-wrapper class))
706 (lclass (layout-classoid layout))
707 (lclass-pcl-class (classoid-pcl-class lclass))
708 (olclass (find-classoid name nil)))
709 (if lclass-pcl-class
710 (aver (eq class lclass-pcl-class))
711 (setf (classoid-pcl-class lclass) class))
713 (%update-lisp-class-layout class layout)
715 (cond (olclass
716 (aver (eq lclass olclass)))
718 (setf (find-classoid name) lclass)))
720 (%set-class-type-translation class name))))
722 (setq **boot-state** 'braid)
724 (defmethod no-applicable-method (generic-function &rest args)
725 (error "~@<There is no applicable method for the generic function ~2I~_~S~
726 ~I~_when called with arguments ~2I~_~S.~:>"
727 generic-function
728 args))
730 (defmethod no-next-method ((generic-function standard-generic-function)
731 (method standard-method) &rest args)
732 (error "~@<There is no next method for the generic function ~2I~_~S~
733 ~I~_when called from method ~2I~_~S~I~_with arguments ~2I~_~S.~:>"
734 generic-function
735 method
736 args))
738 ;;; An extension to the ANSI standard: in the presence of e.g. a
739 ;;; :BEFORE method, it would seem that going through
740 ;;; NO-APPLICABLE-METHOD is prohibited, as in fact there is an
741 ;;; applicable method. -- CSR, 2002-11-15
742 (define-condition no-primary-method (reference-condition error)
743 ((generic-function :initarg :generic-function :reader no-primary-method-generic-function)
744 (args :initarg :args :reader no-primary-method-args))
745 (:report
746 (lambda (c s)
747 (format s "~@<There is no primary method for the generic function ~2I~_~S~
748 ~I~_when called with arguments ~2I~_~S.~:>"
749 (no-primary-method-generic-function c)
750 (no-primary-method-args c))))
751 (:default-initargs :references (list '(:ansi-cl :section (7 6 6 2)))))
752 (defmethod no-primary-method (generic-function &rest args)
753 (error 'no-primary-method :generic-function generic-function :args args))
755 (defmethod invalid-qualifiers ((gf generic-function)
756 combin
757 method)
758 (let ((qualifiers (method-qualifiers method)))
759 (let ((why (cond
760 ((cdr qualifiers) "has too many qualifiers")
761 (t (aver (not (member (car qualifiers)
762 '(:around :before :after))))
763 "has an invalid qualifier"))))
764 (invalid-method-error
765 method
766 "The method ~S on ~S ~A.~%~
767 Standard method combination requires all methods to have one~%~
768 of the single qualifiers :AROUND, :BEFORE and :AFTER or to~%~
769 have no qualifier at all."
770 method gf why))))