X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fdefstruct.lisp;h=a3dbf1e2a48aa384d168e11aa5b77706a4b5306e;hb=25fe91bf63fd473d9316675b0e0ca9be0079e9eb;hp=10a1a4073599cb119eaef363f99211d474211f43;hpb=f12f2c5a8ae794dc414dd6a42e0b25740d576aa1;p=sbcl.git diff --git a/src/code/defstruct.lisp b/src/code/defstruct.lisp index 10a1a40..a3dbf1e 100644 --- a/src/code/defstruct.lisp +++ b/src/code/defstruct.lisp @@ -333,7 +333,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 +361,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 +377,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) @@ -858,7 +865,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 +885,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)) @@ -931,14 +941,17 @@ ;;; !DEFSTRUCT-WITH-ALTERNATE-METACLASS weirdosities (defun %compiler-set-up-layout (dd &optional - ;; Several special cases (STRUCTURE-OBJECT - ;; itself, and structures with alternate - ;; metaclasses) call this function directly, - ;; and they're all at the base of the - ;; instance class structure, so this is - ;; a handy default. - (inherits (vector (find-layout t) - (find-layout 'instance)))) + ;; Several special cases + ;; (STRUCTURE-OBJECT itself, and + ;; structures with alternate + ;; metaclasses) call this function + ;; directly, and they're all at the + ;; base of the instance class + ;; structure, so this is a handy + ;; default. (But note + ;; FUNCALLABLE-STRUCTUREs need + ;; assistance here) + (inherits (vector (find-layout t)))) (multiple-value-bind (classoid layout old-layout) (multiple-value-bind (clayout clayout-p) @@ -1146,7 +1159,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) @@ -1522,6 +1535,15 @@ reversed-result) (incf index)) (nreverse reversed-result)))) + (case dd-type + ;; We don't support inheritance of alternate metaclass stuff, + ;; and it's not a general-purpose facility, so sanity check our + ;; own code. + (structure + (aver (eq superclass-name 't))) + (funcallable-structure + (aver (eq superclass-name 'function))) + (t (bug "Unknown DD-TYPE in ALTERNATE-METACLASS: ~S" dd-type))) (setf (dd-alternate-metaclass dd) (list superclass-name metaclass-name metaclass-constructor) @@ -1530,6 +1552,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)) @@ -1580,7 +1643,7 @@ `(progn (eval-when (:compile-toplevel :load-toplevel :execute) - (%compiler-set-up-layout ',dd)) + (%compiler-set-up-layout ',dd ',(inherits-for-structure dd))) ;; slot readers and writers (declaim (inline ,@(mapcar #'dsd-accessor-name dd-slots))) @@ -1644,7 +1707,7 @@ ;; Note: This has an ALTERNATE-METACLASS only because of blind ;; clueless imitation of the CMU CL code -- dunno if or why it's ;; needed. -- WHN - (dd-alternate-metaclass dd) '(instance) + (dd-alternate-metaclass dd) '(t) (dd-slots dd) nil (dd-length dd) 1 (dd-type dd) 'structure)