X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fpcl%2Fstd-class.lisp;h=cec50b1581688c224055656cea9f3a68d8b38ab3;hb=095564c28a259002c7e34fd1d861f5bbd0a959b6;hp=46cdf63c861965a38b15f4371c9ace1d25a52c54;hpb=ff92598854bf7cae8d57fe49cef4d9a98e1ab345;p=sbcl.git diff --git a/src/pcl/std-class.lisp b/src/pcl/std-class.lisp index 46cdf63..cec50b1 100644 --- a/src/pcl/std-class.lisp +++ b/src/pcl/std-class.lisp @@ -133,6 +133,10 @@ (allocate-instance class) (allocate-standard-instance wrapper)))))) +(defmethod class-prototype ((class condition-class)) + (with-slots (prototype) class + (or prototype (setf prototype (allocate-instance class))))) + (defmethod class-direct-default-initargs ((class slot-class)) (plist-value class 'direct-default-initargs)) @@ -141,6 +145,8 @@ (defmethod class-slot-cells ((class std-class)) (plist-value class 'class-slot-cells)) +(defmethod (setf class-slot-cells) (new-value (class std-class)) + (setf (plist-value class 'class-slot-cells) new-value)) ;;;; class accessors that are even a little bit more complicated than those ;;;; above. These have a protocol for updating them, we must implement that @@ -279,16 +285,23 @@ (defmethod shared-initialize :after ((specl eql-specializer) slot-names &key) (declare (ignore slot-names)) - (setf (slot-value specl 'type) `(eql ,(specializer-object specl)))) + (setf (slot-value specl 'type) + `(eql ,(specializer-object specl))) + (setf (info :type :translator specl) + (constantly (make-member-type :members (list (specializer-object specl)))))) + -(defun real-load-defclass (name metaclass-name supers slots other) - (let ((res (apply #'ensure-class name :metaclass metaclass-name - :direct-superclasses supers - :direct-slots slots - :definition-source `((defclass ,name) - ,*load-pathname*) - other))) - res)) +(defun real-load-defclass (name metaclass-name supers slots other + readers writers slot-names) + (with-single-package-locked-error (:symbol name "defining ~S as a class") + (%compiler-defclass name readers writers slot-names) + (let ((res (apply #'ensure-class name :metaclass metaclass-name + :direct-superclasses supers + :direct-slots slots + :definition-source `((defclass ,name) + ,*load-pathname*) + other))) + res))) (setf (gdefinition 'load-defclass) #'real-load-defclass) @@ -302,25 +315,25 @@ args)) (defmethod ensure-class-using-class ((class null) name &rest args &key) - (without-package-locks - (multiple-value-bind (meta initargs) - (ensure-class-values class args) - (set-class-type-translation (class-prototype meta) name) - (setf class (apply #'make-instance meta :name name initargs) - (find-class name) class) - (set-class-type-translation class name) - class))) + (multiple-value-bind (meta initargs) + (ensure-class-values class args) + (set-class-type-translation (class-prototype meta) name) + (setf class (apply #'make-instance meta :name name initargs)) + (without-package-locks + (setf (find-class name) class)) + (set-class-type-translation class name) + class)) (defmethod ensure-class-using-class ((class pcl-class) name &rest args &key) - (without-package-locks - (multiple-value-bind (meta initargs) - (ensure-class-values class args) - (unless (eq (class-of class) meta) - (apply #'change-class class meta initargs)) - (apply #'reinitialize-instance class initargs) - (setf (find-class name) class) - (set-class-type-translation class name) - class))) + (multiple-value-bind (meta initargs) + (ensure-class-values class args) + (unless (eq (class-of class) meta) + (apply #'change-class class meta initargs)) + (apply #'reinitialize-instance class initargs) + (without-package-locks + (setf (find-class name) class)) + (set-class-type-translation class name) + class)) (defmethod class-predicate-name ((class t)) 'constantly-nil) @@ -577,7 +590,8 @@ &key direct-slots direct-superclasses) (declare (ignore slot-names)) (let ((classoid (find-classoid (class-name class)))) - (with-slots (wrapper class-precedence-list prototype predicate-name + (with-slots (wrapper class-precedence-list cpl-available-p + prototype predicate-name (direct-supers direct-superclasses)) class (setf (slot-value class 'direct-slots) @@ -588,7 +602,7 @@ (setq direct-supers direct-superclasses) (setq wrapper (classoid-layout classoid)) (setq class-precedence-list (compute-class-precedence-list class)) - (setq prototype (make-condition (class-name class))) + (setq cpl-available-p t) (add-direct-subclasses class direct-superclasses) (setq predicate-name (make-class-predicate-name (class-name class))) (make-class-predicate class predicate-name) @@ -718,12 +732,12 @@ instance)))) (defmethod shared-initialize :after - ((class structure-class) - slot-names - &key (direct-superclasses nil direct-superclasses-p) - (direct-slots nil direct-slots-p) - direct-default-initargs - (predicate-name nil predicate-name-p)) + ((class structure-class) + slot-names + &key (direct-superclasses nil direct-superclasses-p) + (direct-slots nil direct-slots-p) + direct-default-initargs + (predicate-name nil predicate-name-p)) (declare (ignore slot-names direct-default-initargs)) (if direct-superclasses-p (setf (slot-value class 'direct-superclasses) @@ -770,7 +784,8 @@ (make-defstruct-allocation-function class))) (add-direct-subclasses class direct-superclasses) (setf (slot-value class 'class-precedence-list) - (compute-class-precedence-list class)) + (compute-class-precedence-list class)) + (setf (slot-value class 'cpl-available-p) t) (setf (slot-value class 'slots) (compute-slots class)) (let ((lclass (find-classoid (class-name class)))) (setf (classoid-pcl-class lclass) class) @@ -801,28 +816,27 @@ (fix-slot-accessors class dslotds 'remove)) (defun fix-slot-accessors (class dslotds add/remove) - ;; We disable package locks here, since defining a class can trigger - ;; the update of the accessors of another class -- which might lead - ;; to package lock violations if we didn't. - (without-package-locks - (flet ((fix (gfspec name r/w) - (let* ((ll (case r/w (r '(object)) (w '(new-value object)))) - (gf (if (fboundp gfspec) - (ensure-generic-function gfspec) - (ensure-generic-function gfspec :lambda-list ll)))) - (case r/w - (r (if (eq add/remove 'add) - (add-reader-method class gf name) - (remove-reader-method class gf))) - (w (if (eq add/remove 'add) - (add-writer-method class gf name) - (remove-writer-method class gf))))))) - (dolist (dslotd dslotds) - (let ((slot-name (slot-definition-name dslotd))) - (dolist (r (slot-definition-readers dslotd)) - (fix r slot-name 'r)) - (dolist (w (slot-definition-writers dslotd)) - (fix w slot-name 'w))))))) + (flet ((fix (gfspec name r/w) + (let ((gf (if (fboundp gfspec) + (without-package-locks + (ensure-generic-function gfspec)) + (ensure-generic-function + gfspec :lambda-list (case r/w + (r '(object)) + (w '(new-value object))))))) + (case r/w + (r (if (eq add/remove 'add) + (add-reader-method class gf name) + (remove-reader-method class gf))) + (w (if (eq add/remove 'add) + (add-writer-method class gf name) + (remove-writer-method class gf))))))) + (dolist (dslotd dslotds) + (let ((slot-name (slot-definition-name dslotd))) + (dolist (r (slot-definition-readers dslotd)) + (fix r slot-name 'r)) + (dolist (w (slot-definition-writers dslotd)) + (fix w slot-name 'w)))))) (defun add-direct-subclasses (class supers) (dolist (super supers) @@ -873,7 +887,7 @@ (update-cpl class (compute-class-precedence-list class)) ;; This invocation of UPDATE-SLOTS, in practice, finalizes the ;; class. The hoops above are to ensure that FINALIZE-INHERITANCE - ;; is called at finalization, so that MOP programmers can hook + ;; is called at finalization, so that MOP programmers can hook ;; into the system as described in "Class Finalization Protocol" ;; (section 5.5.2 of AMOP). (update-slots class (compute-slots class)) @@ -894,8 +908,11 @@ ;; Need to have the cpl setup before update-lisp-class-layout ;; is called on CMU CL. (setf (slot-value class 'class-precedence-list) cpl) + (setf (slot-value class 'cpl-available-p) t) (force-cache-flushes class)) - (setf (slot-value class 'class-precedence-list) cpl)) + (progn + (setf (slot-value class 'class-precedence-list) cpl) + (setf (slot-value class 'cpl-available-p) t))) (update-class-can-precede-p cpl)) (defun update-class-can-precede-p (cpl) @@ -1031,13 +1048,25 @@ (location -1)) (dolist (eslotd eslotds eslotds) (setf (slot-definition-location eslotd) - (ecase (slot-definition-allocation eslotd) + (case (slot-definition-allocation eslotd) (:instance (incf location)) (:class (let* ((name (slot-definition-name eslotd)) - (from-class (slot-definition-allocation-class eslotd)) - (cell (assq name (class-slot-cells from-class)))) + (from-class + (or + (slot-definition-allocation-class eslotd) + ;; we get here if the user adds an extra slot + ;; himself... + (setf (slot-definition-allocation-class eslotd) + class))) + ;; which raises the question of what we should + ;; do if we find that said user has added a slot + ;; with the same name as another slot... + (cell (or (assq name (class-slot-cells from-class)) + (setf (class-slot-cells from-class) + (cons (cons name +slot-unbound+) + (class-slot-cells from-class)))))) (aver (consp cell)) (if (eq +slot-unbound+ (cdr cell)) ;; We may have inherited an initfunction @@ -1046,6 +1075,8 @@ (rplacd cell (funcall initfun)) cell)) cell))))) + (unless (slot-definition-class eslotd) + (setf (slot-definition-class eslotd) class)) (initialize-internal-slot-functions eslotd)))) (defmethod compute-slots ((class funcallable-standard-class)) @@ -1079,7 +1110,7 @@ (instance-slots ()) (class-slots ())) (dolist (slotd all-slotds) - (ecase (slot-definition-allocation slotd) + (case (slot-definition-allocation slotd) (:instance (push slotd instance-slots)) (:class (push slotd class-slots)))) (let ((layout (compute-layout instance-slots)))