X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fdefstruct.lisp;h=97dc74e1ee5a0f6c7893802fb431c0568032cf62;hb=a572ab7de4266dec958d50612a8376df6bb45226;hp=5ba663c4640d79b40e887d920412d0308ae0c91d;hpb=0aecc2b20142e08068c3434273500131cb13fe2d;p=sbcl.git diff --git a/src/code/defstruct.lisp b/src/code/defstruct.lisp index 5ba663c..97dc74e 100644 --- a/src/code/defstruct.lisp +++ b/src/code/defstruct.lisp @@ -58,10 +58,6 @@ (error "Class is not a structure class: ~S" ',name)) ,layout)))))) -;;; Get layout right away. -(sb!xc:defmacro compile-time-find-layout (name) - (find-layout name)) - ;;; re. %DELAYED-GET-COMPILER-LAYOUT and COMPILE-TIME-FIND-LAYOUT, above.. ;;; ;;; FIXME: Perhaps both should be defined with DEFMACRO-MUNDANELY? @@ -333,7 +329,8 @@ `((setf (structure-classoid-constructor (find-classoid ',name)) #',def-con)))))))) -;;; shared logic for CL:DEFSTRUCT and SB!XC:DEFSTRUCT +;;; shared logic for host macroexpansion for SB!XC:DEFSTRUCT and +;;; cross-compiler macroexpansion for CL:DEFSTRUCT (defmacro !expander-for-defstruct (name-and-options slot-descriptions expanding-into-code-for-xc-host-p) @@ -360,7 +357,7 @@ ;; class. (with-single-package-locked-error (:symbol ',name "defining ~A as a structure")) - (%defstruct ',dd ',inherits) + (%defstruct ',dd ',inherits (sb!c:source-location)) (eval-when (:compile-toplevel :load-toplevel :execute) (%compiler-defstruct ',dd ',inherits)) ,@(unless expanding-into-code-for-xc-host-p @@ -376,11 +373,17 @@ (:symbol ',name "defining ~A as a structure")) (eval-when (:compile-toplevel :load-toplevel :execute) (setf (info :typed-structure :info ',name) ',dd)) + (eval-when (:load-toplevel :execute) + (setf (info :source-location :typed-structure ',name) + (sb!c:source-location))) ,@(unless expanding-into-code-for-xc-host-p (append (typed-accessor-definitions dd) (typed-predicate-definitions dd) (typed-copier-definitions dd) - (constructor-definitions dd))) + (constructor-definitions dd) + (when (dd-doc dd) + `((setf (fdocumentation ',(dd-name dd) 'structure) + ',(dd-doc dd)))))) ',name))))) (sb!xc:defmacro defstruct (name-and-options &rest slot-descriptions) @@ -472,7 +475,8 @@ (let ((inherited (accessor-inherited-data name defstruct))) (cond ((not inherited) - (stuff `(declaim (inline ,name (setf ,name)))) + (stuff `(declaim (inline ,name ,@(unless (dsd-read-only slot) + `((setf ,name)))))) ;; FIXME: The arguments in the next two DEFUNs should ;; be gensyms. (Otherwise e.g. if NEW-VALUE happened to ;; be the name of a special variable, things could get @@ -858,7 +862,7 @@ ;;; incompatible redefinition. Define those functions which are ;;; sufficiently stereotyped that we can implement them as standard ;;; closures. -(defun %defstruct (dd inherits) +(defun %defstruct (dd inherits source-location) (declare (type defstruct-description dd)) ;; We set up LAYOUTs even in the cross-compilation host. @@ -878,6 +882,9 @@ (setq layout (classoid-layout classoid)))) (setf (find-classoid (dd-name dd)) classoid) + (sb!c:with-source-location (source-location) + (setf (layout-source-location layout) source-location)) + ;; Various other operations only make sense on the target SBCL. #-sb-xc-host (%target-defstruct dd layout)) @@ -923,9 +930,14 @@ ;;; Return a LAMBDA form which can be used to set a slot. (defun slot-setter-lambda-form (dd dsd) - `(lambda (new-value instance) - ,(funcall (nth-value 1 (slot-accessor-transforms dd dsd)) - '(dummy new-value instance)))) + ;; KLUDGE: Evaluating the results of SLOT-ACCESSOR-TRANSFORMS needs + ;; a lexenv. + (let ((sb!c:*lexenv* (if (boundp 'sb!c:*lexenv*) + sb!c:*lexenv* + (sb!c::make-null-lexenv)))) + `(lambda (new-value instance) + ,(funcall (nth-value 1 (slot-accessor-transforms dd dsd)) + '(dummy new-value instance))))) ;;; core compile-time setup of any class with a LAYOUT, used even by ;;; !DEFSTRUCT-WITH-ALTERNATE-METACLASS weirdosities @@ -956,14 +968,15 @@ (when (and (classoid-subclasses classoid) (not (eq layout old-layout))) (collect ((subs)) - (dohash (classoid layout (classoid-subclasses classoid)) - (declare (ignore layout)) - (undefine-structure classoid) - (subs (classoid-proper-name classoid))) - (when (subs) - (warn "removing old subclasses of ~S:~% ~S" - (classoid-name classoid) - (subs)))))) + (dohash ((classoid layout) (classoid-subclasses classoid) + :locked t) + (declare (ignore layout)) + (undefine-structure classoid) + (subs (classoid-proper-name classoid))) + (when (subs) + (warn "removing old subclasses of ~S:~% ~S" + (classoid-name classoid) + (subs)))))) (t (unless (eq (classoid-layout classoid) layout) (register-layout layout :invalidate nil)) @@ -1019,6 +1032,7 @@ (let* ((accessor-name (dsd-accessor-name dsd)) (dsd-type (dsd-type dsd))) (when accessor-name + (setf (info :function :structure-accessor accessor-name) dd) (let ((inherited (accessor-inherited-data accessor-name dd))) (cond ((not inherited) @@ -1149,7 +1163,7 @@ (lambda (x) (sb!xc:typep x 'structure-classoid)) (lambda (x) - (sb!xc:typep x (find-classoid class)))) + (sb!xc:typep x (classoid-name (find-classoid class))))) (fdefinition constructor))) (setf (classoid-direct-superclasses class) (case (dd-name info) @@ -1542,6 +1556,47 @@ (dd-type dd) dd-type) dd)) +;;; make !DEFSTRUCT-WITH-ALTERNATE-METACLASS compilable by the host +;;; lisp, installing the information we need to reason about the +;;; structures (layouts and classoids). +;;; +;;; FIXME: we should share the parsing and the DD construction between +;;; this and the cross-compiler version, but my brain was too small to +;;; get that right. -- CSR, 2006-09-14 +#+sb-xc-host +(defmacro !defstruct-with-alternate-metaclass + (class-name &key + (slot-names (missing-arg)) + (boa-constructor (missing-arg)) + (superclass-name (missing-arg)) + (metaclass-name (missing-arg)) + (metaclass-constructor (missing-arg)) + (dd-type (missing-arg)) + predicate + (runtime-type-checks-p t)) + + (declare (type (and list (not null)) slot-names)) + (declare (type (and symbol (not null)) + boa-constructor + superclass-name + metaclass-name + metaclass-constructor)) + (declare (type symbol predicate)) + (declare (type (member structure funcallable-structure) dd-type)) + (declare (ignore boa-constructor predicate runtime-type-checks-p)) + + (let* ((dd (make-dd-with-alternate-metaclass + :class-name class-name + :slot-names slot-names + :superclass-name superclass-name + :metaclass-name metaclass-name + :metaclass-constructor metaclass-constructor + :dd-type dd-type))) + `(progn + + (eval-when (:compile-toplevel :load-toplevel :execute) + (%compiler-set-up-layout ',dd ',(inherits-for-structure dd)))))) + (sb!xc:defmacro !defstruct-with-alternate-metaclass (class-name &key (slot-names (missing-arg)) @@ -1674,4 +1729,12 @@ (inherits (inherits-for-structure dd))) (%compiler-defstruct dd inherits))) +;;; finding these beasts +(defun find-defstruct-description (name &optional (errorp t)) + (let ((info (layout-info (classoid-layout (find-classoid name errorp))))) + (if (defstruct-description-p info) + info + (when errorp + (error "No DEFSTRUCT-DESCRIPTION for ~S." name))))) + (/show0 "code/defstruct.lisp end of file")