b331634755b090d5901ae0ccdc16f559e788f474
[sbcl.git] / src / pcl / braid.lisp
1 ;;;; bootstrapping the meta-braid
2 ;;;;
3 ;;;; The code in this file takes the early definitions that have been saved
4 ;;;; up and actually builds those class objects. This work is largely driven
5 ;;;; off of those class definitions, but the fact that STANDARD-CLASS is the
6 ;;;; class of all metaclasses in the braid is built into this code pretty
7 ;;;; deeply.
8
9 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; more information.
11
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.
17
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.
31
32 (in-package "SB-PCL")
33 \f
34 (defun allocate-standard-instance (wrapper
35                                    &optional (slots-init nil slots-init-p))
36   (let ((instance (%%allocate-instance--class))
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 sb-int:index i))
48                      (setf (aref slots i) (first rem-slots)))
49                    slots))
50                 (t
51                  (make-array no-of-slots
52                              :initial-element +slot-unbound+))))
53     instance))
54
55 (defmacro allocate-funcallable-instance-slots (wrapper &optional
56                                                        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+))))
63
64 (defun allocate-funcallable-instance (wrapper &optional
65                                               (slots-init nil slots-init-p))
66   (let ((fin (allocate-funcallable-instance-1)))
67     (set-funcallable-instance-function
68      fin
69      #'(sb-kernel:instance-lambda (&rest args)
70          (declare (ignore args))
71          (error "The function of the funcallable-instance ~S has not been set."
72                 fin)))
73     (setf (fsc-instance-wrapper fin) wrapper
74           (fsc-instance-slots fin) (allocate-funcallable-instance-slots
75                                     wrapper slots-init-p slots-init))
76     fin))
77
78 (defun allocate-structure-instance (wrapper &optional
79                                             (slots-init nil slots-init-p))
80   (let* ((class (wrapper-class wrapper))
81          (constructor (class-defstruct-constructor class)))
82     (if constructor
83         (let ((instance (funcall constructor))
84               (slots (class-slots class)))
85           (when slots-init-p
86             (dolist (slot slots)
87               (setf (slot-value-using-class class instance slot)
88                     (pop slots-init))))
89           instance)
90         (error "can't allocate an instance of class ~S" (class-name class)))))
91 \f
92 ;;;; BOOTSTRAP-META-BRAID
93 ;;;;
94 ;;;; This function builds the base metabraid from the early class definitions.
95 ;;;;
96 ;;;; FIXME: This, like lotso the other stuff in PCL, is not needed in target
97 ;;;; Lisp, only at bootstrap time. Perhaps we should do something kludgy like
98 ;;;; putting a special character (#\$, perhaps) at the beginning of each
99 ;;;; needed-only-at-bootstrap-time symbol and then UNINTERN them all once we're
100 ;;;; done bootstrapping?
101
102 (defmacro initial-classes-and-wrappers (&rest classes)
103   `(progn
104      ,@(mapcar #'(lambda (class)
105                    (let ((wr (intern (format nil "~A-WRAPPER" class)
106                                      *pcl-package*)))
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)))
119
120 (defun bootstrap-meta-braid ()
121   (let* ((name 'class)
122          (predicate-name (make-type-predicate-name name)))
123     (setf (gdefinition predicate-name)
124           #'(lambda (x) (declare (ignore x)) t))
125     (do-satisfies-deftype name predicate-name))
126   (let* ((*create-classes-from-internal-structure-definitions-p* nil)
127          std-class-wrapper std-class
128          standard-class-wrapper standard-class
129          funcallable-standard-class-wrapper funcallable-standard-class
130          slot-class-wrapper slot-class
131          built-in-class-wrapper built-in-class
132          structure-class-wrapper structure-class
133          standard-direct-slot-definition-wrapper
134          standard-direct-slot-definition
135          standard-effective-slot-definition-wrapper
136          standard-effective-slot-definition
137          class-eq-specializer-wrapper class-eq-specializer
138          standard-generic-function-wrapper standard-generic-function)
139     (initial-classes-and-wrappers
140      standard-class funcallable-standard-class
141      slot-class built-in-class structure-class std-class
142      standard-direct-slot-definition standard-effective-slot-definition
143      class-eq-specializer standard-generic-function)
144     ;; First, make a class metaobject for each of the early classes. For
145     ;; each metaobject we also set its wrapper. Except for the class T,
146     ;; the wrapper is always that of STANDARD-CLASS.
147     (dolist (definition *early-class-definitions*)
148       (let* ((name (ecd-class-name definition))
149              (meta (ecd-metaclass definition))
150              (wrapper (ecase meta
151                         (slot-class slot-class-wrapper)
152                         (std-class std-class-wrapper)
153                         (standard-class standard-class-wrapper)
154                         (funcallable-standard-class
155                          funcallable-standard-class-wrapper)
156                         (built-in-class built-in-class-wrapper)
157                         (structure-class structure-class-wrapper)))
158              (class (or (find-class name nil)
159                         (allocate-standard-instance wrapper))))
160         (when (or (eq meta 'standard-class)
161                   (eq meta 'funcallable-standard-class))
162           (inform-type-system-about-std-class name))
163         (setf (find-class name) class)))
164     (dolist (definition *early-class-definitions*)
165       (let ((name (ecd-class-name definition))
166             (meta (ecd-metaclass definition))
167             (source (ecd-source definition))
168             (direct-supers (ecd-superclass-names definition))
169             (direct-slots  (ecd-canonical-slots definition))
170             (other-initargs (ecd-other-initargs definition)))
171         (let ((direct-default-initargs
172                (getf other-initargs :direct-default-initargs)))
173           (multiple-value-bind (slots cpl default-initargs direct-subclasses)
174               (early-collect-inheritance name)
175             (let* ((class (find-class name))
176                    (wrapper (cond ((eq class slot-class)
177                                    slot-class-wrapper)
178                                   ((eq class std-class)
179                                    std-class-wrapper)
180                                   ((eq class standard-class)
181                                    standard-class-wrapper)
182                                   ((eq class funcallable-standard-class)
183                                    funcallable-standard-class-wrapper)
184                                   ((eq class standard-direct-slot-definition)
185                                    standard-direct-slot-definition-wrapper)
186                                   ((eq class
187                                        standard-effective-slot-definition)
188                                    standard-effective-slot-definition-wrapper)
189                                   ((eq class built-in-class)
190                                    built-in-class-wrapper)
191                                   ((eq class structure-class)
192                                    structure-class-wrapper)
193                                   ((eq class class-eq-specializer)
194                                    class-eq-specializer-wrapper)
195                                   ((eq class standard-generic-function)
196                                    standard-generic-function-wrapper)
197                                   (t
198                                    (boot-make-wrapper (length slots) name))))
199                    (proto nil))
200               (when (eq name 't) (setq *the-wrapper-of-t* wrapper))
201               (set (intern (format nil "*THE-CLASS-~A*" (symbol-name name))
202                            *pcl-package*)
203                    class)
204               (dolist (slot slots)
205                 (unless (eq (getf slot :allocation :instance) :instance)
206                   (error "Slot allocation ~S is not supported in bootstrap.")))
207
208               (when (typep wrapper 'wrapper)
209                 (setf (wrapper-instance-slots-layout wrapper)
210                       (mapcar #'canonical-slot-name slots))
211                 (setf (wrapper-class-slots wrapper)
212                       ()))
213
214               (setq proto (if (eq meta 'funcallable-standard-class)
215                               (allocate-funcallable-instance wrapper)
216                               (allocate-standard-instance wrapper)))
217
218               (setq direct-slots
219                     (bootstrap-make-slot-definitions
220                      name class direct-slots
221                      standard-direct-slot-definition-wrapper nil))
222               (setq slots
223                     (bootstrap-make-slot-definitions
224                      name class slots
225                      standard-effective-slot-definition-wrapper t))
226
227               (case meta
228                 ((std-class standard-class funcallable-standard-class)
229                  (bootstrap-initialize-class
230                   meta
231                   class name class-eq-specializer-wrapper source
232                   direct-supers direct-subclasses cpl wrapper proto
233                   direct-slots slots direct-default-initargs default-initargs))
234                 (built-in-class         ; *the-class-t*
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
250     (let* ((smc-class (find-class 'standard-method-combination))
251            (smc-wrapper (bootstrap-get-slot 'standard-class
252                                             smc-class
253                                             'wrapper))
254            (smc (allocate-standard-instance smc-wrapper)))
255       (flet ((set-slot (name value)
256                (bootstrap-set-slot 'standard-method-combination
257                                    smc
258                                    name
259                                    value)))
260         (set-slot 'source *load-truename*)
261         (set-slot 'type 'standard)
262         (set-slot 'documentation "The standard method combination.")
263         (set-slot 'options ()))
264       (setq *standard-method-combination* smc))))
265
266 ;;; Initialize a class metaobject.
267 ;;;
268 ;;; FIXME: This and most stuff in this file is probably only needed at init
269 ;;; time.
270 (defun bootstrap-initialize-class
271        (metaclass-name class name
272         class-eq-wrapper source direct-supers direct-subclasses cpl wrapper
273         &optional
274         proto direct-slots slots direct-default-initargs default-initargs)
275   (flet ((classes (names) (mapcar #'find-class names))
276          (set-slot (slot-name value)
277            (bootstrap-set-slot metaclass-name class slot-name value)))
278     (set-slot 'name name)
279     (set-slot 'source source)
280     (set-slot 'type (if (eq class (find-class 't))
281                         t
282                         `(class ,class)))
283     (set-slot 'class-eq-specializer
284               (let ((spec (allocate-standard-instance class-eq-wrapper)))
285                 (bootstrap-set-slot 'class-eq-specializer spec 'type
286                                     `(class-eq ,class))
287                 (bootstrap-set-slot 'class-eq-specializer spec 'object
288                                     class)
289                 spec))
290     (set-slot 'class-precedence-list (classes cpl))
291     (set-slot 'can-precede-list (classes (cdr cpl)))
292     (set-slot 'incompatible-superclass-list nil)
293     (set-slot 'direct-superclasses (classes direct-supers))
294     (set-slot 'direct-subclasses (classes direct-subclasses))
295     (set-slot 'direct-methods (cons nil nil))
296     (set-slot 'wrapper wrapper)
297     (set-slot 'predicate-name (or (cadr (assoc name *early-class-predicates*))
298                                   (make-class-predicate-name name)))
299     (set-slot 'plist
300               `(,@(and direct-default-initargs
301                        `(direct-default-initargs ,direct-default-initargs))
302                 ,@(and default-initargs
303                        `(default-initargs ,default-initargs))))
304     (when (memq metaclass-name '(standard-class funcallable-standard-class
305                                  structure-class slot-class std-class))
306       (set-slot 'direct-slots direct-slots)
307       (set-slot 'slots slots)
308       (set-slot 'initialize-info nil))
309     (if (eq metaclass-name 'structure-class)
310         (let ((constructor-sym '|STRUCTURE-OBJECT class constructor|))
311           (set-slot 'predicate-name (or (cadr (assoc name
312                                                      *early-class-predicates*))
313                                         (make-class-predicate-name name)))
314           (set-slot 'defstruct-form
315                     `(defstruct (structure-object (:constructor
316                                                    ,constructor-sym))))
317           (set-slot 'defstruct-constructor constructor-sym)
318           (set-slot 'from-defclass-p t)
319           (set-slot 'plist nil)
320           (set-slot 'prototype (funcall constructor-sym)))
321         (set-slot 'prototype (or proto (allocate-standard-instance wrapper))))
322     class))
323
324 (defun bootstrap-make-slot-definitions (name class slots wrapper effective-p)
325   (let ((index -1))
326     (mapcar #'(lambda (slot)
327                 (incf index)
328                 (bootstrap-make-slot-definition
329                   name class slot wrapper effective-p index))
330             slots)))
331
332 (defun bootstrap-make-slot-definition
333     (name class slot wrapper effective-p index)
334   (let* ((slotd-class-name (if effective-p
335                                'standard-effective-slot-definition
336                                'standard-direct-slot-definition))
337          (slotd (allocate-standard-instance wrapper))
338          (slot-name (getf slot :name)))
339     (flet ((get-val (name) (getf slot name))
340            (set-val (name val)
341                     (bootstrap-set-slot slotd-class-name slotd name val)))
342       (set-val 'name     slot-name)
343       (set-val 'initform     (get-val :initform))
344       (set-val 'initfunction (get-val :initfunction))
345       (set-val 'initargs     (get-val :initargs))
346       (set-val 'readers      (get-val :readers))
347       (set-val 'writers      (get-val :writers))
348       (set-val 'allocation   :instance)
349       (set-val 'type     (or (get-val :type) t))
350       (set-val 'documentation (or (get-val :documentation) ""))
351       (set-val 'class   class)
352       (when effective-p
353         (set-val 'location index)
354         (let ((fsc-p nil))
355           (set-val 'reader-function (make-optimized-std-reader-method-function
356                                      fsc-p slot-name index))
357           (set-val 'writer-function (make-optimized-std-writer-method-function
358                                      fsc-p slot-name index))
359           (set-val 'boundp-function (make-optimized-std-boundp-method-function
360                                      fsc-p slot-name index)))
361         (set-val 'accessor-flags 7)
362         (let ((table (or (gethash slot-name *name->class->slotd-table*)
363                          (setf (gethash slot-name *name->class->slotd-table*)
364                                (make-hash-table :test 'eq :size 5)))))
365           (setf (gethash class table) slotd)))
366       (when (and (eq name 'standard-class)
367                  (eq slot-name 'slots) effective-p)
368         (setq *the-eslotd-standard-class-slots* slotd))
369       (when (and (eq name 'funcallable-standard-class)
370                  (eq slot-name 'slots) effective-p)
371         (setq *the-eslotd-funcallable-standard-class-slots* slotd))
372       slotd)))
373
374 (defun bootstrap-accessor-definitions (early-p)
375   (let ((*early-p* early-p))
376     (dolist (definition *early-class-definitions*)
377       (let ((name (ecd-class-name definition))
378             (meta (ecd-metaclass definition)))
379         (unless (eq meta 'built-in-class)
380           (let ((direct-slots  (ecd-canonical-slots definition)))
381             (dolist (slotd direct-slots)
382               (let ((slot-name (getf slotd :name))
383                     (readers (getf slotd :readers))
384                     (writers (getf slotd :writers)))
385                 (bootstrap-accessor-definitions1
386                  name
387                  slot-name
388                  readers
389                  writers
390                  nil)
391                 (bootstrap-accessor-definitions1
392                  'slot-object
393                  slot-name
394                  (list (slot-reader-symbol slot-name))
395                  (list (slot-writer-symbol slot-name))
396                  (list (slot-boundp-symbol slot-name)))))))))))
397
398 (defun bootstrap-accessor-definition (class-name accessor-name slot-name type)
399   (multiple-value-bind (accessor-class make-method-function arglist specls doc)
400       (ecase type
401         (reader (values 'standard-reader-method
402                         #'make-std-reader-method-function
403                         (list class-name)
404                         (list class-name)
405                         "automatically generated reader method"))
406         (writer (values 'standard-writer-method
407                         #'make-std-writer-method-function
408                         (list 'new-value class-name)
409                         (list 't class-name)
410                         "automatically generated writer method"))
411         (boundp (values 'standard-boundp-method
412                         #'make-std-boundp-method-function
413                         (list class-name)
414                         (list class-name)
415                         "automatically generated boundp method")))
416     (let ((gf (ensure-generic-function accessor-name)))
417       (if (find specls (early-gf-methods gf)
418                 :key #'early-method-specializers
419                 :test 'equal)
420           (unless (assoc accessor-name *generic-function-fixups*
421                          :test #'equal)
422             (update-dfun gf))
423           (add-method gf
424                       (make-a-method accessor-class
425                                      ()
426                                      arglist specls
427                                      (funcall make-method-function
428                                               class-name slot-name)
429                                      doc
430                                      slot-name))))))
431
432 (defun bootstrap-accessor-definitions1 (class-name
433                                         slot-name
434                                         readers
435                                         writers
436                                         boundps)
437   (flet ((do-reader-definition (reader)
438            (bootstrap-accessor-definition class-name
439                                           reader
440                                           slot-name
441                                           'reader))
442          (do-writer-definition (writer)
443            (bootstrap-accessor-definition class-name
444                                           writer
445                                           slot-name
446                                           'writer))
447          (do-boundp-definition (boundp)
448            (bootstrap-accessor-definition class-name
449                                           boundp
450                                           slot-name
451                                           'boundp)))
452     (dolist (reader readers) (do-reader-definition reader))
453     (dolist (writer writers) (do-writer-definition writer))
454     (dolist (boundp boundps) (do-boundp-definition boundp))))
455
456 (defun bootstrap-class-predicates (early-p)
457   (let ((*early-p* early-p))
458     (dolist (definition *early-class-definitions*)
459       (let* ((name (ecd-class-name definition))
460              (class (find-class name)))
461         (setf (find-class-predicate name)
462               (make-class-predicate class (class-predicate-name class)))))))
463
464 (defun bootstrap-built-in-classes ()
465
466   ;; First make sure that all the supers listed in
467   ;; *BUILT-IN-CLASS-LATTICE* are themselves defined by
468   ;; *BUILT-IN-CLASS-LATTICE*. This is just to check for typos and
469   ;; other sorts of brainos.
470   (dolist (e *built-in-classes*)
471     (dolist (super (cadr e))
472       (unless (or (eq super 't)
473                   (assq super *built-in-classes*))
474         (error "in *BUILT-IN-CLASSES*: ~S has ~S as a super,~%~
475                 but ~S is not itself a class in *BUILT-IN-CLASSES*."
476                (car e) super super))))
477
478   ;; In the first pass, we create a skeletal object to be bound to the
479   ;; class name.
480   (let* ((built-in-class (find-class 'built-in-class))
481          (built-in-class-wrapper (class-wrapper built-in-class)))
482     (dolist (e *built-in-classes*)
483       (let ((class (allocate-standard-instance built-in-class-wrapper)))
484         (setf (find-class (car e)) class))))
485
486   ;; In the second pass, we initialize the class objects.
487   (let ((class-eq-wrapper (class-wrapper (find-class 'class-eq-specializer))))
488     (dolist (e *built-in-classes*)
489       (destructuring-bind (name supers subs cpl prototype) e
490         (let* ((class (find-class name))
491                (lclass (cl:find-class name))
492                (wrapper (sb-kernel:class-layout lclass)))
493           (set (get-built-in-class-symbol name) class)
494           (set (get-built-in-wrapper-symbol name) wrapper)
495           (setf (sb-kernel:class-pcl-class lclass) class)
496
497           (bootstrap-initialize-class 'built-in-class class
498                                       name class-eq-wrapper nil
499                                       supers subs
500                                       (cons name cpl)
501                                       wrapper prototype)))))
502
503   (dolist (e *built-in-classes*)
504     (let* ((name (car e))
505            (class (find-class name)))
506       (setf (find-class-predicate name)
507             (make-class-predicate class (class-predicate-name class))))))
508 \f
509 (defmacro wrapper-of-macro (x)
510   `(sb-kernel:layout-of ,x))
511
512 (defun class-of (x)
513   (wrapper-class* (wrapper-of-macro x)))
514
515 ;;; FIXME: We probably don't need both WRAPPER-OF and WRAPPER-OF-MACRO.
516 #-sb-fluid (declaim (inline wrapper-of))
517 (defun wrapper-of (x)
518   (wrapper-of-macro x))
519
520 (defvar *find-structure-class* nil)
521
522 (defun eval-form (form)
523   #'(lambda () (eval form)))
524
525 (defun slot-initargs-from-structure-slotd (slotd)
526   `(:name ,(structure-slotd-name slotd)
527     :defstruct-accessor-symbol ,(structure-slotd-accessor-symbol slotd)
528     :internal-reader-function ,(structure-slotd-reader-function slotd)
529     :internal-writer-function ,(structure-slotd-writer-function slotd)
530     :type ,(or (structure-slotd-type slotd) t)
531     :initform ,(structure-slotd-init-form slotd)
532     :initfunction ,(eval-form (structure-slotd-init-form slotd))))
533
534 (defun find-structure-class (symbol)
535   (if (structure-type-p symbol)
536       (unless (eq *find-structure-class* symbol)
537         (let ((*find-structure-class* symbol))
538           (ensure-class symbol
539                         :metaclass 'structure-class
540                         :name symbol
541                         :direct-superclasses
542                         (cond ;; Handle our CMU-CL-ish structure-based
543                               ;; conditions.
544                               ((cl:subtypep symbol 'condition)
545                                (mapcar #'cl:class-name
546                                        (sb-kernel:class-direct-superclasses
547                                         (cl:find-class symbol))))
548                               ;; a hack to add the STREAM class as a
549                               ;; mixin to the LISP-STREAM class.
550                               ((eq symbol 'sb-sys:lisp-stream)
551                                '(structure-object stream))
552                               ((structure-type-included-type-name symbol)
553                                (list (structure-type-included-type-name
554                                       symbol))))
555                         :direct-slots
556                         (mapcar #'slot-initargs-from-structure-slotd
557                                 (structure-type-slot-description-list
558                                  symbol)))))
559       (error "~S is not a legal structure class name." symbol)))
560 \f
561 (defun method-function-returning-nil (args next-methods)
562   (declare (ignore args next-methods))
563   nil)
564
565 (defun method-function-returning-t (args next-methods)
566   (declare (ignore args next-methods))
567   t)
568
569 (defun make-class-predicate (class name)
570   (let* ((gf (ensure-generic-function name))
571          (mlist (if (eq *boot-state* 'complete)
572                     (generic-function-methods gf)
573                     (early-gf-methods gf))))
574     (unless mlist
575       (unless (eq class *the-class-t*)
576         (let* ((default-method-function #'method-function-returning-nil)
577                (default-method-initargs (list :function
578                                               default-method-function))
579                (default-method (make-a-method 'standard-method
580                                               ()
581                                               (list 'object)
582                                               (list *the-class-t*)
583                                               default-method-initargs
584                                               "class predicate default method")))
585           (setf (method-function-get default-method-function :constant-value)
586                 nil)
587           (add-method gf default-method)))
588       (let* ((class-method-function #'method-function-returning-t)
589              (class-method-initargs (list :function
590                                           class-method-function))
591              (class-method (make-a-method 'standard-method
592                                           ()
593                                           (list 'object)
594                                           (list class)
595                                           class-method-initargs
596                                           "class predicate class method")))
597         (setf (method-function-get class-method-function :constant-value) t)
598         (add-method gf class-method)))
599     gf))
600
601 ;;; Set the inherits from CPL, and register the layout. This actually
602 ;;; installs the class in the Lisp type system.
603 (defun update-lisp-class-layout (class layout)
604   (let ((lclass (sb-kernel:layout-class layout)))
605     (unless (eq (sb-kernel:class-layout lclass) layout)
606       (setf (sb-kernel:layout-inherits layout)
607             (map 'vector #'class-wrapper
608                  (reverse (rest (class-precedence-list class)))))
609       (sb-kernel:register-layout layout :invalidate nil)
610
611       ;; Subclasses of formerly forward-referenced-class may be unknown
612       ;; to CL:FIND-CLASS and also anonymous. This functionality moved
613       ;; here from (SETF FIND-CLASS).
614       (let ((name (class-name class)))
615         (setf (cl:find-class name) lclass
616               ;; FIXME: It's nasty to use double colons. Perhaps the
617               ;; best way to fix this is not to export CLASS-%NAME
618               ;; from SB-KERNEL, but instead to move the whole
619               ;; UPDATE-LISP-CLASS-LAYOUT function to SB-KERNEL, and
620               ;; export it. (since it's also nasty for us to be
621               ;; reaching into %KERNEL implementation details my
622               ;; messing with raw CLASS-%NAME)
623               (sb-kernel::class-%name lclass) name)))))
624
625 (eval-when (:load-toplevel :execute)
626
627   (clrhash *find-class*)
628   (bootstrap-meta-braid)
629   (bootstrap-accessor-definitions t)
630   (bootstrap-class-predicates t)
631   (bootstrap-accessor-definitions nil)
632   (bootstrap-class-predicates nil)
633   (bootstrap-built-in-classes)
634
635   (sb-int:dohash (name x *find-class*)
636     (let* ((class (find-class-from-cell name x))
637            (layout (class-wrapper class))
638            (lclass (sb-kernel:layout-class layout))
639            (lclass-pcl-class (sb-kernel:class-pcl-class lclass))
640            (olclass (cl:find-class name nil)))
641       (if lclass-pcl-class
642           (assert (eq class lclass-pcl-class))
643           (setf (sb-kernel:class-pcl-class lclass) class))
644
645       (update-lisp-class-layout class layout)
646
647       (cond (olclass
648              (assert (eq lclass olclass)))
649             (t
650              (setf (cl:find-class name) lclass)))))
651
652   (setq *boot-state* 'braid)
653
654   ) ; EVAL-WHEN
655
656 (defmethod no-applicable-method (generic-function &rest args)
657   ;; FIXME: probably could be ERROR instead of CERROR
658   (cerror "Retry call to ~S."
659           "There is no matching method for the generic function ~S~@
660           when called with arguments ~S."
661           generic-function
662           args)
663   (apply generic-function args))