X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fdefstruct.lisp;h=41f2ff14bb0473fcefedfa881d5a2c4fcbbfcf36;hb=aa1a5c6ea31c248587d78f62943ad749ea8fbe2f;hp=dc182089ba30042029b90674f6fe071485b9090b;hpb=14c8e1a7d219eaccf6657b3fa3f24de9a24717cb;p=sbcl.git diff --git a/src/code/defstruct.lisp b/src/code/defstruct.lisp index dc18208..41f2ff1 100644 --- a/src/code/defstruct.lisp +++ b/src/code/defstruct.lisp @@ -47,12 +47,25 @@ ,@slot-vars)))))) (declaim (ftype (sfunction (defstruct-description list) function) - %Make-structure-instance-allocator)) + %make-structure-instance-allocator)) (defun %make-structure-instance-allocator (dd slot-specs) (let ((vars (make-gensym-list (length slot-specs)))) (values (compile nil `(lambda (,@vars) (%make-structure-instance-macro ,dd ',slot-specs ,@vars)))))) +(defun %make-funcallable-structure-instance-allocator (dd slot-specs) + (when slot-specs + (bug "funcallable-structure-instance allocation with slots unimplemented")) + (let ((name (dd-name dd)) + (length (dd-length dd)) + (nobject (gensym "OBJECT"))) + (values + (compile nil `(lambda () + (let ((,nobject (%make-funcallable-instance ,length))) + (setf (%funcallable-instance-layout ,nobject) + (%delayed-get-compiler-layout ,name)) + ,nobject)))))) + ;;; Delay looking for compiler-layout until the constructor is being ;;; compiled, since it doesn't exist until after the EVAL-WHEN ;;; (COMPILE) stuff is compiled. (Or, in the oddball case when @@ -979,6 +992,46 @@ ,(funcall (nth-value 1 (slot-accessor-transforms dd dsd)) '(dummy new-value instance))))) +;;; Blow away all the compiler info for the structure CLASS. Iterate +;;; over this type, clearing the compiler structure type info, and +;;; undefining all the associated functions. If SUBCLASSES-P, also do +;;; the same for subclasses. FIXME: maybe rename UNDEFINE-FUN-NAME to +;;; UNDECLARE-FUNCTION-NAME? +(defun undeclare-structure (classoid subclasses-p) + (let ((info (layout-info (classoid-layout classoid)))) + (when (defstruct-description-p info) + (let ((type (dd-name info))) + (remhash type *typecheckfuns*) + (setf (info :type :compiler-layout type) nil) + (undefine-fun-name (dd-copier-name info)) + (undefine-fun-name (dd-predicate-name info)) + (dolist (slot (dd-slots info)) + (let ((fun (dsd-accessor-name slot))) + (unless (accessor-inherited-data fun info) + (undefine-fun-name fun) + (unless (dsd-read-only slot) + (undefine-fun-name `(setf ,fun))))))) + ;; Clear out the SPECIFIER-TYPE cache so that subsequent + ;; references are unknown types. + (values-specifier-type-cache-clear))) + (when subclasses-p + (let ((subclasses (classoid-subclasses classoid))) + (when subclasses + (collect ((subs)) + (dohash ((classoid layout) + subclasses + :locked t) + (declare (ignore layout)) + (undeclare-structure classoid nil) + (subs (classoid-proper-name classoid))) + ;; Is it really necessary to warn about + ;; undeclaring functions for subclasses? + (when (subs) + (warn "undeclaring functions for old subclasses ~ + of ~S:~% ~S" + (classoid-name classoid) + (subs)))))))) + ;;; core compile-time setup of any class with a LAYOUT, used even by ;;; !DEFSTRUCT-WITH-ALTERNATE-METACLASS weirdosities (defun %compiler-set-up-layout (dd @@ -1006,53 +1059,15 @@ "the most recently loaded" :compiler-layout clayout)) (cond (old-layout - (labels - ;; Blow away all the compiler info for the structure - ;; CLASS. Iterate over this type, clearing the compiler - ;; structure type info, and undefining all the - ;; associated functions. FIXME: maybe rename - ;; UNDEFINE-FUN-NAME to UNDECLARE-FUNCTION-NAME? - ((undeclare-structure (classoid subclasses-p) - (let ((info (layout-info (classoid-layout classoid)))) - (when (defstruct-description-p info) - (let ((type (dd-name info))) - (remhash type *typecheckfuns*) - (setf (info :type :compiler-layout type) nil) - (undefine-fun-name (dd-copier-name info)) - (undefine-fun-name (dd-predicate-name info)) - (dolist (slot (dd-slots info)) - (let ((fun (dsd-accessor-name slot))) - (unless (accessor-inherited-data fun info) - (undefine-fun-name fun) - (unless (dsd-read-only slot) - (undefine-fun-name `(setf ,fun))))))) - ;; Clear out the SPECIFIER-TYPE cache so that subsequent - ;; references are unknown types. - (values-specifier-type-cache-clear))) - (when subclasses-p - (collect ((subs)) - (dohash ((classoid layout) - (classoid-subclasses classoid) - :locked t) - (declare (ignore layout)) - (undeclare-structure classoid nil) - (subs (classoid-proper-name classoid))) - ;; Is it really necessary to warn about - ;; undeclaring functions for subclasses? - (when (subs) - (warn "undeclaring functions for old subclasses ~ - of ~S:~% ~S" - (classoid-name classoid) - (subs))))))) - (undeclare-structure (layout-classoid old-layout) - (and (classoid-subclasses classoid) - (not (eq layout old-layout)))) - (setf (layout-invalid layout) nil) - ;; FIXME: it might be polite to hold onto old-layout and - ;; restore it at the end of the file. -- RMK 2008-09-19 - ;; (International Talk Like a Pirate Day). - (warn "~@" - classoid))) + (undeclare-structure (layout-classoid old-layout) + (and (classoid-subclasses classoid) + (not (eq layout old-layout)))) + (setf (layout-invalid layout) nil) + ;; FIXME: it might be polite to hold onto old-layout and + ;; restore it at the end of the file. -- RMK 2008-09-19 + ;; (International Talk Like a Pirate Day). + (warn "~@" + classoid)) (t (unless (eq (classoid-layout classoid) layout) (register-layout layout :invalidate nil)) @@ -1701,6 +1716,8 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (%compiler-set-up-layout ',dd ',(inherits-for-structure dd)))))) +(sb!xc:proclaim '(special *defstruct-hooks*)) + (sb!xc:defmacro !defstruct-with-alternate-metaclass (class-name &key (slot-names (missing-arg)) @@ -1795,7 +1812,11 @@ ;; code, which knows how to generate inline type tests ;; for the whole CMU CL INSTANCE menagerie. `(defun ,predicate (,object-gensym) - (typep ,object-gensym ',class-name))))))) + (typep ,object-gensym ',class-name))) + + (when (boundp '*defstruct-hooks*) + (dolist (fun *defstruct-hooks*) + (funcall fun (find-classoid ',(dd-name dd))))))))) ;;;; finalizing bootstrapping