/[cmucl]/src/pcl/std-class.lisp
ViewVC logotype

Contents of /src/pcl/std-class.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Mon Nov 9 15:21:49 1992 UTC (21 years, 5 months ago) by ram
Branch: MAIN
Changes since 1.5: +438 -862 lines
This is September 92 PCL.
1 ;;;-*-Mode:LISP; Package:PCL; Base:10; Syntax:Common-lisp -*-
2 ;;;
3 ;;; *************************************************************************
4 ;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
5 ;;; All rights reserved.
6 ;;;
7 ;;; Use and copying of this software and preparation of derivative works
8 ;;; based upon this software are permitted. Any distribution of this
9 ;;; software or derivative works must comply with all applicable United
10 ;;; States export control laws.
11 ;;;
12 ;;; This software is made available AS IS, and Xerox Corporation makes no
13 ;;; warranty about the software, its performance or its conformity to any
14 ;;; specification.
15 ;;;
16 ;;; Any person obtaining a copy of this software is requested to send their
17 ;;; name and post office or electronic mail address to:
18 ;;; CommonLoops Coordinator
19 ;;; Xerox PARC
20 ;;; 3333 Coyote Hill Rd.
21 ;;; Palo Alto, CA 94304
22 ;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
23 ;;;
24 ;;; Suggestions, comments and requests for improvements are also welcome.
25 ;;; *************************************************************************
26 ;;;
27
28 (in-package 'pcl)
29
30 (defmethod slot-accessor-function ((slotd effective-slot-definition) type)
31 (ecase type
32 (reader (slot-definition-reader-function slotd))
33 (writer (slot-definition-writer-function slotd))
34 (boundp (slot-definition-boundp-function slotd))))
35
36 (defmethod (setf slot-accessor-function) (function
37 (slotd effective-slot-definition) type)
38 (ecase type
39 (reader (setf (slot-definition-reader-function slotd) function))
40 (writer (setf (slot-definition-writer-function slotd) function))
41 (boundp (setf (slot-definition-boundp-function slotd) function))))
42
43 (defconstant *slotd-reader-function-std-p* 1)
44 (defconstant *slotd-writer-function-std-p* 2)
45 (defconstant *slotd-boundp-function-std-p* 4)
46 (defconstant *slotd-all-function-std-p* 7)
47
48 (defmethod slot-accessor-std-p ((slotd effective-slot-definition) type)
49 (let ((flags (slot-value slotd 'accessor-flags)))
50 (declare (type fixnum flags))
51 (if (eq type 'all)
52 (eql *slotd-all-function-std-p* flags)
53 (let ((mask (ecase type
54 (reader *slotd-reader-function-std-p*)
55 (writer *slotd-writer-function-std-p*)
56 (boundp *slotd-boundp-function-std-p*))))
57 (declare (type fixnum mask))
58 (not (zerop (the fixnum (logand mask flags))))))))
59
60 (defmethod (setf slot-accessor-std-p) (value (slotd effective-slot-definition) type)
61 (let ((mask (ecase type
62 (reader *slotd-reader-function-std-p*)
63 (writer *slotd-writer-function-std-p*)
64 (boundp *slotd-boundp-function-std-p*)))
65 (flags (slot-value slotd 'accessor-flags)))
66 (declare (type fixnum mask flags))
67 (setf (slot-value slotd 'accessor-flags)
68 (if value
69 (the fixnum (logior mask flags))
70 (the fixnum (logand (the fixnum (lognot mask)) flags)))))
71 value)
72
73 (defmethod initialize-internal-slot-functions ((slotd effective-slot-definition))
74 (let* ((name (slot-value slotd 'name))
75 (class (slot-value slotd 'class)))
76 (let ((table (or (gethash name *name->class->slotd-table*)
77 (setf (gethash name *name->class->slotd-table*)
78 (make-hash-table :test 'eq :size 5)))))
79 (setf (gethash class table) slotd))
80 (dolist (type '(reader writer boundp))
81 (let* ((gf-name (ecase type
82 (reader 'slot-value-using-class)
83 (writer '(setf slot-value-using-class))
84 (boundp 'slot-boundp-using-class)))
85 (gf (gdefinition gf-name)))
86 (compute-slot-accessor-info slotd type gf)))
87 (initialize-internal-slot-gfs name)))
88
89 (defmethod compute-slot-accessor-info ((slotd effective-slot-definition) type gf)
90 (let* ((name (slot-value slotd 'name))
91 (class (slot-value slotd 'class))
92 (old-slotd (find-slot-definition class name))
93 (old-std-p (and old-slotd (slot-accessor-std-p old-slotd 'all))))
94 (multiple-value-bind (function std-p)
95 (if (eq *boot-state* 'complete)
96 (get-accessor-method-function gf type class slotd)
97 (get-optimized-std-accessor-method-function class slotd type))
98 #+kcl (si:turbo-closure function)
99 (setf (slot-accessor-std-p slotd type) std-p)
100 (setf (slot-accessor-function slotd type) function))
101 (when (and old-slotd (not (eq old-std-p (slot-accessor-std-p slotd 'all))))
102 (push (cons class name) *pv-table-cache-update-info*))))
103
104 (defmethod slot-definition-allocation ((slotd structure-slot-definition))
105 :instance)
106
107
108
109 (defmethod shared-initialize :after ((object documentation-mixin)
110 slot-names
111 &key (documentation nil documentation-p))
112 (declare (ignore slot-names))
113 (when documentation-p
114 (setf (plist-value object 'documentation) documentation)))
115
116 (defmethod documentation (object &optional doc-type)
117 (lisp:documentation object doc-type))
118
119 (defmethod (setf documentation) (new-value object &optional doc-type)
120 (declare (ignore new-value doc-type))
121 (error "Can't change the documentation of ~S." object))
122
123
124 (defmethod documentation ((object documentation-mixin) &optional doc-type)
125 (declare (ignore doc-type))
126 (plist-value object 'documentation))
127
128 (defmethod (setf documentation) (new-value (object documentation-mixin) &optional doc-type)
129 (declare (ignore doc-type))
130 (setf (plist-value object 'documentation) new-value))
131
132
133 (defmethod documentation ((slotd standard-slot-definition) &optional doc-type)
134 (declare (ignore doc-type))
135 (slot-value slotd 'documentation))
136
137 (defmethod (setf documentation) (new-value (slotd standard-slot-definition) &optional doc-type)
138 (declare (ignore doc-type))
139 (setf (slot-value slotd 'documentation) new-value))
140
141
142 ;;;
143 ;;; Various class accessors that are a little more complicated than can be
144 ;;; done with automatically generated reader methods.
145 ;;;
146 (defmethod class-finalized-p ((class pcl-class))
147 (with-slots (wrapper) class
148 (not (null wrapper))))
149
150 (defmethod class-prototype ((class std-class))
151 (with-slots (prototype) class
152 (or prototype (setq prototype (allocate-instance class)))))
153
154 (defmethod class-prototype ((class structure-class))
155 (with-slots (prototype wrapper defstruct-constructor) class
156 (or prototype
157 (setq prototype
158 (if #-new-kcl-wrapper defstruct-constructor #+new-kcl-wrapper nil
159 (allocate-instance class)
160 (allocate-standard-instance wrapper))))))
161
162 (defmethod class-direct-default-initargs ((class slot-class))
163 (plist-value class 'direct-default-initargs))
164
165 (defmethod class-default-initargs ((class slot-class))
166 (plist-value class 'default-initargs))
167
168 (defmethod class-constructors ((class slot-class))
169 (plist-value class 'constructors))
170
171 (defmethod class-slot-cells ((class std-class))
172 (plist-value class 'class-slot-cells))
173
174
175 ;;;
176 ;;; Class accessors that are even a little bit more complicated than those
177 ;;; above. These have a protocol for updating them, we must implement that
178 ;;; protocol.
179 ;;;
180
181 ;;;
182 ;;; Maintaining the direct subclasses backpointers. The update methods are
183 ;;; here, the values are read by an automatically generated reader method.
184 ;;;
185 (defmethod add-direct-subclass ((class class) (subclass class))
186 (with-slots (direct-subclasses) class
187 (pushnew subclass direct-subclasses)
188 subclass))
189
190 (defmethod remove-direct-subclass ((class class) (subclass class))
191 (with-slots (direct-subclasses) class
192 (setq direct-subclasses (remove subclass direct-subclasses))
193 subclass))
194
195 ;;;
196 ;;; Maintaining the direct-methods and direct-generic-functions backpointers.
197 ;;;
198 ;;; There are four generic functions involved, each has one method for the
199 ;;; class case and another method for the damned EQL specializers. All of
200 ;;; these are specified methods and appear in their specified place in the
201 ;;; class graph.
202 ;;;
203 ;;; ADD-DIRECT-METHOD
204 ;;; REMOVE-DIRECT-METHOD
205 ;;; SPECIALIZER-DIRECT-METHODS
206 ;;; SPECIALIZER-DIRECT-GENERIC-FUNCTIONS
207 ;;;
208 ;;; In each case, we maintain one value which is a cons. The car is the list
209 ;;; methods. The cdr is a list of the generic functions. The cdr is always
210 ;;; computed lazily.
211 ;;;
212
213 (defmethod add-direct-method ((specializer class) (method method))
214 (with-slots (direct-methods) specializer
215 (setf (car direct-methods) (adjoin method (car direct-methods)) ;PUSH
216 (cdr direct-methods) ()))
217 method)
218
219 (defmethod remove-direct-method ((specializer class) (method method))
220 (with-slots (direct-methods) specializer
221 (setf (car direct-methods) (remove method (car direct-methods))
222 (cdr direct-methods) ()))
223 method)
224
225 (defmethod specializer-direct-methods ((specializer class))
226 (with-slots (direct-methods) specializer
227 (car direct-methods)))
228
229 (defmethod specializer-direct-generic-functions ((specializer class))
230 (with-slots (direct-methods) specializer
231 (or (cdr direct-methods)
232 (setf (cdr direct-methods)
233 (gathering1 (collecting-once)
234 (dolist (m (car direct-methods))
235 (gather1 (method-generic-function m))))))))
236
237
238
239 ;;;
240 ;;; This hash table is used to store the direct methods and direct generic
241 ;;; functions of EQL specializers. Each value in the table is the cons.
242 ;;;
243 (defvar *eql-specializer-methods* (make-hash-table :test #'eql))
244 (defvar *class-eq-specializer-methods* (make-hash-table :test #'eq))
245
246 (defmethod specializer-method-table ((specializer eql-specializer))
247 *eql-specializer-methods*)
248
249 (defmethod specializer-method-table ((specializer class-eq-specializer))
250 *class-eq-specializer-methods*)
251
252 (defmethod add-direct-method ((specializer specializer-with-object) (method method))
253 (let* ((object (specializer-object specializer))
254 (table (specializer-method-table specializer))
255 (entry (gethash object table)))
256 (unless entry
257 (setq entry
258 (setf (gethash object table)
259 (cons nil nil))))
260 (setf (car entry) (adjoin method (car entry))
261 (cdr entry) ())
262 method))
263
264 (defmethod remove-direct-method ((specializer specializer-with-object) (method method))
265 (let* ((object (specializer-object specializer))
266 (entry (gethash object (specializer-method-table specializer))))
267 (when entry
268 (setf (car entry) (remove method (car entry))
269 (cdr entry) ()))
270 method))
271
272 (defmethod specializer-direct-methods ((specializer specializer-with-object))
273 (car (gethash (specializer-object specializer)
274 (specializer-method-table specializer))))
275
276 (defmethod specializer-direct-generic-functions ((specializer specializer-with-object))
277 (let* ((object (specializer-object specializer))
278 (entry (gethash object (specializer-method-table specializer))))
279 (when entry
280 (or (cdr entry)
281 (setf (cdr entry)
282 (gathering1 (collecting-once)
283 (dolist (m (car entry))
284 (gather1 (method-generic-function m)))))))))
285
286 (defun map-specializers (function)
287 (map-all-classes #'(lambda (class)
288 (funcall function (class-eq-specializer class))
289 (funcall function class)))
290 (maphash #'(lambda (object methods)
291 (declare (ignore methods))
292 (intern-eql-specializer object))
293 *eql-specializer-methods*)
294 (maphash #'(lambda (object specl)
295 (declare (ignore object))
296 (funcall function specl))
297 *eql-specializer-table*)
298 nil)
299
300 (defun map-all-generic-functions (function)
301 (let ((all-generic-functions (make-hash-table :test 'eq)))
302 (map-specializers #'(lambda (specl)
303 (dolist (gf (specializer-direct-generic-functions specl))
304 (unless (gethash gf all-generic-functions)
305 (setf (gethash gf all-generic-functions) t)
306 (funcall function gf))))))
307 nil)
308
309 (defmethod shared-initialize :after ((specl class-eq-specializer) slot-names &key)
310 (declare (ignore slot-names))
311 (setf (slot-value specl 'type) `(class-eq ,(specializer-class specl))))
312
313 (defmethod shared-initialize :after ((specl eql-specializer) slot-names &key)
314 (declare (ignore slot-names))
315 (setf (slot-value specl 'type) `(eql ,(specializer-object specl))))
316
317
318
319 (defun real-load-defclass (name metaclass-name supers slots other accessors)
320 (do-standard-defsetfs-for-defclass accessors) ;***
321 (apply #'ensure-class name :metaclass metaclass-name
322 :direct-superclasses supers
323 :direct-slots slots
324 :definition-source `((defclass ,name)
325 ,(load-truename))
326 other))
327
328 (setf (symbol-function 'load-defclass) #'real-load-defclass)
329
330 (defun ensure-class (name &rest all)
331 (apply #'ensure-class-using-class name (find-class name nil) all))
332
333 (defmethod ensure-class-using-class (name (class null) &rest args &key)
334 (multiple-value-bind (meta initargs)
335 (ensure-class-values class args)
336 (inform-type-system-about-class (class-prototype meta) name);***
337 (setf class (apply #'make-instance meta :name name initargs)
338 (find-class name) class
339 (find-class-predicate name) (symbol-function (class-predicate-name class)))
340 (inform-type-system-about-class class name) ;***
341 class))
342
343 (defmethod ensure-class-using-class (name (class pcl-class) &rest args &key)
344 (multiple-value-bind (meta initargs)
345 (ensure-class-values class args)
346 (unless (eq (class-of class) meta) (change-class class meta))
347 (apply #'reinitialize-instance class initargs)
348 (inform-type-system-about-class class name) ;***
349 class))
350
351 (defun ensure-class-values (class args)
352 (let* ((initargs (copy-list args))
353 (unsupplied (list 1))
354 (supplied-meta (getf initargs :metaclass unsupplied))
355 (supplied-supers (getf initargs :direct-superclasses unsupplied))
356 (supplied-slots (getf initargs :direct-slots unsupplied))
357 (meta
358 (cond ((neq supplied-meta unsupplied)
359 (find-class supplied-meta))
360 ((or (null class)
361 (forward-referenced-class-p class))
362 *the-class-standard-class*)
363 (t
364 (class-of class)))))
365 (flet ((fix-super (s)
366 (cond ((classp s) s)
367 ((not (legal-class-name-p s))
368 (error "~S is not a class or a legal class name." s))
369 (t
370 (or (find-class s nil)
371 (setf (find-class s)
372 (make-instance 'forward-referenced-class
373 :name s)))))))
374 (loop (unless (remf initargs :metaclass) (return)))
375 (loop (unless (remf initargs :direct-superclasses) (return)))
376 (loop (unless (remf initargs :direct-slots) (return)))
377 (values meta
378 (list* :direct-superclasses
379 (and (neq supplied-supers unsupplied)
380 (mapcar #'fix-super supplied-supers))
381 :direct-slots
382 (and (neq supplied-slots unsupplied) supplied-slots)
383 initargs)))))
384
385
386 ;;;
387 ;;;
388 ;;;
389 #|| ; since it doesn't do anything
390 (defmethod shared-initialize :before ((class std-class)
391 slot-names
392 &key direct-superclasses)
393 (declare (ignore slot-names))
394 ;; *** error checking
395 )
396 ||#
397
398 (defmethod shared-initialize :after
399 ((class std-class)
400 slot-names
401 &key (direct-superclasses nil direct-superclasses-p)
402 (direct-slots nil direct-slots-p)
403 (direct-default-initargs nil direct-default-initargs-p)
404 (predicate-name nil predicate-name-p))
405 (declare (ignore slot-names))
406 (if direct-superclasses-p
407 (progn
408 (setq direct-superclasses (or direct-superclasses
409 (list *the-class-standard-object*)))
410 (dolist (superclass direct-superclasses)
411 (unless (validate-superclass class superclass)
412 (error "The class ~S was specified as a~%super-class of the class ~S;~%~
413 but the meta-classes ~S and~%~S are incompatible."
414 superclass class (class-of superclass) (class-of class))))
415 (setf (slot-value class 'direct-superclasses) direct-superclasses))
416 (setq direct-superclasses (slot-value class 'direct-superclasses)))
417 (setq direct-slots
418 (if direct-slots-p
419 (setf (slot-value class 'direct-slots)
420 (mapcar #'(lambda (pl) (make-direct-slotd class pl)) direct-slots))
421 (slot-value class 'direct-slots)))
422 (if direct-default-initargs-p
423 (setf (plist-value class 'direct-default-initargs) direct-default-initargs)
424 (setq direct-default-initargs (plist-value class 'direct-default-initargs)))
425 (setf (plist-value class 'class-slot-cells)
426 (gathering1 (collecting)
427 (dolist (dslotd direct-slots)
428 (when (eq (slot-definition-allocation dslotd) class)
429 (let ((initfunction (slot-definition-initfunction dslotd)))
430 (gather1 (cons (slot-definition-name dslotd)
431 (if initfunction
432 (funcall initfunction)
433 *slot-unbound*))))))))
434 (setq predicate-name (if predicate-name-p
435 (setf (slot-value class 'predicate-name)
436 (car predicate-name))
437 (or (slot-value class 'predicate-name)
438 (setf (slot-value class 'predicate-name)
439 (make-class-predicate-name (class-name class))))))
440 (add-direct-subclasses class direct-superclasses)
441 (update-class class nil)
442 (make-class-predicate class predicate-name)
443 (add-slot-accessors class direct-slots))
444
445 (defmethod shared-initialize :before ((class class) slot-names &key name)
446 (declare (ignore slot-names name))
447 (setf (slot-value class 'type) `(class ,class))
448 (setf (slot-value class 'class-eq-specializer)
449 (make-instance 'class-eq-specializer :class class)))
450
451 (defmethod reinitialize-instance :before ((class slot-class) &key)
452 (remove-direct-subclasses class (class-direct-superclasses class))
453 (remove-slot-accessors class (class-direct-slots class)))
454
455 (defmethod reinitialize-instance :after ((class slot-class)
456 &rest initargs
457 &key)
458 (map-dependents class
459 #'(lambda (dependent)
460 (apply #'update-dependent class dependent initargs))))
461
462 (defmethod shared-initialize :after
463 ((class structure-class)
464 slot-names
465 &key (direct-superclasses nil direct-superclasses-p)
466 (direct-slots nil direct-slots-p)
467 direct-default-initargs
468 (predicate-name nil predicate-name-p))
469 (declare (ignore slot-names direct-default-initargs))
470 (if direct-superclasses-p
471 (setf (slot-value class 'direct-superclasses)
472 (or direct-superclasses
473 (setq direct-superclasses
474 (and (not (eq (class-name class) 'structure-object))
475 (list *the-class-structure-object*)))))
476 (setq direct-superclasses (slot-value class 'direct-superclasses)))
477 (let* ((name (class-name class))
478 (from-defclass-p (slot-value class 'from-defclass-p))
479 (defstruct-p (or from-defclass-p (not (structure-type-p name)))))
480 (if direct-slots-p
481 (setf (slot-value class 'direct-slots)
482 (setq direct-slots
483 (mapcar #'(lambda (pl)
484 (when defstruct-p
485 (let* ((slot-name (getf pl :name))
486 (acc-name (format nil "~s structure class ~a"
487 name slot-name))
488 (accessor (intern acc-name)))
489 (setq pl (list* :defstruct-accessor-symbol accessor
490 pl))))
491 (make-direct-slotd class pl))
492 direct-slots)))
493 (setq direct-slots (slot-value class 'direct-slots)))
494 (when defstruct-p
495 (let* ((include (car (slot-value class 'direct-superclasses)))
496 (conc-name (intern (format nil "~s structure class " name)))
497 (constructor (intern (format nil "~a constructor" conc-name)))
498 (defstruct `(defstruct (,name
499 ,@(when include
500 `((:include ,(class-name include))))
501 (:print-function print-std-instance)
502 (:predicate nil)
503 (:conc-name ,conc-name)
504 (:constructor ,constructor ()))
505 ,@(mapcar #'(lambda (slot)
506 `(,(slot-definition-name slot)
507 *slot-unbound*))
508 direct-slots)))
509 (reader-names (mapcar #'(lambda (slotd)
510 (intern (format nil "~A~A reader" conc-name
511 (slot-definition-name slotd))))
512 direct-slots))
513 (writer-names (mapcar #'(lambda (slotd)
514 (intern (format nil "~A~A writer" conc-name
515 (slot-definition-name slotd))))
516 direct-slots))
517 (readers-init
518 (mapcar #'(lambda (slotd reader-name)
519 (let ((accessor
520 (slot-definition-defstruct-accessor-symbol slotd)))
521 `(defun ,reader-name (obj)
522 (declare (type ,name obj))
523 (,accessor obj))))
524 direct-slots reader-names))
525 (writers-init
526 (mapcar #'(lambda (slotd writer-name)
527 (let ((accessor
528 (slot-definition-defstruct-accessor-symbol slotd)))
529 `(defun ,writer-name (nv obj)
530 (declare (type ,name obj))
531 (setf (,accessor obj) nv))))
532 direct-slots writer-names))
533 (defstruct-form
534 `(progn
535 ,defstruct
536 ,@readers-init ,@writers-init
537 (declare-structure ',name nil nil))))
538 (unless (structure-type-p name) (eval defstruct-form))
539 (mapc #'(lambda (dslotd reader-name writer-name)
540 (let* ((reader (gdefinition reader-name))
541 (writer (when (gboundp writer-name)
542 (gdefinition writer-name))))
543 (setf (slot-value dslotd 'internal-reader-function) reader)
544 (setf (slot-value dslotd 'internal-writer-function) writer)))
545 direct-slots reader-names writer-names)
546 (setf (slot-value class 'defstruct-form) defstruct-form)
547 (setf (slot-value class 'defstruct-constructor) constructor))))
548 (add-direct-subclasses class direct-superclasses)
549 (setf (slot-value class 'class-precedence-list)
550 (compute-class-precedence-list class))
551 (setf (slot-value class 'slots) (compute-slots class))
552 #-new-kcl-wrapper
553 (unless (slot-value class 'wrapper)
554 (setf (slot-value class 'wrapper) (make-wrapper 0 class)))
555 #+new-kcl-wrapper
556 (let ((wrapper (get (class-name class) 'si::s-data)))
557 (setf (slot-value class 'wrapper) wrapper)
558 (setf (wrapper-class wrapper) class))
559 (update-pv-table-cache-info class)
560 (setq predicate-name (if predicate-name-p
561 (setf (slot-value class 'predicate-name)
562 (car predicate-name))
563 (or (slot-value class 'predicate-name)
564 (setf (slot-value class 'predicate-name)
565 (make-class-predicate-name (class-name class))))))
566 (make-class-predicate class predicate-name)
567 (add-slot-accessors class direct-slots))
568
569 (defmethod direct-slot-definition-class ((class structure-class) initargs)
570 (declare (ignore initargs))
571 (find-class 'structure-direct-slot-definition))
572
573 (defmethod finalize-inheritance ((class structure-class))
574 nil) ; always finalized
575
576 (defun add-slot-accessors (class dslotds)
577 (fix-slot-accessors class dslotds 'add))
578
579 (defun remove-slot-accessors (class dslotds)
580 (fix-slot-accessors class dslotds 'remove))
581
582 (defun fix-slot-accessors (class dslotds add/remove)
583 (flet ((fix (gfspec name r/w)
584 (let ((gf (ensure-generic-function gfspec)))
585 (case r/w
586 (r (if (eq add/remove 'add)
587 (add-reader-method class gf name)
588 (remove-reader-method class gf)))
589 (w (if (eq add/remove 'add)
590 (add-writer-method class gf name)
591 (remove-writer-method class gf)))))))
592 (dolist (dslotd dslotds)
593 (let ((slot-name (slot-definition-name dslotd)))
594 (dolist (r (slot-definition-readers dslotd)) (fix r slot-name 'r))
595 (dolist (w (slot-definition-writers dslotd)) (fix w slot-name 'w))))))
596
597
598 (defun add-direct-subclasses (class new)
599 (dolist (n new)
600 (unless (memq class (class-direct-subclasses class))
601 (add-direct-subclass n class))))
602
603 (defun remove-direct-subclasses (class new)
604 (let ((old (class-direct-superclasses class)))
605 (dolist (o (set-difference old new))
606 (remove-direct-subclass o class))))
607
608
609 ;;;
610 ;;;
611 ;;;
612 (defmethod finalize-inheritance ((class std-class))
613 (update-class class t))
614
615
616 (defun class-has-a-forward-referenced-superclass-p (class)
617 (or (forward-referenced-class-p class)
618 (some #'class-has-a-forward-referenced-superclass-p
619 (class-direct-superclasses class))))
620
621 ;;;
622 ;;; Called by :after shared-initialize whenever a class is initialized or
623 ;;; reinitialized. The class may or may not be finalized.
624 ;;;
625 (defun update-class (class finalizep)
626 (when (or finalizep (class-finalized-p class)
627 (not (class-has-a-forward-referenced-superclass-p class)))
628 (update-cpl class (compute-class-precedence-list class))
629 (update-slots class (compute-slots class))
630 (update-gfs-of-class class)
631 (update-inits class (compute-default-initargs class))
632 (update-constructors class))
633 (unless finalizep
634 (dolist (sub (class-direct-subclasses class)) (update-class sub nil))))
635
636 (defun update-cpl (class cpl)
637 (when (class-finalized-p class)
638 (unless (equal (class-precedence-list class) cpl)
639 (force-cache-flushes class)))
640 (setf (slot-value class 'class-precedence-list) cpl)
641 (update-class-can-precede-p cpl))
642
643 (defun update-class-can-precede-p (cpl)
644 (when cpl
645 (let ((first (car cpl)))
646 (dolist (c (cdr cpl))
647 (pushnew c (slot-value first 'can-precede-list))))
648 (update-class-can-precede-p (cdr cpl))))
649
650 (defun class-can-precede-p (class1 class2)
651 (member class2 (class-can-precede-list class1)))
652
653 (defun update-slots (class eslotds)
654 (let ((instance-slots ())
655 (class-slots ()))
656 (dolist (eslotd eslotds)
657 (let ((alloc (slot-definition-allocation eslotd)))
658 (cond ((eq alloc :instance) (push eslotd instance-slots))
659 ((classp alloc) (push eslotd class-slots)))))
660 ;;
661 ;; If there is a change in the shape of the instances then the
662 ;; old class is now obsolete.
663 ;;
664 (let* ((nlayout (mapcar #'slot-definition-name
665 (sort instance-slots #'< :key #'slot-definition-location)))
666 (nslots (length nlayout))
667 (nwrapper-class-slots (compute-class-slots class-slots))
668 (owrapper (class-wrapper class))
669 (olayout (and owrapper (wrapper-instance-slots-layout owrapper)))
670 (owrapper-class-slots (and owrapper (wrapper-class-slots owrapper)))
671 (nwrapper
672 (cond ((null owrapper)
673 (make-wrapper nslots class))
674 ((and (equal nlayout olayout)
675 (not
676 (iterate ((o (list-elements owrapper-class-slots))
677 (n (list-elements nwrapper-class-slots)))
678 (unless (eq (car o) (car n)) (return t)))))
679 owrapper)
680 (t
681 ;;
682 ;; This will initialize the new wrapper to have the same
683 ;; state as the old wrapper. We will then have to change
684 ;; that. This may seem like wasted work (it is), but the
685 ;; spec requires that we call make-instances-obsolete.
686 ;;
687 (make-instances-obsolete class)
688 (class-wrapper class)))))
689 (with-slots (wrapper slots) class
690 #+new-kcl-wrapper
691 (setf (si::s-data-name nwrapper) (class-name class))
692 (setf slots eslotds
693 (wrapper-instance-slots-layout nwrapper) nlayout
694 (wrapper-class-slots nwrapper) nwrapper-class-slots
695 (wrapper-no-of-instance-slots nwrapper) nslots
696 wrapper nwrapper))
697 (unless (eq owrapper nwrapper)
698 (update-pv-table-cache-info class)))))
699
700 (defun compute-class-slots (eslotds)
701 (gathering1 (collecting)
702 (dolist (eslotd eslotds)
703 (gather1
704 (assoc (slot-definition-name eslotd)
705 (class-slot-cells (slot-definition-allocation eslotd)))))))
706
707 (defun compute-layout (cpl instance-eslotds)
708 (let* ((names
709 (gathering1 (collecting)
710 (dolist (eslotd instance-eslotds)
711 (when (eq (slot-definition-allocation eslotd) :instance)
712 (gather1 (slot-definition-name eslotd))))))
713 (order ()))
714 (labels ((rwalk (tail)
715 (when tail
716 (rwalk (cdr tail))
717 (dolist (ss (class-slots (car tail)))
718 (let ((n (slot-definition-name ss)))
719 (when (member n names)
720 (setq order (cons n order)
721 names (remove n names))))))))
722 (rwalk (if (slot-boundp (car cpl) 'slots)
723 cpl
724 (cdr cpl)))
725 (reverse (append names order)))))
726
727 (defun update-gfs-of-class (class)
728 (when (and (class-finalized-p class)
729 (let ((cpl (class-precedence-list class)))
730 (or (member *the-class-slot-class* cpl)
731 (member *the-class-standard-effective-slot-definition* cpl))))
732 (let ((gf-table (make-hash-table :test 'eq)))
733 (labels ((collect-gfs (class)
734 (dolist (gf (specializer-direct-generic-functions class))
735 (setf (gethash gf gf-table) t))
736 (mapc #'collect-gfs (class-direct-superclasses class))))
737 (collect-gfs class)
738 (maphash #'(lambda (gf ignore)
739 (declare (ignore ignore))
740 (update-gf-dfun class gf))
741 gf-table)))))
742
743 (defun update-inits (class inits)
744 (setf (plist-value class 'default-initargs) inits))
745
746
747 ;;;
748 ;;;
749 ;;;
750 (defmethod compute-default-initargs ((class slot-class))
751 (let ((cpl (class-precedence-list class))
752 (direct (class-direct-default-initargs class)))
753 (labels ((walk (tail)
754 (if (null tail)
755 nil
756 (let ((c (pop tail)))
757 (append (if (eq c class)
758 direct
759 (class-direct-default-initargs c))
760 (walk tail))))))
761 (let ((initargs (walk cpl)))
762 (delete-duplicates initargs :test #'eq :key #'car :from-end t)))))
763
764
765 ;;;
766 ;;; Protocols for constructing direct and effective slot definitions.
767 ;;;
768 ;;;
769 ;;;
770 ;;;
771 (defmethod direct-slot-definition-class ((class std-class) initargs)
772 (declare (ignore initargs))
773 (find-class 'standard-direct-slot-definition))
774
775 (defun make-direct-slotd (class initargs)
776 (let ((initargs (list* :class class initargs)))
777 (apply #'make-instance (direct-slot-definition-class class initargs) initargs)))
778
779 ;;;
780 ;;;
781 ;;;
782 (defmethod compute-slots ((class std-class))
783 ;;
784 ;; As specified, we must call COMPUTE-EFFECTIVE-SLOT-DEFINITION once
785 ;; for each different slot name we find in our superclasses. Each
786 ;; call receives the class and a list of the dslotds with that name.
787 ;; The list is in most-specific-first order.
788 ;;
789 (let ((name-dslotds-alist ()))
790 (dolist (c (class-precedence-list class))
791 (let ((dslotds (class-direct-slots c)))
792 (dolist (d dslotds)
793 (let* ((name (slot-definition-name d))
794 (entry (assq name name-dslotds-alist)))
795 (if entry
796 (push d (cdr entry))
797 (push (list name d) name-dslotds-alist))))))
798 (mapcar #'(lambda (direct)
799 (compute-effective-slot-definition class
800 (nreverse (cdr direct))))
801 name-dslotds-alist)))
802
803 (defmethod compute-slots :around ((class std-class))
804 (let ((eslotds (call-next-method))
805 (cpl (class-precedence-list class))
806 (instance-slots ())
807 (class-slots ()))
808 (dolist (eslotd eslotds)
809 (let ((alloc (slot-definition-allocation eslotd)))
810 (cond ((eq alloc :instance) (push eslotd instance-slots))
811 ((classp alloc) (push eslotd class-slots)))))
812 (let ((nlayout (compute-layout cpl instance-slots)))
813 (dolist (eslotd instance-slots)
814 (setf (slot-definition-location eslotd)
815 (position (slot-definition-name eslotd) nlayout))))
816 (dolist (eslotd class-slots)
817 (setf (slot-definition-location eslotd)
818 (assoc (slot-definition-name eslotd)
819 (class-slot-cells (slot-definition-allocation eslotd)))))
820 (mapc #'initialize-internal-slot-functions eslotds)
821 eslotds))
822
823 (defmethod compute-slots ((class structure-class))
824 (mapcan #'(lambda (superclass)
825 (mapcar #'(lambda (dslotd)
826 (compute-effective-slot-definition class
827 (list dslotd)))
828 (class-direct-slots superclass)))
829 (reverse (slot-value class 'class-precedence-list))))
830
831 (defmethod compute-slots :around ((class structure-class))
832 (let ((eslotds (call-next-method)))
833 (mapc #'initialize-internal-slot-functions eslotds)
834 eslotds))
835
836 (defmethod compute-effective-slot-definition ((class slot-class) dslotds)
837 (let* ((initargs (compute-effective-slot-definition-initargs class dslotds))
838 (class (effective-slot-definition-class class initargs)))
839 (apply #'make-instance class initargs)))
840
841 (defmethod effective-slot-definition-class ((class std-class) initargs)
842 (declare (ignore initargs))
843 (find-class 'standard-effective-slot-definition))
844
845 (defmethod effective-slot-definition-class ((class structure-class) initargs)
846 (declare (ignore initargs))
847 (find-class 'structure-effective-slot-definition))
848
849 (defmethod compute-effective-slot-definition-initargs
850 ((class slot-class) direct-slotds)
851 (let* ((name nil)
852 (initfunction nil)
853 (initform nil)
854 (initargs nil)
855 (allocation nil)
856 (type t)
857 (namep nil)
858 (initp nil)
859 (allocp nil))
860
861 (dolist (slotd direct-slotds)
862 (when slotd
863 (unless namep
864 (setq name (slot-definition-name slotd)
865 namep t))
866 (unless initp
867 (when (slot-definition-initfunction slotd)
868 (setq initform (slot-definition-initform slotd)
869 initfunction (slot-definition-initfunction slotd)
870 initp t)))
871 (unless allocp
872 (setq allocation (slot-definition-allocation slotd)
873 allocp t))
874 (setq initargs (append (slot-definition-initargs slotd) initargs))
875 (let ((slotd-type (slot-definition-type slotd)))
876 (setq type (cond ((eq type 't) slotd-type)
877 ((*subtypep type slotd-type) type)
878 (t `(and ,type ,slotd-type)))))))
879 (list :name name
880 :initform initform
881 :initfunction initfunction
882 :initargs initargs
883 :allocation allocation
884 :type type
885 :class class)))
886
887 (defmethod compute-effective-slot-definition-initargs :around
888 ((class structure-class) direct-slotds)
889 (let ((slotd (car direct-slotds)))
890 (list* :defstruct-accessor-symbol (slot-definition-defstruct-accessor-symbol slotd)
891 :internal-reader-function (slot-definition-internal-reader-function slotd)
892 :internal-writer-function (slot-definition-internal-writer-function slotd)
893 (call-next-method))))
894
895 ;;;
896 ;;; NOTE: For bootstrapping considerations, these can't use make-instance
897 ;;; to make the method object. They have to use make-a-method which
898 ;;; is a specially bootstrapped mechanism for making standard methods.
899 ;;;
900 (defmethod reader-method-class ((class slot-class) direct-slot &rest initargs)
901 (declare (ignore direct-slot initargs))
902 (find-class 'standard-reader-method))
903
904 (defmethod add-reader-method ((class slot-class) generic-function slot-name)
905 (add-method generic-function
906 (make-a-method 'standard-reader-method
907 ()
908 (list (or (class-name class) 'object))
909 (list class)
910 (make-reader-method-function class slot-name)
911 "automatically generated reader method"
912 slot-name)))
913
914 (defmethod writer-method-class ((class slot-class) direct-slot &rest initargs)
915 (declare (ignore direct-slot initargs))
916 (find-class 'standard-writer-method))
917
918 (defmethod add-writer-method ((class slot-class) generic-function slot-name)
919 (add-method generic-function
920 (make-a-method 'standard-writer-method
921 ()
922 (list 'new-value (or (class-name class) 'object))
923 (list *the-class-t* class)
924 (make-writer-method-function class slot-name)
925 "automatically generated writer method"
926 slot-name)))
927
928 (defmethod add-boundp-method ((class slot-class) generic-function slot-name)
929 (add-method generic-function
930 (make-a-method 'standard-boundp-method
931 ()
932 (list (or (class-name class) 'object))
933 (list class)
934 (make-boundp-method-function class slot-name)
935 "automatically generated boundp method"
936 slot-name)))
937
938 (defmethod remove-reader-method ((class slot-class) generic-function)
939 (let ((method (get-method generic-function () (list class) nil)))
940 (when method (remove-method generic-function method))))
941
942 (defmethod remove-writer-method ((class slot-class) generic-function)
943 (let ((method
944 (get-method generic-function () (list *the-class-t* class) nil)))
945 (when method (remove-method generic-function method))))
946
947 (defmethod remove-boundp-method ((class slot-class) generic-function)
948 (let ((method (get-method generic-function () (list class) nil)))
949 (when method (remove-method generic-function method))))
950
951
952 ;;;
953 ;;; make-reader-method-function and make-write-method function are NOT part of
954 ;;; the standard protocol. They are however useful, PCL makes uses makes use
955 ;;; of them internally and documents them for PCL users.
956 ;;;
957 ;;; *** This needs work to make type testing by the writer functions which
958 ;;; *** do type testing faster. The idea would be to have one constructor
959 ;;; *** for each possible type test. In order to do this it would be nice
960 ;;; *** to have help from inform-type-system-about-class and friends.
961 ;;;
962 ;;; *** There is a subtle bug here which is going to have to be fixed.
963 ;;; *** Namely, the simplistic use of the template has to be fixed. We
964 ;;; *** have to give the optimize-slot-value method the user might have
965 ;;; *** defined for this metclass a chance to run.
966 ;;;
967 (defmethod make-reader-method-function ((class slot-class) slot-name)
968 (make-std-reader-method-function (class-name class) slot-name))
969
970 (defmethod make-writer-method-function ((class slot-class) slot-name)
971 (make-std-writer-method-function (class-name class) slot-name))
972
973 (defmethod make-boundp-method-function ((class slot-class) slot-name)
974 (make-std-boundp-method-function (class-name class) slot-name))
975
976
977 ;;;; inform-type-system-about-class
978 ;;;; make-type-predicate
979 ;;;
980 ;;; These are NOT part of the standard protocol. They are internal mechanism
981 ;;; which PCL uses to *try* and tell the type system about class definitions.
982 ;;; In a more fully integrated implementation of CLOS, the type system would
983 ;;; know about class objects and class names in a more fundamental way and
984 ;;; the mechanism used to inform the type system about new classes would be
985 ;;; different.
986 ;;;
987 (defmethod inform-type-system-about-class ((class std-class) name)
988 (inform-type-system-about-std-class name))
989
990
991 ;;;
992 ;;; These 4 definitions appear here for bootstrapping reasons. Logically,
993 ;;; they should be in the construct file. For documentation purposes, a
994 ;;; copy of these definitions appears in the construct file. If you change
995 ;;; one of the definitions here, be sure to change the copy there.
996 ;;;
997 (defvar *initialization-generic-functions*
998 (list #'make-instance
999 #'default-initargs
1000 #'allocate-instance
1001 #'initialize-instance
1002 #'shared-initialize))
1003
1004 (defmethod maybe-update-constructors
1005 ((generic-function generic-function)
1006 (method method))
1007 (when (memq generic-function *initialization-generic-functions*)
1008 (labels ((recurse (class)
1009 (update-constructors class)
1010 (dolist (subclass (class-direct-subclasses class))
1011 (recurse subclass))))
1012 (when (classp (car (method-specializers method)))
1013 (recurse (car (method-specializers method)))))))
1014
1015 (defmethod update-constructors ((class slot-class))
1016 (dolist (cons (class-constructors class))
1017 (install-lazy-constructor-installer cons)))
1018
1019 (defmethod update-constructors ((class class))
1020 ())
1021
1022
1023
1024 (defmethod compatible-meta-class-change-p (class proto-new-class)
1025 (eq (class-of class) (class-of proto-new-class)))
1026
1027 (defmethod validate-superclass ((class class) (new-super class))
1028 (or (eq new-super *the-class-t*)
1029 (eq (class-of class) (class-of new-super))))
1030
1031
1032
1033 ;;;
1034 ;;;
1035 ;;;
1036 (defun force-cache-flushes (class)
1037 (let* ((owrapper (class-wrapper class))
1038 (state (wrapper-state owrapper)))
1039 ;;
1040 ;; We only need to do something if the state is still T. If the
1041 ;; state isn't T, it will be FLUSH or OBSOLETE, and both of those
1042 ;; will already be doing what we want. In particular, we must be
1043 ;; sure we never change an OBSOLETE into a FLUSH since OBSOLETE
1044 ;; means do what FLUSH does and then some.
1045 ;;
1046 (when (eq state 't)
1047 (let ((nwrapper (make-wrapper (wrapper-no-of-instance-slots owrapper)
1048 class)))
1049 (setf (wrapper-instance-slots-layout nwrapper)
1050 (wrapper-instance-slots-layout owrapper))
1051 (setf (wrapper-class-slots nwrapper)
1052 (wrapper-class-slots owrapper))
1053 (without-interrupts
1054 (setf (slot-value class 'wrapper) nwrapper)
1055 (invalidate-wrapper owrapper ':flush nwrapper))
1056 (update-constructors class))))) ;??? ***
1057
1058 (defun flush-cache-trap (owrapper nwrapper instance)
1059 (declare (ignore owrapper))
1060 (set-wrapper instance nwrapper))
1061
1062
1063
1064 ;;;
1065 ;;; make-instances-obsolete can be called by user code. It will cause the
1066 ;;; next access to the instance (as defined in 88-002R) to trap through the
1067 ;;; update-instance-for-redefined-class mechanism.
1068 ;;;
1069 (defmethod make-instances-obsolete ((class std-class))
1070 (let* ((owrapper (class-wrapper class))
1071 (nwrapper (make-wrapper (wrapper-no-of-instance-slots owrapper)
1072 class)))
1073 (setf (wrapper-instance-slots-layout nwrapper)
1074 (wrapper-instance-slots-layout owrapper))
1075 (setf (wrapper-class-slots nwrapper)
1076 (wrapper-class-slots owrapper))
1077 (without-interrupts
1078 (setf (slot-value class 'wrapper) nwrapper)
1079 (invalidate-wrapper owrapper ':obsolete nwrapper)
1080 class)))
1081
1082 (defmethod make-instances-obsolete ((class symbol))
1083 (make-instances-obsolete (find-class class)))
1084
1085
1086 ;;;
1087 ;;; obsolete-instance-trap is the internal trap that is called when we see
1088 ;;; an obsolete instance. The times when it is called are:
1089 ;;; - when the instance is involved in method lookup
1090 ;;; - when attempting to access a slot of an instance
1091 ;;;
1092 ;;; It is not called by class-of, wrapper-of, or any of the low-level instance
1093 ;;; access macros.
1094 ;;;
1095 ;;; Of course these times when it is called are an internal implementation
1096 ;;; detail of PCL and are not part of the documented description of when the
1097 ;;; obsolete instance update happens. The documented description is as it
1098 ;;; appears in 88-002R.
1099 ;;;
1100 ;;; This has to return the new wrapper, so it counts on all the methods on
1101 ;;; obsolete-instance-trap-internal to return the new wrapper. It also does
1102 ;;; a little internal error checking to make sure that the traps are only
1103 ;;; happening when they should, and that the trap methods are computing
1104 ;;; apropriate new wrappers.
1105 ;;;
1106 (defun obsolete-instance-trap (owrapper nwrapper instance)
1107 ;;
1108 ;; local --> local transfer
1109 ;; local --> shared discard
1110 ;; local --> -- discard
1111 ;; shared --> local transfer
1112 ;; shared --> shared discard
1113 ;; shared --> -- discard
1114 ;; -- --> local add
1115 ;; -- --> shared --
1116 ;;
1117 (let* ((class (wrapper-class* nwrapper))
1118 (guts (allocate-instance class)) ;??? allocate-instance ???
1119 (olayout (wrapper-instance-slots-layout owrapper))
1120 (nlayout (wrapper-instance-slots-layout nwrapper))
1121 (oslots (get-slots instance))
1122 (nslots (get-slots guts))
1123 (oclass-slots (wrapper-class-slots owrapper))
1124 (added ())
1125 (discarded ())
1126 (plist ()))
1127 ;;
1128 ;; Go through all the old local slots.
1129 ;;
1130 (iterate ((name (list-elements olayout))
1131 (opos (interval :from 0)))
1132 (let ((npos (posq name nlayout)))
1133 (if npos
1134 (setf (instance-ref nslots npos) (instance-ref oslots opos))
1135 (progn (push name discarded)
1136 (unless (eq (instance-ref oslots opos) *slot-unbound*)
1137 (setf (getf plist name) (instance-ref oslots opos)))))))
1138 ;;
1139 ;; Go through all the old shared slots.
1140 ;;
1141 (iterate ((oclass-slot-and-val (list-elements oclass-slots)))
1142 (let ((name (car oclass-slot-and-val))
1143 (val (cdr oclass-slot-and-val)))
1144 (let ((npos (posq name nlayout)))
1145 (if npos
1146 (setf (instance-ref nslots npos) (cdr oclass-slot-and-val))
1147 (progn (push name discarded)
1148 (unless (eq val *slot-unbound*)
1149 (setf (getf plist name) val)))))))
1150 ;;
1151 ;; Go through all the new local slots to compute the added slots.
1152 ;;
1153 (dolist (nlocal nlayout)
1154 (unless (or (memq nlocal olayout)
1155 (assq nlocal oclass-slots))
1156 (push nlocal added)))
1157
1158 (swap-wrappers-and-slots instance guts)
1159
1160 (update-instance-for-redefined-class instance
1161 added
1162 discarded
1163 plist)
1164 nwrapper))
1165
1166
1167
1168 ;;;
1169 ;;;
1170 ;;;
1171 (defmacro copy-instance-internal (instance)
1172 `(#+new-kcl-wrapper if #-new-kcl-wrapper progn
1173 #+new-kcl-wrapper (not (std-instance-p ,instance))
1174 (let* ((class (class-of instance))
1175 (copy (allocate-instance class)))
1176 (if (std-instance-p ,instance)
1177 (setf (std-instance-slots ,instance) (std-instance-slots ,instance))
1178 (setf (fsc-instance-slots ,instance) (fsc-instance-slots ,instance)))
1179 copy)
1180 #+new-kcl-wrapper
1181 (copy-structure-header ,instance)))
1182
1183 (defun change-class-internal (instance new-class)
1184 (let* ((old-class (class-of instance))
1185 (copy (copy-instance-internal instance))
1186 (guts (allocate-instance new-class))
1187 (new-wrapper (get-wrapper guts))
1188 (old-wrapper (class-wrapper old-class))
1189 (old-layout (wrapper-instance-slots-layout old-wrapper))
1190 (new-layout (wrapper-instance-slots-layout new-wrapper))
1191 (old-slots (get-slots instance))
1192 (new-slots (get-slots guts))
1193 (old-class-slots (wrapper-class-slots old-wrapper)))
1194
1195 ;;
1196 ;; "The values of local slots specified by both the class Cto and
1197 ;; Cfrom are retained. If such a local slot was unbound, it remains
1198 ;; unbound."
1199 ;;
1200 (iterate ((new-slot (list-elements new-layout))
1201 (new-position (interval :from 0)))
1202 (let ((old-position (posq new-slot old-layout)))
1203 (when old-position
1204 (setf (instance-ref new-slots new-position)
1205 (instance-ref old-slots old-position)))))
1206
1207 ;;
1208 ;; "The values of slots specified as shared in the class Cfrom and
1209 ;; as local in the class Cto are retained."
1210 ;;
1211 (iterate ((slot-and-val (list-elements old-class-slots)))
1212 (let ((position (posq (car slot-and-val) new-layout)))
1213 (when position
1214 (setf (instance-ref new-slots position) (cdr slot-and-val)))))
1215
1216 ;; Make the copy point to the old instance's storage, and make the
1217 ;; old instance point to the new storage.
1218 (swap-wrappers-and-slots instance guts)
1219
1220 (update-instance-for-different-class copy instance)
1221 instance))
1222
1223 (defmethod change-class ((instance standard-object)
1224 (new-class standard-class))
1225 (unless (std-instance-p instance)
1226 (error "Can't change the class of ~S to ~S~@
1227 because it isn't already an instance with metaclass~%~S."
1228 instance
1229 new-class
1230 'standard-class))
1231 (change-class-internal instance new-class))
1232
1233 (defmethod change-class ((instance standard-object)
1234 (new-class funcallable-standard-class))
1235 (unless (fsc-instance-p instance)
1236 (error "Can't change the class of ~S to ~S~@
1237 because it isn't already an instance with metaclass~%~S."
1238 instance
1239 new-class
1240 'funcallable-standard-class))
1241 (change-class-internal instance new-class))
1242
1243 (defmethod change-class ((instance t) (new-class-name symbol))
1244 (change-class instance (find-class new-class-name)))
1245
1246
1247
1248 ;;;
1249 ;;; The metaclass BUILT-IN-CLASS
1250 ;;;
1251 ;;; This metaclass is something of a weird creature. By this point, all
1252 ;;; instances of it which will exist have been created, and no instance
1253 ;;; is ever created by calling MAKE-INSTANCE.
1254 ;;;
1255 ;;; But, there are other parts of the protcol we must follow and those
1256 ;;; definitions appear here.
1257 ;;;
1258 (defmethod shared-initialize :before
1259 ((class built-in-class) slot-names &rest initargs)
1260 (declare (ignore slot-names initargs))
1261 (error "Attempt to initialize or reinitialize a built in class."))
1262
1263 (defmethod class-direct-slots ((class built-in-class)) ())
1264 (defmethod class-slots ((class built-in-class)) ())
1265 (defmethod class-direct-default-initargs ((class built-in-class)) ())
1266 (defmethod class-default-initargs ((class built-in-class)) ())
1267
1268 (defmethod validate-superclass ((c class) (s built-in-class))
1269 (eq s *the-class-t*))
1270
1271
1272
1273 ;;;
1274 ;;;
1275 ;;;
1276
1277 (defmethod validate-superclass ((c slot-class)
1278 (f forward-referenced-class))
1279 't)
1280
1281
1282 ;;;
1283 ;;;
1284 ;;;
1285
1286 (defmethod add-dependent ((metaobject dependent-update-mixin) dependent)
1287 (pushnew dependent (plist-value metaobject 'dependents)))
1288
1289 (defmethod remove-dependent ((metaobject dependent-update-mixin) dependent)
1290 (setf (plist-value metaobject 'dependents)
1291 (delete dependent (plist-value metaobject 'dependents))))
1292
1293 (defmethod map-dependents ((metaobject dependent-update-mixin) function)
1294 (dolist (dependent (plist-value metaobject 'dependents))
1295 (funcall function dependent)))
1296

  ViewVC Help
Powered by ViewVC 1.1.5