/[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.9.2.2 - (show annotations)
Sat Aug 30 18:41:37 1997 UTC (16 years, 7 months ago) by dtc
Branch: RELENG_18
CVS Tags: RELEASE_18a
Changes since 1.9.2.1: +6 -7 lines
Re-define the documentation function according to the ANSI CL spec.;
the doc-type argument is no longer optional.
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 doc-type)
117 (declare (ignore object doc-type))
118 nil)
119
120 (defmethod (setf documentation) (new-value object doc-type)
121 (declare (ignore new-value doc-type))
122 (error "Can't change the documentation of ~S." object))
123
124 (defmethod documentation ((object documentation-mixin) doc-type)
125 (declare (ignore doc-type))
126 (plist-value object 'documentation))
127
128 (defmethod (setf documentation) (new-value (object documentation-mixin) doc-type)
129 (declare (ignore doc-type))
130 (setf (plist-value object 'documentation) new-value))
131
132
133 (defmethod documentation ((slotd standard-slot-definition) doc-type)
134 (declare (ignore doc-type))
135 (slot-value slotd 'documentation))
136
137 (defmethod (setf documentation) (new-value (slotd standard-slot-definition) 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 (let ((res (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 #+cmu17 (kernel:layout-class (class-wrapper res))
328 #-cmu17 res))
329
330 (setf (gdefinition 'load-defclass) #'real-load-defclass)
331
332 (defun ensure-class (name &rest all)
333 (apply #'ensure-class-using-class name (find-class name nil) all))
334
335 (defmethod ensure-class-using-class (name (class null) &rest args &key)
336 (multiple-value-bind (meta initargs)
337 (ensure-class-values class args)
338 (inform-type-system-about-class (class-prototype meta) name);***
339 (setf class (apply #'make-instance meta :name name initargs)
340 (find-class name) class)
341 (inform-type-system-about-class class name) ;***
342 class))
343
344 (defmethod ensure-class-using-class (name (class pcl-class) &rest args &key)
345 (multiple-value-bind (meta initargs)
346 (ensure-class-values class args)
347 (unless (eq (class-of class) meta) (change-class class meta))
348 (apply #'reinitialize-instance class initargs)
349 (setf (find-class name) class)
350 (inform-type-system-about-class class name) ;***
351 class))
352
353 (defmethod class-predicate-name ((class t))
354 'function-returning-nil)
355
356 (defun ensure-class-values (class args)
357 (let* ((initargs (copy-list args))
358 (unsupplied (list 1))
359 (supplied-meta (getf initargs :metaclass unsupplied))
360 (supplied-supers (getf initargs :direct-superclasses unsupplied))
361 (supplied-slots (getf initargs :direct-slots unsupplied))
362 (meta
363 (cond ((neq supplied-meta unsupplied)
364 (find-class supplied-meta))
365 ((or (null class)
366 (forward-referenced-class-p class))
367 *the-class-standard-class*)
368 (t
369 (class-of class)))))
370 (flet ((fix-super (s)
371 (cond ((classp s) s)
372 ((not (legal-class-name-p s))
373 (error "~S is not a class or a legal class name." s))
374 (t
375 (or (find-class s nil)
376 (setf (find-class s)
377 (make-instance 'forward-referenced-class
378 :name s)))))))
379 (loop (unless (remf initargs :metaclass) (return)))
380 (loop (unless (remf initargs :direct-superclasses) (return)))
381 (loop (unless (remf initargs :direct-slots) (return)))
382 (values meta
383 (list* :direct-superclasses
384 (and (neq supplied-supers unsupplied)
385 (mapcar #'fix-super supplied-supers))
386 :direct-slots
387 (and (neq supplied-slots unsupplied) supplied-slots)
388 initargs)))))
389
390
391 ;;;
392 ;;;
393 ;;;
394 #|| ; since it doesn't do anything
395 (defmethod shared-initialize :before ((class std-class)
396 slot-names
397 &key direct-superclasses)
398 (declare (ignore slot-names))
399 ;; *** error checking
400 )
401 ||#
402
403 (defmethod shared-initialize :after
404 ((class std-class)
405 slot-names
406 &key (direct-superclasses nil direct-superclasses-p)
407 (direct-slots nil direct-slots-p)
408 (direct-default-initargs nil direct-default-initargs-p)
409 (predicate-name nil predicate-name-p))
410 (declare (ignore slot-names))
411 (if direct-superclasses-p
412 (progn
413 (setq direct-superclasses (or direct-superclasses
414 (list *the-class-standard-object*)))
415 (dolist (superclass direct-superclasses)
416 (unless (validate-superclass class superclass)
417 (error "The class ~S was specified as a~%super-class of the class ~S;~%~
418 but the meta-classes ~S and~%~S are incompatible.~%
419 Define a method for ~S to avoid this error."
420 superclass class (class-of superclass) (class-of class)
421 'validate-superclass)))
422 (setf (slot-value class 'direct-superclasses) direct-superclasses))
423 (setq direct-superclasses (slot-value class 'direct-superclasses)))
424 (setq direct-slots
425 (if direct-slots-p
426 (setf (slot-value class 'direct-slots)
427 (mapcar #'(lambda (pl) (make-direct-slotd class pl)) direct-slots))
428 (slot-value class 'direct-slots)))
429 (if direct-default-initargs-p
430 (setf (plist-value class 'direct-default-initargs) direct-default-initargs)
431 (setq direct-default-initargs (plist-value class 'direct-default-initargs)))
432 (setf (plist-value class 'class-slot-cells)
433 (gathering1 (collecting)
434 (dolist (dslotd direct-slots)
435 (when (eq (slot-definition-allocation dslotd) class)
436 (let ((initfunction (slot-definition-initfunction dslotd)))
437 (gather1 (cons (slot-definition-name dslotd)
438 (if initfunction
439 (funcall initfunction)
440 *slot-unbound*))))))))
441 (setq predicate-name (if predicate-name-p
442 (setf (slot-value class 'predicate-name)
443 (car predicate-name))
444 (or (slot-value class 'predicate-name)
445 (setf (slot-value class 'predicate-name)
446 (make-class-predicate-name (class-name class))))))
447 (add-direct-subclasses class direct-superclasses)
448 (update-class class nil)
449 (make-class-predicate class predicate-name)
450 (add-slot-accessors class direct-slots))
451
452 (defmethod shared-initialize :before ((class class) slot-names &key name)
453 (declare (ignore slot-names name))
454 (setf (slot-value class 'type) `(class ,class))
455 (setf (slot-value class 'class-eq-specializer)
456 (make-instance 'class-eq-specializer :class class)))
457
458 (defmethod reinitialize-instance :before ((class slot-class) &key)
459 (remove-direct-subclasses class (class-direct-superclasses class))
460 (remove-slot-accessors class (class-direct-slots class)))
461
462 (defmethod reinitialize-instance :after ((class slot-class)
463 &rest initargs
464 &key)
465 (map-dependents class
466 #'(lambda (dependent)
467 (apply #'update-dependent class dependent initargs))))
468
469 (defmethod shared-initialize :after
470 ((class structure-class)
471 slot-names
472 &key (direct-superclasses nil direct-superclasses-p)
473 (direct-slots nil direct-slots-p)
474 direct-default-initargs
475 (predicate-name nil predicate-name-p))
476 (declare (ignore slot-names direct-default-initargs))
477 (if direct-superclasses-p
478 (setf (slot-value class 'direct-superclasses)
479 (or direct-superclasses
480 (setq direct-superclasses
481 (and (not (eq (class-name class) 'structure-object))
482 (list *the-class-structure-object*)))))
483 (setq direct-superclasses (slot-value class 'direct-superclasses)))
484 (let* ((name (class-name class))
485 (from-defclass-p (slot-value class 'from-defclass-p))
486 (defstruct-p (or from-defclass-p (not (structure-type-p name)))))
487 (if direct-slots-p
488 (setf (slot-value class 'direct-slots)
489 (setq direct-slots
490 (mapcar #'(lambda (pl)
491 (when defstruct-p
492 (let* ((slot-name (getf pl :name))
493 (acc-name (format nil "~s structure class ~a"
494 name slot-name))
495 (accessor (intern acc-name)))
496 (setq pl (list* :defstruct-accessor-symbol accessor
497 pl))))
498 (make-direct-slotd class pl))
499 direct-slots)))
500 (setq direct-slots (slot-value class 'direct-slots)))
501 (when defstruct-p
502 (let* ((include (car (slot-value class 'direct-superclasses)))
503 (conc-name (intern (format nil "~s structure class " name)))
504 (constructor (intern (format nil "~a constructor" conc-name)))
505 (defstruct `(defstruct (,name
506 ,@(when include
507 `((:include ,(class-name include))))
508 (:print-function print-std-instance)
509 (:predicate nil)
510 (:conc-name ,conc-name)
511 (:constructor ,constructor ()))
512 ,@(mapcar #'(lambda (slot)
513 `(,(slot-definition-name slot)
514 *slot-unbound*))
515 direct-slots)))
516 (reader-names (mapcar #'(lambda (slotd)
517 (intern (format nil "~A~A reader" conc-name
518 (slot-definition-name slotd))))
519 direct-slots))
520 (writer-names (mapcar #'(lambda (slotd)
521 (intern (format nil "~A~A writer" conc-name
522 (slot-definition-name slotd))))
523 direct-slots))
524 (readers-init
525 (mapcar #'(lambda (slotd reader-name)
526 (let ((accessor
527 (slot-definition-defstruct-accessor-symbol slotd)))
528 `(defun ,reader-name (obj)
529 (declare (type ,name obj))
530 (,accessor obj))))
531 direct-slots reader-names))
532 (writers-init
533 (mapcar #'(lambda (slotd writer-name)
534 (let ((accessor
535 (slot-definition-defstruct-accessor-symbol slotd)))
536 `(defun ,writer-name (nv obj)
537 (declare (type ,name obj))
538 (setf (,accessor obj) nv))))
539 direct-slots writer-names))
540 (defstruct-form
541 `(progn
542 ,defstruct
543 ,@readers-init ,@writers-init
544 (declare-structure ',name nil nil))))
545 (unless (structure-type-p name) (eval defstruct-form))
546 (mapc #'(lambda (dslotd reader-name writer-name)
547 (let* ((reader (gdefinition reader-name))
548 (writer (when (gboundp writer-name)
549 (gdefinition writer-name))))
550 (setf (slot-value dslotd 'internal-reader-function) reader)
551 (setf (slot-value dslotd 'internal-writer-function) writer)))
552 direct-slots reader-names writer-names)
553 (setf (slot-value class 'defstruct-form) defstruct-form)
554 (setf (slot-value class 'defstruct-constructor) constructor))))
555 (add-direct-subclasses class direct-superclasses)
556 (setf (slot-value class 'class-precedence-list)
557 (compute-class-precedence-list class))
558 (setf (slot-value class 'slots) (compute-slots class))
559 #-(or cmu17 new-kcl-wrapper)
560 (unless (slot-value class 'wrapper)
561 (setf (slot-value class 'wrapper) (make-wrapper 0 class)))
562 #+cmu17
563 (let ((lclass (lisp:find-class (class-name class))))
564 (setf (kernel:class-pcl-class lclass) class)
565 (setf (slot-value class 'wrapper) (kernel:class-layout lclass)))
566 #+new-kcl-wrapper
567 (let ((wrapper (get (class-name class) 'si::s-data)))
568 (setf (slot-value class 'wrapper) wrapper)
569 (setf (wrapper-class wrapper) class))
570 (update-pv-table-cache-info class)
571 (setq predicate-name (if predicate-name-p
572 (setf (slot-value class 'predicate-name)
573 (car predicate-name))
574 (or (slot-value class 'predicate-name)
575 (setf (slot-value class 'predicate-name)
576 (make-class-predicate-name (class-name class))))))
577 (make-class-predicate class predicate-name)
578 (add-slot-accessors class direct-slots))
579
580 (defmethod direct-slot-definition-class ((class structure-class) initargs)
581 (declare (ignore initargs))
582 (find-class 'structure-direct-slot-definition))
583
584 (defmethod finalize-inheritance ((class structure-class))
585 nil) ; always finalized
586
587 (defun add-slot-accessors (class dslotds)
588 (fix-slot-accessors class dslotds 'add))
589
590 (defun remove-slot-accessors (class dslotds)
591 (fix-slot-accessors class dslotds 'remove))
592
593 (defun fix-slot-accessors (class dslotds add/remove)
594 (flet ((fix (gfspec name r/w)
595 (let ((gf (ensure-generic-function gfspec)))
596 (case r/w
597 (r (if (eq add/remove 'add)
598 (add-reader-method class gf name)
599 (remove-reader-method class gf)))
600 (w (if (eq add/remove 'add)
601 (add-writer-method class gf name)
602 (remove-writer-method class gf)))))))
603 (dolist (dslotd dslotds)
604 (let ((slot-name (slot-definition-name dslotd)))
605 (dolist (r (slot-definition-readers dslotd)) (fix r slot-name 'r))
606 (dolist (w (slot-definition-writers dslotd)) (fix w slot-name 'w))))))
607
608
609 (defun add-direct-subclasses (class new)
610 (dolist (n new)
611 (unless (memq class (class-direct-subclasses class))
612 (add-direct-subclass n class))))
613
614 (defun remove-direct-subclasses (class new)
615 (let ((old (class-direct-superclasses class)))
616 (dolist (o (set-difference old new))
617 (remove-direct-subclass o class))))
618
619
620 ;;;
621 ;;;
622 ;;;
623 (defmethod finalize-inheritance ((class std-class))
624 (update-class class t))
625
626
627 (defun class-has-a-forward-referenced-superclass-p (class)
628 (or (forward-referenced-class-p class)
629 (some #'class-has-a-forward-referenced-superclass-p
630 (class-direct-superclasses class))))
631
632 ;;;
633 ;;; Called by :after shared-initialize whenever a class is initialized or
634 ;;; reinitialized. The class may or may not be finalized.
635 ;;;
636 (defun update-class (class finalizep)
637 (when (or finalizep (class-finalized-p class)
638 (not (class-has-a-forward-referenced-superclass-p class)))
639 (update-cpl class (compute-class-precedence-list class))
640 (update-slots class (compute-slots class))
641 (update-gfs-of-class class)
642 (update-inits class (compute-default-initargs class))
643 (update-make-instance-function-table class))
644 (unless finalizep
645 (dolist (sub (class-direct-subclasses class)) (update-class sub nil))))
646
647 (defun update-cpl (class cpl)
648 (when (class-finalized-p class)
649 (unless (equal (class-precedence-list class) cpl)
650 (force-cache-flushes class)))
651 (setf (slot-value class 'class-precedence-list) cpl)
652 (update-class-can-precede-p cpl))
653
654 (defun update-class-can-precede-p (cpl)
655 (when cpl
656 (let ((first (car cpl)))
657 (dolist (c (cdr cpl))
658 (pushnew c (slot-value first 'can-precede-list))))
659 (update-class-can-precede-p (cdr cpl))))
660
661 (defun class-can-precede-p (class1 class2)
662 (member class2 (class-can-precede-list class1)))
663
664 (defun update-slots (class eslotds)
665 (let ((instance-slots ())
666 (class-slots ()))
667 (dolist (eslotd eslotds)
668 (let ((alloc (slot-definition-allocation eslotd)))
669 (cond ((eq alloc :instance) (push eslotd instance-slots))
670 ((classp alloc) (push eslotd class-slots)))))
671 ;;
672 ;; If there is a change in the shape of the instances then the
673 ;; old class is now obsolete.
674 ;;
675 (let* ((nlayout (mapcar #'slot-definition-name
676 (sort instance-slots #'< :key #'slot-definition-location)))
677 (nslots (length nlayout))
678 (nwrapper-class-slots (compute-class-slots class-slots))
679 (owrapper (class-wrapper class))
680 (olayout (and owrapper (wrapper-instance-slots-layout owrapper)))
681 (owrapper-class-slots (and owrapper (wrapper-class-slots owrapper)))
682 (nwrapper
683 (cond ((null owrapper)
684 (make-wrapper nslots class))
685 ((and (equal nlayout olayout)
686 (not
687 (iterate ((o (list-elements owrapper-class-slots))
688 (n (list-elements nwrapper-class-slots)))
689 (unless (eq (car o) (car n)) (return t)))))
690 owrapper)
691 (t
692 ;;
693 ;; This will initialize the new wrapper to have the same
694 ;; state as the old wrapper. We will then have to change
695 ;; that. This may seem like wasted work (it is), but the
696 ;; spec requires that we call make-instances-obsolete.
697 ;;
698 (make-instances-obsolete class)
699 (class-wrapper class)))))
700
701 (with-slots (wrapper slots) class
702 #+new-kcl-wrapper
703 (setf (si::s-data-name nwrapper) (class-name class))
704 #+cmu17
705 (update-lisp-class-layout class nwrapper)
706 (setf slots eslotds
707 (wrapper-instance-slots-layout nwrapper) nlayout
708 (wrapper-class-slots nwrapper) nwrapper-class-slots
709 (wrapper-no-of-instance-slots nwrapper) nslots
710 wrapper nwrapper))
711
712 (unless (eq owrapper nwrapper)
713 (update-pv-table-cache-info class)))))
714
715 (defun compute-class-slots (eslotds)
716 (gathering1 (collecting)
717 (dolist (eslotd eslotds)
718 (gather1
719 (assoc (slot-definition-name eslotd)
720 (class-slot-cells (slot-definition-allocation eslotd)))))))
721
722 (defun compute-layout (cpl instance-eslotds)
723 (let* ((names
724 (gathering1 (collecting)
725 (dolist (eslotd instance-eslotds)
726 (when (eq (slot-definition-allocation eslotd) :instance)
727 (gather1 (slot-definition-name eslotd))))))
728 (order ()))
729 (labels ((rwalk (tail)
730 (when tail
731 (rwalk (cdr tail))
732 (dolist (ss (class-slots (car tail)))
733 (let ((n (slot-definition-name ss)))
734 (when (member n names)
735 (setq order (cons n order)
736 names (remove n names))))))))
737 (rwalk (if (slot-boundp (car cpl) 'slots)
738 cpl
739 (cdr cpl)))
740 (reverse (append names order)))))
741
742 (defun update-gfs-of-class (class)
743 (when (and (class-finalized-p class)
744 (let ((cpl (class-precedence-list class)))
745 (or (member *the-class-slot-class* cpl)
746 (member *the-class-standard-effective-slot-definition* cpl))))
747 (let ((gf-table (make-hash-table :test 'eq)))
748 (labels ((collect-gfs (class)
749 (dolist (gf (specializer-direct-generic-functions class))
750 (setf (gethash gf gf-table) t))
751 (mapc #'collect-gfs (class-direct-superclasses class))))
752 (collect-gfs class)
753 (maphash #'(lambda (gf ignore)
754 (declare (ignore ignore))
755 (update-gf-dfun class gf))
756 gf-table)))))
757
758 (defun update-inits (class inits)
759 (setf (plist-value class 'default-initargs) inits))
760
761
762 ;;;
763 ;;;
764 ;;;
765 (defmethod compute-default-initargs ((class slot-class))
766 (let ((cpl (class-precedence-list class))
767 (direct (class-direct-default-initargs class)))
768 (labels ((walk (tail)
769 (if (null tail)
770 nil
771 (let ((c (pop tail)))
772 (append (if (eq c class)
773 direct
774 (class-direct-default-initargs c))
775 (walk tail))))))
776 (let ((initargs (walk cpl)))
777 (delete-duplicates initargs :test #'eq :key #'car :from-end t)))))
778
779
780 ;;;
781 ;;; Protocols for constructing direct and effective slot definitions.
782 ;;;
783 ;;;
784 ;;;
785 ;;;
786 (defmethod direct-slot-definition-class ((class std-class) initargs)
787 (declare (ignore initargs))
788 (find-class 'standard-direct-slot-definition))
789
790 (defun make-direct-slotd (class initargs)
791 (let ((initargs (list* :class class initargs)))
792 (apply #'make-instance (direct-slot-definition-class class initargs) initargs)))
793
794 ;;;
795 ;;;
796 ;;;
797 (defmethod compute-slots ((class std-class))
798 ;;
799 ;; As specified, we must call COMPUTE-EFFECTIVE-SLOT-DEFINITION once
800 ;; for each different slot name we find in our superclasses. Each
801 ;; call receives the class and a list of the dslotds with that name.
802 ;; The list is in most-specific-first order.
803 ;;
804 (let ((name-dslotds-alist ()))
805 (dolist (c (class-precedence-list class))
806 (let ((dslotds (class-direct-slots c)))
807 (dolist (d dslotds)
808 (let* ((name (slot-definition-name d))
809 (entry (assq name name-dslotds-alist)))
810 (if entry
811 (push d (cdr entry))
812 (push (list name d) name-dslotds-alist))))))
813 (mapcar #'(lambda (direct)
814 (compute-effective-slot-definition class
815 (nreverse (cdr direct))))
816 name-dslotds-alist)))
817
818 (defmethod compute-slots :around ((class std-class))
819 (let ((eslotds (call-next-method))
820 (cpl (class-precedence-list class))
821 (instance-slots ())
822 (class-slots ()))
823 (dolist (eslotd eslotds)
824 (let ((alloc (slot-definition-allocation eslotd)))
825 (cond ((eq alloc :instance) (push eslotd instance-slots))
826 ((classp alloc) (push eslotd class-slots)))))
827 (let ((nlayout (compute-layout cpl instance-slots)))
828 (dolist (eslotd instance-slots)
829 (setf (slot-definition-location eslotd)
830 (position (slot-definition-name eslotd) nlayout))))
831 (dolist (eslotd class-slots)
832 (setf (slot-definition-location eslotd)
833 (assoc (slot-definition-name eslotd)
834 (class-slot-cells (slot-definition-allocation eslotd)))))
835 (mapc #'initialize-internal-slot-functions eslotds)
836 eslotds))
837
838 (defmethod compute-slots ((class structure-class))
839 (mapcan #'(lambda (superclass)
840 (mapcar #'(lambda (dslotd)
841 (compute-effective-slot-definition class
842 (list dslotd)))
843 (class-direct-slots superclass)))
844 (reverse (slot-value class 'class-precedence-list))))
845
846 (defmethod compute-slots :around ((class structure-class))
847 (let ((eslotds (call-next-method)))
848 (mapc #'initialize-internal-slot-functions eslotds)
849 eslotds))
850
851 (defmethod compute-effective-slot-definition ((class slot-class) dslotds)
852 (let* ((initargs (compute-effective-slot-definition-initargs class dslotds))
853 (class (effective-slot-definition-class class initargs)))
854 (apply #'make-instance class initargs)))
855
856 (defmethod effective-slot-definition-class ((class std-class) initargs)
857 (declare (ignore initargs))
858 (find-class 'standard-effective-slot-definition))
859
860 (defmethod effective-slot-definition-class ((class structure-class) initargs)
861 (declare (ignore initargs))
862 (find-class 'structure-effective-slot-definition))
863
864 (defmethod compute-effective-slot-definition-initargs
865 ((class slot-class) direct-slotds)
866 (let* ((name nil)
867 (initfunction nil)
868 (initform nil)
869 (initargs nil)
870 (allocation nil)
871 (type t)
872 (namep nil)
873 (initp nil)
874 (allocp nil))
875
876 (dolist (slotd direct-slotds)
877 (when slotd
878 (unless namep
879 (setq name (slot-definition-name slotd)
880 namep t))
881 (unless initp
882 (when (slot-definition-initfunction slotd)
883 (setq initform (slot-definition-initform slotd)
884 initfunction (slot-definition-initfunction slotd)
885 initp t)))
886 (unless allocp
887 (setq allocation (slot-definition-allocation slotd)
888 allocp t))
889 (setq initargs (append (slot-definition-initargs slotd) initargs))
890 (let ((slotd-type (slot-definition-type slotd)))
891 (setq type (cond ((eq type 't) slotd-type)
892 ((*subtypep type slotd-type) type)
893 (t `(and ,type ,slotd-type)))))))
894 (list :name name
895 :initform initform
896 :initfunction initfunction
897 :initargs initargs
898 :allocation allocation
899 :type type
900 :class class)))
901
902 (defmethod compute-effective-slot-definition-initargs :around
903 ((class structure-class) direct-slotds)
904 (let ((slotd (car direct-slotds)))
905 (list* :defstruct-accessor-symbol (slot-definition-defstruct-accessor-symbol slotd)
906 :internal-reader-function (slot-definition-internal-reader-function slotd)
907 :internal-writer-function (slot-definition-internal-writer-function slotd)
908 (call-next-method))))
909
910 ;;;
911 ;;; NOTE: For bootstrapping considerations, these can't use make-instance
912 ;;; to make the method object. They have to use make-a-method which
913 ;;; is a specially bootstrapped mechanism for making standard methods.
914 ;;;
915 (defmethod reader-method-class ((class slot-class) direct-slot &rest initargs)
916 (declare (ignore direct-slot initargs))
917 (find-class 'standard-reader-method))
918
919 (defmethod add-reader-method ((class slot-class) generic-function slot-name)
920 (add-method generic-function
921 (make-a-method 'standard-reader-method
922 ()
923 (list (or (class-name class) 'object))
924 (list class)
925 (make-reader-method-function class slot-name)
926 "automatically generated reader method"
927 slot-name)))
928
929 (defmethod writer-method-class ((class slot-class) direct-slot &rest initargs)
930 (declare (ignore direct-slot initargs))
931 (find-class 'standard-writer-method))
932
933 (defmethod add-writer-method ((class slot-class) generic-function slot-name)
934 (add-method generic-function
935 (make-a-method 'standard-writer-method
936 ()
937 (list 'new-value (or (class-name class) 'object))
938 (list *the-class-t* class)
939 (make-writer-method-function class slot-name)
940 "automatically generated writer method"
941 slot-name)))
942
943 (defmethod add-boundp-method ((class slot-class) generic-function slot-name)
944 (add-method generic-function
945 (make-a-method 'standard-boundp-method
946 ()
947 (list (or (class-name class) 'object))
948 (list class)
949 (make-boundp-method-function class slot-name)
950 "automatically generated boundp method"
951 slot-name)))
952
953 (defmethod remove-reader-method ((class slot-class) generic-function)
954 (let ((method (get-method generic-function () (list class) nil)))
955 (when method (remove-method generic-function method))))
956
957 (defmethod remove-writer-method ((class slot-class) generic-function)
958 (let ((method
959 (get-method generic-function () (list *the-class-t* class) nil)))
960 (when method (remove-method generic-function method))))
961
962 (defmethod remove-boundp-method ((class slot-class) generic-function)
963 (let ((method (get-method generic-function () (list class) nil)))
964 (when method (remove-method generic-function method))))
965
966
967 ;;;
968 ;;; make-reader-method-function and make-write-method function are NOT part of
969 ;;; the standard protocol. They are however useful, PCL makes uses makes use
970 ;;; of them internally and documents them for PCL users.
971 ;;;
972 ;;; *** This needs work to make type testing by the writer functions which
973 ;;; *** do type testing faster. The idea would be to have one constructor
974 ;;; *** for each possible type test. In order to do this it would be nice
975 ;;; *** to have help from inform-type-system-about-class and friends.
976 ;;;
977 ;;; *** There is a subtle bug here which is going to have to be fixed.
978 ;;; *** Namely, the simplistic use of the template has to be fixed. We
979 ;;; *** have to give the optimize-slot-value method the user might have
980 ;;; *** defined for this metclass a chance to run.
981 ;;;
982 (defmethod make-reader-method-function ((class slot-class) slot-name)
983 (make-std-reader-method-function (class-name class) slot-name))
984
985 (defmethod make-writer-method-function ((class slot-class) slot-name)
986 (make-std-writer-method-function (class-name class) slot-name))
987
988 (defmethod make-boundp-method-function ((class slot-class) slot-name)
989 (make-std-boundp-method-function (class-name class) slot-name))
990
991
992 ;;;; inform-type-system-about-class
993 ;;;; make-type-predicate
994 ;;;
995 ;;; These are NOT part of the standard protocol. They are internal mechanism
996 ;;; which PCL uses to *try* and tell the type system about class definitions.
997 ;;; In a more fully integrated implementation of CLOS, the type system would
998 ;;; know about class objects and class names in a more fundamental way and
999 ;;; the mechanism used to inform the type system about new classes would be
1000 ;;; different.
1001 ;;;
1002 (defmethod inform-type-system-about-class ((class std-class) name)
1003 (inform-type-system-about-std-class name))
1004
1005
1006 (defmethod compatible-meta-class-change-p (class proto-new-class)
1007 (eq (class-of class) (class-of proto-new-class)))
1008
1009 (defmethod validate-superclass ((class class) (new-super class))
1010 (or (eq new-super *the-class-t*)
1011 (eq (class-of class) (class-of new-super))))
1012
1013
1014
1015 ;;;
1016 ;;;
1017 ;;;
1018 (defun force-cache-flushes (class)
1019 (let* ((owrapper (class-wrapper class))
1020 (state (wrapper-state owrapper)))
1021 ;;
1022 ;; We only need to do something if the state is still T. If the
1023 ;; state isn't T, it will be FLUSH or OBSOLETE, and both of those
1024 ;; will already be doing what we want. In particular, we must be
1025 ;; sure we never change an OBSOLETE into a FLUSH since OBSOLETE
1026 ;; means do what FLUSH does and then some.
1027 ;;
1028 (when (eq state 't)
1029 (let ((nwrapper (make-wrapper (wrapper-no-of-instance-slots owrapper)
1030 class)))
1031 (setf (wrapper-instance-slots-layout nwrapper)
1032 (wrapper-instance-slots-layout owrapper))
1033 (setf (wrapper-class-slots nwrapper)
1034 (wrapper-class-slots owrapper))
1035 (without-interrupts
1036 #+cmu17
1037 (update-lisp-class-layout class nwrapper)
1038 (setf (slot-value class 'wrapper) nwrapper)
1039 (invalidate-wrapper owrapper ':flush nwrapper))))))
1040
1041 (defun flush-cache-trap (owrapper nwrapper instance)
1042 (declare (ignore owrapper))
1043 (set-wrapper instance nwrapper))
1044
1045
1046
1047 ;;;
1048 ;;; make-instances-obsolete can be called by user code. It will cause the
1049 ;;; next access to the instance (as defined in 88-002R) to trap through the
1050 ;;; update-instance-for-redefined-class mechanism.
1051 ;;;
1052 (defmethod make-instances-obsolete ((class std-class))
1053 (let* ((owrapper (class-wrapper class))
1054 (nwrapper (make-wrapper (wrapper-no-of-instance-slots owrapper)
1055 class)))
1056 (setf (wrapper-instance-slots-layout nwrapper)
1057 (wrapper-instance-slots-layout owrapper))
1058 (setf (wrapper-class-slots nwrapper)
1059 (wrapper-class-slots owrapper))
1060 (without-interrupts
1061 #+cmu17
1062 (update-lisp-class-layout class nwrapper)
1063 (setf (slot-value class 'wrapper) nwrapper)
1064 (invalidate-wrapper owrapper ':obsolete nwrapper)
1065 class)))
1066
1067 (defmethod make-instances-obsolete ((class symbol))
1068 (make-instances-obsolete (find-class class)))
1069
1070
1071 ;;;
1072 ;;; obsolete-instance-trap is the internal trap that is called when we see
1073 ;;; an obsolete instance. The times when it is called are:
1074 ;;; - when the instance is involved in method lookup
1075 ;;; - when attempting to access a slot of an instance
1076 ;;;
1077 ;;; It is not called by class-of, wrapper-of, or any of the low-level instance
1078 ;;; access macros.
1079 ;;;
1080 ;;; Of course these times when it is called are an internal implementation
1081 ;;; detail of PCL and are not part of the documented description of when the
1082 ;;; obsolete instance update happens. The documented description is as it
1083 ;;; appears in 88-002R.
1084 ;;;
1085 ;;; This has to return the new wrapper, so it counts on all the methods on
1086 ;;; obsolete-instance-trap-internal to return the new wrapper. It also does
1087 ;;; a little internal error checking to make sure that the traps are only
1088 ;;; happening when they should, and that the trap methods are computing
1089 ;;; apropriate new wrappers.
1090 ;;;
1091
1092 ;;; obsolete-instance-trap might be called on structure instances
1093 ;;; after a structure is redefined. In most cases, obsolete-instance-trap
1094 ;;; will not be able to fix the old instance, so it must signal an
1095 ;;; error. The hard part of this is that the error system and debugger
1096 ;;; might cause obsolete-instance-trap to be called again, so in that
1097 ;;; case, we have to return some reasonable wrapper, instead.
1098
1099 (defvar *in-obsolete-instance-trap* nil)
1100 (defvar *the-wrapper-of-structure-object*
1101 (class-wrapper (find-class 'structure-object)))
1102
1103 #+cmu17
1104 (define-condition obsolete-structure (error)
1105 ((datum :reader obsolete-structure-datum :initarg :datum))
1106 (:report
1107 (lambda (condition stream)
1108 ;; Don't try to print the structure, since it probably
1109 ;; won't work.
1110 (format stream "Obsolete structure error in ~S:~@
1111 For a structure of type: ~S"
1112 (conditions::condition-function-name condition)
1113 (type-of (obsolete-structure-datum condition))))))
1114
1115 (defun obsolete-instance-trap (owrapper nwrapper instance)
1116 (if (not #-(or cmu17 new-kcl-wrapper)
1117 (or (std-instance-p instance) (fsc-instance-p instance))
1118 #+cmu17
1119 (pcl-instance-p instance)
1120 #+new-kcl-wrapper
1121 nil)
1122 (if *in-obsolete-instance-trap*
1123 *the-wrapper-of-structure-object*
1124 (let ((*in-obsolete-instance-trap* t))
1125 #-cmu17
1126 (error "The structure ~S is obsolete." instance)
1127 #+cmu17
1128 (error 'obsolete-structure :datum instance)))
1129 (let* ((class (wrapper-class* nwrapper))
1130 (copy (allocate-instance class)) ;??? allocate-instance ???
1131 (olayout (wrapper-instance-slots-layout owrapper))
1132 (nlayout (wrapper-instance-slots-layout nwrapper))
1133 (oslots (get-slots instance))
1134 (nslots (get-slots copy))
1135 (oclass-slots (wrapper-class-slots owrapper))
1136 (added ())
1137 (discarded ())
1138 (plist ()))
1139 ;; local --> local transfer
1140 ;; local --> shared discard
1141 ;; local --> -- discard
1142 ;; shared --> local transfer
1143 ;; shared --> shared discard
1144 ;; shared --> -- discard
1145 ;; -- --> local add
1146 ;; -- --> shared --
1147 ;;
1148 ;; Go through all the old local slots.
1149 ;;
1150 (iterate ((name (list-elements olayout))
1151 (opos (interval :from 0)))
1152 (let ((npos (posq name nlayout)))
1153 (if npos
1154 (setf (instance-ref nslots npos) (instance-ref oslots opos))
1155 (progn
1156 (push name discarded)
1157 (unless (eq (instance-ref oslots opos) *slot-unbound*)
1158 (setf (getf plist name) (instance-ref oslots opos)))))))
1159 ;;
1160 ;; Go through all the old shared slots.
1161 ;;
1162 (iterate ((oclass-slot-and-val (list-elements oclass-slots)))
1163 (let ((name (car oclass-slot-and-val))
1164 (val (cdr oclass-slot-and-val)))
1165 (let ((npos (posq name nlayout)))
1166 (if npos
1167 (setf (instance-ref nslots npos) (cdr oclass-slot-and-val))
1168 (progn (push name discarded)
1169 (unless (eq val *slot-unbound*)
1170 (setf (getf plist name) val)))))))
1171 ;;
1172 ;; Go through all the new local slots to compute the added slots.
1173 ;;
1174 (dolist (nlocal nlayout)
1175 (unless (or (memq nlocal olayout)
1176 (assq nlocal oclass-slots))
1177 (push nlocal added)))
1178
1179 (swap-wrappers-and-slots instance copy)
1180
1181 (update-instance-for-redefined-class instance
1182 added
1183 discarded
1184 plist)
1185 nwrapper)))
1186
1187
1188 ;;;
1189 ;;;
1190 ;;;
1191 (defmacro copy-instance-internal (instance)
1192 `(#+new-kcl-wrapper if #-new-kcl-wrapper progn
1193 #+new-kcl-wrapper (not (std-instance-p ,instance))
1194 (let* ((class (class-of instance))
1195 (copy (allocate-instance class)))
1196 (if (std-instance-p ,instance)
1197 (setf (std-instance-slots ,instance) (std-instance-slots ,instance))
1198 (setf (fsc-instance-slots ,instance) (fsc-instance-slots ,instance)))
1199 copy)
1200 #+new-kcl-wrapper
1201 (copy-structure-header ,instance)))
1202
1203 (defun change-class-internal (instance new-class)
1204 (let* ((old-class (class-of instance))
1205 (copy (allocate-instance new-class))
1206 (new-wrapper (get-wrapper copy))
1207 (old-wrapper (class-wrapper old-class))
1208 (old-layout (wrapper-instance-slots-layout old-wrapper))
1209 (new-layout (wrapper-instance-slots-layout new-wrapper))
1210 (old-slots (get-slots instance))
1211 (new-slots (get-slots copy))
1212 (old-class-slots (wrapper-class-slots old-wrapper)))
1213
1214 ;;
1215 ;; "The values of local slots specified by both the class Cto and
1216 ;; Cfrom are retained. If such a local slot was unbound, it remains
1217 ;; unbound."
1218 ;;
1219 (iterate ((new-slot (list-elements new-layout))
1220 (new-position (interval :from 0)))
1221 (let ((old-position (posq new-slot old-layout)))
1222 (when old-position
1223 (setf (instance-ref new-slots new-position)
1224 (instance-ref old-slots old-position)))))
1225
1226 ;;
1227 ;; "The values of slots specified as shared in the class Cfrom and
1228 ;; as local in the class Cto are retained."
1229 ;;
1230 (iterate ((slot-and-val (list-elements old-class-slots)))
1231 (let ((position (posq (car slot-and-val) new-layout)))
1232 (when position
1233 (setf (instance-ref new-slots position) (cdr slot-and-val)))))
1234
1235 ;; Make the copy point to the old instance's storage, and make the
1236 ;; old instance point to the new storage.
1237 (swap-wrappers-and-slots instance copy)
1238
1239 (update-instance-for-different-class copy instance)
1240 instance))
1241
1242 (defmethod change-class ((instance standard-object)
1243 (new-class standard-class))
1244 (unless (std-instance-p instance)
1245 (error "Can't change the class of ~S to ~S~@
1246 because it isn't already an instance with metaclass~%~S."
1247 instance
1248 new-class
1249 'standard-class))
1250 (change-class-internal instance new-class))
1251
1252 (defmethod change-class ((instance standard-object)
1253 (new-class funcallable-standard-class))
1254 (unless (fsc-instance-p instance)
1255 (error "Can't change the class of ~S to ~S~@
1256 because it isn't already an instance with metaclass~%~S."
1257 instance
1258 new-class
1259 'funcallable-standard-class))
1260 (change-class-internal instance new-class))
1261
1262 (defmethod change-class ((instance t) (new-class-name symbol))
1263 (change-class instance (find-class new-class-name)))
1264
1265
1266
1267 ;;;
1268 ;;; The metaclass BUILT-IN-CLASS
1269 ;;;
1270 ;;; This metaclass is something of a weird creature. By this point, all
1271 ;;; instances of it which will exist have been created, and no instance
1272 ;;; is ever created by calling MAKE-INSTANCE.
1273 ;;;
1274 ;;; But, there are other parts of the protcol we must follow and those
1275 ;;; definitions appear here.
1276 ;;;
1277 (defmethod shared-initialize :before
1278 ((class built-in-class) slot-names &rest initargs)
1279 (declare (ignore slot-names initargs))
1280 (error "Attempt to initialize or reinitialize a built in class."))
1281
1282 (defmethod class-direct-slots ((class built-in-class)) ())
1283 (defmethod class-slots ((class built-in-class)) ())
1284 (defmethod class-direct-default-initargs ((class built-in-class)) ())
1285 (defmethod class-default-initargs ((class built-in-class)) ())
1286
1287 (defmethod validate-superclass ((c class) (s built-in-class))
1288 (eq s *the-class-t*))
1289
1290
1291
1292 ;;;
1293 ;;;
1294 ;;;
1295
1296 (defmethod validate-superclass ((c slot-class)
1297 (f forward-referenced-class))
1298 't)
1299
1300
1301 ;;;
1302 ;;;
1303 ;;;
1304
1305 (defmethod add-dependent ((metaobject dependent-update-mixin) dependent)
1306 (pushnew dependent (plist-value metaobject 'dependents)))
1307
1308 (defmethod remove-dependent ((metaobject dependent-update-mixin) dependent)
1309 (setf (plist-value metaobject 'dependents)
1310 (delete dependent (plist-value metaobject 'dependents))))
1311
1312 (defmethod map-dependents ((metaobject dependent-update-mixin) function)
1313 (dolist (dependent (plist-value metaobject 'dependents))
1314 (funcall function dependent)))
1315

  ViewVC Help
Powered by ViewVC 1.1.5