tests: Avoid nonsensical classes and methods in deprecation.impure.lisp
[sbcl.git] / src / pcl / braid.lisp
blob685cc38766b9f739436fbe0e8fc8b9c8f91a7052
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 (let ((instance (%make-standard-instance
36 (make-array (layout-length wrapper)
37 :initial-element +slot-unbound+)
38 #-compact-instance-header 0)))
39 (setf (%instance-layout instance) wrapper)
40 instance))
42 (define-condition unset-funcallable-instance-function
43 (reference-condition simple-error)
45 (:default-initargs
46 :references (list '(:amop :generic-function allocate-instance)
47 '(:amop :function set-funcallable-instance-function))))
49 (defun allocate-standard-funcallable-instance (wrapper)
50 (let* ((slots (make-array (layout-length wrapper) :initial-element +slot-unbound+))
51 (fin (cond #+(and compact-instance-header immobile-code)
52 ((not (eql (layout-bitmap wrapper) -1))
53 (let ((f (truly-the funcallable-instance
54 (sb-sys:%primitive sb-vm::alloc-generic-function slots))))
55 ;; Set layout prior to writing raw slots
56 (setf (%funcallable-instance-layout f) wrapper)
57 (sb-vm::%set-fin-trampoline f)))
59 (let ((f (%make-standard-funcallable-instance
60 slots
61 #-compact-instance-header (sb-impl::new-instance-hash-code))))
62 (setf (%funcallable-instance-layout f) wrapper)
63 f)))))
64 #+compact-instance-header
65 (set-header-data slots
66 (ash (logand (sb-impl::new-instance-hash-code) #xFFFFFFFF) 24))
67 (set-funcallable-instance-function
68 fin
69 #'(lambda (&rest args)
70 (declare (ignore args))
71 (error 'unset-funcallable-instance-function
72 :format-control "~@<The function of funcallable instance ~
73 ~S has not been set.~@:>"
74 :format-arguments (list fin))))
75 fin))
77 (defun classify-slotds (slotds)
78 (let (instance-slots class-slots custom-slots bootp)
79 (dolist (slotd slotds)
80 (let ((alloc (cond ((consp slotd) ; bootstrap
81 (setf bootp t)
82 :instance)
84 (slot-definition-allocation slotd)))))
85 (case alloc
86 (:instance
87 (push slotd instance-slots))
88 (:class
89 (push slotd class-slots))
91 (push slotd custom-slots)))))
92 (values (if bootp
93 (nreverse instance-slots)
94 (when slotds
95 (sort instance-slots #'< :key #'slot-definition-location)))
96 class-slots
97 custom-slots)))
99 ;;;; BOOTSTRAP-META-BRAID
100 ;;;;
101 ;;;; This function builds the base metabraid from the early class definitions.
103 (defmacro !initial-classes-and-wrappers (&rest classes)
104 `(progn
105 ,@(mapcar (lambda (class)
106 (let ((wr (format-symbol *pcl-package* "~A-WRAPPER" class)))
107 `(setf ,wr ,(if (eq class 'standard-generic-function)
108 '*sgf-wrapper*
109 `(!boot-make-wrapper
110 (!early-class-size ',class)
111 ',class))
112 ,class (allocate-standard-instance
113 ,(if (eq class 'standard-generic-function)
114 'funcallable-standard-class-wrapper
115 'standard-class-wrapper))
116 (wrapper-class ,wr) ,class
117 (find-class ',class) ,class)))
118 classes)))
120 (defun !wrapper-p (x) (and (sb-kernel::layout-p x) (layout-for-std-class-p x)))
122 (defun !bootstrap-meta-braid ()
123 (let* ((*create-classes-from-internal-structure-definitions-p* nil)
124 standard-class-wrapper standard-class
125 funcallable-standard-class-wrapper funcallable-standard-class
126 slot-class-wrapper slot-class
127 system-class-wrapper system-class
128 built-in-class-wrapper built-in-class
129 structure-class-wrapper structure-class
130 condition-class-wrapper condition-class
131 standard-direct-slot-definition-wrapper
132 standard-direct-slot-definition
133 standard-effective-slot-definition-wrapper
134 standard-effective-slot-definition
135 class-eq-specializer-wrapper class-eq-specializer
136 standard-generic-function-wrapper standard-generic-function)
137 (!initial-classes-and-wrappers
138 standard-class funcallable-standard-class
139 slot-class system-class built-in-class structure-class condition-class
140 standard-direct-slot-definition standard-effective-slot-definition
141 class-eq-specializer standard-generic-function)
142 ;; First, make a class metaobject for each of the early classes. For
143 ;; each metaobject we also set its wrapper. Except for the class T,
144 ;; the wrapper is always that of STANDARD-CLASS.
145 (dolist (definition *!early-class-definitions*)
146 (let* ((name (ecd-class-name definition))
147 (meta (ecd-metaclass definition))
148 (wrapper (ecase meta
149 (slot-class slot-class-wrapper)
150 (standard-class standard-class-wrapper)
151 (funcallable-standard-class
152 funcallable-standard-class-wrapper)
153 (built-in-class built-in-class-wrapper)
154 (system-class system-class-wrapper)
155 (structure-class structure-class-wrapper)
156 (condition-class condition-class-wrapper)))
157 (class (or (find-class name nil)
158 (allocate-standard-instance wrapper))))
159 (setf (find-class name) class)))
160 (dolist (definition *!early-class-definitions*)
161 (let ((name (ecd-class-name definition))
162 (meta (ecd-metaclass definition))
163 (source (ecd-source-location definition))
164 (direct-supers (ecd-superclass-names definition))
165 (direct-slots (ecd-canonical-slots definition))
166 (other-initargs (ecd-other-initargs definition)))
167 (let ((direct-default-initargs
168 (getf other-initargs :direct-default-initargs)))
169 (multiple-value-bind (slots cpl default-initargs direct-subclasses)
170 (!early-collect-inheritance name)
171 (let* ((class (find-class name))
172 (wrapper (cond ((eq class slot-class)
173 slot-class-wrapper)
174 ((eq class standard-class)
175 standard-class-wrapper)
176 ((eq class funcallable-standard-class)
177 funcallable-standard-class-wrapper)
178 ((eq class standard-direct-slot-definition)
179 standard-direct-slot-definition-wrapper)
180 ((eq class
181 standard-effective-slot-definition)
182 standard-effective-slot-definition-wrapper)
183 ((eq class system-class) system-class-wrapper)
184 ((eq class built-in-class)
185 built-in-class-wrapper)
186 ((eq class structure-class)
187 structure-class-wrapper)
188 ((eq class condition-class)
189 condition-class-wrapper)
190 ((eq class class-eq-specializer)
191 class-eq-specializer-wrapper)
192 ((eq class standard-generic-function)
193 standard-generic-function-wrapper)
195 (!boot-make-wrapper (length slots) name))))
196 (proto nil))
197 (set (make-class-symbol name) class)
198 (dolist (slot slots)
199 (unless (eq (getf slot :allocation :instance) :instance)
200 (error "Slot allocation ~S is not supported in bootstrap."
201 (getf slot :allocation))))
203 (when (!wrapper-p wrapper)
204 (setf (layout-slot-list wrapper) slots))
206 (setq proto (if (eq meta 'funcallable-standard-class)
207 (allocate-standard-funcallable-instance wrapper)
208 (allocate-standard-instance wrapper)))
210 (setq direct-slots
211 (!bootstrap-make-slot-definitions
212 name class direct-slots
213 standard-direct-slot-definition-wrapper nil))
214 (setq slots
215 (!bootstrap-make-slot-definitions
216 name class slots
217 standard-effective-slot-definition-wrapper t))
219 (setf (layout-slot-table wrapper) (make-slot-table class slots t))
220 (when (!wrapper-p wrapper)
221 (setf (layout-slot-list wrapper) slots))
223 (case meta
224 ((standard-class funcallable-standard-class)
225 (!bootstrap-initialize-class
226 meta
227 class name class-eq-specializer-wrapper source
228 direct-supers direct-subclasses cpl wrapper proto
229 direct-slots slots direct-default-initargs default-initargs))
230 (built-in-class ; *the-class-t*
231 (!bootstrap-initialize-class
232 meta
233 class name class-eq-specializer-wrapper source
234 direct-supers direct-subclasses cpl wrapper proto))
235 (system-class
236 (!bootstrap-initialize-class
237 meta
238 class name class-eq-specializer-wrapper source
239 direct-supers direct-subclasses cpl wrapper proto))
240 (slot-class ; *the-class-slot-object*
241 (!bootstrap-initialize-class
242 meta
243 class name class-eq-specializer-wrapper source
244 direct-supers direct-subclasses cpl wrapper proto))
245 (structure-class ; *the-class-structure-object*
246 (!bootstrap-initialize-class
247 meta
248 class name class-eq-specializer-wrapper source
249 direct-supers direct-subclasses cpl wrapper))
250 (condition-class
251 (!bootstrap-initialize-class
252 meta
253 class name class-eq-specializer-wrapper source
254 direct-supers direct-subclasses cpl wrapper))))))))
256 (setq **standard-method-classes**
257 (mapcar (lambda (name)
258 (symbol-value (make-class-symbol name)))
259 *standard-method-class-names*))
261 (flet ((make-method-combination (class-name)
262 (let* ((class (find-class class-name))
263 (wrapper (!bootstrap-get-slot
264 'standard-class class 'wrapper))
265 (instance (allocate-standard-instance wrapper)))
266 (flet ((set-slot (name value)
267 (!bootstrap-set-slot class-name instance name value)))
268 (values instance #'set-slot)))))
269 ;; Create the STANDARD method combination object.
270 (multiple-value-bind (method-combination set-slot)
271 (make-method-combination 'standard-method-combination)
272 (funcall set-slot 'source nil)
273 (funcall set-slot 'type-name 'standard)
274 (funcall set-slot 'options '())
275 (funcall set-slot '%documentation "The standard method combination.")
276 (setq *standard-method-combination* method-combination))
277 ;; Create the OR method combination object.
278 (multiple-value-bind (method-combination set-slot)
279 (make-method-combination 'short-method-combination)
280 (funcall set-slot 'source 'nil)
281 (funcall set-slot 'type-name 'or)
282 (funcall set-slot 'operator 'or)
283 (funcall set-slot 'identity-with-one-argument t)
284 (funcall set-slot '%documentation nil)
285 (funcall set-slot 'options '(:most-specific-first))
286 (setq *or-method-combination* method-combination)))))
288 ;;; Initialize a class metaobject.
289 (defun !bootstrap-initialize-class
290 (metaclass-name class name
291 class-eq-wrapper source direct-supers direct-subclasses cpl wrapper
292 &optional
293 (proto nil proto-p)
294 direct-slots slots direct-default-initargs default-initargs)
295 (flet ((classes (names) (mapcar #'find-class names))
296 (set-slot (slot-name value)
297 (!bootstrap-set-slot metaclass-name class slot-name value)))
298 (set-slot 'name name)
299 (set-slot 'finalized-p t)
300 (set-slot 'source source)
301 (set-slot 'safe-p nil)
302 (set-slot '%type (if (eq class (find-class t))
304 ;; FIXME: Could this just be CLASS instead
305 ;; of `(CLASS ,CLASS)? If not, why not?
306 ;; (See also similar expression in
307 ;; SHARED-INITIALIZE :BEFORE (CLASS).)
308 `(class ,class)))
309 (set-slot 'class-eq-specializer
310 (let ((spec (allocate-standard-instance class-eq-wrapper)))
311 (!bootstrap-set-slot 'class-eq-specializer spec '%type
312 `(class-eq ,class))
313 (!bootstrap-set-slot 'class-eq-specializer spec 'object
314 class)
315 spec))
316 (set-slot '%class-precedence-list (classes cpl))
317 (set-slot 'cpl-available-p t)
318 (set-slot 'can-precede-list (classes (cdr cpl)))
319 (set-slot 'incompatible-superclass-list nil)
320 (set-slot 'direct-superclasses (classes direct-supers))
321 (set-slot 'direct-subclasses (classes direct-subclasses))
322 (set-slot 'direct-methods (cons nil nil))
323 (set-slot 'wrapper wrapper)
324 (set-slot '%documentation nil)
325 (set-slot 'plist
326 `(,@(and direct-default-initargs
327 `(direct-default-initargs ,direct-default-initargs))
328 ,@(and default-initargs
329 `(default-initargs ,default-initargs))))
330 (when (memq metaclass-name '(standard-class funcallable-standard-class
331 structure-class condition-class
332 slot-class))
333 (set-slot 'direct-slots direct-slots)
334 (set-slot 'slots slots)
335 (setf (layout-slot-table wrapper)
336 (make-slot-table class slots
337 (member metaclass-name
338 '(standard-class funcallable-standard-class))))
339 (when (!wrapper-p wrapper)
340 (setf (layout-slot-list wrapper) slots)))
342 ;; For all direct superclasses SUPER of CLASS, make sure CLASS is
343 ;; a direct subclass of SUPER. Note that METACLASS-NAME doesn't
344 ;; matter here for the slot DIRECT-SUBCLASSES, since every class
345 ;; inherits the slot from class CLASS.
346 (dolist (super direct-supers)
347 (let* ((super (find-class super))
348 (subclasses (!bootstrap-get-slot metaclass-name super
349 'direct-subclasses)))
350 (cond ((eq +slot-unbound+ subclasses)
351 (!bootstrap-set-slot metaclass-name super 'direct-subclasses
352 (list class)))
353 ((not (memq class subclasses))
354 (!bootstrap-set-slot metaclass-name super 'direct-subclasses
355 (cons class subclasses))))))
357 (case metaclass-name
358 (structure-class
359 (let ((constructor-sym '|STRUCTURE-OBJECT class constructor|))
360 (set-slot 'defstruct-form
361 `(defstruct (structure-object (:constructor
362 ,constructor-sym)
363 (:copier nil))))
364 (set-slot 'defstruct-constructor constructor-sym)
365 (set-slot 'from-defclass-p t)
366 (set-slot 'plist nil)
367 (set-slot 'prototype (funcall constructor-sym))))
368 (condition-class
369 (set-slot 'prototype (make-condition name)))
371 (set-slot 'prototype
372 (if proto-p proto (allocate-standard-instance wrapper)))))
373 class))
375 (defun !bootstrap-make-slot-definitions (name class slots wrapper effective-p)
376 (let ((index -1))
377 (mapcar (lambda (slot)
378 (incf index)
379 (!bootstrap-make-slot-definition
380 name class slot wrapper effective-p index))
381 slots)))
383 (defun !bootstrap-make-slot-definition
384 (name class slot wrapper effective-p index)
385 (let* ((slotd-class-name (if effective-p
386 'standard-effective-slot-definition
387 'standard-direct-slot-definition))
388 (slotd (allocate-standard-instance wrapper))
389 (slot-name (getf slot :name)))
390 (flet ((get-val (name) (getf slot name))
391 (set-val (name val)
392 (!bootstrap-set-slot slotd-class-name slotd name val)))
393 (set-val 'name slot-name)
394 (set-val 'initform (get-val :initform))
395 (set-val 'initfunction (get-val :initfunction))
396 (set-val 'initargs (get-val :initargs))
397 (unless effective-p
398 (set-val 'readers (get-val :readers))
399 (set-val 'writers (get-val :writers)))
400 (set-val 'allocation :instance)
401 (set-val '%type (or (get-val :type) t))
402 (set-val '%documentation (or (get-val :documentation) ""))
403 (set-val '%class class)
404 (when effective-p
405 (set-val 'location index)
406 (set-val 'accessor-flags 7)
407 (set-val
408 'info
409 (make-slot-info
410 :reader
411 (make-optimized-std-reader-method-function nil nil slot-name index)
412 :writer
413 (make-optimized-std-writer-method-function nil nil slot-name index)
414 :boundp
415 (make-optimized-std-boundp-method-function nil nil slot-name index))))
416 (when (and (eq name 'standard-class)
417 (eq slot-name 'slots) effective-p)
418 (setq *the-eslotd-standard-class-slots* slotd))
419 (when (and (eq name 'funcallable-standard-class)
420 (eq slot-name 'slots) effective-p)
421 (setq *the-eslotd-funcallable-standard-class-slots* slotd))
422 slotd)))
424 (defun !bootstrap-accessor-definitions (early-p)
425 (let ((*early-p* early-p))
426 (dolist (definition *!early-class-definitions*)
427 (let ((name (ecd-class-name definition))
428 (meta (ecd-metaclass definition)))
429 (unless (or (eq meta 'built-in-class) (eq meta 'system-class))
430 (let ((direct-slots (ecd-canonical-slots definition)))
431 (dolist (slotd direct-slots)
432 (let ((slot-name (getf slotd :name))
433 (readers (getf slotd :readers))
434 (writers (getf slotd :writers)))
435 (!bootstrap-accessor-definitions1
436 name
437 slot-name
438 readers
439 writers
441 (ecd-source-location definition))))))))))
443 (defun !bootstrap-accessor-definition (class-name accessor-name slot-name type source-location)
444 (multiple-value-bind (accessor-class make-method-function arglist specls doc)
445 (ecase type
446 (reader (values 'standard-reader-method
447 #'make-std-reader-method-function
448 (list class-name)
449 (list class-name)
450 "automatically generated reader method"))
451 (writer (values 'standard-writer-method
452 #'make-std-writer-method-function
453 (list 'new-value class-name)
454 (list t class-name)
455 "automatically generated writer method"))
456 (boundp (values 'standard-boundp-method
457 #'make-std-boundp-method-function
458 (list class-name)
459 (list class-name)
460 "automatically generated boundp method")))
461 (let ((gf (ensure-generic-function accessor-name :lambda-list arglist)))
462 (if (find specls (early-gf-methods gf)
463 :key #'early-method-specializers
464 :test 'equal)
465 (unless (assoc accessor-name *!generic-function-fixups*
466 :test #'equal)
467 (update-dfun gf))
468 (add-method gf
469 (make-a-method accessor-class
471 arglist specls
472 (funcall make-method-function
473 class-name slot-name)
475 :slot-name slot-name
476 :object-class class-name
477 :method-class-function (constantly (find-class accessor-class))
478 :definition-source source-location))))))
480 (defun !bootstrap-accessor-definitions1 (class-name
481 slot-name
482 readers
483 writers
484 boundps
485 source-location)
486 (flet ((do-reader-definition (reader)
487 (!bootstrap-accessor-definition class-name
488 reader
489 slot-name
490 'reader
491 source-location))
492 (do-writer-definition (writer)
493 (!bootstrap-accessor-definition class-name
494 writer
495 slot-name
496 'writer
497 source-location))
498 (do-boundp-definition (boundp)
499 (!bootstrap-accessor-definition class-name
500 boundp
501 slot-name
502 'boundp
503 source-location)))
504 (dolist (reader readers) (do-reader-definition reader))
505 (dolist (writer writers) (do-writer-definition writer))
506 (dolist (boundp boundps) (do-boundp-definition boundp))))
508 (defun !bootstrap-built-in-classes ()
510 ;; First make sure that all the supers listed in
511 ;; *BUILT-IN-CLASS-LATTICE* are themselves defined by
512 ;; *BUILT-IN-CLASS-LATTICE*. This is just to check for typos and
513 ;; other sorts of brainos. (The exceptions, T and SEQUENCE, are
514 ;; those classes which are SYSTEM-CLASSes which nevertheless have
515 ;; BUILT-IN-CLASS subclasses.)
516 (dolist (e *built-in-classes*)
517 (dolist (super (cadr e))
518 (unless (or (eq super t)
519 (eq super 'sequence)
520 (assq super *built-in-classes*))
521 (error "in *BUILT-IN-CLASSES*: ~S has ~S as a super,~%~
522 but ~S is not itself a class in *BUILT-IN-CLASSES*."
523 (car e) super super))))
525 ;; In the first pass, we create a skeletal object to be bound to the
526 ;; class name.
527 (let* ((built-in-class (find-class 'built-in-class))
528 (built-in-class-wrapper (class-wrapper built-in-class)))
529 (dolist (e *built-in-classes*)
530 (let ((class (allocate-standard-instance built-in-class-wrapper)))
531 (setf (find-class (car e)) class))))
533 ;; In the second pass, we initialize the class objects.
534 (let ((class-eq-wrapper (class-wrapper (find-class 'class-eq-specializer))))
535 (dolist (e *built-in-classes*)
536 (destructuring-bind (name supers subs cpl prototype) e
537 (let* ((class (find-class name))
538 (lclass (find-classoid name))
539 (wrapper (classoid-layout lclass)))
540 (set (get-built-in-class-symbol name) class)
541 (setf (classoid-pcl-class lclass) class)
543 (!bootstrap-initialize-class 'built-in-class class
544 name class-eq-wrapper nil
545 supers subs
546 (cons name cpl)
547 wrapper prototype))))))
549 (defun class-of (x)
550 (declare (explicit-check))
551 (wrapper-class* (layout-of x)))
553 (defun eval-form (form)
554 (lambda () (eval form)))
556 (defun ensure-non-standard-class (name classoid &optional existing-class)
557 (flet
558 ((ensure (metaclass slots)
559 (let ((supers (mapcar #'classoid-name (classoid-direct-superclasses classoid))))
560 (ensure-class-using-class existing-class name
561 :metaclass metaclass :name name
562 :direct-superclasses supers
563 :direct-slots slots)))
564 (slot-initargs-from-structure-slotd (slotd)
565 (let ((accessor (structure-slotd-accessor-symbol slotd)))
566 `(:name ,(structure-slotd-name slotd)
567 :defstruct-accessor-symbol ,accessor
568 :internal-reader-function ,(structure-slotd-reader-function slotd)
569 :internal-writer-function ,(structure-slotd-writer-function name slotd)
570 :type ,(or (structure-slotd-type slotd) t)
571 :initform ,(structure-slotd-init-form slotd)
572 :initfunction ,(eval-form (structure-slotd-init-form slotd)))))
573 (slot-initargs-from-condition-slot (slot)
574 `(:name ,(condition-slot-name slot)
575 :initargs ,(condition-slot-initargs slot)
576 :readers ,(condition-slot-readers slot)
577 :writers ,(condition-slot-writers slot)
578 ,@(when (condition-slot-initform-p slot)
579 (let ((initform (condition-slot-initform slot))
580 (initfun (condition-slot-initfunction slot)))
581 `(:initform ',initform :initfunction ,initfun)))
582 :allocation ,(condition-slot-allocation slot)
583 :documentation ,(condition-slot-documentation slot))))
584 (cond ((structure-type-p name)
585 (ensure 'structure-class
586 (mapcar #'slot-initargs-from-structure-slotd
587 (structure-type-slot-description-list name))))
588 ((condition-type-p name)
589 (ensure 'condition-class
590 (mapcar #'slot-initargs-from-condition-slot
591 (condition-classoid-slots classoid))))
593 (error "~@<~S is not the name of a class.~@:>" name)))))
595 (defun ensure-deffoo-class (classoid)
596 (let ((class (classoid-pcl-class classoid)))
597 (cond (class
598 (ensure-non-standard-class (class-name class) classoid class))
599 ((eq 'complete **boot-state**)
600 (ensure-non-standard-class (classoid-name classoid) classoid)))))
602 (pushnew 'ensure-deffoo-class sb-kernel::*defstruct-hooks*)
603 (pushnew 'ensure-deffoo-class sb-kernel::*define-condition-hooks*)
605 (defun !make-class-predicate (class name source-location)
606 (let* ((gf (ensure-generic-function name :lambda-list '(object)
607 :definition-source source-location))
608 (mlist (if (eq **boot-state** 'complete)
609 (early-gf-methods gf)
610 (generic-function-methods gf))))
611 (unless mlist
612 (unless (eq class *the-class-t*)
613 (let* ((default-method-function #'constantly-nil)
614 (default-method-initargs (list :function default-method-function
615 'plist '(:constant-value nil)))
616 (default-method (make-a-method
617 'standard-method
619 (list 'object)
620 (list *the-class-t*)
621 default-method-initargs
622 "class predicate default method")))
623 (add-method gf default-method)))
624 (let* ((class-method-function #'constantly-t)
625 (class-method-initargs (list :function class-method-function
626 'plist '(:constant-value t)))
627 (class-method (make-a-method 'standard-method
629 (list 'object)
630 (list class)
631 class-method-initargs
632 "class predicate class method")))
633 (add-method gf class-method)))
634 gf))
636 ;;; Set the inherits from CPL, and register the layout. This actually
637 ;;; installs the class in the Lisp type system.
638 (defun %update-lisp-class-layout (class layout)
639 ;; Protected by *world-lock* in callers.
640 (let ((classoid (layout-classoid layout)))
641 (unless (eq (classoid-layout classoid) layout)
642 (setf (layout-inherits layout)
643 (order-layout-inherits
644 (map 'simple-vector #'class-wrapper
645 (reverse (rest (class-precedence-list class))))))
646 (register-layout layout :invalidate t)
648 ;; FIXME: I don't think this should be necessary, but without it
649 ;; we are unable to compile (TYPEP foo '<class-name>) in the
650 ;; same file as the class is defined. If we had environments,
651 ;; then I think the classsoid whould only be associated with the
652 ;; name in that environment... Alternatively, fix the compiler
653 ;; so that TYPEP foo '<class-name> is slow but compileable.
654 (let ((name (class-name class)))
655 (when (and name (symbolp name) (eq name (classoid-name classoid)))
656 (setf (find-classoid name) classoid))))))
658 (!bootstrap-meta-braid)
659 (!bootstrap-accessor-definitions t)
660 (!bootstrap-accessor-definitions nil)
661 (!bootstrap-built-in-classes)
663 (loop for (name . x)
664 in (let (classoid-cells)
665 (do-all-symbols (s classoid-cells)
666 (let ((cell (sb-int:info :type :classoid-cell s)))
667 (when cell
668 (push (cons s cell) classoid-cells)))))
670 (when (classoid-cell-pcl-class x)
671 (let* ((class (find-class-from-cell name x))
672 (layout (class-wrapper class))
673 (lclass (layout-classoid layout))
674 (lclass-pcl-class (classoid-pcl-class lclass))
675 (olclass (find-classoid name nil)))
676 (if lclass-pcl-class
677 (aver (eq class lclass-pcl-class))
678 (setf (classoid-pcl-class lclass) class))
680 (%update-lisp-class-layout class layout)
682 (cond (olclass
683 (aver (eq lclass olclass)))
685 (setf (find-classoid name) lclass)))
689 (setq **boot-state** 'braid)
691 (defmethod no-applicable-method (generic-function &rest args)
692 (error "~@<There is no applicable method for the generic function ~2I~_~S~
693 ~I~_when called with arguments ~2I~_~S.~:>"
694 generic-function
695 args))
697 (defmethod no-next-method ((generic-function standard-generic-function)
698 (method standard-method) &rest args)
699 (error "~@<There is no next method for the generic function ~2I~_~S~
700 ~I~_when called from method ~2I~_~S~I~_with arguments ~2I~_~S.~:>"
701 generic-function
702 method
703 args))
705 ;;; An extension to the ANSI standard: in the presence of e.g. a
706 ;;; :BEFORE method, it would seem that going through
707 ;;; NO-APPLICABLE-METHOD is prohibited, as in fact there is an
708 ;;; applicable method. -- CSR, 2002-11-15
709 (define-condition no-primary-method (reference-condition error)
710 ((generic-function :initarg :generic-function :reader no-primary-method-generic-function)
711 (args :initarg :args :reader no-primary-method-args))
712 (:report
713 (lambda (c s)
714 (format s "~@<There is no primary method for the generic function ~2I~_~S~
715 ~I~_when called with arguments ~2I~_~S.~:>"
716 (no-primary-method-generic-function c)
717 (no-primary-method-args c))))
718 (:default-initargs :references (list '(:ansi-cl :section (7 6 6 2)))))
719 (defmethod no-primary-method (generic-function &rest args)
720 (error 'no-primary-method :generic-function generic-function :args args))
722 ;; FIXME shouldn't this specialize on STANDARD-METHOD-COMBINATION?
723 (defmethod invalid-qualifiers ((gf generic-function)
724 combin
725 method)
726 (let* ((qualifiers (method-qualifiers method))
727 (qualifier (first qualifiers))
728 (type-name (method-combination-type-name combin))
729 (why (cond
730 ((cdr qualifiers)
731 "has too many qualifiers")
733 (aver (not (standard-method-combination-qualifier-p
734 qualifier)))
735 "has an invalid qualifier"))))
736 (invalid-method-error
737 method
738 "~@<The method ~S on ~S ~A.~
739 ~@:_~@:_~
740 ~@(~A~) method combination requires all methods to have one of ~
741 the single qualifiers ~{~S~#[~; and ~:;, ~]~} or to have no ~
742 qualifier at all.~@:>"
743 method gf why type-name +standard-method-combination-qualifiers+)))