| 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 |
;;; |
| 11 |
;;; COMMON LISP CLASSES HIERARCHY |
| 12 |
;;; |
| 13 |
;;; The following set of constants describe the slots, the names of |
| 14 |
;;; the classes and their relation, including both standard Commmon Lisp |
| 15 |
;;; and the MetaObject Protocol. This information is only loaded when |
| 16 |
;;; bootstrapping and compiling ECL. |
| 17 |
;;; |
| 18 |
|
| 19 |
(in-package "CLOS") |
| 20 |
|
| 21 |
;;; ---------------------------------------------------------------------- |
| 22 |
;;; Class SPECIALIZER |
| 23 |
|
| 24 |
(eval-when (:compile-toplevel :execute) |
| 25 |
;; Specializer class has a SPECIALIZER-METHOD-HOLDER accessor which |
| 26 |
;; is a cons cell. Direct methods are stored in CAR and direct |
| 27 |
;; generic functions are lazily computed from CAR and stored in |
| 28 |
;; CDR. This approach is taken to avoid metastability issues. For |
| 29 |
;; more details see stdmethod.lsp and the commit message. |
| 30 |
|
| 31 |
(defparameter +specializer-slots+ |
| 32 |
'((flag :initform nil :accessor eql-specializer-flag) |
| 33 |
(holder :initform (cons nil nil) :accessor specializer-method-holder) |
| 34 |
(slot-padding :initform nil))) |
| 35 |
|
| 36 |
(defparameter +eql-specializer-slots+ |
| 37 |
'((flag :initform t :accessor eql-specializer-flag) |
| 38 |
(holder :initform (cons nil nil) :accessor specializer-method-holder) |
| 39 |
(object :initarg :object :accessor eql-specializer-object)))) |
| 40 |
|
| 41 |
;;; ---------------------------------------------------------------------- |
| 42 |
;;; Class METHOD-COMBINATION |
| 43 |
|
| 44 |
(eval-when (:compile-toplevel :execute) |
| 45 |
(defparameter +method-combination-slots+ |
| 46 |
`((name :initarg :name :accessor method-combination-name) |
| 47 |
(compiler :initarg :compiler :accessor method-combination-compiler) |
| 48 |
(options :initarg :options :accessor method-combination-options)))) |
| 49 |
|
| 50 |
;;; ---------------------------------------------------------------------- |
| 51 |
;;; Class CLASS |
| 52 |
|
| 53 |
(eval-when (:compile-toplevel :execute) |
| 54 |
(defparameter +class-slots+ |
| 55 |
`(,@+specializer-slots+ |
| 56 |
(name :initarg :name :initform nil :accessor class-id) |
| 57 |
(direct-superclasses :initarg :direct-superclasses :initform nil |
| 58 |
:accessor class-direct-superclasses) |
| 59 |
(direct-subclasses :initform nil :accessor class-direct-subclasses) |
| 60 |
(slots :accessor class-slots) |
| 61 |
(precedence-list :accessor class-precedence-list) |
| 62 |
(direct-slots :initarg :direct-slots :accessor class-direct-slots) |
| 63 |
(direct-default-initargs :initarg :direct-default-initargs |
| 64 |
:initform nil :accessor class-direct-default-initargs) |
| 65 |
(default-initargs :accessor class-default-initargs) |
| 66 |
(finalized :initform nil :accessor class-finalized-p) |
| 67 |
(docstring :initarg :documentation :initform nil) |
| 68 |
(size :accessor class-size) |
| 69 |
(sealedp :initarg :sealedp :initform nil :accessor class-sealedp) |
| 70 |
(prototype) |
| 71 |
(dependents :initform nil :accessor class-dependents) |
| 72 |
(valid-initargs :accessor class-valid-initargs) |
| 73 |
(slot-table :accessor slot-table) |
| 74 |
(location-table :initform nil :accessor class-location-table))) |
| 75 |
;; INV these assertions validate constants hardcoded in symbols_list.h. |
| 76 |
(assert (= +class-name-ndx+ |
| 77 |
(position 'name +class-slots+ :key #'first))) |
| 78 |
(assert (= +class-precedence-list-ndx+ |
| 79 |
(position 'precedence-list +class-slots+ :key #'first)))) |
| 80 |
|
| 81 |
;;; ---------------------------------------------------------------------- |
| 82 |
;;; STANDARD-CLASS |
| 83 |
|
| 84 |
(eval-when (:compile-toplevel :execute) |
| 85 |
(defparameter +standard-class-slots+ |
| 86 |
(append +class-slots+ |
| 87 |
'((optimize-slot-access) |
| 88 |
(forward))))) |
| 89 |
|
| 90 |
;;; ---------------------------------------------------------------------- |
| 91 |
;;; STRUCTURE-CLASS |
| 92 |
|
| 93 |
(eval-when (:compile-toplevel :execute) |
| 94 |
(defparameter +structure-class-slots+ |
| 95 |
(append +class-slots+ |
| 96 |
'((slot-descriptions) |
| 97 |
(initial-offset) |
| 98 |
(defstruct-form) |
| 99 |
(constructors) |
| 100 |
(documentation) |
| 101 |
(copier) |
| 102 |
(predicate) |
| 103 |
(print-function))))) |
| 104 |
|
| 105 |
;;; ---------------------------------------------------------------------- |
| 106 |
;;; STANDARD-GENERIC-FUNCTION |
| 107 |
|
| 108 |
(eval-when (:compile-toplevel :execute) |
| 109 |
(defparameter +standard-generic-function-slots+ |
| 110 |
;; INV: some of these slots are expected to have fixed positions. See |
| 111 |
;; src/h/internal.h:GFUN_NAME etc. |
| 112 |
'((name :initarg :name :initform nil :reader generic-function-name) |
| 113 |
(spec-list :initform nil :accessor generic-function-spec-list) |
| 114 |
(method-combination |
| 115 |
:initarg :method-combination :initform (find-method-combination (class-prototype (find-class 'standard-generic-function)) 'standard nil) |
| 116 |
:accessor generic-function-method-combination) |
| 117 |
(lambda-list :initarg :lambda-list :accessor generic-function-lambda-list) |
| 118 |
(argument-precedence-order |
| 119 |
:initarg :argument-precedence-order |
| 120 |
:initform nil |
| 121 |
:accessor generic-function-argument-precedence-order) |
| 122 |
(method-class |
| 123 |
:initarg :method-class |
| 124 |
:initform (find-class 'standard-method)) |
| 125 |
(docstring :initarg :documentation :initform nil) |
| 126 |
(methods :initform nil :accessor generic-function-methods) |
| 127 |
(a-p-o-function :initform nil :accessor generic-function-a-p-o-function) |
| 128 |
(declarations |
| 129 |
:initarg :declarations |
| 130 |
:initform nil |
| 131 |
:accessor generic-function-declarations) |
| 132 |
(dependents :initform nil :accessor generic-function-dependents)))) |
| 133 |
|
| 134 |
;;; ---------------------------------------------------------------------- |
| 135 |
;;; STANDARD-METHOD |
| 136 |
|
| 137 |
(eval-when (:compile-toplevel :execute) |
| 138 |
(defparameter +standard-method-slots+ |
| 139 |
'((the-generic-function :initarg :generic-function :initform nil |
| 140 |
:accessor method-generic-function) |
| 141 |
(lambda-list :initarg :lambda-list |
| 142 |
:accessor method-lambda-list) |
| 143 |
(specializers :initarg :specializers :accessor method-specializers) |
| 144 |
(qualifiers :initform nil :initarg :qualifiers :accessor method-qualifiers) |
| 145 |
(the-function :initarg :function :accessor method-function) |
| 146 |
(docstring :initarg :documentation :initform nil) |
| 147 |
(plist :initform nil :initarg :plist :accessor method-plist) |
| 148 |
(keywords :initform nil :accessor method-keywords))) |
| 149 |
|
| 150 |
(defparameter +standard-accessor-method-slots+ |
| 151 |
(append +standard-method-slots+ |
| 152 |
'((slot-definition :initarg :slot-definition |
| 153 |
:initform nil |
| 154 |
;; FIXME! Should be a :reader |
| 155 |
:accessor accessor-method-slot-definition))))) |
| 156 |
|
| 157 |
;;; ---------------------------------------------------------------------- |
| 158 |
;;; SLOT-DEFINITION |
| 159 |
;;; |
| 160 |
|
| 161 |
(eval-when (:compile-toplevel :load-toplevel :execute) |
| 162 |
(defconstant +slot-definition-slots+ |
| 163 |
'((name :initarg :name :initform nil :accessor slot-definition-name) |
| 164 |
(initform :initarg :initform :initform +initform-unsupplied+ :accessor slot-definition-initform) |
| 165 |
(initfunction :initarg :initfunction :initform nil :accessor slot-definition-initfunction) |
| 166 |
(declared-type :initarg :type :initform t :accessor slot-definition-type) |
| 167 |
(allocation :initarg :allocation :initform :instance :accessor slot-definition-allocation) |
| 168 |
(initargs :initarg :initargs :initform nil :accessor slot-definition-initargs) |
| 169 |
(readers :initarg :readers :initform nil :accessor slot-definition-readers) |
| 170 |
(writers :initarg :writers :initform nil :accessor slot-definition-writers) |
| 171 |
(docstring :initarg :documentation :initform nil :accessor slot-definition-documentation) |
| 172 |
(location :initarg :location :initform nil :accessor slot-definition-location) |
| 173 |
))) |
| 174 |
|
| 175 |
;;; ---------------------------------------------------------------------- |
| 176 |
(eval-when (:compile-toplevel :execute) |
| 177 |
;; |
| 178 |
;; All changes to this are connected to the changes in |
| 179 |
;; the code of cl_class_of() in src/clos/instance.d |
| 180 |
;; |
| 181 |
(defconstant +builtin-classes-list+ |
| 182 |
'(;(t object) |
| 183 |
(sequence) |
| 184 |
(list sequence) |
| 185 |
(cons list) |
| 186 |
(array) |
| 187 |
(vector array sequence) |
| 188 |
(string vector) |
| 189 |
(:unicode base-string string vector) |
| 190 |
(bit-vector vector) |
| 191 |
(stream) |
| 192 |
(ext:ansi-stream stream) |
| 193 |
(file-stream ext:ansi-stream) |
| 194 |
(echo-stream ext:ansi-stream) |
| 195 |
(string-stream ext:ansi-stream) |
| 196 |
(two-way-stream ext:ansi-stream) |
| 197 |
(synonym-stream ext:ansi-stream) |
| 198 |
(broadcast-stream ext:ansi-stream) |
| 199 |
(concatenated-stream ext:ansi-stream) |
| 200 |
(ext:sequence-stream ext:ansi-stream) |
| 201 |
(character) |
| 202 |
(number) |
| 203 |
(real number) |
| 204 |
(rational real) |
| 205 |
(integer rational) |
| 206 |
(fixnum integer) |
| 207 |
(bignum integer) |
| 208 |
(ratio rational) |
| 209 |
(float real) |
| 210 |
(single-float float) |
| 211 |
(double-float float) |
| 212 |
(long-float float) |
| 213 |
(complex number) |
| 214 |
(:complex-float si:complex-float complex) |
| 215 |
(:complex-float si:complex-single-float si:complex-float) |
| 216 |
(:complex-float si:complex-double-float si:complex-float) |
| 217 |
(:complex-float si:complex-long-float si:complex-float) |
| 218 |
(symbol) |
| 219 |
(null symbol list) |
| 220 |
(keyword symbol) |
| 221 |
(package) |
| 222 |
(function) |
| 223 |
(pathname) |
| 224 |
(logical-pathname pathname) |
| 225 |
(hash-table) |
| 226 |
(random-state) |
| 227 |
(readtable) |
| 228 |
(si::code-block) |
| 229 |
(si::foreign-data) |
| 230 |
(si::frame) |
| 231 |
(si::weak-pointer) |
| 232 |
(:threads mp::process) |
| 233 |
(:threads mp::lock) |
| 234 |
(:threads mp::rwlock) |
| 235 |
(:threads mp::condition-variable) |
| 236 |
(:threads mp::semaphore) |
| 237 |
(:threads mp::barrier) |
| 238 |
(:threads mp::mailbox) |
| 239 |
(:sse2 ext::sse-pack)))) |
| 240 |
|
| 241 |
;;; FROM AMOP: |
| 242 |
;;; |
| 243 |
;;; Class hierachy: (entries marked with `*` are abstract base classes) |
| 244 |
;;; |
| 245 |
;;; Metaobject Class Direct Superclasses |
| 246 |
;;; standard-object (t) |
| 247 |
;;; funcallable-standard-object (standard-object function) |
| 248 |
;;; * metaobject (standard-object) |
| 249 |
;;; * generic-function (metaobject funcallable-standard-object) |
| 250 |
;;; standard-generic-function (generic-function) |
| 251 |
;;; * method (metaobject) |
| 252 |
;;; standard-method (method) |
| 253 |
;;; * standard-accessor-method (standard-method) |
| 254 |
;;; standard-reader-method (standard-accessor-method) |
| 255 |
;;; standard-writer-method (standard-accessor-method) |
| 256 |
;;; * method-combination (metaobject) |
| 257 |
;;; * slot-definition (metaobject) |
| 258 |
;;; * direct-slot-definition (slot-definition) |
| 259 |
;;; * effective-slot-definition (slot-definition) |
| 260 |
;;; * standard-slot-definition (slot-definition) |
| 261 |
;;; standard-direct-slot-definition (standard-slot-definition direct-slot-definition) |
| 262 |
;;; standard-effective-slot-definition (standard-slot-definition effective-slot-definition) |
| 263 |
;;; * specializer (metaobject) |
| 264 |
;;; eql-specializer (specializer) |
| 265 |
;;; * class (specializer) |
| 266 |
;;; built-in-class (class) |
| 267 |
;;; forward-referenced-class (class) |
| 268 |
;;; standard-class (class) |
| 269 |
;;; funcallable-standard-class (class) |
| 270 |
;;; |
| 271 |
(eval-when (eval) |
| 272 |
(defconstant +class-hierarchy+ |
| 273 |
`((standard-class) |
| 274 |
(standard-effective-slot-definition) |
| 275 |
(standard-direct-slot-definition) |
| 276 |
(standard-class |
| 277 |
:metaclass nil ; Special-cased in boot.lsp |
| 278 |
:direct-slots #.+standard-class-slots+) |
| 279 |
(standard-direct-slot-definition |
| 280 |
:direct-slots #3=#.+slot-definition-slots+) |
| 281 |
(standard-effective-slot-definition |
| 282 |
:direct-slots #3#) |
| 283 |
(t |
| 284 |
:index 0) |
| 285 |
(standard-object |
| 286 |
:direct-superclasses (t)) |
| 287 |
(metaobject |
| 288 |
:direct-superclasses (standard-object)) |
| 289 |
(slot-definition |
| 290 |
:direct-superclasses (metaobject) |
| 291 |
:direct-slots #3#) |
| 292 |
(standard-slot-definition |
| 293 |
:direct-superclasses (slot-definition) |
| 294 |
:direct-slots #3#) |
| 295 |
(direct-slot-definition |
| 296 |
:direct-superclasses (slot-definition) |
| 297 |
:direct-slots #3#) |
| 298 |
(effective-slot-definition |
| 299 |
:direct-superclasses (slot-definition) |
| 300 |
:direct-slots #3#) |
| 301 |
(standard-direct-slot-definition |
| 302 |
:direct-superclasses (standard-slot-definition direct-slot-definition) |
| 303 |
:direct-slots #3#) |
| 304 |
(standard-effective-slot-definition |
| 305 |
:direct-superclasses (standard-slot-definition effective-slot-definition) |
| 306 |
:direct-slots #3#) |
| 307 |
(method-combination |
| 308 |
:direct-superclasses (metaobject) |
| 309 |
:direct-slots #.+method-combination-slots+) |
| 310 |
(specializer |
| 311 |
:direct-superclasses (metaobject) |
| 312 |
:direct-slots #.+specializer-slots+) |
| 313 |
(eql-specializer |
| 314 |
:direct-superclasses (specializer) |
| 315 |
:direct-slots #.+eql-specializer-slots+) |
| 316 |
(class |
| 317 |
:direct-superclasses (specializer) |
| 318 |
:direct-slots #.+class-slots+) |
| 319 |
(forward-referenced-class |
| 320 |
:direct-superclasses (class) |
| 321 |
:direct-slots #.+class-slots+) |
| 322 |
(built-in-class |
| 323 |
:direct-superclasses (class) |
| 324 |
:direct-slots #1=#.+standard-class-slots+) |
| 325 |
(std-class |
| 326 |
:direct-superclasses (class) |
| 327 |
:direct-slots #1#) |
| 328 |
(standard-class |
| 329 |
:direct-superclasses (std-class) |
| 330 |
:direct-slots #1# |
| 331 |
:metaclass standard-class) |
| 332 |
(funcallable-standard-class |
| 333 |
:direct-superclasses (std-class) |
| 334 |
:direct-slots #1#) |
| 335 |
,@(loop for (name . rest) in +builtin-classes-list+ |
| 336 |
for index from 1 |
| 337 |
for feature-flag = (if (keywordp name) |
| 338 |
(prog1 name |
| 339 |
(setf name (first rest) rest (rest rest))) |
| 340 |
nil) |
| 341 |
when (or (not feature-flag) (member feature-flag *features*)) |
| 342 |
collect (list name :metaclass 'built-in-class |
| 343 |
:index index |
| 344 |
:direct-superclasses (or rest '(t)))) |
| 345 |
(funcallable-standard-object |
| 346 |
:metaclass funcallable-standard-class |
| 347 |
:direct-superclasses (standard-object function)) |
| 348 |
(generic-function |
| 349 |
:metaclass funcallable-standard-class |
| 350 |
:direct-superclasses (metaobject funcallable-standard-object)) |
| 351 |
(standard-generic-function |
| 352 |
:direct-superclasses (generic-function) |
| 353 |
:direct-slots #.+standard-generic-function-slots+ |
| 354 |
:metaclass funcallable-standard-class) |
| 355 |
(method |
| 356 |
:direct-superclasses (metaobject)) |
| 357 |
(standard-method |
| 358 |
:direct-superclasses (method) |
| 359 |
:direct-slots #.+standard-method-slots+) |
| 360 |
(standard-accessor-method |
| 361 |
:direct-superclasses (standard-method) |
| 362 |
:direct-slots #2=#.+standard-accessor-method-slots+) |
| 363 |
(standard-reader-method |
| 364 |
:direct-superclasses (standard-accessor-method) |
| 365 |
:direct-slots #2#) |
| 366 |
(standard-writer-method |
| 367 |
:direct-superclasses (standard-accessor-method) |
| 368 |
:direct-slots #2#) |
| 369 |
(standard-optimized-reader-method |
| 370 |
:direct-superclasses (standard-reader-method) |
| 371 |
:direct-slots #2#) |
| 372 |
(standard-optimized-writer-method |
| 373 |
:direct-superclasses (standard-writer-method) |
| 374 |
:direct-slots #2#) |
| 375 |
(structure-class |
| 376 |
:direct-superclasses (class) |
| 377 |
:direct-slots #.+structure-class-slots+) |
| 378 |
(structure-object |
| 379 |
:metaclass structure-class |
| 380 |
:direct-superclasses (t)) |
| 381 |
))) |
| 382 |
|