X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fpcl%2Fstd-class.lisp;h=558d920f3bec45a6f32cac08153b26185031762f;hb=50f728671defadb8f7b1e8691c984cb0e6aba17c;hp=a34f739671ddf5ef29a3a3fb7ccf800a8c63c454;hpb=3ecee4526a55b3b4e6d7f86d69dc411f074968ec;p=sbcl.git diff --git a/src/pcl/std-class.lisp b/src/pcl/std-class.lisp index a34f739..558d920 100644 --- a/src/pcl/std-class.lisp +++ b/src/pcl/std-class.lisp @@ -322,30 +322,29 @@ :definition-source `((defclass ,name) ,*load-pathname*) other))) - ;; Defclass of a class with a forward-referenced superclass does not - ;; have a wrapper. RES is the incomplete PCL class. The Lisp class - ;; does not yet exist. Maybe should return NIL in that case as RES - ;; is not useful to the user? - (and (class-wrapper res) (sb-kernel:layout-class (class-wrapper res))))) + res)) (setf (gdefinition 'load-defclass) #'real-load-defclass) (defun ensure-class (name &rest all) - (apply #'ensure-class-using-class name (find-class name nil) all)) + (apply #'ensure-class-using-class (find-class name nil) name all)) -(defmethod ensure-class-using-class (name (class null) &rest args &key) +(defmethod ensure-class-using-class ((class null) name &rest args &key) (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)) -(defmethod ensure-class-using-class (name (class pcl-class) &rest args &key) +(defmethod ensure-class-using-class ((class pcl-class) name &rest args &key) (multiple-value-bind (meta initargs) (ensure-class-values class args) (unless (eq (class-of class) meta) (change-class class meta)) (apply #'reinitialize-instance class initargs) (setf (find-class name) class) + (set-class-type-translation class name) class)) (defmethod class-predicate-name ((class t)) @@ -382,45 +381,77 @@ ;; However, after playing around a little, I couldn't find that ;; way, so I've left it as is, but if someone does come up with a ;; better way... -- CSR, 2002-09-08 - (loop for (slot . more) on (getf initargs :direct-slots) - for slot-name = (getf slot :name) - if (some (lambda (s) (eq slot-name (getf s :name))) more) - ;; FIXME: It's quite possible that we ought to define an - ;; SB-INT:PROGRAM-ERROR function to signal these and other - ;; errors throughout the code base that are required to be - ;; of type PROGRAM-ERROR. - do (error 'simple-program-error - :format-control "More than one direct slot with name ~S." - :format-arguments (list slot-name)) - else - do (loop for (option value . more) on slot by #'cddr - when (and (member option - '(:allocation :type + (do ((direct-slots (getf initargs :direct-slots) (cdr direct-slots))) + ((endp direct-slots) nil) + (destructuring-bind (slot &rest more) direct-slots + (let ((slot-name (getf slot :name))) + (when (some (lambda (s) (eq slot-name (getf s :name))) more) + ;; FIXME: It's quite possible that we ought to define an + ;; SB-INT:PROGRAM-ERROR function to signal these and other + ;; errors throughout the codebase that are required to be + ;; of type PROGRAM-ERROR. + (error 'simple-program-error + :format-control "~@" + :format-arguments (list slot-name))) + (do ((stuff slot (cddr stuff))) + ((endp stuff) nil) + (destructuring-bind (option value &rest more) stuff + (cond + ((and (member option '(:allocation :type :initform :documentation)) - (not (eq unsupplied - (getf more option unsupplied)))) - do (error 'simple-program-error - :format-control "Duplicate slot option ~S for slot ~S." - :format-arguments (list option slot-name)))) + (not (eq unsupplied + (getf more option unsupplied)))) + (error 'simple-program-error + :format-control "~@" + :format-arguments (list option slot-name))) + ((and (eq option :readers) + (notevery #'symbolp value)) + (error 'simple-program-error + :format-control "~@" + :format-arguments (list slot-name))) + ((and (eq option :initargs) + (notevery #'symbolp value)) + (error 'simple-program-error + :format-control "~@" + :format-arguments (list slot-name))))))))) (loop for (initarg . more) on (getf initargs :direct-default-initargs) for name = (car initarg) when (some (lambda (a) (eq (car a) name)) more) do (error 'simple-program-error - :format-control "Duplicate initialization argument ~ - name ~S in :default-initargs of class ~A." + :format-control "~@" :format-arguments (list name class))) - (loop (unless (remf initargs :metaclass) (return))) + (let ((metaclass 0) + (default-initargs 0)) + (do ((args initargs (cddr args))) + ((endp args) nil) + (case (car args) + (:metaclass + (when (> (incf metaclass) 1) + (error 'simple-program-error + :format-control "~@"))) + (:direct-default-initargs + (when (> (incf default-initargs) 1) + (error 'simple-program-error + :format-control "~@")))))) + (remf initargs :metaclass) (loop (unless (remf initargs :direct-superclasses) (return))) (loop (unless (remf initargs :direct-slots) (return))) - (values meta - (list* :direct-superclasses - (and (neq supplied-supers unsupplied) - (mapcar #'fix-super supplied-supers)) - :direct-slots - (and (neq supplied-slots unsupplied) supplied-slots) - initargs)))) + (values + meta + (nconc + (when (neq supplied-supers unsupplied) + (list :direct-superclasses (mapcar #'fix-super supplied-supers))) + (when (neq supplied-slots unsupplied) + (list :direct-slots supplied-slots)) + initargs)))) - (defmethod shared-initialize :after ((class std-class) slot-names @@ -499,6 +530,22 @@ (lambda (dependent) (apply #'update-dependent class dependent initargs)))) +(defmethod shared-initialize :after ((class condition-class) slot-names + &key direct-superclasses) + (declare (ignore slot-names)) + (let ((classoid (find-classoid (class-name class)))) + (with-slots (wrapper class-precedence-list prototype predicate-name + (direct-supers direct-superclasses)) + class + (setf (classoid-pcl-class classoid) class) + (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))) + (add-direct-subclasses class direct-superclasses) + (setq predicate-name (make-class-predicate-name (class-name class))) + (make-class-predicate class predicate-name)))) + (defmethod shared-initialize :after ((slotd structure-slot-definition) slot-names &key (allocation :instance) allocation-class) @@ -521,18 +568,14 @@ +slot-unbound+)) direct-slots))) (reader-names (mapcar (lambda (slotd) - (intern (format nil - "~A~A reader" - conc-name - (slot-definition-name - slotd)))) + (list 'slot-accessor name + (slot-definition-name slotd) + 'reader)) direct-slots)) (writer-names (mapcar (lambda (slotd) - (intern (format nil - "~A~A writer" - conc-name - (slot-definition-name - slotd)))) + (list 'slot-accessor name + (slot-definition-name slotd) + 'writer)) direct-slots)) (readers-init (mapcar (lambda (slotd reader-name) @@ -613,9 +656,9 @@ (setf (slot-value class 'class-precedence-list) (compute-class-precedence-list class)) (setf (slot-value class 'slots) (compute-slots class)) - (let ((lclass (cl:find-class (class-name class)))) - (setf (sb-kernel:class-pcl-class lclass) class) - (setf (slot-value class 'wrapper) (sb-kernel:class-layout lclass))) + (let ((lclass (find-classoid (class-name class)))) + (setf (classoid-pcl-class lclass) class) + (setf (slot-value class 'wrapper) (classoid-layout lclass))) (update-pv-table-cache-info class) (setq predicate-name (if predicate-name-p (setf (slot-value class 'predicate-name) @@ -626,7 +669,7 @@ (class-name class)))))) (make-class-predicate class predicate-name) (add-slot-accessors class direct-slots))) - + (defmethod direct-slot-definition-class ((class structure-class) initargs) (declare (ignore initargs)) (find-class 'structure-direct-slot-definition)) @@ -708,7 +751,7 @@ (update-slots class (compute-slots class)) (update-gfs-of-class class) (update-inits class (compute-default-initargs class)) - (update-make-instance-function-table class)) + (update-ctors 'finalize-inheritance :class class)) (unless finalizep (dolist (sub (class-direct-subclasses class)) (update-class sub nil)))) @@ -1101,7 +1144,7 @@ ;;; obsolete the wrapper. ;;; ;;; FIXME: either here or in INVALID-WRAPPER-P looks like a good place -;;; for (AVER (NOT (EQ (SB-KERNEL:LAYOUT-INVALID OWRAPPER) +;;; for (AVER (NOT (EQ (LAYOUT-INVALID OWRAPPER) ;;; :UNINITIALIZED))) ;;; ;;; Thanks to Gerd Moellmann for the explanation. -- CSR, 2002-10-29 @@ -1117,14 +1160,14 @@ ;; a violation of locality or what might be considered ;; good style. There has to be a better way! -- CSR, ;; 2002-10-29 - (eq (sb-kernel:layout-invalid owrapper) t)) + (eq (layout-invalid owrapper) t)) (let ((nwrapper (make-wrapper (wrapper-no-of-instance-slots owrapper) class))) (setf (wrapper-instance-slots-layout nwrapper) (wrapper-instance-slots-layout owrapper)) (setf (wrapper-class-slots nwrapper) (wrapper-class-slots owrapper)) - (sb-sys:without-interrupts + (with-pcl-lock (update-lisp-class-layout class nwrapper) (setf (slot-value class 'wrapper) nwrapper) (invalidate-wrapper owrapper :flush nwrapper)))))) @@ -1144,7 +1187,7 @@ (wrapper-instance-slots-layout owrapper)) (setf (wrapper-class-slots nwrapper) (wrapper-class-slots owrapper)) - (sb-sys:without-interrupts + (with-pcl-lock (update-lisp-class-layout class nwrapper) (setf (slot-value class 'wrapper) nwrapper) (invalidate-wrapper owrapper :obsolete nwrapper)