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 2013/06/01 22:48:51 UTC

[lucy-commits] [1/3] git commit: refs/heads/separate-clownfish-wip2 - Create C representations lazily

Updated Branches:
  refs/heads/separate-clownfish-wip2 393c79b3a -> 08f19a969


Create C representations lazily


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/39f8c208
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/39f8c208
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/39f8c208

Branch: refs/heads/separate-clownfish-wip2
Commit: 39f8c2082078c04738fd4055534d23568581986f
Parents: 393c79b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jun 1 21:55:12 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 1 21:55:12 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/perl/lib/Clownfish/CFC.pm |    4 +-
 clownfish/compiler/perl/lib/Clownfish/CFC.xs |    9 +-
 clownfish/compiler/perl/t/100-type.t         |    6 +-
 clownfish/compiler/src/CFCDumpable.c         |    3 -
 clownfish/compiler/src/CFCMethod.c           |   44 ++++----
 clownfish/compiler/src/CFCParamList.c        |    9 +-
 clownfish/compiler/src/CFCTestType.c         |   25 ++---
 clownfish/compiler/src/CFCType.c             |  126 +++++++++------------
 clownfish/compiler/src/CFCType.h             |   10 +--
 clownfish/compiler/src/CFCVariable.c         |   39 ++++---
 10 files changed, 120 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/perl/lib/Clownfish/CFC.pm
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/lib/Clownfish/CFC.pm b/clownfish/compiler/perl/lib/Clownfish/CFC.pm
index 8a7572f..b891516 100644
--- a/clownfish/compiler/perl/lib/Clownfish/CFC.pm
+++ b/clownfish/compiler/perl/lib/Clownfish/CFC.pm
@@ -431,7 +431,6 @@ BEGIN { XSLoader::load( 'Clownfish::CFC', '0.01' ) }
         specifier   => undef,
         indirection => undef,
         parcel      => undef,
-        c_string    => undef,
         void        => undef,
         object      => undef,
         primitive   => undef,
@@ -469,9 +468,8 @@ BEGIN { XSLoader::load( 'Clownfish::CFC', '0.01' ) }
 
         my $indirection = $args{indirection} || 0;
         my $specifier   = $args{specifier}   || '';
-        my $c_string    = $args{c_string}    || '';
 
-        return _new( $flags, $parcel, $specifier, $indirection, $c_string );
+        return _new( $flags, $parcel, $specifier, $indirection );
     }
 
     our %new_integer_PARAMS = (

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/lib/Clownfish/CFC.xs b/clownfish/compiler/perl/lib/Clownfish/CFC.xs
index 9c1b385..bddcce9 100644
--- a/clownfish/compiler/perl/lib/Clownfish/CFC.xs
+++ b/clownfish/compiler/perl/lib/Clownfish/CFC.xs
@@ -1386,15 +1386,13 @@ PPCODE:
 MODULE = Clownfish::CFC   PACKAGE = Clownfish::CFC::Model::Type
 
 SV*
-_new(flags, parcel, specifier, indirection, c_string)
+_new(flags, parcel, specifier, indirection)
     int flags;
     CFCParcel *parcel;
     const char *specifier;
     int indirection;
-    const char *c_string;
 CODE:
-    CFCType *self = CFCType_new(flags, parcel, specifier, indirection,
-                                c_string);
+    CFCType *self = CFCType_new(flags, parcel, specifier, indirection);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
@@ -1604,7 +1602,6 @@ ALIAS:
     get_specifier   = 2
     get_parcel      = 4
     get_indirection = 6
-    set_c_string    = 7
     to_c            = 8
     const           = 10
     set_nullable    = 11
@@ -1641,8 +1638,6 @@ PPCODE:
         case 6:
             retval = newSViv(CFCType_get_indirection(self));
             break;
-        case 7:
-            CFCType_set_c_string(self, SvPV_nolen(ST(1)));
         case 8: {
                 const char *c_string = CFCType_to_c(self);
                 retval = newSVpvn(c_string, strlen(c_string));

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/perl/t/100-type.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/100-type.t b/clownfish/compiler/perl/t/100-type.t
index 025c76a..a881883 100644
--- a/clownfish/compiler/perl/t/100-type.t
+++ b/clownfish/compiler/perl/t/100-type.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 11;
+use Test::More tests => 10;
 use Clownfish::CFC::Model::Parcel;
 
 my $neato_parcel = Clownfish::CFC::Model::Parcel->new( name => 'Neato' );
@@ -29,9 +29,7 @@ my $type = Clownfish::CFC::Model::Type->new(
 is( ${ $type->get_parcel },
     $$neato_parcel, "constructor changes parcel name to Parcel singleton" );
 
-is( $type->to_c, '', "to_c()" );
-$type->set_c_string("mytype_t");
-is( $type->to_c, "mytype_t", "set_c_string()" );
+is( $type->to_c, "mytype_t", "to_c()" );
 ok( !$type->const, "const() is off by default" );
 is( $type->get_specifier, "mytype_t", "get_specifier()" );
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/src/CFCDumpable.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCDumpable.c b/clownfish/compiler/src/CFCDumpable.c
index 150b363..c8bbf92 100644
--- a/clownfish/compiler/src/CFCDumpable.c
+++ b/clownfish/compiler/src/CFCDumpable.c
@@ -145,9 +145,6 @@ S_make_method_obj(CFCClass *klass, const char *method_name) {
     CFCMethod *method = CFCMethod_new(klass_parcel, "public", klass_name,
                                       klass_cnick, method_name, return_type,
                                       param_list, NULL, false, false);
-    // Hack
-    CFCClass *dummy_class = NULL;
-    CFCMethod_resolve_types(method, &dummy_class);
 
     CFCBase_decref((CFCBase*)param_list);
     CFCBase_decref((CFCBase*)self_type);

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMethod.c b/clownfish/compiler/src/CFCMethod.c
index f659323..2299e5a 100644
--- a/clownfish/compiler/src/CFCMethod.c
+++ b/clownfish/compiler/src/CFCMethod.c
@@ -105,6 +105,24 @@ CFCMethod_init(CFCMethod *self, CFCParcel *parcel, const char *exposure,
                      docucomment, false);
     FREEMEM(micro_sym);
 
+    // Verify that the first element in the arg list is a self.
+    CFCVariable **args = CFCParamList_get_variables(param_list);
+    if (!args[0]) { CFCUtil_die("Missing 'self' argument"); }
+    CFCType *type = CFCVariable_get_type(args[0]);
+    const char *specifier = CFCType_get_specifier(type);
+    const char *prefix    = CFCMethod_get_prefix(self);
+    const char *last_colon = strrchr(class_name, ':');
+    const char *struct_sym = last_colon ? last_colon + 1 : class_name;
+    if (strcmp(specifier, struct_sym) != 0) {
+        char *wanted = CFCUtil_sprintf("%s%s", prefix, struct_sym);
+        int mismatch = strcmp(wanted, specifier);
+        FREEMEM(wanted);
+        if (mismatch) {
+            CFCUtil_die("First arg type doesn't match class: '%s' '%s'",
+                        class_name, specifier);
+        }
+    }
+
     self->macro_sym     = CFCUtil_strdup(macro_sym);
     self->is_final      = is_final;
     self->is_abstract   = is_abstract;
@@ -121,27 +139,6 @@ CFCMethod_init(CFCMethod *self, CFCParcel *parcel, const char *exposure,
 void
 CFCMethod_resolve_types(CFCMethod *self, struct CFCClass **classes) {
     CFCFunction_resolve_types((CFCFunction*)self, classes);
-
-    // Verify that the first element in the arg list is a self.
-    CFCVariable **args = CFCParamList_get_variables(self->function.param_list);
-    if (!args[0]) { CFCUtil_die("Missing 'self' argument"); }
-    CFCType *type = CFCVariable_get_type(args[0]);
-    const char *specifier = CFCType_get_specifier(type);
-    const char *prefix    = CFCMethod_get_prefix(self);
-    const char *class_name = CFCMethod_get_class_name(self);
-    const char *last_colon = strrchr(class_name, ':');
-    const char *struct_sym = last_colon ? last_colon + 1 : class_name;
-    char *wanted = CFCUtil_sprintf("%s%s", prefix, struct_sym);
-    int mismatch = strcmp(wanted, specifier);
-    FREEMEM(wanted);
-    if (mismatch) {
-        CFCUtil_die("First arg type doesn't match class: '%s' '%s'",
-                    class_name, specifier);
-    }
-
-    // Derive more symbols.
-    const char *full_func_sym = CFCMethod_implementing_func_sym(self);
-    self->full_override_sym = CFCUtil_sprintf("%s_OVERRIDE", full_func_sym);
 }
 
 void
@@ -296,6 +293,11 @@ CFCMethod_full_typedef(CFCMethod *self, CFCClass *invoker) {
 
 const char*
 CFCMethod_full_override_sym(CFCMethod *self) {
+    if (!self->full_override_sym) {
+        const char *full_func_sym = CFCMethod_implementing_func_sym(self);
+        self->full_override_sym
+            = CFCUtil_sprintf("%s_OVERRIDE", full_func_sym);
+    }
     return self->full_override_sym;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/src/CFCParamList.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParamList.c b/clownfish/compiler/src/CFCParamList.c
index 2845480..087030c 100644
--- a/clownfish/compiler/src/CFCParamList.c
+++ b/clownfish/compiler/src/CFCParamList.c
@@ -55,8 +55,8 @@ CFCParamList_init(CFCParamList *self, int variadic) {
     self->num_vars  = 0;
     self->variables = (CFCVariable**)CALLOCATE(1, sizeof(void*));
     self->values    = (char**)CALLOCATE(1, sizeof(char*));
-    self->c_string  = CFCUtil_strdup("");
-    self->name_list = CFCUtil_strdup("");
+    self->c_string  = NULL;
+    self->name_list = NULL;
     return self;
 }
 
@@ -65,7 +65,6 @@ CFCParamList_resolve_types(CFCParamList *self, struct CFCClass **classes) {
     for (size_t i = 0; self->variables[i]; ++i) {
         CFCVariable_resolve_type(self->variables[i], classes);
     }
-    S_generate_c_strings(self);
 }
 
 void
@@ -115,8 +114,6 @@ S_generate_c_strings(CFCParamList *self) {
     if (self->num_vars == 0) {
         c_string_size += sizeof("void");
     }
-    FREEMEM(self->c_string);
-    FREEMEM(self->name_list);
     self->c_string  = (char*)MALLOCATE(c_string_size);
     self->name_list = (char*)MALLOCATE(name_list_size);
     self->c_string[0] = '\0';
@@ -169,11 +166,13 @@ CFCParamList_variadic(CFCParamList *self) {
 
 const char*
 CFCParamList_to_c(CFCParamList *self) {
+    if (!self->c_string) { S_generate_c_strings(self); }
     return self->c_string;
 }
 
 const char*
 CFCParamList_name_list(CFCParamList *self) {
+    if (!self->name_list) { S_generate_c_strings(self); }
     return self->name_list;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/src/CFCTestType.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestType.c b/clownfish/compiler/src/CFCTestType.c
index 9dc135f..d1d9b08 100644
--- a/clownfish/compiler/src/CFCTestType.c
+++ b/clownfish/compiler/src/CFCTestType.c
@@ -60,7 +60,7 @@ S_run_composite_tests(CFCTest *test);
 
 const CFCTestBatch CFCTEST_BATCH_TYPE = {
     "Clownfish::CFC::Model::Type",
-    361,
+    360,
     S_run_tests
 };
 
@@ -81,12 +81,10 @@ static void
 S_run_basic_tests(CFCTest *test) {
     CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, false);
     CFCParcel_register(neato_parcel);
-    CFCType *type = CFCType_new(0, neato_parcel, "mytype_t", 0, NULL);
+    CFCType *type = CFCType_new(0, neato_parcel, "mytype_t", 0);
 
     OK(test, CFCType_get_parcel(type) == neato_parcel, "get_parcel");
-    STR_EQ(test, CFCType_to_c(type), "", "to_c");
-    CFCType_set_c_string(type, "mytype_t");
-    STR_EQ(test, CFCType_to_c(type), "mytype_t", "set_c_string");
+    STR_EQ(test, CFCType_to_c(type), "mytype_t", "to_c");
     STR_EQ(test, CFCType_get_specifier(type), "mytype_t", "get_specifier");
 
 #define TEST_BOOL_ACCESSOR(type, name) \
@@ -115,27 +113,24 @@ S_run_basic_tests(CFCTest *test) {
 static void
 S_run_primitive_tests(CFCTest *test) {
     CFCParcel *parcel = CFCParcel_default_parcel();
-    CFCType *type = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0, NULL);
+    CFCType *type = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0);
     OK(test, CFCType_is_primitive(type), "is_primitive");
 
     {
-        CFCType *twin
-            = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0, NULL);
+        CFCType *twin = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0);
         OK(test, CFCType_equals(type, twin), "equals");
         CFCBase_decref((CFCBase*)twin);
     }
 
     {
-        CFCType *other
-            = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "dump_t", 0, NULL);
+        CFCType *other = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "dump_t", 0);
         OK(test, !CFCType_equals(type, other), "equals spoiled by specifier");
         CFCBase_decref((CFCBase*)other);
     }
 
     {
-        CFCType *other
-            = CFCType_new(CFCTYPE_PRIMITIVE|CFCTYPE_CONST, parcel, "hump_t", 0,
-                          NULL);
+        CFCType *other = CFCType_new(CFCTYPE_PRIMITIVE|CFCTYPE_CONST, parcel,
+                                     "hump_t", 0);
         OK(test, !CFCType_equals(type, other), "equals spoiled by const");
         CFCBase_decref((CFCBase*)other);
     }
@@ -234,7 +229,7 @@ S_run_void_tests(CFCTest *test) {
     CFCParser *parser = CFCParser_new();
 
     {
-        CFCType *type = CFCType_new_void(0);
+        CFCType *type = CFCType_new_void(false);
         STR_EQ(test, CFCType_get_specifier(type), "void", "get_specifier");
         STR_EQ(test, CFCType_to_c(type), "void", "to_c");
         OK(test, CFCType_is_void(type), "is_void");
@@ -242,7 +237,7 @@ S_run_void_tests(CFCTest *test) {
     }
 
     {
-        CFCType *type = CFCType_new_void(CFCTYPE_CONST);
+        CFCType *type = CFCType_new_void(true);
         STR_EQ(test, CFCType_to_c(type), "const void",
                "'const' in C representation");
         CFCBase_decref((CFCBase*)type);

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/src/CFCType.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCType.c b/clownfish/compiler/src/CFCType.c
index d0b68ec..73044e1 100644
--- a/clownfish/compiler/src/CFCType.c
+++ b/clownfish/compiler/src/CFCType.c
@@ -52,10 +52,9 @@ static const CFCMeta CFCTYPE_META = {
 
 CFCType*
 CFCType_new(int flags, struct CFCParcel *parcel, const char *specifier,
-            int indirection, const char *c_string) {
+            int indirection) {
     CFCType *self = (CFCType*)CFCBase_allocate(&CFCTYPE_META);
-    return CFCType_init(self, flags, parcel, specifier, indirection,
-                        c_string);
+    return CFCType_init(self, flags, parcel, specifier, indirection);
 }
 
 static void
@@ -84,12 +83,12 @@ S_check_flags(int supplied, int acceptable, const char *type_name) {
 
 CFCType*
 CFCType_init(CFCType *self, int flags, struct CFCParcel *parcel,
-             const char *specifier, int indirection, const char *c_string) {
+             const char *specifier, int indirection) {
     self->flags       = flags;
     self->parcel      = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
     self->specifier   = CFCUtil_strdup(specifier);
     self->indirection = indirection;
-    self->c_string    = c_string ? CFCUtil_strdup(c_string) : CFCUtil_strdup("");
+    self->c_string    = NULL;
     self->width       = 0;
     self->array       = NULL;
     self->child       = NULL;
@@ -127,22 +126,13 @@ CFCType_new_integer(int flags, const char *specifier) {
         CFCUtil_die("Unknown integer specifier: '%s'", specifier);
     }
 
-    // Cache the C representation of this type.
-    char c_string[32];
-    if (flags & CFCTYPE_CONST) {
-        sprintf(c_string, "const %s", specifier);
-    }
-    else {
-        strcpy(c_string, specifier);
-    }
-
     // Add flags.
     flags |= CFCTYPE_PRIMITIVE;
     flags |= CFCTYPE_INTEGER;
     S_check_flags(flags, CFCTYPE_CONST | CFCTYPE_PRIMITIVE | CFCTYPE_INTEGER,
                   "Integer");
 
-    CFCType *self = CFCType_new(flags, NULL, specifier, 0, c_string);
+    CFCType *self = CFCType_new(flags, NULL, specifier, 0);
     self->width = width;
     return self;
 }
@@ -165,21 +155,12 @@ CFCType_new_float(int flags, const char *specifier) {
         }
     }
 
-    // Cache the C representation of this type.
-    char c_string[32];
-    if (flags & CFCTYPE_CONST) {
-        sprintf(c_string, "const %s", specifier);
-    }
-    else {
-        strcpy(c_string, specifier);
-    }
-
     flags |= CFCTYPE_PRIMITIVE;
     flags |= CFCTYPE_FLOATING;
     S_check_flags(flags, CFCTYPE_CONST | CFCTYPE_PRIMITIVE | CFCTYPE_FLOATING,
                   "Floating");
 
-    return CFCType_new(flags, NULL, specifier, 0, c_string);
+    return CFCType_new(flags, NULL, specifier, 0);
 }
 
 #define MAX_SPECIFIER_LEN 256
@@ -246,11 +227,9 @@ CFCType_new_object(int flags, CFCParcel *parcel, const char *specifier,
                            | CFCTYPE_DECREMENTED;
     S_check_flags(flags, acceptable_flags, "Object");
 
-    return CFCType_new(flags, parcel, specifier, 1, NULL);
+    return CFCType_new(flags, parcel, specifier, 1);
 }
 
-#define MAX_COMPOSITE_LEN 256
-
 CFCType*
 CFCType_new_composite(int flags, CFCType *child, int indirection,
                       const char *array) {
@@ -261,7 +240,7 @@ CFCType_new_composite(int flags, CFCType *child, int indirection,
     S_check_flags(flags, CFCTYPE_COMPOSITE | CFCTYPE_NULLABLE, "Composite");
 
     CFCType *self = CFCType_new(flags, NULL, CFCType_get_specifier(child),
-                                indirection, NULL);
+                                indirection);
     self->child = (CFCType*)CFCBase_incref((CFCBase*)child);
 
     // Record array spec.
@@ -276,14 +255,13 @@ CFCType_new_composite(int flags, CFCType *child, int indirection,
 CFCType*
 CFCType_new_void(int is_const) {
     int flags = CFCTYPE_VOID;
-    const char *c_string = is_const ? "const void" : "void";
     if (is_const) { flags |= CFCTYPE_CONST; }
-    return CFCType_new(flags, NULL, "void", 0, c_string);
+    return CFCType_new(flags, NULL, "void", 0);
 }
 
 CFCType*
 CFCType_new_va_list(void) {
-    return CFCType_new(CFCTYPE_VA_LIST, NULL, "va_list", 0, "va_list");
+    return CFCType_new(CFCTYPE_VA_LIST, NULL, "va_list", 0);
 }
 
 CFCType*
@@ -295,30 +273,13 @@ CFCType_new_arbitrary(CFCParcel *parcel, const char *specifier) {
         }
     }
 
-    return CFCType_new(CFCTYPE_ARBITRARY, parcel, specifier, 0, specifier);
+    return CFCType_new(CFCTYPE_ARBITRARY, parcel, specifier, 0);
 }
 
 void
 CFCType_resolve(CFCType *self, CFCClass **classes) {
     if (CFCType_is_composite(self)) {
         CFCType_resolve(self->child, classes);
-
-        // Cache C representation.
-        // NOTE: Array postfixes are NOT included.
-        const char   *child_c_string = CFCType_to_c(self->child);
-        size_t        child_c_len    = strlen(child_c_string);
-        size_t        amount         = child_c_len + self->indirection;
-        if (amount > MAX_COMPOSITE_LEN) {
-            CFCUtil_die("C representation too long");
-        }
-        char c_string[MAX_COMPOSITE_LEN + 1];
-        strcpy(c_string, child_c_string);
-        for (int i = 0; i < self->indirection; i++) {
-            strncat(c_string, "*", 1);
-        }
-        FREEMEM(self->c_string);
-        self->c_string = CFCUtil_strdup(c_string);
-
         return;
     }
     if (!CFCType_is_object(self)) {
@@ -376,23 +337,6 @@ CFCType_resolve(CFCType *self, CFCClass **classes) {
         CFCParcel *class_parcel = CFCClass_get_parcel(klass);
         CFCParcel_add_dependent_parcel(self->parcel, class_parcel);
     }
-
-    // Cache C representation.
-    char c_string[MAX_SPECIFIER_LEN + 10];
-    if (CFCType_const(self)) {
-        sprintf(c_string, "const %s*", self->specifier);
-    }
-    else {
-        sprintf(c_string, "%s*", self->specifier);
-    }
-    FREEMEM(self->c_string);
-    self->c_string = CFCUtil_strdup(c_string);
-
-    // Cache name of VTable variable.
-    self->vtable_var = CFCUtil_strdup(self->specifier);
-    for (int i = 0; self->vtable_var[i] != 0; i++) {
-        self->vtable_var[i] = toupper(self->vtable_var[i]);
-    }
 }
 
 void
@@ -467,6 +411,12 @@ CFCType_get_specifier(CFCType *self) {
 
 const char*
 CFCType_get_vtable_var(CFCType *self) {
+    if (!self->vtable_var) {
+        self->vtable_var = CFCUtil_strdup(self->specifier);
+        for (int i = 0; self->vtable_var[i] != 0; i++) {
+            self->vtable_var[i] = toupper(self->vtable_var[i]);
+        }
+    }
     return self->vtable_var;
 }
 
@@ -480,15 +430,43 @@ CFCType_get_parcel(CFCType *self) {
     return self->parcel;
 }
 
-void
-CFCType_set_c_string(CFCType *self, const char *c_string) {
-    FREEMEM(self->c_string);
-    self->c_string = CFCUtil_strdup(c_string);
-}
-
 const char*
 CFCType_to_c(CFCType *self) {
-    return self->c_string;
+    char *c_string = self->c_string;
+
+    if (c_string) { return c_string; }
+
+    if (CFCType_is_composite(self)) {
+        // NOTE: Array postfixes are NOT included.
+        const char *child_c_string = CFCType_to_c(self->child);
+        size_t      child_c_len    = strlen(child_c_string);
+        size_t      amount         = child_c_len + self->indirection;
+        c_string = (char*)MALLOCATE(amount + 1);
+        strcpy(c_string, child_c_string);
+        for (int i = 0; i < self->indirection; i++) {
+            strncat(c_string, "*", 1);
+        }
+    }
+    else if (CFCType_is_object(self)) {
+        if (CFCType_const(self)) {
+            c_string = CFCUtil_sprintf("const %s*", self->specifier);
+        }
+        else {
+            c_string = CFCUtil_sprintf("%s*", self->specifier);
+        }
+    }
+    else {
+        if (CFCType_const(self)) {
+            c_string = CFCUtil_sprintf("const %s", self->specifier);
+        }
+        else {
+            c_string = CFCUtil_strdup(self->specifier);
+        }
+    }
+
+    self->c_string = c_string;
+
+    return c_string;
 }
 
 size_t

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/src/CFCType.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCType.h b/clownfish/compiler/src/CFCType.h
index 937ae94..fbf18e7 100644
--- a/clownfish/compiler/src/CFCType.h
+++ b/clownfish/compiler/src/CFCType.h
@@ -51,15 +51,14 @@ struct CFCParcel;
  * array subscripts.
  * @param indirection integer indicating level of indirection. Example: the C
  * type "float**" has a specifier of "float" and indirection 2.
- * @param c_string The C representation of the type.
  */
 CFCType*
 CFCType_new(int flags, struct CFCParcel *parcel, const char *specifier,
-            int indirection, const char *c_string);
+            int indirection);
 
 CFCType*
 CFCType_init(CFCType *self, int flags, struct CFCParcel *parcel,
-             const char *specifier, int indirection, const char *c_string);
+             const char *specifier, int indirection);
 
 /** Return a Type representing an integer primitive.
  *
@@ -214,11 +213,6 @@ CFCType_get_indirection(CFCType *self);
 struct CFCParcel*
 CFCType_get_parcel(CFCType *self);
 
-/** Set the C representation of the Type.
- */
-void
-CFCType_set_c_string(CFCType *self, const char *c_string);
-
 /** Return the C representation of the type.
  */
 const char*

http://git-wip-us.apache.org/repos/asf/lucy/blob/39f8c208/clownfish/compiler/src/CFCVariable.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCVariable.c b/clownfish/compiler/src/CFCVariable.c
index 54c2a17..4292e35 100644
--- a/clownfish/compiler/src/CFCVariable.c
+++ b/clownfish/compiler/src/CFCVariable.c
@@ -44,6 +44,9 @@ static const CFCMeta CFCVARIABLE_META = {
     (CFCBase_destroy_t)CFCVariable_destroy
 };
 
+static void
+S_generate_c_strings(CFCVariable *self);
+
 CFCVariable*
 CFCVariable_new(struct CFCParcel *parcel, const char *exposure,
                 const char *class_name, const char *class_cnick,
@@ -81,23 +84,9 @@ CFCVariable_init(CFCVariable *self, struct CFCParcel *parcel,
     return self;
 }
 
-// Cache various C string representations. Will be called after type has
-// been resolved.
 void
 CFCVariable_resolve_type(CFCVariable *self, struct CFCClass **classes) {
-    CFCType *type = self->type;
-    CFCType_resolve(type, classes);
-
-    const char *type_str = CFCType_to_c(type);
-    const char *postfix  = "";
-    if (CFCType_is_composite(type) && CFCType_get_array(type) != NULL) {
-        postfix = CFCType_get_array(type);
-    }
-    const char *micro_sym = CFCVariable_micro_sym(self);
-    self->local_c = CFCUtil_sprintf("%s %s%s", type_str, micro_sym, postfix);
-    self->local_dec = CFCUtil_sprintf("%s;", self->local_c);
-    const char *full_sym = CFCVariable_full_sym(self);
-    self->global_c = CFCUtil_sprintf("%s %s%s", type_str, full_sym, postfix);
+    CFCType_resolve(self->type, classes);
 }
 
 void
@@ -115,6 +104,23 @@ CFCVariable_equals(CFCVariable *self, CFCVariable *other) {
     return CFCSymbol_equals((CFCSymbol*)self, (CFCSymbol*)other);
 }
 
+// Cache various C string representations.
+static void
+S_generate_c_strings(CFCVariable *self) {
+    const char *type_str = CFCType_to_c(self->type);
+    const char *postfix  = "";
+    if (CFCType_is_composite(self->type)
+        && CFCType_get_array(self->type) != NULL
+       ) {
+        postfix = CFCType_get_array(self->type);
+    }
+    const char *micro_sym = CFCVariable_micro_sym(self);
+    self->local_c = CFCUtil_sprintf("%s %s%s", type_str, micro_sym, postfix);
+    self->local_dec = CFCUtil_sprintf("%s;", self->local_c);
+    const char *full_sym = CFCVariable_full_sym(self);
+    self->global_c = CFCUtil_sprintf("%s %s%s", type_str, full_sym, postfix);
+}
+
 CFCType*
 CFCVariable_get_type(CFCVariable *self) {
     return self->type;
@@ -127,16 +133,19 @@ CFCVariable_inert(CFCVariable *self) {
 
 const char*
 CFCVariable_local_c(CFCVariable *self) {
+    if (!self->local_c) { S_generate_c_strings(self); }
     return self->local_c;
 }
 
 const char*
 CFCVariable_global_c(CFCVariable *self) {
+    if (!self->global_c) { S_generate_c_strings(self); }
     return self->global_c;
 }
 
 const char*
 CFCVariable_local_declaration(CFCVariable *self) {
+    if (!self->local_dec) { S_generate_c_strings(self); }
     return self->local_dec;
 }
 


[lucy-commits] [3/3] git commit: refs/heads/separate-clownfish-wip2 - Don't allow variadic methods

Posted by nw...@apache.org.
Don't allow variadic methods


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/08f19a96
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/08f19a96
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/08f19a96

Branch: refs/heads/separate-clownfish-wip2
Commit: 08f19a969d5b3822c34d2d3c792063bb225d8052
Parents: dd2ac60
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jun 1 22:46:57 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 1 22:46:57 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindMethod.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/08f19a96/clownfish/compiler/src/CFCBindMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindMethod.c b/clownfish/compiler/src/CFCBindMethod.c
index 996192a..c2214a1 100644
--- a/clownfish/compiler/src/CFCBindMethod.c
+++ b/clownfish/compiler/src/CFCBindMethod.c
@@ -97,6 +97,9 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
 
     // Prepare parameter lists, minus invoker.  The invoker gets forced to
     // "self" later.
+    if (CFCParamList_variadic(param_list)) {
+        CFCUtil_die("Variadic methods not supported");
+    }
     const char *arg_names_minus_invoker = CFCParamList_name_list(param_list);
     const char *params_minus_invoker    = CFCParamList_to_c(param_list);
     while (*arg_names_minus_invoker && *arg_names_minus_invoker != ',') {


[lucy-commits] [2/3] git commit: refs/heads/separate-clownfish-wip2 - Revert variadic methods back to functions

Posted by nw...@apache.org.
Revert variadic methods back to functions

Variadic methods don't work.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/dd2ac608
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/dd2ac608
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/dd2ac608

Branch: refs/heads/separate-clownfish-wip2
Commit: dd2ac608fd8b6079fc412f220402e7313709f7d0
Parents: 39f8c20
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jun 1 22:45:33 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 1 22:45:33 2013 +0200

----------------------------------------------------------------------
 core/Clownfish/TestHarness/TestBatchRunner.c   |   10 ++--
 core/Clownfish/TestHarness/TestBatchRunner.cfh |   48 +++++++++---------
 core/Clownfish/TestHarness/TestFormatter.cfh   |   12 ++--
 3 files changed, 35 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/dd2ac608/core/Clownfish/TestHarness/TestBatchRunner.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/TestHarness/TestBatchRunner.c b/core/Clownfish/TestHarness/TestBatchRunner.c
index 2263d0d..b4a24be 100644
--- a/core/Clownfish/TestHarness/TestBatchRunner.c
+++ b/core/Clownfish/TestHarness/TestBatchRunner.c
@@ -86,12 +86,12 @@ TestBatchRunner_run_batch(TestBatchRunner *self, TestBatch *batch) {
     }
     if (self->num_failed > 0) {
         failed = true;
-        TestFormatter_Batch_Comment(self->formatter, "%d/%d tests failed.\n",
+        TestFormatter_batch_comment(self->formatter, "%d/%d tests failed.\n",
                                     self->num_failed, self->test_num);
     }
     if (self->test_num != self->num_planned) {
         failed = true;
-        TestFormatter_Batch_Comment(self->formatter,
+        TestFormatter_batch_comment(self->formatter,
                                     "Bad plan: You planned %d tests but ran"
                                     " %d.\n",
                                     self->num_planned, self->test_num);
@@ -228,7 +228,7 @@ TestBatchRunner_vtest_int_equals(TestBatchRunner *self, long got,
     bool pass = (got == expected);
     S_vtest_true(self, pass, pattern, args);
     if (!pass) {
-        TestFormatter_Test_Comment(self->formatter,
+        TestFormatter_test_comment(self->formatter,
                                    "Expected '%ld', got '%ld'.\n",
                                    expected, got);
     }
@@ -243,7 +243,7 @@ TestBatchRunner_vtest_float_equals(TestBatchRunner *self, double got,
     bool   pass           = (fabs(relative_error) < 1e-6);
     S_vtest_true(self, pass, pattern, args);
     if (!pass) {
-        TestFormatter_Test_Comment(self->formatter,
+        TestFormatter_test_comment(self->formatter,
                                    "Expected '%e', got '%e'.\n",
                                    expected, got);
     }
@@ -257,7 +257,7 @@ TestBatchRunner_vtest_string_equals(TestBatchRunner *self, const char *got,
     bool pass = (strcmp(got, expected) == 0);
     S_vtest_true(self, pass, pattern, args);
     if (!pass) {
-        TestFormatter_Test_Comment(self->formatter,
+        TestFormatter_test_comment(self->formatter,
                                    "Expected '%s', got '%s'.\n",
                                    expected, got);
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/dd2ac608/core/Clownfish/TestHarness/TestBatchRunner.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/TestHarness/TestBatchRunner.cfh b/core/Clownfish/TestHarness/TestBatchRunner.cfh
index ea993bb..cde51f7 100644
--- a/core/Clownfish/TestHarness/TestBatchRunner.cfh
+++ b/core/Clownfish/TestHarness/TestBatchRunner.cfh
@@ -60,33 +60,33 @@ class Clownfish::TestHarness::TestBatchRunner inherits Clownfish::Obj {
     uint32_t
     Get_Num_Failed(TestBatchRunner *self);
 
-    bool
-    Test_True(TestBatchRunner *self, bool condition, const char *pattern, ...);
+    inert bool
+    test_true(TestBatchRunner *self, bool condition, const char *pattern, ...);
 
-    bool
-    Test_False(TestBatchRunner *self, bool condition, const char *pattern,
+    inert bool
+    test_false(TestBatchRunner *self, bool condition, const char *pattern,
                ...);
 
-    bool
-    Test_Int_Equals(TestBatchRunner *self, long got, long expected,
+    inert bool
+    test_int_equals(TestBatchRunner *self, long got, long expected,
                     const char *pattern, ...);
 
-    bool
-    Test_Float_Equals(TestBatchRunner *self, double got, double expected,
+    inert bool
+    test_float_equals(TestBatchRunner *self, double got, double expected,
                       const char *pattern, ...);
 
-    bool
-    Test_String_Equals(TestBatchRunner *self, const char *got,
+    inert bool
+    test_string_equals(TestBatchRunner *self, const char *got,
                        const char *expected, const char *pattern, ...);
 
-    bool
-    Pass(TestBatchRunner *self, const char *pattern, ...);
+    inert bool
+    pass(TestBatchRunner *self, const char *pattern, ...);
 
-    bool
-    Fail(TestBatchRunner *self, const char *pattern, ...);
+    inert bool
+    fail(TestBatchRunner *self, const char *pattern, ...);
 
-    void
-    Skip(TestBatchRunner *self, const char *pattern, ...);
+    inert void
+    skip(TestBatchRunner *self, const char *pattern, ...);
 
     bool
     VTest_True(TestBatchRunner *self, bool condition, const char *pattern,
@@ -121,14 +121,14 @@ class Clownfish::TestHarness::TestBatchRunner inherits Clownfish::Obj {
 
 __C__
 #ifdef CFISH_USE_SHORT_NAMES
-  #define TEST_TRUE            Cfish_TestBatchRunner_Test_True
-  #define TEST_FALSE           Cfish_TestBatchRunner_Test_False
-  #define TEST_INT_EQ          Cfish_TestBatchRunner_Test_Int_Equals
-  #define TEST_FLOAT_EQ        Cfish_TestBatchRunner_Test_Float_Equals
-  #define TEST_STR_EQ          Cfish_TestBatchRunner_Test_String_Equals
-  #define PASS                 Cfish_TestBatchRunner_Pass
-  #define FAIL                 Cfish_TestBatchRunner_Fail
-  #define SKIP                 Cfish_TestBatchRunner_Skip
+  #define TEST_TRUE            cfish_TestBatchRunner_test_true
+  #define TEST_FALSE           cfish_TestBatchRunner_test_false
+  #define TEST_INT_EQ          cfish_TestBatchRunner_test_int_equals
+  #define TEST_FLOAT_EQ        cfish_TestBatchRunner_test_float_equals
+  #define TEST_STR_EQ          cfish_TestBatchRunner_test_string_equals
+  #define PASS                 cfish_TestBatchRunner_pass
+  #define FAIL                 cfish_TestBatchRunner_fail
+  #define SKIP                 cfish_TestBatchRunner_skip
 #endif
 __END_C__
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/dd2ac608/core/Clownfish/TestHarness/TestFormatter.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/TestHarness/TestFormatter.cfh b/core/Clownfish/TestHarness/TestFormatter.cfh
index d42c6fa..92ca911 100644
--- a/core/Clownfish/TestHarness/TestFormatter.cfh
+++ b/core/Clownfish/TestHarness/TestFormatter.cfh
@@ -22,15 +22,15 @@ abstract class Clownfish::TestHarness::TestFormatter inherits Clownfish::Obj {
     inert TestFormatter*
     init(TestFormatter *self);
 
-    void
-    Test_Result(TestFormatter *self, bool pass, uint32_t test_num,
+    inert void
+    test_result(TestFormatter *self, bool pass, uint32_t test_num,
                 const char *fmt, ...);
 
-    void
-    Test_Comment(TestFormatter *self, const char *fmt, ...);
+    inert void
+    test_comment(TestFormatter *self, const char *fmt, ...);
 
-    void
-    Batch_Comment(TestFormatter *self, const char *fmt, ...);
+    inert void
+    batch_comment(TestFormatter *self, const char *fmt, ...);
 
     /** Print output at the beginning of a test batch.
      *