X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fpcl%2Fctor.lisp;h=df5e2dcc855e554c6636cbeaf073a35f5224a675;hb=3d9d3088982414ca5617caf62bd37b4fecac29b6;hp=dde1c3fd01ad3ebe3a078802d3265c819293f2f0;hpb=1e08b23e730c7a1c9cda1b918e9fdca38b8c4e17;p=sbcl.git diff --git a/src/pcl/ctor.lisp b/src/pcl/ctor.lisp index dde1c3f..df5e2dc 100644 --- a/src/pcl/ctor.lisp +++ b/src/pcl/ctor.lisp @@ -92,13 +92,13 @@ ;;; When the optimized function is computed, the function of the ;;; funcallable instance is set to it. ;;; -(sb-kernel:!defstruct-with-alternate-metaclass ctor +(!defstruct-with-alternate-metaclass ctor :slot-names (function-name class-name class initargs) :boa-constructor %make-ctor :superclass-name pcl-funcallable-instance - :metaclass-name sb-kernel:random-pcl-class - :metaclass-constructor sb-kernel:make-random-pcl-class - :dd-type sb-kernel:funcallable-structure + :metaclass-name random-pcl-classoid + :metaclass-constructor make-random-pcl-classoid + :dd-type funcallable-structure :runtime-type-checks-p nil) ;;; List of all defined ctors. @@ -115,11 +115,11 @@ (defun install-initial-constructor (ctor &key force-p) (when (or force-p (ctor-class ctor)) (setf (ctor-class ctor) nil) - (setf (sb-kernel:funcallable-instance-fun ctor) - #'(sb-kernel:instance-lambda (&rest args) + (setf (funcallable-instance-fun ctor) + #'(instance-lambda (&rest args) (install-optimized-constructor ctor) (apply ctor args))) - (setf (sb-kernel:%funcallable-instance-info ctor 1) + (setf (%funcallable-instance-info ctor 1) (ctor-function-name ctor)))) ;;; @@ -210,8 +210,8 @@ (function-name (make-ctor-function-name class-name initargs))) ;; ;; Prevent compiler warnings for calling the ctor. - (sb-kernel:proclaim-as-fun-name function-name) - (sb-kernel:note-name-defined function-name :function) + (proclaim-as-fun-name function-name) + (note-name-defined function-name :function) (when (eq (info :function :where-from function-name) :assumed) (setf (info :function :where-from function-name) :defined) (when (info :function :assumed-type function-name) @@ -252,7 +252,7 @@ (finalize-inheritance class)) (setf (ctor-class ctor) class) (pushnew ctor (plist-value class 'ctors)) - (setf (sb-kernel:funcallable-instance-fun ctor) + (setf (funcallable-instance-fun ctor) ;; KLUDGE: Gerd here has the equivalent of (COMPILE NIL ;; (CONSTRUCTOR-FUNCTION-FORM)), but SBCL's COMPILE doesn't ;; deal with INSTANCE-LAMBDA expressions, only with LAMBDA @@ -287,8 +287,8 @@ (or (and (not (structure-class-p class)) (null (cdr make-instance-methods)) (null (cdr allocate-instance-methods)) - (check-initargs-1 class (plist-keys (ctor-initargs ctor)) - (append ii-methods si-methods) nil nil) + (null (check-initargs-1 class (plist-keys (ctor-initargs ctor)) + (append ii-methods si-methods) nil nil)) (not (around-or-nonstandard-primary-method-p ii-methods *the-system-ii-method*)) (not (around-or-nonstandard-primary-method-p @@ -312,13 +312,13 @@ (defun fallback-generator (ctor ii-methods si-methods) (declare (ignore ii-methods si-methods)) - `(sb-kernel:instance-lambda ,(make-ctor-parameter-list ctor) + `(instance-lambda ,(make-ctor-parameter-list ctor) (make-instance ,(ctor-class ctor) ,@(ctor-initargs ctor)))) (defun optimizing-generator (ctor ii-methods si-methods) (multiple-value-bind (body before-method-p) (fake-initialization-emf ctor ii-methods si-methods) - `(sb-kernel:instance-lambda ,(make-ctor-parameter-list ctor) + `(instance-lambda ,(make-ctor-parameter-list ctor) (declare #.*optimize-speed*) ,(wrap-in-allocate-forms ctor body before-method-p)))) @@ -339,7 +339,7 @@ `(let ((.instance. (%make-standard-instance nil (get-instance-hash-code))) (.slots. (make-array - ,(sb-kernel:layout-length wrapper) + ,(layout-length wrapper) ,@(when before-method-p '(:initial-element +slot-unbound+))))) (setf (std-instance-wrapper .instance.) ,wrapper) @@ -426,7 +426,7 @@ (initargs (ctor-initargs ctor)) (initkeys (plist-keys initargs)) (slot-vector - (make-array (sb-kernel:layout-length (class-wrapper class)) + (make-array (layout-length (class-wrapper class)) :initial-element nil)) (class-inits ()) (default-initargs (class-default-initargs class)) @@ -556,30 +556,38 @@ ;;; ******************************* (defun update-ctors (reason &key class name generic-function method) - (flet ((reset-class-ctors (class) - (loop for ctor in (plist-value class 'ctors) do - (install-initial-constructor ctor)))) + (labels ((reset (class &optional ri-cache-p (ctorsp t)) + (when ctorsp + (dolist (ctor (plist-value class 'ctors)) + (install-initial-constructor ctor))) + (when ri-cache-p + (setf (plist-value class 'ri-initargs) ())) + (dolist (subclass (class-direct-subclasses class)) + (reset subclass ri-cache-p ctorsp)))) (ecase reason ;; ;; CLASS must have been specified. (finalize-inheritance - (reset-class-ctors class)) + (reset class t)) ;; ;; NAME must have been specified. (setf-find-class (loop for ctor in *all-ctors* when (eq (ctor-class-name ctor) name) do (when (ctor-class ctor) - (reset-class-ctors (ctor-class ctor))) + (reset (ctor-class ctor))) (loop-finish))) ;; ;; GENERIC-FUNCTION and METHOD must have been specified. ((add-method remove-method) - (case (generic-function-name generic-function) - ((make-instance allocate-instance initialize-instance - shared-initialize) - (let ((type (first (method-specializers method)))) - (reset-class-ctors (type-class type))))))))) + (flet ((class-of-1st-method-param (method) + (type-class (first (method-specializers method))))) + (case (generic-function-name generic-function) + ((make-instance allocate-instance + initialize-instance shared-initialize) + (reset (class-of-1st-method-param method) t t)) + ((reinitialize-instance) + (reset (class-of-1st-method-param method) t nil)))))))) (defun precompile-ctors () (dolist (ctor *all-ctors*) @@ -588,4 +596,27 @@ (when (and class (class-finalized-p class)) (install-optimized-constructor ctor)))))) +(defun check-ri-initargs (instance initargs) + (let* ((class (class-of instance)) + (keys (plist-keys initargs)) + (cached (assoc keys (plist-value class 'ri-initargs) + :test #'equal)) + (invalid-keys + (if (consp cached) + (cdr cached) + (let ((invalid + ;; FIXME: give CHECK-INITARGS-1 and friends a + ;; more mnemonic name and (possibly) a nicer, + ;; more orthogonal interface. + (check-initargs-1 + class initargs + (list (list* 'reinitialize-instance instance initargs) + (list* 'shared-initialize instance nil initargs)) + t nil))) + (setf (plist-value class 'ri-initargs) + (acons keys invalid cached)) + invalid)))) + (when invalid-keys + (error 'initarg-error :class class :initargs invalid-keys)))) + ;;; end of ctor.lisp