[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MAKE-LOAD-FORM can handle circularities [was Compilation implications]
> Simply allow the second form to contain a reference to the object
> being dumped.
>
> Neat, yes? File-level EQ preservation works to restore the embedded
> object reference "for free".
Yes.
> Define a generic function MAKE-LOAD-FORM which takes one argument and
> returns one or two values. This function is called whenever
> COMPILE-FILE needs to dump an object whose class is of type
> STANDARD-CLASS or STRUCTURE-CLASS.
Or if its class is a user-defined metaclass, even if not a subclass of
STANDARD-CLASS. Maybe it would be best to say anything whose metaclass is
not BUILT-IN-CLASS.
> The allocator must wholly or partially build the reconstructed object,
> and return an ordinary Lisp reference to it. The initializer, if
> supplied and non-null, must finish any initialization required by the
> object's class. It is an error if the result of this second form is not
> EQ to the result of the first.
It would be a convenient convention for the second form to return the
object, but the value returned by the second form would not actually be
used for anything, so it doesn't need to be constrained. Or maybe you
just want to verify that it did what it was intended to?
> Example:
> (defclass tree-with-parent () (parent children))
> (defmethod make-load-form ((x tree-with-parent))
> (values
> `(allocate-instance (class-of x) :children ',(slot-value x 'children))
> `(initialize-instance ',x :parent ',(slot-value x 'parent))))
This isn't quite right because ALLOCATE-INSTANCE doesn't fill in any slot
values. Maybe what you want is something like
(defclass tree-with-parent () ((parent :accessor tree-parent)
(children :initarg :children)))
(defmethod make-load-form ((x tree-with-parent))
(values
`(make-instance ',(class-of x) :children ',(slot-value x 'children))
`(setf (tree-parent ',x) ',(slot-value x 'parent))))