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