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