| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: CLOS -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 1992, Giuseppe Attardi.o |
| 6 |
;;;; Copyright (c) 2001, Juan Jose Garcia Ripoll. |
| 7 |
;;;; |
| 8 |
;;;; See file 'LICENSE' for the copyright details. |
| 9 |
|
| 10 |
(in-package "CLOS") |
| 11 |
|
| 12 |
(defconstant +builtin-classes-pre-array+ |
| 13 |
(make-array (1+ #.(length +builtin-classes-list+)))) |
| 14 |
|
| 15 |
;;; ---------------------------------------------------------------------- |
| 16 |
;;; Building the classes T, CLASS, STANDARD-OBJECT and STANDARD-CLASS. |
| 17 |
;;; |
| 18 |
;;; We cannot use the functions CREATE-STANDARD-CLASS and others because SLOTS, |
| 19 |
;;; DIRECT-SLOTS, etc are empty and therefore SLOT-VALUE does not work. |
| 20 |
|
| 21 |
(defun make-empty-standard-class (name &key (metaclass 'standard-class) |
| 22 |
direct-superclasses direct-slots index) |
| 23 |
(declare (optimize speed (safety 0))) |
| 24 |
(let* ((the-metaclass (and metaclass (gethash metaclass si::*class-name-hash-table*))) |
| 25 |
(class (or (gethash name si::*class-name-hash-table*) |
| 26 |
(si:allocate-raw-instance nil the-metaclass |
| 27 |
#.(length +standard-class-slots+))))) |
| 28 |
(with-early-accessors (+standard-class-slots+) |
| 29 |
(when (eq name 'standard-class) |
| 30 |
(defconstant +the-standard-class+ class) |
| 31 |
(si:instance-class-set class class)) |
| 32 |
(setf (class-id class) name |
| 33 |
(class-direct-subclasses class) nil |
| 34 |
(class-direct-default-initargs class) nil |
| 35 |
(class-default-initargs class) nil |
| 36 |
(class-finalized-p class) t |
| 37 |
(eql-specializer-flag class) nil |
| 38 |
(specializer-method-holder class) (cons nil nil) |
| 39 |
(gethash name si::*class-name-hash-table*) class |
| 40 |
(class-sealedp class) nil |
| 41 |
(class-dependents class) nil |
| 42 |
(class-valid-initargs class) nil |
| 43 |
) |
| 44 |
(add-slots class direct-slots) |
| 45 |
(let ((superclasses (loop for name in direct-superclasses |
| 46 |
for parent = (find-class name) |
| 47 |
do (push class (class-direct-subclasses parent)) |
| 48 |
collect parent))) |
| 49 |
(setf (class-direct-superclasses class) superclasses |
| 50 |
(class-precedence-list class) |
| 51 |
(compute-clos-class-precedence-list class superclasses))) |
| 52 |
(when index |
| 53 |
(setf (aref +builtin-classes-pre-array+ index) class)) |
| 54 |
(si:instance-new-stamp class) |
| 55 |
class))) |
| 56 |
|
| 57 |
(defun remove-accessors (slotds) |
| 58 |
(declare (optimize speed (safety 0))) |
| 59 |
(loop for i in slotds |
| 60 |
for j = (copy-list i) |
| 61 |
do (remf (cdr j) :accessor) |
| 62 |
collect j)) |
| 63 |
|
| 64 |
(defun add-slots (class slots) |
| 65 |
(declare (si::c-local) |
| 66 |
(optimize speed (safety 0))) |
| 67 |
;; It does not matter that we pass NIL instead of a class object, |
| 68 |
;; because CANONICAL-SLOT-TO-DIRECT-SLOT will make simple slots. |
| 69 |
(with-early-accessors (+standard-class-slots+ |
| 70 |
+slot-definition-slots+) |
| 71 |
(let* ((table (make-hash-table :size (if slots 24 0))) |
| 72 |
(location-table (make-hash-table :size (if slots 24 0))) |
| 73 |
(slots (parse-slots slots)) |
| 74 |
(direct-slots (loop for slotd in slots |
| 75 |
collect (apply #'make-simple-slotd |
| 76 |
(find-class 'standard-direct-slot-definition) |
| 77 |
slotd))) |
| 78 |
(effective-slots (loop for i from 0 |
| 79 |
for slotd in slots |
| 80 |
for name = (getf slotd :name) |
| 81 |
for s = (apply #'make-simple-slotd |
| 82 |
(find-class 'standard-effective-slot-definition) |
| 83 |
slotd) |
| 84 |
do (setf (slot-definition-location s) i |
| 85 |
(gethash name location-table) i |
| 86 |
(gethash name table) s) |
| 87 |
collect s))) |
| 88 |
(setf (class-slots class) effective-slots |
| 89 |
(class-direct-slots class) direct-slots |
| 90 |
(class-size class) (length slots) |
| 91 |
(slot-table class) table |
| 92 |
(class-location-table class) location-table)))) |
| 93 |
|
| 94 |
;; 1) Create the classes |
| 95 |
;; |
| 96 |
;; Notice that, due to circularity in the definition, STANDARD-CLASS has |
| 97 |
;; itself as metaclass. MAKE-EMPTY-STANDARD-CLASS takes care of that. |
| 98 |
;; |
| 99 |
(let* ((class-hierarchy '#.+class-hierarchy+)) |
| 100 |
(let ((all-classes (loop for c in class-hierarchy |
| 101 |
for class = (apply #'make-empty-standard-class c) |
| 102 |
collect class))) |
| 103 |
(defconstant +the-t-class+ (find-class 't nil)) |
| 104 |
(defconstant +the-class+ (find-class 'class nil)) |
| 105 |
(defconstant +the-std-class+ (find-class 'std-class nil)) |
| 106 |
(defconstant +the-funcallable-standard-class+ |
| 107 |
(find-class 'funcallable-standard-class nil)) |
| 108 |
;; |
| 109 |
;; 2) Class T had its metaclass wrong. Fix it. |
| 110 |
;; |
| 111 |
(si:instance-class-set (find-class 't) (find-class 'built-in-class)) |
| 112 |
;; |
| 113 |
;; 3) Finalize |
| 114 |
;; |
| 115 |
(mapc #'si::instance-new-stamp all-classes) |
| 116 |
(mapc #'si::instance-sig-set all-classes) |
| 117 |
;; |
| 118 |
;; 4) This is needed for further optimization |
| 119 |
;; |
| 120 |
(setf (slot-value (find-class 'method-combination) 'sealedp) t) |
| 121 |
;; |
| 122 |
;; 5) This is needed so that slot-definition objects are not marked |
| 123 |
;; obsolete and need to be updated |
| 124 |
;; |
| 125 |
(with-early-accessors (+standard-class-slots+) |
| 126 |
(loop for c in all-classes |
| 127 |
do (loop for s in (class-direct-slots c) |
| 128 |
do (si::instance-sig-set s)) |
| 129 |
do (loop for s in (class-slots c) |
| 130 |
do (si::instance-sig-set s)))) |
| 131 |
)) |