0.pre7.74:
[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
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.
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 (%make-standard-instance nil))
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))
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 (%make-pcl-funcallable-instance nil nil)))
67     (set-funcallable-instance-fun
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 (defmacro !initial-classes-and-wrappers (&rest classes)
97   `(progn
98      ,@(mapcar #'(lambda (class)
99                    (let ((wr (intern (format nil "~A-WRAPPER" class)
100                                      *pcl-package*)))
101                      `(setf ,wr ,(if (eq class 'standard-generic-function)
102                                      '*sgf-wrapper*
103                                      `(boot-make-wrapper
104                                        (early-class-size ',class)
105                                        ',class))
106                             ,class (allocate-standard-instance
107                                     ,(if (eq class 'standard-generic-function)
108                                          'funcallable-standard-class-wrapper
109                                          'standard-class-wrapper))
110                             (wrapper-class ,wr) ,class
111                             (find-class ',class) ,class)))
112               classes)))
113
114 (defun !bootstrap-meta-braid ()
115   (let* ((*create-classes-from-internal-structure-definitions-p* nil)
116          std-class-wrapper std-class
117          standard-class-wrapper standard-class
118          funcallable-standard-class-wrapper funcallable-standard-class
119          slot-class-wrapper slot-class
120          built-in-class-wrapper built-in-class
121          structure-class-wrapper structure-class
122          standard-direct-slot-definition-wrapper
123          standard-direct-slot-definition
124          standard-effective-slot-definition-wrapper
125          standard-effective-slot-definition
126          class-eq-specializer-wrapper class-eq-specializer
127          standard-generic-function-wrapper standard-generic-function)
128     (!initial-classes-and-wrappers
129      standard-class funcallable-standard-class
130      slot-class built-in-class structure-class std-class
131      standard-direct-slot-definition standard-effective-slot-definition
132      class-eq-specializer standard-generic-function)
133     ;; First, make a class metaobject for each of the early classes. For
134     ;; each metaobject we also set its wrapper. Except for the class T,
135     ;; the wrapper is always that of STANDARD-CLASS.
136     (dolist (definition *early-class-definitions*)
137       (let* ((name (ecd-class-name definition))
138              (meta (ecd-metaclass definition))
139              (wrapper (ecase meta
140                         (slot-class slot-class-wrapper)
141                         (std-class std-class-wrapper)
142                         (standard-class standard-class-wrapper)
143                         (funcallable-standard-class
144                          funcallable-standard-class-wrapper)
145                         (built-in-class built-in-class-wrapper)
146                         (structure-class structure-class-wrapper)))
147              (class (or (find-class name nil)
148                         (allocate-standard-instance wrapper))))
149         (when (or (eq meta 'standard-class)
150                   (eq meta 'funcallable-standard-class))
151           (inform-type-system-about-std-class name))
152         (setf (find-class name) class)))
153     (dolist (definition *early-class-definitions*)
154       (let ((name (ecd-class-name definition))
155             (meta (ecd-metaclass definition))
156             (source (ecd-source definition))
157             (direct-supers (ecd-superclass-names definition))
158             (direct-slots  (ecd-canonical-slots definition))
159             (other-initargs (ecd-other-initargs definition)))
160         (let ((direct-default-initargs
161                (getf other-initargs :direct-default-initargs)))
162           (multiple-value-bind (slots cpl default-initargs direct-subclasses)
163               (early-collect-inheritance name)
164             (let* ((class (find-class name))
165                    (wrapper (cond ((eq class slot-class)
166                                    slot-class-wrapper)
167                                   ((eq class std-class)
168                                    std-class-wrapper)
169                                   ((eq class standard-class)
170                                    standard-class-wrapper)
171                                   ((eq class funcallable-standard-class)
172                                    funcallable-standard-class-wrapper)
173                                   ((eq class standard-direct-slot-definition)
174                                    standard-direct-slot-definition-wrapper)
175                                   ((eq class
176                                        standard-effective-slot-definition)
177                                    standard-effective-slot-definition-wrapper)
178                                   ((eq class built-in-class)
179                                    built-in-class-wrapper)
180                                   ((eq class structure-class)
181                                    structure-class-wrapper)
182                                   ((eq class class-eq-specializer)
183                                    class-eq-specializer-wrapper)
184                                   ((eq class standard-generic-function)
185                                    standard-generic-function-wrapper)
186                                   (t
187                                    (boot-make-wrapper (length slots) name))))
188                    (proto nil))
189               (when (eq name t) (setq *the-wrapper-of-t* wrapper))
190               (set (intern (format nil "*THE-CLASS-~A*" (symbol-name name))
191                            *pcl-package*)
192                    class)
193               (dolist (slot slots)
194                 (unless (eq (getf slot :allocation :instance) :instance)
195                   (error "Slot allocation ~S is not supported in bootstrap.")))
196
197               (when (typep wrapper 'wrapper)
198                 (setf (wrapper-instance-slots-layout wrapper)
199                       (mapcar #'canonical-slot-name slots))
200                 (setf (wrapper-class-slots wrapper)
201                       ()))
202
203               (setq proto (if (eq meta 'funcallable-standard-class)
204                               (allocate-funcallable-instance wrapper)
205                               (allocate-standard-instance wrapper)))
206
207               (setq direct-slots
208                     (!bootstrap-make-slot-definitions
209                      name class direct-slots
210                      standard-direct-slot-definition-wrapper nil))
211               (setq slots
212                     (!bootstrap-make-slot-definitions
213                      name class slots
214                      standard-effective-slot-definition-wrapper t))
215
216               (case meta
217                 ((std-class standard-class funcallable-standard-class)
218                  (!bootstrap-initialize-class
219                   meta
220                   class name class-eq-specializer-wrapper source
221                   direct-supers direct-subclasses cpl wrapper proto
222                   direct-slots slots direct-default-initargs default-initargs))
223                 (built-in-class         ; *the-class-t*
224                  (!bootstrap-initialize-class
225                   meta
226                   class name class-eq-specializer-wrapper source
227                   direct-supers direct-subclasses cpl wrapper proto))
228                 (slot-class             ; *the-class-slot-object*
229                  (!bootstrap-initialize-class
230                   meta
231                   class name class-eq-specializer-wrapper source
232                   direct-supers direct-subclasses cpl wrapper proto))
233                 (structure-class        ; *the-class-structure-object*
234                  (!bootstrap-initialize-class
235                   meta
236                   class name class-eq-specializer-wrapper source
237                   direct-supers direct-subclasses cpl wrapper))))))))
238
239     (let* ((smc-class (find-class 'standard-method-combination))
240            (smc-wrapper (!bootstrap-get-slot 'standard-class
241                                              smc-class
242                                              'wrapper))
243            (smc (allocate-standard-instance smc-wrapper)))
244       (flet ((set-slot (name value)
245                (!bootstrap-set-slot 'standard-method-combination
246                                     smc
247                                     name
248                                     value)))
249         (set-slot 'source *load-truename*)
250         (set-slot 'type 'standard)
251         (set-slot 'documentation "The standard method combination.")
252         (set-slot 'options ()))
253       (setq *standard-method-combination* smc))))
254
255 ;;; Initialize a class metaobject.
256 (defun !bootstrap-initialize-class
257        (metaclass-name class name
258         class-eq-wrapper source direct-supers direct-subclasses cpl wrapper
259         &optional
260         proto direct-slots slots direct-default-initargs default-initargs)
261   (flet ((classes (names) (mapcar #'find-class names))
262          (set-slot (slot-name value)
263            (!bootstrap-set-slot metaclass-name class slot-name value)))
264     (set-slot 'name name)
265     (set-slot 'source source)
266     (set-slot 'type (if (eq class (find-class t))
267                         t
268                         ;; FIXME: Could this just be CLASS instead
269                         ;; of `(CLASS ,CLASS)? If not, why not?
270                         ;; (See also similar expression in 
271                         ;; SHARED-INITIALIZE :BEFORE (CLASS).)
272                         `(class ,class)))
273     (set-slot 'class-eq-specializer
274               (let ((spec (allocate-standard-instance class-eq-wrapper)))
275                 (!bootstrap-set-slot 'class-eq-specializer spec 'type
276                                      `(class-eq ,class))
277                 (!bootstrap-set-slot 'class-eq-specializer spec 'object
278                                      class)
279                 spec))
280     (set-slot 'class-precedence-list (classes cpl))
281     (set-slot 'can-precede-list (classes (cdr cpl)))
282     (set-slot 'incompatible-superclass-list nil)
283     (set-slot 'direct-superclasses (classes direct-supers))
284     (set-slot 'direct-subclasses (classes direct-subclasses))
285     (set-slot 'direct-methods (cons nil nil))
286     (set-slot 'wrapper wrapper)
287     (set-slot 'predicate-name (or (cadr (assoc name *early-class-predicates*))
288                                   (make-class-predicate-name name)))
289     (set-slot 'plist
290               `(,@(and direct-default-initargs
291                        `(direct-default-initargs ,direct-default-initargs))
292                 ,@(and default-initargs
293                        `(default-initargs ,default-initargs))))
294     (when (memq metaclass-name '(standard-class funcallable-standard-class
295                                  structure-class slot-class std-class))
296       (set-slot 'direct-slots direct-slots)
297       (set-slot 'slots slots)
298       (set-slot 'initialize-info nil))
299     (if (eq metaclass-name 'structure-class)
300         (let ((constructor-sym '|STRUCTURE-OBJECT class constructor|))
301           (set-slot 'predicate-name (or (cadr (assoc name
302                                                      *early-class-predicates*))
303                                         (make-class-predicate-name name)))
304           (set-slot 'defstruct-form
305                     `(defstruct (structure-object (:constructor
306                                                    ,constructor-sym)
307                                                   (:copier nil))))
308           (set-slot 'defstruct-constructor constructor-sym)
309           (set-slot 'from-defclass-p t)
310           (set-slot 'plist nil)
311           (set-slot 'prototype (funcall constructor-sym)))
312         (set-slot 'prototype (or proto (allocate-standard-instance wrapper))))
313     class))
314
315 (defun !bootstrap-make-slot-definitions (name class slots wrapper effective-p)
316   (let ((index -1))
317     (mapcar (lambda (slot)
318               (incf index)
319               (!bootstrap-make-slot-definition
320                name class slot wrapper effective-p index))
321             slots)))
322
323 (defun !bootstrap-make-slot-definition
324     (name class slot wrapper effective-p index)
325   (let* ((slotd-class-name (if effective-p
326                                'standard-effective-slot-definition
327                                'standard-direct-slot-definition))
328          (slotd (allocate-standard-instance wrapper))
329          (slot-name (getf slot :name)))
330     (flet ((get-val (name) (getf slot name))
331            (set-val (name val)
332                     (!bootstrap-set-slot slotd-class-name slotd name val)))
333       (set-val 'name         slot-name)
334       (set-val 'initform     (get-val :initform))
335       (set-val 'initfunction (get-val :initfunction))
336       (set-val 'initargs     (get-val :initargs))
337       (set-val 'readers      (get-val :readers))
338       (set-val 'writers      (get-val :writers))
339       (set-val 'allocation   :instance)
340       (set-val 'type         (or (get-val :type) t))
341       (set-val 'documentation (or (get-val :documentation) ""))
342       (set-val 'class   class)
343       (when effective-p
344         (set-val 'location index)
345         (let ((fsc-p nil))
346           (set-val 'reader-function (make-optimized-std-reader-method-function
347                                      fsc-p slot-name index))
348           (set-val 'writer-function (make-optimized-std-writer-method-function
349                                      fsc-p slot-name index))
350           (set-val 'boundp-function (make-optimized-std-boundp-method-function
351                                      fsc-p slot-name index)))
352         (set-val 'accessor-flags 7)
353         (let ((table (or (gethash slot-name *name->class->slotd-table*)
354                          (setf (gethash slot-name *name->class->slotd-table*)
355                                (make-hash-table :test 'eq :size 5)))))
356           (setf (gethash class table) slotd)))
357       (when (and (eq name 'standard-class)
358                  (eq slot-name 'slots) effective-p)
359         (setq *the-eslotd-standard-class-slots* slotd))
360       (when (and (eq name 'funcallable-standard-class)
361                  (eq slot-name 'slots) effective-p)
362         (setq *the-eslotd-funcallable-standard-class-slots* slotd))
363       slotd)))
364
365 (defun !bootstrap-accessor-definitions (early-p)
366   (let ((*early-p* early-p))
367     (dolist (definition *early-class-definitions*)
368       (let ((name (ecd-class-name definition))
369             (meta (ecd-metaclass definition)))
370         (unless (eq meta 'built-in-class)
371           (let ((direct-slots  (ecd-canonical-slots definition)))
372             (dolist (slotd direct-slots)
373               (let ((slot-name (getf slotd :name))
374                     (readers (getf slotd :readers))
375                     (writers (getf slotd :writers)))
376                 (!bootstrap-accessor-definitions1
377                  name
378                  slot-name
379                  readers
380                  writers
381                  nil)
382                 (!bootstrap-accessor-definitions1
383                  'slot-object
384                  slot-name
385                  (list (slot-reader-symbol slot-name))
386                  (list (slot-writer-symbol slot-name))
387                  (list (slot-boundp-symbol slot-name)))))))))))
388
389 (defun !bootstrap-accessor-definition (class-name accessor-name slot-name type)
390   (multiple-value-bind (accessor-class make-method-function arglist specls doc)
391       (ecase type
392         (reader (values 'standard-reader-method
393                         #'make-std-reader-method-function
394                         (list class-name)
395                         (list class-name)
396                         "automatically generated reader method"))
397         (writer (values 'standard-writer-method
398                         #'make-std-writer-method-function
399                         (list 'new-value class-name)
400                         (list t class-name)
401                         "automatically generated writer method"))
402         (boundp (values 'standard-boundp-method
403                         #'make-std-boundp-method-function
404                         (list class-name)
405                         (list class-name)
406                         "automatically generated boundp method")))
407     (let ((gf (ensure-generic-function accessor-name)))
408       (if (find specls (early-gf-methods gf)
409                 :key #'early-method-specializers
410                 :test 'equal)
411           (unless (assoc accessor-name *!generic-function-fixups*
412                          :test #'equal)
413             (update-dfun gf))
414           (add-method gf
415                       (make-a-method accessor-class
416                                      ()
417                                      arglist specls
418                                      (funcall make-method-function
419                                               class-name slot-name)
420                                      doc
421                                      slot-name))))))
422
423 (defun !bootstrap-accessor-definitions1 (class-name
424                                         slot-name
425                                         readers
426                                         writers
427                                         boundps)
428   (flet ((do-reader-definition (reader)
429            (!bootstrap-accessor-definition class-name
430                                            reader
431                                            slot-name
432                                            'reader))
433          (do-writer-definition (writer)
434            (!bootstrap-accessor-definition class-name
435                                            writer
436                                            slot-name
437                                            'writer))
438          (do-boundp-definition (boundp)
439            (!bootstrap-accessor-definition class-name
440                                            boundp
441                                            slot-name
442                                            'boundp)))
443     (dolist (reader readers) (do-reader-definition reader))
444     (dolist (writer writers) (do-writer-definition writer))
445     (dolist (boundp boundps) (do-boundp-definition boundp))))
446
447 (defun !bootstrap-class-predicates (early-p)
448   (let ((*early-p* early-p))
449     (dolist (definition *early-class-definitions*)
450       (let* ((name (ecd-class-name definition))
451              (class (find-class name)))
452         (setf (find-class-predicate name)
453               (make-class-predicate class (class-predicate-name class)))))))
454
455 (defun !bootstrap-built-in-classes ()
456
457   ;; First make sure that all the supers listed in
458   ;; *BUILT-IN-CLASS-LATTICE* are themselves defined by
459   ;; *BUILT-IN-CLASS-LATTICE*. This is just to check for typos and
460   ;; other sorts of brainos.
461   (dolist (e *built-in-classes*)
462     (dolist (super (cadr e))
463       (unless (or (eq super t)
464                   (assq super *built-in-classes*))
465         (error "in *BUILT-IN-CLASSES*: ~S has ~S as a super,~%~
466                 but ~S is not itself a class in *BUILT-IN-CLASSES*."
467                (car e) super super))))
468
469   ;; In the first pass, we create a skeletal object to be bound to the
470   ;; class name.
471   (let* ((built-in-class (find-class 'built-in-class))
472          (built-in-class-wrapper (class-wrapper built-in-class)))
473     (dolist (e *built-in-classes*)
474       (let ((class (allocate-standard-instance built-in-class-wrapper)))
475         (setf (find-class (car e)) class))))
476
477   ;; In the second pass, we initialize the class objects.
478   (let ((class-eq-wrapper (class-wrapper (find-class 'class-eq-specializer))))
479     (dolist (e *built-in-classes*)
480       (destructuring-bind (name supers subs cpl prototype) e
481         (let* ((class (find-class name))
482                (lclass (cl:find-class name))
483                (wrapper (sb-kernel:class-layout lclass)))
484           (set (get-built-in-class-symbol name) class)
485           (set (get-built-in-wrapper-symbol name) wrapper)
486           (setf (sb-kernel:class-pcl-class lclass) class)
487
488           (!bootstrap-initialize-class 'built-in-class class
489                                        name class-eq-wrapper nil
490                                        supers subs
491                                        (cons name cpl)
492                                        wrapper prototype)))))
493
494   (dolist (e *built-in-classes*)
495     (let* ((name (car e))
496            (class (find-class name)))
497       (setf (find-class-predicate name)
498             (make-class-predicate class (class-predicate-name class))))))
499 \f
500 (defmacro wrapper-of-macro (x)
501   `(sb-kernel:layout-of ,x))
502
503 (defun class-of (x)
504   (wrapper-class* (wrapper-of-macro x)))
505
506 ;;; FIXME: We probably don't need both WRAPPER-OF and WRAPPER-OF-MACRO.
507 #-sb-fluid (declaim (inline wrapper-of))
508 (defun wrapper-of (x)
509   (wrapper-of-macro x))
510
511 (defvar *find-structure-class* nil)
512
513 (defun eval-form (form)
514   #'(lambda () (eval form)))
515
516 (defun slot-initargs-from-structure-slotd (slotd)
517   `(:name ,(structure-slotd-name slotd)
518     :defstruct-accessor-symbol ,(structure-slotd-accessor-symbol slotd)
519     :internal-reader-function ,(structure-slotd-reader-function slotd)
520     :internal-writer-function ,(structure-slotd-writer-function slotd)
521     :type ,(or (structure-slotd-type slotd) t)
522     :initform ,(structure-slotd-init-form slotd)
523     :initfunction ,(eval-form (structure-slotd-init-form slotd))))
524
525 (defun find-structure-class (symbol)
526   (if (structure-type-p symbol)
527       (unless (eq *find-structure-class* symbol)
528         (let ((*find-structure-class* symbol))
529           (ensure-class symbol
530                         :metaclass 'structure-class
531                         :name symbol
532                         :direct-superclasses
533                         (mapcar #'cl:class-name
534                                 (sb-kernel:class-direct-superclasses
535                                  (cl:find-class symbol)))
536                         :direct-slots
537                         (mapcar #'slot-initargs-from-structure-slotd
538                                 (structure-type-slot-description-list
539                                  symbol)))))
540       (error "~S is not a legal structure class name." symbol)))
541 \f
542 (defun make-class-predicate (class name)
543   (let* ((gf (ensure-generic-function name))
544          (mlist (if (eq *boot-state* 'complete)
545                     (generic-function-methods gf)
546                     (early-gf-methods gf))))
547     (unless mlist
548       (unless (eq class *the-class-t*)
549         (let* ((default-method-function #'constantly-nil)
550                (default-method-initargs (list :function
551                                               default-method-function))
552                (default-method (make-a-method
553                                 'standard-method
554                                 ()
555                                 (list 'object)
556                                 (list *the-class-t*)
557                                 default-method-initargs
558                                 "class predicate default method")))
559           (setf (method-function-get default-method-function :constant-value)
560                 nil)
561           (add-method gf default-method)))
562       (let* ((class-method-function #'constantly-t)
563              (class-method-initargs (list :function
564                                           class-method-function))
565              (class-method (make-a-method 'standard-method
566                                           ()
567                                           (list 'object)
568                                           (list class)
569                                           class-method-initargs
570                                           "class predicate class method")))
571         (setf (method-function-get class-method-function :constant-value) t)
572         (add-method gf class-method)))
573     gf))
574
575 ;;; Set the inherits from CPL, and register the layout. This actually
576 ;;; installs the class in the Lisp type system.
577 (defun update-lisp-class-layout (class layout)
578   (let ((lclass (sb-kernel:layout-class layout)))
579     (unless (eq (sb-kernel:class-layout lclass) layout)
580       (setf (sb-kernel:layout-inherits layout)
581               (sb-kernel:order-layout-inherits
582                (map 'simple-vector #'class-wrapper
583                     (reverse (rest (class-precedence-list class))))))
584       (sb-kernel:register-layout layout :invalidate nil)
585
586       ;; Subclasses of formerly forward-referenced-class may be
587       ;; unknown to CL:FIND-CLASS and also anonymous. This
588       ;; functionality moved here from (SETF FIND-CLASS).
589       (let ((name (class-name class)))
590         (setf (cl:find-class name) lclass
591               ;; FIXME: It's nasty to use double colons. Perhaps the
592               ;; best way to fix this is not to export CLASS-%NAME
593               ;; from SB-KERNEL, but instead to move the whole
594               ;; UPDATE-LISP-CLASS-LAYOUT function to SB-KERNEL, and
595               ;; export it. (since it's also nasty for us to be
596               ;; reaching into %KERNEL implementation details my
597               ;; messing with raw CLASS-%NAME)
598               (sb-kernel::class-%name lclass) name)))))
599
600 (clrhash *find-class*)
601 (!bootstrap-meta-braid)
602 (!bootstrap-accessor-definitions t)
603 (!bootstrap-class-predicates t)
604 (!bootstrap-accessor-definitions nil)
605 (!bootstrap-class-predicates nil)
606 (!bootstrap-built-in-classes)
607
608 (dohash (name x *find-class*)
609         (let* ((class (find-class-from-cell name x))
610                (layout (class-wrapper class))
611                (lclass (sb-kernel:layout-class layout))
612                (lclass-pcl-class (sb-kernel:class-pcl-class lclass))
613                (olclass (cl:find-class name nil)))
614           (if lclass-pcl-class
615               (aver (eq class lclass-pcl-class))
616               (setf (sb-kernel:class-pcl-class lclass) class))
617
618           (update-lisp-class-layout class layout)
619
620           (cond (olclass
621                  (aver (eq lclass olclass)))
622                 (t
623                  (setf (cl:find-class name) lclass)))))
624
625 (setq *boot-state* 'braid)
626
627 (defmethod no-applicable-method (generic-function &rest args)
628   (error "~@<There is no matching method for the generic function ~2I~_~S~
629           ~I~_when called with arguments ~2I~_~S.~:>"
630          generic-function
631          args))