It will make much less sense later.
Classes can declare initial values for their slots. A class object's @|init|
slot points to a function which will establish the appropriate initial values
for a new instance's slots. Slots are not initialized in any particularly
-useful order. The @|init| function also imprints the instance storage.
+useful order.
The provided initialization protocol is extremely simplistic; most notably,
it's not possible to pass parameters into the initialization process.
\{ \\ \ind
void *p = malloc(c@->cls.initsz); \\
if (!p) return (0); \\
+ c@->cls.imprint(p); \\
c@->cls.init(p); \\
return (p); \- \\
\}
the vtable and class pointers are properly initialized, but the slots are
left untouched. The function returns its argument @<p>.
- \item[init] A pointer to a function: given a pointer @<p> to at least
- @<initsz> bytes of appropriately aligned memory, initialize an instance
- of the class in it: all of the vtable and class pointers are initialized,
- as are slots for which initializers are defined. Other slots are left
- untouched. The function returns its argument @<p>.
+ \item[init] A pointer to a function: given a pointer @<p> to an imprinted
+ instance, initialize all of its slots for which initializers are defined.
+ Other slots are left untouched. The function returns its argument @<p>.
\item[n_supers] The number of direct superclasses. (This is zero exactly
in the case of @|SodObject|.)
A pointer to a function:
given a pointer
.I p
-to at least
-.I initsz
-bytes of appropriately aligned memory,
-initialize an instance of the class in it:
-all of the vtable and class pointers are initialized,
-as are slots for which initializers are defined.
+to an imprinted instance,
+initialize all of its slots for which initializers are defined.
Other slots are left untouched.
The function returns its argument
.IR p .
#define SOD_DECL(cls_, var_) \
struct cls_##__ilayout var_##__layout; \
- cls_ *var_ = cls_##__class->cls.init(&var_##__layout)
+ cls_ *var_ = \
+ cls_##__class->cls.init(cls_##__class->cls.imprint(&var_##__layout))
/*----- Functions provided ------------------------------------------------*/
(format nil "~A__init" class)
;; FIXME this needs a metaobject protocol
- (let ((ilayout (sod-class-ilayout class))
- (used nil))
+ (let ((ilayout (sod-class-ilayout class)))
(format stream "~&~:
/* Provide initial values for an instance's slots. */
static void *~A__init(void *p)~%{~%" class)
(let ((dslot (effective-slot-direct-slot slot))
(init (effective-slot-initializer slot)))
(when init
- (unless used
- (format stream
- " struct ~A *sod__obj = ~A__imprint(p);~2%"
- (ilayout-struct-tag class) class)
- (setf used t))
(format stream " {~% ")
(pprint-c-type (sod-slot-type dslot) stream
*sod-tmp-val*)
(sod-initializer-value init)
isl (sod-slot-name dslot)
*sod-tmp-val*))))))))))
- (unless used
- (format stream " ~A__imprint(p);~%" class))
(format stream "~&~:
return (p);
}~2%")))