Move ARM number stack pointer to r14.
[sbcl/nyef.git] / src / pcl / braid.lisp
blob3565b52d5bbdaf6bf42941a68a8d7fbcd0af6106
1 ;;;; bootstrapping the meta-braid
2 ;;;;
3 ;;;; The code in this file takes the early definitions that have been
4 ;;;; saved up and actually builds those class objects. This work is
5 ;;;; largely driven off of those class definitions, but the fact that
6 ;;;; STANDARD-CLASS is the class of all metaclasses in the braid is
7 ;;;; built into this code pretty deeply.
9 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; more information.
12 ;;;; This software is derived from software originally released by Xerox
13 ;;;; Corporation. Copyright and release statements follow. Later modifications
14 ;;;; to the software are in the public domain and are provided with
15 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
16 ;;;; information.
18 ;;;; copyright information from original PCL sources:
19 ;;;;
20 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
21 ;;;; All rights reserved.
22 ;;;;
23 ;;;; Use and copying of this software and preparation of derivative works based
24 ;;;; upon this software are permitted. Any distribution of this software or
25 ;;;; derivative works must comply with all applicable United States export
26 ;;;; control laws.
27 ;;;;
28 ;;;; This software is made available AS IS, and Xerox Corporation makes no
29 ;;;; warranty about the software, its performance or its conformity to any
30 ;;;; specification.
32 (in-package "SB-PCL")
34 (defun allocate-standard-instance (wrapper
35 &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))
51 (make-array no-of-slots
52 :initial-element +slot-unbound+))))
53 instance))
55 (defmacro allocate-standard-funcallable-instance-slots
56 (wrapper &optional 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+))))
64 (define-condition unset-funcallable-instance-function
65 (reference-condition simple-error)
67 (:default-initargs
68 :references (list '(:amop :generic-function allocate-instance)
69 '(:amop :function set-funcallable-instance-function))))
71 (defun allocate-standard-funcallable-instance
72 (wrapper &optional (slots-init nil slots-init-p))
73 (let ((fin (%make-standard-funcallable-instance
74 nil nil (get-instance-hash-code))))
75 (set-funcallable-instance-function
76 fin
77 #'(lambda (&rest args)
78 (declare (ignore args))
79 (error 'unset-funcallable-instance-function
80 :format-control "~@<The function of funcallable instance ~
81 ~S has not been set.~@:>"
82 :format-arguments (list fin))))
83 (setf (fsc-instance-wrapper fin) wrapper
84 (fsc-instance-slots fin)
85 (allocate-standard-funcallable-instance-slots
86 wrapper slots-init-p slots-init))
87 fin))
89 (defun classify-slotds (slotds)
90 (let (instance-slots class-slots custom-slots bootp)
91 (dolist (slotd slotds)
92 (let ((alloc (cond ((consp slotd) ; bootstrap
93 (setf bootp t)
94 :instance)
96 (slot-definition-allocation slotd)))))
97 (case alloc
98 (:instance
99 (push slotd instance-slots))
100 (:class
101 (push slotd class-slots))
103 (push slotd custom-slots)))))
104 (values (if bootp
105 (nreverse instance-slots)
106 (when slotds
107 (sort instance-slots #'< :key #'slot-definition-location)))
108 class-slots
109 custom-slots)))
111 ;;;; BOOTSTRAP-META-BRAID
112 ;;;;
113 ;;;; This function builds the base metabraid from the early class definitions.
115 (defmacro !initial-classes-and-wrappers (&rest classes)
116 `(progn
117 ,@(mapcar (lambda (class)
118 (let ((wr (format-symbol *pcl-package* "~A-WRAPPER" class)))
119 `(setf ,wr ,(if (eq class 'standard-generic-function)
120 '*sgf-wrapper*
121 `(!boot-make-wrapper
122 (early-class-size ',class)
123 ',class))
124 ,class (allocate-standard-instance
125 ,(if (eq class 'standard-generic-function)
126 'funcallable-standard-class-wrapper
127 'standard-class-wrapper))
128 (wrapper-class ,wr) ,class
129 (find-class ',class) ,class)))
130 classes)))
132 (defun !wrapper-p (x) (and (sb-kernel::layout-p x) (layout-for-std-class-p x)))
134 (defun !bootstrap-meta-braid ()
135 (let* ((*create-classes-from-internal-structure-definitions-p* nil)
136 standard-class-wrapper standard-class
137 funcallable-standard-class-wrapper funcallable-standard-class
138 slot-class-wrapper slot-class
139 built-in-class-wrapper built-in-class
140 structure-class-wrapper structure-class
141 condition-class-wrapper condition-class
142 standard-direct-slot-definition-wrapper
143 standard-direct-slot-definition
144 standard-effective-slot-definition-wrapper
145 standard-effective-slot-definition
146 class-eq-specializer-wrapper class-eq-specializer
147 standard-generic-function-wrapper standard-generic-function)
148 (!initial-classes-and-wrappers
149 standard-class funcallable-standard-class
150 slot-class built-in-class structure-class condition-class
151 standard-direct-slot-definition standard-effective-slot-definition
152 class-eq-specializer standard-generic-function)
153 ;; First, make a class metaobject for each of the early classes. For
154 ;; each metaobject we also set its wrapper. Except for the class T,
155 ;; the wrapper is always that of STANDARD-CLASS.
156 (dolist (definition *early-class-definitions*)
157 (let* ((name (ecd-class-name definition))
158 (meta (ecd-metaclass definition))
159 (wrapper (ecase meta
160 (slot-class slot-class-wrapper)
161 (standard-class standard-class-wrapper)
162 (funcallable-standard-class
163 funcallable-standard-class-wrapper)
164 (built-in-class built-in-class-wrapper)
165 (structure-class structure-class-wrapper)
166 (condition-class condition-class-wrapper)))
167 (class (or (find-class name nil)
168 (allocate-standard-instance wrapper))))
169 (setf (find-class name) class)))
170 (dolist (definition *early-class-definitions*)
171 (let ((name (ecd-class-name definition))
172 (meta (ecd-metaclass definition))
173 (source (ecd-source-location definition))
174 (direct-supers (ecd-superclass-names definition))
175 (direct-slots (ecd-canonical-slots definition))
176 (other-initargs (ecd-other-initargs definition)))
177 (let ((direct-default-initargs
178 (getf other-initargs :direct-default-initargs)))
179 (multiple-value-bind (slots cpl default-initargs direct-subclasses)
180 (early-collect-inheritance name)
181 (let* ((class (find-class name))
182 (wrapper (cond ((eq class slot-class)
183 slot-class-wrapper)
184 ((eq class standard-class)
185 standard-class-wrapper)
186 ((eq class funcallable-standard-class)
187 funcallable-standard-class-wrapper)
188 ((eq class standard-direct-slot-definition)
189 standard-direct-slot-definition-wrapper)
190 ((eq class
191 standard-effective-slot-definition)
192 standard-effective-slot-definition-wrapper)
193 ((eq class built-in-class)
194 built-in-class-wrapper)
195 ((eq class structure-class)
196 structure-class-wrapper)
197 ((eq class condition-class)
198 condition-class-wrapper)
199 ((eq class class-eq-specializer)
200 class-eq-specializer-wrapper)
201 ((eq class standard-generic-function)
202 standard-generic-function-wrapper)
204 (!boot-make-wrapper (length slots) name))))
205 (proto nil))
206 (when (eq name t) (setq *the-wrapper-of-t* wrapper))
207 (set (make-class-symbol name) class)
208 (dolist (slot slots)
209 (unless (eq (getf slot :allocation :instance) :instance)
210 (error "Slot allocation ~S is not supported in bootstrap."
211 (getf slot :allocation))))
213 (when (!wrapper-p wrapper)
214 (setf (layout-slot-list wrapper) slots))
216 (setq proto (if (eq meta 'funcallable-standard-class)
217 (allocate-standard-funcallable-instance wrapper)
218 (allocate-standard-instance wrapper)))
220 (setq direct-slots
221 (!bootstrap-make-slot-definitions
222 name class direct-slots
223 standard-direct-slot-definition-wrapper nil))
224 (setq slots
225 (!bootstrap-make-slot-definitions
226 name class slots
227 standard-effective-slot-definition-wrapper t))
229 (setf (layout-slot-table wrapper) (make-slot-table class slots t))
230 (when (!wrapper-p wrapper)
231 (setf (layout-slot-list wrapper) slots))
233 (case meta
234 ((standard-class funcallable-standard-class)
235 (!bootstrap-initialize-class
236 meta
237 class name class-eq-specializer-wrapper source
238 direct-supers direct-subclasses cpl wrapper proto
239 direct-slots slots direct-default-initargs default-initargs))
240 (built-in-class ; *the-class-t*
241 (!bootstrap-initialize-class
242 meta
243 class name class-eq-specializer-wrapper source
244 direct-supers direct-subclasses cpl wrapper proto))
245 (slot-class ; *the-class-slot-object*
246 (!bootstrap-initialize-class
247 meta
248 class name class-eq-specializer-wrapper source
249 direct-supers direct-subclasses cpl wrapper proto))
250 (structure-class ; *the-class-structure-object*
251 (!bootstrap-initialize-class
252 meta
253 class name class-eq-specializer-wrapper source
254 direct-supers direct-subclasses cpl wrapper))
255 (condition-class
256 (!bootstrap-initialize-class
257 meta
258 class name class-eq-specializer-wrapper source
259 direct-supers direct-subclasses cpl wrapper))))))))
261 (setq **standard-method-classes**
262 (mapcar (lambda (name)
263 (symbol-value (make-class-symbol name)))
264 *standard-method-class-names*))
266 (let* ((smc-class (find-class 'standard-method-combination))
267 (smc-wrapper (!bootstrap-get-slot 'standard-class
268 smc-class
269 'wrapper))
270 (smc (allocate-standard-instance smc-wrapper)))
271 (flet ((set-slot (name value)
272 (!bootstrap-set-slot 'standard-method-combination
274 name
275 value)))
276 (set-slot 'source nil)
277 (set-slot 'type-name 'standard)
278 (set-slot '%documentation "The standard method combination.")
279 (set-slot 'options ()))
280 (setq *standard-method-combination* smc))))
282 ;;; Initialize a class metaobject.
283 (defun !bootstrap-initialize-class
284 (metaclass-name class name
285 class-eq-wrapper source direct-supers direct-subclasses cpl wrapper
286 &optional
287 (proto nil proto-p)
288 direct-slots slots direct-default-initargs default-initargs)
289 (flet ((classes (names) (mapcar #'find-class names))
290 (set-slot (slot-name value)
291 (!bootstrap-set-slot metaclass-name class slot-name value)))
292 (set-slot 'name name)
293 (set-slot 'finalized-p t)
294 (set-slot 'source source)
295 (set-slot 'safe-p nil)
296 (set-slot '%type (if (eq class (find-class t))
298 ;; FIXME: Could this just be CLASS instead
299 ;; of `(CLASS ,CLASS)? If not, why not?
300 ;; (See also similar expression in
301 ;; SHARED-INITIALIZE :BEFORE (CLASS).)
302 `(class ,class)))
303 (set-slot 'class-eq-specializer
304 (let ((spec (allocate-standard-instance class-eq-wrapper)))
305 (!bootstrap-set-slot 'class-eq-specializer spec '%type
306 `(class-eq ,class))
307 (!bootstrap-set-slot 'class-eq-specializer spec 'object
308 class)
309 spec))
310 (set-slot '%class-precedence-list (classes cpl))
311 (set-slot 'cpl-available-p t)
312 (set-slot 'can-precede-list (classes (cdr cpl)))
313 (set-slot 'incompatible-superclass-list nil)
314 (set-slot 'direct-superclasses (classes direct-supers))
315 (set-slot 'direct-subclasses (classes direct-subclasses))
316 (set-slot 'direct-methods (cons nil nil))
317 (set-slot 'wrapper wrapper)
318 (set-slot '%documentation nil)
319 (set-slot 'plist
320 `(,@(and direct-default-initargs
321 `(direct-default-initargs ,direct-default-initargs))
322 ,@(and default-initargs
323 `(default-initargs ,default-initargs))))
324 (when (memq metaclass-name '(standard-class funcallable-standard-class
325 structure-class condition-class
326 slot-class))
327 (set-slot 'direct-slots direct-slots)
328 (set-slot 'slots slots)
329 (setf (layout-slot-table wrapper)
330 (make-slot-table class slots
331 (member metaclass-name
332 '(standard-class funcallable-standard-class))))
333 (when (!wrapper-p wrapper)
334 (setf (layout-slot-list wrapper) slots)))
336 ;; For all direct superclasses SUPER of CLASS, make sure CLASS is
337 ;; a direct subclass of SUPER. Note that METACLASS-NAME doesn't
338 ;; matter here for the slot DIRECT-SUBCLASSES, since every class
339 ;; inherits the slot from class CLASS.
340 (dolist (super direct-supers)
341 (let* ((super (find-class super))
342 (subclasses (!bootstrap-get-slot metaclass-name super
343 'direct-subclasses)))
344 (cond ((eq +slot-unbound+ subclasses)
345 (!bootstrap-set-slot metaclass-name super 'direct-subclasses
346 (list class)))
347 ((not (memq class subclasses))
348 (!bootstrap-set-slot metaclass-name super 'direct-subclasses
349 (cons class subclasses))))))
351 (case metaclass-name
352 (structure-class
353 (let ((constructor-sym '|STRUCTURE-OBJECT class constructor|))
354 (set-slot 'defstruct-form
355 `(defstruct (structure-object (:constructor
356 ,constructor-sym)
357 (:copier nil))))
358 (set-slot 'defstruct-constructor constructor-sym)
359 (set-slot 'from-defclass-p t)
360 (set-slot 'plist nil)
361 (set-slot 'prototype (funcall constructor-sym))))
362 (condition-class
363 (set-slot 'prototype (make-condition name)))
365 (set-slot 'prototype
366 (if proto-p proto (allocate-standard-instance wrapper)))))
367 class))
369 (defun !bootstrap-make-slot-definitions (name class slots wrapper effective-p)
370 (let ((index -1))
371 (mapcar (lambda (slot)
372 (incf index)
373 (!bootstrap-make-slot-definition
374 name class slot wrapper effective-p index))
375 slots)))
377 (defun !bootstrap-make-slot-definition
378 (name class slot wrapper effective-p index)
379 (let* ((slotd-class-name (if effective-p
380 'standard-effective-slot-definition
381 'standard-direct-slot-definition))
382 (slotd (allocate-standard-instance wrapper))
383 (slot-name (getf slot :name)))
384 (flet ((get-val (name) (getf slot name))
385 (set-val (name val)
386 (!bootstrap-set-slot slotd-class-name slotd name val)))
387 (set-val 'name slot-name)
388 (set-val 'initform (get-val :initform))
389 (set-val 'initfunction (get-val :initfunction))
390 (set-val 'initargs (get-val :initargs))
391 (unless effective-p
392 (set-val 'readers (get-val :readers))
393 (set-val 'writers (get-val :writers)))
394 (set-val 'allocation :instance)
395 (set-val '%type (or (get-val :type) t))
396 (set-val '%documentation (or (get-val :documentation) ""))
397 (set-val '%class class)
398 (when effective-p
399 (set-val 'location index)
400 (set-val 'accessor-flags 7)
401 (set-val
402 'info
403 (make-slot-info
404 :reader
405 (make-optimized-std-reader-method-function nil nil slot-name index)
406 :writer
407 (make-optimized-std-writer-method-function nil nil slot-name index)
408 :boundp
409 (make-optimized-std-boundp-method-function nil nil slot-name index))))
410 (when (and (eq name 'standard-class)
411 (eq slot-name 'slots) effective-p)
412 (setq *the-eslotd-standard-class-slots* slotd))
413 (when (and (eq name 'funcallable-standard-class)
414 (eq slot-name 'slots) effective-p)
415 (setq *the-eslotd-funcallable-standard-class-slots* slotd))
416 slotd)))
418 (defun !bootstrap-accessor-definitions (early-p)
419 (let ((*early-p* early-p))
420 (dolist (definition *early-class-definitions*)
421 (let ((name (ecd-class-name definition))
422 (meta (ecd-metaclass definition)))
423 (unless (eq meta 'built-in-class)
424 (let ((direct-slots (ecd-canonical-slots definition)))
425 (dolist (slotd direct-slots)
426 (let ((slot-name (getf slotd :name))
427 (readers (getf slotd :readers))
428 (writers (getf slotd :writers)))
429 (!bootstrap-accessor-definitions1
430 name
431 slot-name
432 readers
433 writers
435 (ecd-source-location definition))))))))))
437 (defun !bootstrap-accessor-definition (class-name accessor-name slot-name type source-location)
438 (multiple-value-bind (accessor-class make-method-function arglist specls doc)
439 (ecase type
440 (reader (values 'standard-reader-method
441 #'make-std-reader-method-function
442 (list class-name)
443 (list class-name)
444 "automatically generated reader method"))
445 (writer (values 'standard-writer-method
446 #'make-std-writer-method-function
447 (list 'new-value class-name)
448 (list t class-name)
449 "automatically generated writer method"))
450 (boundp (values 'standard-boundp-method
451 #'make-std-boundp-method-function
452 (list class-name)
453 (list class-name)
454 "automatically generated boundp method")))
455 (let ((gf (ensure-generic-function accessor-name :lambda-list arglist)))
456 (if (find specls (early-gf-methods gf)
457 :key #'early-method-specializers
458 :test 'equal)
459 (unless (assoc accessor-name *!generic-function-fixups*
460 :test #'equal)
461 (update-dfun gf))
462 (add-method gf
463 (make-a-method accessor-class
465 arglist specls
466 (funcall make-method-function
467 class-name slot-name)
469 :slot-name slot-name
470 :object-class class-name
471 :method-class-function (constantly (find-class accessor-class))
472 :definition-source source-location))))))
474 (defun !bootstrap-accessor-definitions1 (class-name
475 slot-name
476 readers
477 writers
478 boundps
479 source-location)
480 (flet ((do-reader-definition (reader)
481 (!bootstrap-accessor-definition class-name
482 reader
483 slot-name
484 'reader
485 source-location))
486 (do-writer-definition (writer)
487 (!bootstrap-accessor-definition class-name
488 writer
489 slot-name
490 'writer
491 source-location))
492 (do-boundp-definition (boundp)
493 (!bootstrap-accessor-definition class-name
494 boundp
495 slot-name
496 'boundp
497 source-location)))
498 (dolist (reader readers) (do-reader-definition reader))
499 (dolist (writer writers) (do-writer-definition writer))
500 (dolist (boundp boundps) (do-boundp-definition boundp))))
502 ;;; FIXME: find a better name.
503 (defun !bootstrap-class-predicates (early-p)
504 (let ((*early-p* early-p))
505 (dolist (ecp *early-class-predicates*)
506 (let ((class-name (car ecp))
507 (predicate-name (cadr ecp)))
508 (make-class-predicate (find-class class-name) predicate-name)))))
510 (defun !bootstrap-built-in-classes ()
512 ;; First make sure that all the supers listed in
513 ;; *BUILT-IN-CLASS-LATTICE* are themselves defined by
514 ;; *BUILT-IN-CLASS-LATTICE*. This is just to check for typos and
515 ;; other sorts of brainos.
516 (dolist (e *built-in-classes*)
517 (dolist (super (cadr e))
518 (unless (or (eq super t)
519 (assq super *built-in-classes*))
520 (error "in *BUILT-IN-CLASSES*: ~S has ~S as a super,~%~
521 but ~S is not itself a class in *BUILT-IN-CLASSES*."
522 (car e) super super))))
524 ;; In the first pass, we create a skeletal object to be bound to the
525 ;; class name.
526 (let* ((built-in-class (find-class 'built-in-class))
527 (built-in-class-wrapper (class-wrapper built-in-class)))
528 (dolist (e *built-in-classes*)
529 (let ((class (allocate-standard-instance built-in-class-wrapper)))
530 (setf (find-class (car e)) class))))
532 ;; In the second pass, we initialize the class objects.
533 (let ((class-eq-wrapper (class-wrapper (find-class 'class-eq-specializer))))
534 (dolist (e *built-in-classes*)
535 (destructuring-bind (name supers subs cpl prototype) e
536 (let* ((class (find-class name))
537 (lclass (find-classoid name))
538 (wrapper (classoid-layout lclass)))
539 (set (get-built-in-class-symbol name) class)
540 (set (get-built-in-wrapper-symbol name) wrapper)
541 (setf (classoid-pcl-class lclass) class)
543 (!bootstrap-initialize-class 'built-in-class class
544 name class-eq-wrapper nil
545 supers subs
546 (cons name cpl)
547 wrapper prototype))))))
549 (defun class-of (x)
550 (wrapper-class* (layout-of x)))
552 (defun eval-form (form)
553 (lambda () (eval form)))
555 (defun ensure-non-standard-class (name classoid &optional existing-class)
556 (flet
557 ((ensure (metaclass &optional (slots nil slotsp))
558 (let ((supers (mapcar #'classoid-name (classoid-direct-superclasses classoid))))
559 (if slotsp
560 (ensure-class-using-class existing-class name
561 :metaclass metaclass :name name
562 :direct-superclasses supers
563 :direct-slots slots)
564 (ensure-class-using-class existing-class name
565 :metaclass metaclass :name name
566 :direct-superclasses supers))))
567 (slot-initargs-from-structure-slotd (slotd)
568 (let ((accessor (structure-slotd-accessor-symbol slotd)))
569 `(:name ,(structure-slotd-name slotd)
570 :defstruct-accessor-symbol ,accessor
571 :internal-reader-function ,(structure-slotd-reader-function slotd)
572 :internal-writer-function ,(structure-slotd-writer-function name slotd)
573 :type ,(or (structure-slotd-type slotd) t)
574 :initform ,(structure-slotd-init-form slotd)
575 :initfunction ,(eval-form (structure-slotd-init-form slotd)))))
576 (slot-initargs-from-condition-slot (slot)
577 `(:name ,(condition-slot-name slot)
578 :initargs ,(condition-slot-initargs slot)
579 :readers ,(condition-slot-readers slot)
580 :writers ,(condition-slot-writers slot)
581 ,@(when (condition-slot-initform-p slot)
582 (let ((initform (condition-slot-initform slot))
583 (initfun (condition-slot-initfunction slot)))
584 `(:initform ',initform :initfunction ,initfun)))
585 :allocation ,(condition-slot-allocation slot)
586 :documentation ,(condition-slot-documentation slot))))
587 (cond ((structure-type-p name)
588 (ensure 'structure-class
589 (mapcar #'slot-initargs-from-structure-slotd
590 (structure-type-slot-description-list name))))
591 ((condition-type-p name)
592 (ensure 'condition-class
593 (mapcar #'slot-initargs-from-condition-slot
594 (condition-classoid-slots classoid))))
596 (error "~@<~S is not the name of a class.~@:>" name)))))
598 (defun ensure-deffoo-class (classoid)
599 (let ((class (classoid-pcl-class classoid)))
600 (cond (class
601 (ensure-non-standard-class (class-name class) classoid class))
602 ((eq 'complete **boot-state**)
603 (ensure-non-standard-class (classoid-name classoid) classoid)))))
605 (pushnew 'ensure-deffoo-class sb-kernel::*defstruct-hooks*)
606 (pushnew 'ensure-deffoo-class sb-kernel::*define-condition-hooks*)
608 ;;; FIXME: only needed during bootstrap
609 (defun make-class-predicate (class name)
610 (let* ((gf (ensure-generic-function name :lambda-list '(object)))
611 (mlist (if (eq **boot-state** 'complete)
612 (early-gf-methods gf)
613 (generic-function-methods gf))))
614 (unless mlist
615 (unless (eq class *the-class-t*)
616 (let* ((default-method-function #'constantly-nil)
617 (default-method-initargs (list :function default-method-function
618 'plist '(:constant-value nil)))
619 (default-method (make-a-method
620 'standard-method
622 (list 'object)
623 (list *the-class-t*)
624 default-method-initargs
625 "class predicate default method")))
626 (add-method gf default-method)))
627 (let* ((class-method-function #'constantly-t)
628 (class-method-initargs (list :function class-method-function
629 'plist '(:constant-value t)))
630 (class-method (make-a-method 'standard-method
632 (list 'object)
633 (list class)
634 class-method-initargs
635 "class predicate class method")))
636 (add-method gf class-method)))
637 gf))
639 ;;; Set the inherits from CPL, and register the layout. This actually
640 ;;; installs the class in the Lisp type system.
641 (defun %update-lisp-class-layout (class layout)
642 ;; Protected by *world-lock* in callers.
643 (let ((classoid (layout-classoid layout)))
644 (unless (eq (classoid-layout classoid) layout)
645 (setf (layout-inherits layout)
646 (order-layout-inherits
647 (map 'simple-vector #'class-wrapper
648 (reverse (rest (class-precedence-list class))))))
649 (register-layout layout :invalidate t)
651 ;; FIXME: I don't think this should be necessary, but without it
652 ;; we are unable to compile (TYPEP foo '<class-name>) in the
653 ;; same file as the class is defined. If we had environments,
654 ;; then I think the classsoid whould only be associated with the
655 ;; name in that environment... Alternatively, fix the compiler
656 ;; so that TYPEP foo '<class-name> is slow but compileable.
657 (let ((name (class-name class)))
658 (when (and name (symbolp name) (eq name (classoid-name classoid)))
659 (setf (find-classoid name) classoid))))))
661 (defun %set-class-type-translation (class classoid)
662 (when (not (typep classoid 'classoid))
663 (setq classoid (find-classoid classoid nil)))
664 (etypecase classoid
665 (null)
666 (built-in-classoid
667 (let ((translation (built-in-classoid-translation classoid)))
668 (cond
669 (translation
670 (aver (ctype-p translation))
671 (setf (info :type :translator class)
672 (lambda (spec) (declare (ignore spec)) translation)))
674 (setf (info :type :translator class)
675 (lambda (spec) (declare (ignore spec)) classoid))))))
676 (classoid
677 (setf (info :type :translator class)
678 (lambda (spec) (declare (ignore spec)) classoid)))))
680 (!bootstrap-meta-braid)
681 (!bootstrap-accessor-definitions t)
682 (!bootstrap-class-predicates t)
683 (!bootstrap-accessor-definitions nil)
684 (!bootstrap-class-predicates nil)
685 (!bootstrap-built-in-classes)
687 (loop for (name . x)
688 in (let (classoid-cells)
689 (do-all-symbols (s classoid-cells)
690 (let ((cell (sb-int:info :type :classoid-cell s)))
691 (when cell
692 (push (cons s cell) classoid-cells)))))
694 (when (classoid-cell-pcl-class x)
695 (let* ((class (find-class-from-cell name x))
696 (layout (class-wrapper class))
697 (lclass (layout-classoid layout))
698 (lclass-pcl-class (classoid-pcl-class lclass))
699 (olclass (find-classoid name nil)))
700 (if lclass-pcl-class
701 (aver (eq class lclass-pcl-class))
702 (setf (classoid-pcl-class lclass) class))
704 (%update-lisp-class-layout class layout)
706 (cond (olclass
707 (aver (eq lclass olclass)))
709 (setf (find-classoid name) lclass)))
711 (%set-class-type-translation class name))))
713 (setq **boot-state** 'braid)
715 (defmethod no-applicable-method (generic-function &rest args)
716 (error "~@<There is no applicable method for the generic function ~2I~_~S~
717 ~I~_when called with arguments ~2I~_~S.~:>"
718 generic-function
719 args))
721 (defmethod no-next-method ((generic-function standard-generic-function)
722 (method standard-method) &rest args)
723 (error "~@<There is no next method for the generic function ~2I~_~S~
724 ~I~_when called from method ~2I~_~S~I~_with arguments ~2I~_~S.~:>"
725 generic-function
726 method
727 args))
729 ;;; An extension to the ANSI standard: in the presence of e.g. a
730 ;;; :BEFORE method, it would seem that going through
731 ;;; NO-APPLICABLE-METHOD is prohibited, as in fact there is an
732 ;;; applicable method. -- CSR, 2002-11-15
733 (define-condition no-primary-method (reference-condition error)
734 ((generic-function :initarg :generic-function :reader no-primary-method-generic-function)
735 (args :initarg :args :reader no-primary-method-args))
736 (:report
737 (lambda (c s)
738 (format s "~@<There is no primary method for the generic function ~2I~_~S~
739 ~I~_when called with arguments ~2I~_~S.~:>"
740 (no-primary-method-generic-function c)
741 (no-primary-method-args c))))
742 (:default-initargs :references (list '(:ansi-cl :section (7 6 6 2)))))
743 (defmethod no-primary-method (generic-function &rest args)
744 (error 'no-primary-method :generic-function generic-function :args args))
746 (defmethod invalid-qualifiers ((gf generic-function)
747 combin
748 method)
749 (let ((qualifiers (method-qualifiers method)))
750 (let ((why (cond
751 ((cdr qualifiers) "has too many qualifiers")
752 (t (aver (not (member (car qualifiers)
753 '(:around :before :after))))
754 "has an invalid qualifier"))))
755 (invalid-method-error
756 method
757 "The method ~S on ~S ~A.~%~
758 Standard method combination requires all methods to have one~%~
759 of the single qualifiers :AROUND, :BEFORE and :AFTER or to~%~
760 have no qualifier at all."
761 method gf why))))