You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2012/07/14 15:49:01 UTC
[lucy-commits] svn commit: r1361545 - in /lucy/trunk: clownfish/perl/lib/Clownfish/
clownfish/src/ core/Lucy/Object/
Author: nwellnhof
Date: Sat Jul 14 13:49:00 2012
New Revision: 1361545
URL: http://svn.apache.org/viewvc?rev=1361545&view=rev
Log:
LUCY-233 Rework VTable method initialization
Define method initialization struct only inside parcel.c.
Modified:
lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
lucy/trunk/clownfish/src/CFCBindAliases.c
lucy/trunk/clownfish/src/CFCBindClass.c
lucy/trunk/clownfish/src/CFCBindCore.c
lucy/trunk/clownfish/src/CFCBindMethod.c
lucy/trunk/clownfish/src/CFCBindMethod.h
lucy/trunk/clownfish/src/CFCMethod.c
lucy/trunk/clownfish/src/CFCMethod.h
lucy/trunk/core/Lucy/Object/VTable.c
lucy/trunk/core/Lucy/Object/VTable.cfh
Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs Sat Jul 14 13:49:00 2012
@@ -933,13 +933,13 @@ void
_set_or_get(self, ...)
CFCMethod *self;
ALIAS:
- get_macro_sym = 2
- full_method_meta_sym = 8
- full_override_sym = 10
- abstract = 12
- novel = 14
- final = 16
- self_type = 18
+ get_macro_sym = 2
+ full_spec_sym = 8
+ full_override_sym = 10
+ abstract = 12
+ novel = 14
+ final = 16
+ self_type = 18
PPCODE:
{
START_SET_OR_GET_SWITCH
@@ -949,7 +949,7 @@ PPCODE:
}
break;
case 8: {
- const char *value = CFCMethod_full_method_meta_sym(self);
+ const char *value = CFCMethod_full_spec_sym(self);
retval = newSVpvn(value, strlen(value));
}
break;
@@ -1840,10 +1840,10 @@ CODE:
OUTPUT: RETVAL
SV*
-_method_meta_def(meth)
+_spec_def(meth)
CFCMethod *meth;
CODE:
- RETVAL = S_sv_eat_c_string(CFCBindMeth_method_meta_def(meth));
+ RETVAL = S_sv_eat_c_string(CFCBindMeth_spec_def(meth));
OUTPUT: RETVAL
MODULE = Clownfish::CFC PACKAGE = Clownfish::CFC::Binding::Core::Aliases
Modified: lucy/trunk/clownfish/src/CFCBindAliases.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindAliases.c?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindAliases.c (original)
+++ lucy/trunk/clownfish/src/CFCBindAliases.c Sat Jul 14 13:49:00 2012
@@ -102,6 +102,7 @@ struct alias aliases[] = {
{"CFISH_VTABLE", "LUCY_VTABLE"},
{"cfish_VTable_allocate", "lucy_VTable_allocate"},
{"cfish_VTable_init", "lucy_VTable_init"},
+ {"cfish_VTable_add_method", "lucy_VTable_add_method"},
{"cfish_VTable_add_to_registry", "lucy_VTable_add_to_registry"},
{"cfish_VTable_add_alias_to_registry", "lucy_VTable_add_alias_to_registry"},
{"cfish_VTable_offset_of_parent", "lucy_VTable_offset_of_parent"},
Modified: lucy/trunk/clownfish/src/CFCBindClass.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindClass.c?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindClass.c (original)
+++ lucy/trunk/clownfish/src/CFCBindClass.c Sat Jul 14 13:49:00 2012
@@ -33,7 +33,7 @@
struct CFCBindClass {
CFCBase base;
CFCClass *client;
- char *full_method_meta_var;
+ char *method_specs_var;
char *short_names_macro;
};
@@ -96,9 +96,9 @@ CFCBindClass_init(CFCBindClass *self, CF
const char *full_vtable_var = CFCClass_full_vtable_var(client);
const char *PREFIX = CFCClass_get_PREFIX(client);
- self->full_method_meta_var = (char*)MALLOCATE(strlen(full_vtable_var) + 20);
- self->short_names_macro = (char*)MALLOCATE(strlen(PREFIX) + 20);
- sprintf(self->full_method_meta_var, "%s_META", full_vtable_var);
+ self->method_specs_var = (char*)MALLOCATE(strlen(full_vtable_var) + 20);
+ self->short_names_macro = (char*)MALLOCATE(strlen(PREFIX) + 20);
+ sprintf(self->method_specs_var, "%s_METHODS", full_vtable_var);
sprintf(self->short_names_macro, "%sUSE_SHORT_NAMES", PREFIX);
return self;
@@ -106,7 +106,7 @@ CFCBindClass_init(CFCBindClass *self, CF
void
CFCBindClass_destroy(CFCBindClass *self) {
- FREEMEM(self->full_method_meta_var);
+ FREEMEM(self->method_specs_var);
FREEMEM(self->short_names_macro);
CFCBase_decref((CFCBase*)self->client);
CFCBase_destroy((CFCBase*)self);
@@ -279,17 +279,17 @@ CFCBindClass_to_c_data(CFCBindClass *sel
CFCMethod **methods = CFCClass_methods(client);
CFCMethod **fresh_methods = CFCClass_fresh_methods(client);
- char *offsets = CFCUtil_strdup("");
- char *cb_funcs = CFCUtil_strdup("");
- char *md_objects = CFCUtil_strdup("");
+ char *offsets = CFCUtil_strdup("");
+ char *cb_funcs = CFCUtil_strdup("");
+ char *ms_defs = CFCUtil_strdup("");
- /* Start a NULL-terminated array of cfish_MethodMetaData vars. Since C89
+ /* Start a NULL-terminated array of cfish_MethodSpec vars. Since C89
* doesn't allow us to initialize a pointer to an anonymous array inside a
* global struct, we have to give it a real symbol and then store a pointer
* to that symbol inside the VTable struct. */
- char *md_var = CFCUtil_strdup("");
- md_var = CFCUtil_cat(md_var, "cfish_MethodMetaData *",
- self->full_method_meta_var, "[] = {\n ", NULL);
+ char *ms_var = CFCUtil_strdup("");
+ ms_var = CFCUtil_cat(ms_var, "static cfish_MethodSpec *",
+ self->method_specs_var, "[] = {\n ", NULL);
for (int meth_num = 0; methods[meth_num] != NULL; meth_num++) {
CFCMethod *method = methods[meth_num];
@@ -327,18 +327,18 @@ CFCBindClass_to_c_data(CFCBindClass *sel
cb_funcs = CFCUtil_cat(cb_funcs, cb_def, "\n", NULL);
FREEMEM(cb_def);
}
- char *md_obj_def = CFCBindMeth_method_meta_def(method);
- md_objects = CFCUtil_cat(md_objects, md_obj_def, NULL);
- FREEMEM(md_obj_def);
- const char *full_md_sym = CFCMethod_full_method_meta_sym(method);
- md_var = CFCUtil_cat(md_var, "&", full_md_sym, ",\n ", NULL);
+ char *ms_def = CFCBindMeth_spec_def(method);
+ ms_defs = CFCUtil_cat(ms_defs, ms_def, NULL);
+ FREEMEM(ms_def);
+ const char *full_md_sym = CFCMethod_full_spec_sym(method);
+ ms_var = CFCUtil_cat(ms_var, "&", full_md_sym, ",\n ", NULL);
}
FREEMEM(offset_str);
}
// Close method metadata variable definition.
- md_var = CFCUtil_cat(md_var, "NULL\n};\n", NULL);
+ ms_var = CFCUtil_cat(ms_var, "NULL\n};\n", NULL);
const char pattern[] =
"#include \"%s\"\n"
@@ -355,14 +355,13 @@ CFCBindClass_to_c_data(CFCBindClass *sel
"\n"
"%s\n"
"\n"
- "/* Define the cfish_MethodMetaData objects which provide\n"
- " * introspection information and allow runtime overriding of\n"
- " * dynamic methods.\n"
+ "/* Define the cfish_MethodSpec structs used during VTable\n"
+ " * initialization.\n"
" */\n"
"\n"
"%s\n"
"\n"
- "/* Assemble all the cfish_MethodMetaData objects for this class.\n"
+ "/* Assemble all the cfish_MethodSpec structs for this class.\n"
" */\n"
"\n"
"%s\n"
@@ -381,20 +380,20 @@ CFCBindClass_to_c_data(CFCBindClass *sel
+ strlen(include_h)
+ strlen(offsets)
+ strlen(cb_funcs)
- + strlen(md_objects)
- + strlen(md_var)
+ + strlen(ms_defs)
+ + strlen(ms_var)
+ strlen(vt_var)
+ strlen(autocode)
+ 100;
char *code = (char*)MALLOCATE(size);
- sprintf(code, pattern, include_h, offsets, cb_funcs, md_objects, md_var,
+ sprintf(code, pattern, include_h, offsets, cb_funcs, ms_defs, ms_var,
vt_var, autocode);
FREEMEM(fresh_methods);
FREEMEM(offsets);
FREEMEM(cb_funcs);
- FREEMEM(md_objects);
- FREEMEM(md_var);
+ FREEMEM(ms_defs);
+ FREEMEM(ms_var);
return code;
}
@@ -470,14 +469,12 @@ CFCBindClass_to_vtable_init(CFCBindClass
: "NULL"; // No parent, e.g. Obj or inert classes.
char pattern[] =
- " cfish_VTable_init(\n"
+ " S_init_vtable(\n"
" %s, /* vtable */\n"
" %s, /* parent */\n"
" \"%s\", /* name */\n"
- " 0, /* flags */\n"
- " NULL, /* \"void *x\" member reserved for future use */\n"
" sizeof(%s), /* obj_alloc_size */\n"
- " %s /* method_meta */\n"
+ " %s /* method_specs */\n"
" );\n";
size_t size = sizeof(pattern)
@@ -485,11 +482,11 @@ CFCBindClass_to_vtable_init(CFCBindClass
+ strlen(parent_ref)
+ strlen(class_name)
+ strlen(struct_sym)
- + strlen(self->full_method_meta_var)
+ + strlen(self->method_specs_var)
+ 40;
char *code = (char*)MALLOCATE(size);
sprintf(code, pattern, vt_var, parent_ref, class_name, struct_sym,
- self->full_method_meta_var);
+ self->method_specs_var);
return code;
}
Modified: lucy/trunk/clownfish/src/CFCBindCore.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindCore.c?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindCore.c (original)
+++ lucy/trunk/clownfish/src/CFCBindCore.c Sat Jul 14 13:49:00 2012
@@ -212,13 +212,6 @@ S_write_parcel_h(CFCBindCore *self) {
" #define OVERRIDDEN CFISH_OVERRIDDEN\n"
"#endif\n"
"\n"
- "typedef struct cfish_MethodMetaData {\n"
- " const char *name;\n"
- " cfish_method_t func;\n"
- " cfish_method_t callback_func;\n"
- " size_t *offset;\n"
- "} cfish_MethodMetaData;\n"
- "\n"
"void\n"
"%sbootstrap_parcel();\n"
"\n"
@@ -344,8 +337,36 @@ S_write_parcel_c(CFCBindCore *self) {
"#include \"Lucy/Object/VTable.h\"\n"
"%s\n"
"\n"
+ "typedef struct cfish_MethodSpec {\n"
+ " int is_novel;\n"
+ " const char *name;\n"
+ " cfish_method_t func;\n"
+ " cfish_method_t callback_func;\n"
+ " size_t *offset;\n"
+ "} cfish_MethodSpec;\n"
+ "\n"
"%s\n"
"\n"
+ "static void\n"
+ "S_init_vtable(cfish_VTable *vtable, cfish_VTable *parent,\n"
+ " const char *name, size_t obj_alloc_size,\n"
+ " cfish_MethodSpec **method_specs) {\n"
+ " cfish_CharBuf *cb = cfish_CB_newf(\"%%s\", name);\n"
+ " cfish_VTable_init(vtable, parent, cb, 0, obj_alloc_size);\n"
+ " CFISH_DECREF(cb);\n"
+ " for (int i = 0; method_specs[i]; ++i) {\n"
+ " cfish_MethodSpec *spec = method_specs[i];\n"
+ " if (spec->is_novel) {\n"
+ " cb = cfish_CB_newf(\"%%s\", spec->name);\n"
+ " cfish_VTable_add_method(vtable, cb,\n"
+ " spec->callback_func,\n"
+ " *spec->offset);\n"
+ " CFISH_DECREF(cb);\n"
+ " }\n"
+ " cfish_VTable_override(vtable, spec->func, *spec->offset);\n"
+ " }\n"
+ "}\n"
+ "\n"
"void\n"
"%sbootstrap_parcel() {\n"
" /* Allocate memory for VTables.\n"
Modified: lucy/trunk/clownfish/src/CFCBindMethod.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindMethod.c?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindMethod.c (original)
+++ lucy/trunk/clownfish/src/CFCBindMethod.c Sat Jul 14 13:49:00 2012
@@ -227,14 +227,14 @@ CFCBindMeth_typedef_dec(struct CFCMethod
}
char*
-CFCBindMeth_method_meta_def(CFCMethod *method) {
- const char *full_md_sym = CFCMethod_full_method_meta_sym(method);
+CFCBindMeth_spec_def(CFCMethod *method) {
+ const char *full_ms_sym = CFCMethod_full_spec_sym(method);
const char *macro_sym = CFCMethod_get_macro_sym(method);
const char *impl_sym = CFCMethod_implementing_func_sym(method);
+ int is_novel = CFCMethod_novel(method);
const char *full_override_sym = "NULL";
- if ((CFCMethod_public(method) || CFCMethod_abstract(method))
- && CFCMethod_novel(method)) {
+ if ((CFCMethod_public(method) || CFCMethod_abstract(method)) && is_novel) {
full_override_sym = CFCMethod_full_override_sym(method);
}
@@ -243,21 +243,23 @@ CFCBindMeth_method_meta_def(CFCMethod *m
CFCMethod_full_offset_sym(method, NULL, full_offset_sym, offset_sym_size);
char pattern[] =
- "cfish_MethodMetaData %s = {\n"
+ "static cfish_MethodSpec %s = {\n"
+ " %d, /* is_novel */\n"
" \"%s\", /* name */\n"
" (cfish_method_t)%s, /* func */\n"
" (cfish_method_t)%s, /* callback_func */\n"
" &%s /* offset */\n"
"};\n";
size_t size = sizeof(pattern)
- + strlen(full_md_sym)
+ + strlen(full_ms_sym)
+ + 10 /* for is_novel */
+ strlen(macro_sym)
+ strlen(impl_sym)
+ strlen(full_override_sym)
+ strlen(full_offset_sym)
+ 30;
char *def = (char*)MALLOCATE(size);
- sprintf(def, pattern, full_md_sym, macro_sym, impl_sym,
+ sprintf(def, pattern, full_ms_sym, is_novel, macro_sym, impl_sym,
full_override_sym, full_offset_sym);
FREEMEM(full_offset_sym);
Modified: lucy/trunk/clownfish/src/CFCBindMethod.h
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindMethod.h?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindMethod.h (original)
+++ lucy/trunk/clownfish/src/CFCBindMethod.h Sat Jul 14 13:49:00 2012
@@ -44,11 +44,11 @@ CFCBindMeth_method_def(struct CFCMethod
char*
CFCBindMeth_typedef_dec(struct CFCMethod *method, struct CFCClass *klass);
-/** Return C code defining the MethodMetaData object for this method, which
- * stores introspection data and a pointer to the callback function.
+/** Return C code defining the MethodSpec object for this method, which
+ * is used during VTable initialization.
*/
char*
-CFCBindMeth_method_meta_def(struct CFCMethod *method);
+CFCBindMeth_spec_def(struct CFCMethod *method);
/** Return C code implementing a version of the method which throws an
* "abstract method" error at runtime, for methods which are declared as
Modified: lucy/trunk/clownfish/src/CFCMethod.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCMethod.c?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCMethod.c (original)
+++ lucy/trunk/clownfish/src/CFCMethod.c Sat Jul 14 13:49:00 2012
@@ -37,7 +37,7 @@
struct CFCMethod {
CFCFunction function;
char *macro_sym;
- char *full_method_meta_sym;
+ char *full_spec_sym;
char *full_override_sym;
int is_final;
int is_abstract;
@@ -130,9 +130,9 @@ CFCMethod_init(CFCMethod *self, CFCParce
// Derive more symbols.
const char *full_func_sym = CFCMethod_implementing_func_sym(self);
size_t amount = strlen(full_func_sym) + sizeof("_OVERRIDE") + 1;
- self->full_method_meta_sym = (char*)MALLOCATE(amount);
+ self->full_spec_sym = (char*)MALLOCATE(amount);
self->full_override_sym = (char*)MALLOCATE(amount);
- sprintf(self->full_method_meta_sym, "%s_META", full_func_sym);
+ sprintf(self->full_spec_sym, "%s_SPEC", full_func_sym);
sprintf(self->full_override_sym, "%s_OVERRIDE", full_func_sym);
// Assume that this method is novel until we discover when applying
@@ -145,7 +145,7 @@ CFCMethod_init(CFCMethod *self, CFCParce
void
CFCMethod_destroy(CFCMethod *self) {
FREEMEM(self->macro_sym);
- FREEMEM(self->full_method_meta_sym);
+ FREEMEM(self->full_spec_sym);
FREEMEM(self->full_override_sym);
CFCFunction_destroy((CFCFunction*)self);
}
@@ -319,8 +319,8 @@ CFCMethod_full_typedef(CFCMethod *self,
}
const char*
-CFCMethod_full_method_meta_sym(CFCMethod *self) {
- return self->full_method_meta_sym;
+CFCMethod_full_spec_sym(CFCMethod *self) {
+ return self->full_spec_sym;
}
const char*
Modified: lucy/trunk/clownfish/src/CFCMethod.h
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCMethod.h?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCMethod.h (original)
+++ lucy/trunk/clownfish/src/CFCMethod.h Sat Jul 14 13:49:00 2012
@@ -166,10 +166,10 @@ CFCMethod_full_typedef(CFCMethod *self,
size_t buf_size);
/** Returns the fully qualified name of the variable which stores the method's
- * introspection data, e.g. "crust_LobClaw_pinch_META".
+ * initialization data.
*/
const char*
-CFCMethod_full_method_meta_sym(CFCMethod *self);
+CFCMethod_full_spec_sym(CFCMethod *self);
/** Returns the fully qualified name of the function which implements the
* callback to the host in the event that a host method has been defined which
Modified: lucy/trunk/core/Lucy/Object/VTable.c
URL: http://svn.apache.org/viewvc/lucy/trunk/core/Lucy/Object/VTable.c?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/core/Lucy/Object/VTable.c (original)
+++ lucy/trunk/core/Lucy/Object/VTable.c Sat Jul 14 13:49:00 2012
@@ -53,14 +53,13 @@ VTable_allocate(size_t num_methods) {
}
VTable*
-VTable_init(VTable *self, VTable *parent, const char *name, int flags,
- void *x, size_t obj_alloc_size, void *method_meta) {
+VTable_init(VTable *self, VTable *parent, const CharBuf *name, int flags,
+ size_t obj_alloc_size) {
self->vtable = CFISH_VTABLE;
self->ref.count = 1;
self->parent = parent;
- self->name = CB_newf("%s", name);
+ self->name = CB_Clone(name);
self->flags = flags;
- self->x = x;
self->obj_alloc_size = obj_alloc_size;
self->methods = VA_new(0);
@@ -69,19 +68,13 @@ VTable_init(VTable *self, VTable *parent
- offsetof(cfish_VTable, method_ptrs);
memcpy(self->method_ptrs, parent->method_ptrs, parent_ptrs_size);
}
+}
- cfish_MethodMetaData **md_objs = (cfish_MethodMetaData**)method_meta;
- for (uint32_t i = 0; md_objs[i] != NULL; i++) {
- cfish_MethodMetaData *const md_obj = md_objs[i];
- VTable_override(self, md_obj->func, *md_obj->offset);
- CharBuf *method_name = CB_newf("%s", md_obj->name);
- Method *method = Method_new(method_name, md_obj->callback_func,
- *md_obj->offset);
- VA_Push(self->methods, (Obj*)method);
- DECREF(method_name);
- }
-
- return self;
+void
+VTable_add_method(VTable *self, const CharBuf *name,
+ lucy_method_t callback_func, size_t offset) {
+ Method *method = Method_new(name, callback_func, offset);
+ VA_Push(self->methods, (Obj*)method);
}
void
Modified: lucy/trunk/core/Lucy/Object/VTable.cfh
URL: http://svn.apache.org/viewvc/lucy/trunk/core/Lucy/Object/VTable.cfh?rev=1361545&r1=1361544&r2=1361545&view=diff
==============================================================================
--- lucy/trunk/core/Lucy/Object/VTable.cfh (original)
+++ lucy/trunk/core/Lucy/Object/VTable.cfh Sat Jul 14 13:49:00 2012
@@ -28,7 +28,6 @@ class Lucy::Object::VTable inherits Lucy
VTable *parent;
CharBuf *name;
uint32_t flags;
- void *x; /* Reserved for future expansion */
size_t obj_alloc_size;
size_t vt_alloc_size;
VArray *methods;
@@ -41,8 +40,12 @@ class Lucy::Object::VTable inherits Lucy
allocate(size_t num_methods);
inert VTable*
- init(VTable *self, VTable *parent, const char *name, int flags,
- void *x, size_t obj_alloc_size, void *method_meta);
+ init(VTable *self, VTable *parent, const CharBuf *name, int flags,
+ size_t obj_alloc_size);
+
+ inert void
+ add_method(VTable *self, const CharBuf *name, lucy_method_t callback_func,
+ size_t offset);
/** Return a singleton. If a VTable can be found in the registry based on
* the supplied class name, it will be returned. Otherwise, a new VTable