From 54fa3df9560fe739b5fe20ca561749092cef0fd5 Mon Sep 17 00:00:00 2001 Message-Id: <54fa3df9560fe739b5fe20ca561749092cef0fd5.1716482105.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 7 May 2016 14:45:18 +0100 Subject: [PATCH] Compatibility: the `init' function no longer calls `imprint' for you. Organization: Straylight/Edgeware From: Mark Wooding It will make much less sense later. --- doc/concepts.tex | 3 ++- doc/structures.tex | 8 +++----- lib/sod-structs.3 | 8 ++------ lib/sod.h | 3 ++- src/builtin.lisp | 10 +--------- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/doc/concepts.tex b/doc/concepts.tex index 74e5902..1663939 100644 --- a/doc/concepts.tex +++ b/doc/concepts.tex @@ -727,7 +727,7 @@ linking it into some larger data structure to keep track of it. 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. @@ -743,6 +743,7 @@ returns a pointer to the new instance. \{ \\ \ind void *p = malloc(c@->cls.initsz); \\ if (!p) return (0); \\ + c@->cls.imprint(p); \\ c@->cls.init(p); \\ return (p); \- \\ \} diff --git a/doc/structures.tex b/doc/structures.tex index 0b6be0a..c8d9daf 100644 --- a/doc/structures.tex +++ b/doc/structures.tex @@ -173,11 +173,9 @@ recommended. the vtable and class pointers are properly initialized, but the slots are left untouched. The function returns its argument @

. - \item[init] A pointer to a function: given a pointer @

to at least - @ 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 @

. + \item[init] A pointer to a function: given a pointer @

to an imprinted + instance, initialize all of its slots for which initializers are defined. + Other slots are left untouched. The function returns its argument @

. \item[n_supers] The number of direct superclasses. (This is zero exactly in the case of @|SodObject|.) diff --git a/lib/sod-structs.3 b/lib/sod-structs.3 index 0ef69ca..2d4ecd1 100644 --- a/lib/sod-structs.3 +++ b/lib/sod-structs.3 @@ -271,12 +271,8 @@ The function returns its argument 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 . diff --git a/lib/sod.h b/lib/sod.h index 2705dcc..e0e9193 100644 --- a/lib/sod.h +++ b/lib/sod.h @@ -238,7 +238,8 @@ struct sod_chain { #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 ------------------------------------------------*/ diff --git a/src/builtin.lisp b/src/builtin.lisp index e4b42de..1073cae 100644 --- a/src/builtin.lisp +++ b/src/builtin.lisp @@ -114,8 +114,7 @@ (define-class-slot "init" (class stream) (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) @@ -135,11 +134,6 @@ (define-class-slot "init" (class stream) (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*) @@ -149,8 +143,6 @@ (define-class-slot "init" (class stream) (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%"))) -- [mdw]