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 2014/07/26 15:36:11 UTC
[1/3] git commit: Make sure that ivars typedef is a complete type
Repository: lucy-clownfish
Updated Branches:
refs/heads/ivars_fixes [created] d33f60130
Make sure that ivars typedef is a complete type
If all ancestors of an object are in the same parcel, use object struct
for ivars typedef.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/74cd3e0e
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/74cd3e0e
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/74cd3e0e
Branch: refs/heads/ivars_fixes
Commit: 74cd3e0e00deeabd617e4734fe42a87c70b0e871
Parents: 4e8f130
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Jul 25 18:00:49 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 26 15:33:59 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCBindClass.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/74cd3e0e/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c
index ebeb07d..3714d28 100644
--- a/compiler/src/CFCBindClass.c
+++ b/compiler/src/CFCBindClass.c
@@ -155,6 +155,22 @@ S_ivars_func(CFCBindClass *self) {
const char *short_struct = CFCClass_short_ivars_struct(client);
const char *full_offset = CFCClass_full_ivars_offset(client);
const char *PREFIX = CFCClass_get_PREFIX(client);
+ const char *ivars_or_not = NULL;
+
+ // Try to find first ancestor from a different parcel.
+ CFCParcel *parcel = CFCClass_get_parcel(client);
+ CFCClass *ancestor = CFCClass_get_parent(client);
+ while (ancestor && CFCClass_get_parcel(ancestor) == parcel) {
+ ancestor = CFCClass_get_parent(ancestor);
+ }
+ // Use full struct or ivars struct for typedef.
+ if (!ancestor) {
+ ivars_or_not = CFCClass_full_struct_sym(client);
+ }
+ else {
+ ivars_or_not = full_struct;
+ }
+
char pattern[] =
"extern size_t %s;\n"
"typedef struct %s %s;\n"
@@ -169,7 +185,7 @@ S_ivars_func(CFCBindClass *self) {
"#endif\n";
char *content = CFCUtil_sprintf(pattern,
full_offset,
- full_struct, full_struct,
+ ivars_or_not, full_struct,
full_struct,
full_func, full_type,
full_offset,
@@ -454,7 +470,6 @@ CFCBindClass_spec_def(CFCBindClass *self) {
CFCClass *parent = CFCClass_get_parent(client);
const char *class_name = CFCClass_get_class_name(client);
const char *class_var = CFCClass_full_class_var(client);
- const char *struct_sym = CFCClass_full_struct_sym(client);
const char *ivars_struct = CFCClass_full_ivars_struct(client);
const char *prefix = CFCClass_get_prefix(client);
@@ -502,8 +517,6 @@ CFCBindClass_spec_def(CFCBindClass *self) {
class_var)
: CFCUtil_strdup("NULL");
- const char *ivars_or_not = strcmp(prefix, "cfish_") == 0
- ? struct_sym : ivars_struct;
const char *ivars_offset_name = CFCClass_full_ivars_offset(client);
char pattern[] =
@@ -522,7 +535,7 @@ CFCBindClass_spec_def(CFCBindClass *self) {
" }";
char *code
= CFCUtil_sprintf(pattern, class_var, parent_ref, class_name,
- ivars_or_not, ivars_offset_name, num_novel,
+ ivars_struct, ivars_offset_name, num_novel,
num_overridden, num_inherited, novel_ms_var,
overridden_ms_var, inherited_ms_var);
[3/3] git commit: Include OBJ_HEAD only when needed
Posted by nw...@apache.org.
Include OBJ_HEAD only when needed
If there's an ancestor from a different parcel, the OBJ_HEAD is already
part of that parcel's ivars struct.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d33f6013
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d33f6013
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d33f6013
Branch: refs/heads/ivars_fixes
Commit: d33f601308c2cf750e8f4caa134c1fbd807dd55e
Parents: 6e1e407
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Jul 25 18:27:00 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 26 15:34:52 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCBindClass.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d33f6013/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c
index b767f19..4b24629 100644
--- a/compiler/src/CFCBindClass.c
+++ b/compiler/src/CFCBindClass.c
@@ -423,6 +423,7 @@ CFCBindClass_to_c_data(CFCBindClass *self) {
static char*
S_struct_definition(CFCBindClass *self) {
CFCClass *const client = self->client;
+ char *member_decs = CFCUtil_strdup("");
const char *struct_sym = NULL;
// Try to find first ancestor from a different parcel.
@@ -436,6 +437,8 @@ S_struct_definition(CFCBindClass *self) {
if (!ancestor) {
// All ancestors are in the same parcel. Populate full struct sym.
struct_sym = CFCClass_full_struct_sym(client);
+ // Add object head.
+ member_decs = CFCUtil_cat(member_decs, " CFISH_OBJ_HEAD\n", NULL);
}
else {
// There's an ancestor from a different parcel. Populate ivars struct.
@@ -447,16 +450,16 @@ S_struct_definition(CFCBindClass *self) {
// Add all member variables declared by classes in this package.
CFCVariable **member_vars = CFCClass_member_vars(client);
- char *member_decs = CFCUtil_strdup("");
for (int i = num_non_package_members; member_vars[i] != NULL; i++) {
const char *member_dec = CFCVariable_local_declaration(member_vars[i]);
- size_t needed = strlen(member_decs) + strlen(member_dec) + 10;
- member_decs = (char*)REALLOCATE(member_decs, needed);
- strcat(member_decs, "\n ");
- strcat(member_decs, member_dec);
+ member_decs
+ = CFCUtil_cat(member_decs, " ", member_dec, "\n", NULL);
}
- char pattern[] = "struct %s {\n CFISH_OBJ_HEAD%s\n};\n";
+ char pattern[] =
+ "struct %s {\n"
+ "%s"
+ "};\n";
char *struct_def = CFCUtil_sprintf(pattern, struct_sym, member_decs);
FREEMEM(member_decs);
[2/3] git commit: Generalize object struct optimization
Posted by nw...@apache.org.
Generalize object struct optimization
Populate object struct for objects if all ancestors are in the same
parcel. No more special casing of the cfish parcel.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/6e1e407e
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/6e1e407e
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/6e1e407e
Branch: refs/heads/ivars_fixes
Commit: 6e1e407e8216c8096de168da01e983d921026e27
Parents: 74cd3e0
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Jul 25 18:25:29 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 26 15:34:30 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCBindClass.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6e1e407e/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c
index 3714d28..b767f19 100644
--- a/compiler/src/CFCBindClass.c
+++ b/compiler/src/CFCBindClass.c
@@ -422,25 +422,26 @@ CFCBindClass_to_c_data(CFCBindClass *self) {
// Create the definition for the instantiable object struct.
static char*
S_struct_definition(CFCBindClass *self) {
- CFCClass *const client = self->client;
- const char *struct_sym;
- const char *prefix = CFCClass_get_prefix(client);
- if (strcmp(prefix, "cfish_") == 0) {
- struct_sym = CFCClass_full_struct_sym(client);
- }
- else {
- struct_sym = CFCClass_full_ivars_struct(client);
- }
+ CFCClass *const client = self->client;
+ const char *struct_sym = NULL;
- // Count the number of member variables declared in ancestor classes
- // outside this package so that we can skip over them.
- int num_non_package_members = 0;
+ // Try to find first ancestor from a different parcel.
CFCParcel *parcel = CFCClass_get_parcel(client);
CFCClass *ancestor = CFCClass_get_parent(client);
while (ancestor && CFCClass_get_parcel(ancestor) == parcel) {
ancestor = CFCClass_get_parent(ancestor);
}
- if (ancestor) {
+
+ int num_non_package_members = 0;
+ if (!ancestor) {
+ // All ancestors are in the same parcel. Populate full struct sym.
+ struct_sym = CFCClass_full_struct_sym(client);
+ }
+ else {
+ // There's an ancestor from a different parcel. Populate ivars struct.
+ struct_sym = CFCClass_full_ivars_struct(client);
+ // Count the number of member variables declared in ancestor classes
+ // outside this package so that we can skip over them.
num_non_package_members = CFCClass_num_member_vars(ancestor);
}