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/15 20:45:12 UTC

[lucy-commits] [1/6] git commit: refs/heads/separate-clownfish-wip4 - Remove exclude_method from BBSortEx bindings

Updated Branches:
  refs/heads/separate-clownfish-wip4 c00d65836 -> 730c114a4


Remove exclude_method from BBSortEx bindings

exclude_method only works for novel methods. The BBSortEx methods were
excluded anyway, because they worked on void pointers.


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

Branch: refs/heads/separate-clownfish-wip4
Commit: fb3bd32937c9536e9f00ac77454bee0cc07eb93f
Parents: 26ab0c9
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jun 15 20:18:52 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 15 20:39:29 2013 +0200

----------------------------------------------------------------------
 perl/buildlib/Lucy/Build/Binding/Misc.pm | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/fb3bd329/perl/buildlib/Lucy/Build/Binding/Misc.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Misc.pm b/perl/buildlib/Lucy/Build/Binding/Misc.pm
index 02fcf76..2e6e0e7 100644
--- a/perl/buildlib/Lucy/Build/Binding/Misc.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Misc.pm
@@ -242,7 +242,6 @@ END_XS_CODE
         parcel     => "TestLucy",
         class_name => "Lucy::Test::Util::BBSortEx",
     );
-    $binding->exclude_method($_) for @hand_rolled;
     $binding->append_xs($xs_code);
 
     Clownfish::CFC::Binding::Perl::Class->register($binding);


[lucy-commits] [4/6] git commit: refs/heads/separate-clownfish-wip4 - Use host aliases and excludes from other parcels

Posted by nw...@apache.org.
Use host aliases and excludes from other parcels

If a method is defined in a different parcel, find the novel method in
that parcel and use its host aliases and excludes.


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

Branch: refs/heads/separate-clownfish-wip4
Commit: a44bd3267a6830923642b3eb9f1c26ad33489422
Parents: b2d5dce
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jun 15 20:30:26 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 15 20:39:30 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCPerlClass.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/a44bd326/clownfish/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerlClass.c b/clownfish/compiler/src/CFCPerlClass.c
index f11b7d9..05dc585 100644
--- a/clownfish/compiler/src/CFCPerlClass.c
+++ b/clownfish/compiler/src/CFCPerlClass.c
@@ -256,21 +256,30 @@ CFCPerlClass_method_bindings(CFCPerlClass *self) {
     for (size_t i = 0; fresh_methods[i] != NULL; i++) {
         CFCMethod  *method    = fresh_methods[i];
         const char *meth_name = CFCMethod_get_macro_sym(method);
+        CFCMethod  *novel_method;
 
         // Only deal with methods when they are novel (i.e. first declared)
         // or the parent's definition is from an included parcel (i.e. they
         // are first declared in this parcel).
-        if (!CFCMethod_novel(method)) {
+        if (CFCMethod_novel(method)) {
+            novel_method = method;
+        }
+        else {
             CFCMethod *parent_method = CFCClass_method(parent, meth_name);
             CFCParcel *parcel = CFCMethod_get_parcel(parent_method);
             if (!CFCParcel_included(parcel)) { continue; }
+
+            novel_method = CFCClass_find_novel_method(parent, meth_name);
+            if (!novel_method) {
+                CFCUtil_die("Novel method not found");
+            }
         }
 
         // Skip private methods.
         if (CFCSymbol_private((CFCSymbol*)method)) { continue; }
 
         // Skip methods which have been explicitly excluded.
-        if (CFCMethod_excluded_from_host(method)) {
+        if (CFCMethod_excluded_from_host(novel_method)) {
             continue;
         }
 
@@ -282,7 +291,7 @@ CFCPerlClass_method_bindings(CFCPerlClass *self) {
         }
 
         // See if the user wants the method to have a specific alias.
-        const char *alias = CFCMethod_get_host_alias(method);
+        const char *alias = CFCMethod_get_host_alias(novel_method);
         if (!alias) {
             alias = CFCMethod_micro_sym(method);
         }


[lucy-commits] [6/6] git commit: refs/heads/separate-clownfish-wip4 - Move host method aliases and excludes to CFCMethod

Posted by nw...@apache.org.
Move host method aliases and excludes to CFCMethod

Host method aliases and excludes will be needed for included classes
without CFCPerlClass objects.


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

Branch: refs/heads/separate-clownfish-wip4
Commit: 10c599b40d60be6294945675d0b659a222d4cb99
Parents: fb3bd32
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Jun 12 21:04:57 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 15 20:39:30 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/perl/lib/Clownfish/CFC.xs | 36 +++++++++--
 clownfish/compiler/src/CFCMethod.c           | 49 ++++++++++++--
 clownfish/compiler/src/CFCMethod.h           | 12 ++++
 clownfish/compiler/src/CFCPerlClass.c        | 78 +++++++++--------------
 clownfish/compiler/src/CFCTestMethod.c       | 27 +++++++-
 5 files changed, 144 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/10c599b4/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 01aaf3e..1b36124 100644
--- a/clownfish/compiler/perl/lib/Clownfish/CFC.xs
+++ b/clownfish/compiler/perl/lib/Clownfish/CFC.xs
@@ -927,6 +927,12 @@ PPCODE:
     CFCMethod_resolve_types(self, classes);
     FREEMEM(classes);
 
+void
+exclude_from_host(self)
+    CFCMethod *self;
+PPCODE:
+    CFCMethod_exclude_from_host(self);
+
 SV*
 _various_method_syms(self, invoker)
     CFCMethod *self;
@@ -965,12 +971,15 @@ void
 _set_or_get(self, ...)
     CFCMethod *self;
 ALIAS:
-    get_macro_sym     = 2
-    full_override_sym = 10
-    abstract          = 12
-    novel             = 14
-    final             = 16
-    self_type         = 18
+    get_macro_sym      = 2
+    full_override_sym  = 10
+    abstract           = 12
+    novel              = 14
+    final              = 16
+    self_type          = 18
+    set_host_alias     = 19
+    get_host_alias     = 20
+    excluded_from_host = 22
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -998,6 +1007,21 @@ PPCODE:
                 retval = S_cfcbase_to_perlref(type);
             }
             break;
+        case 19: {
+                const char *value = SvOK(ST(1)) ? SvPVutf8_nolen(ST(1)) : NULL;
+                CFCMethod_set_host_alias(self, value);
+            }
+            break;
+        case 20: {
+                const char *value = CFCMethod_get_host_alias(self);
+                if (value) {
+                    retval = newSVpvn(value, strlen(value));
+                }
+            }
+            break;
+        case 22:
+            retval = newSViv(CFCMethod_excluded_from_host(self));
+            break;
     END_SET_OR_GET_SWITCH
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/10c599b4/clownfish/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMethod.c b/clownfish/compiler/src/CFCMethod.c
index 2299e5a..595cab7 100644
--- a/clownfish/compiler/src/CFCMethod.c
+++ b/clownfish/compiler/src/CFCMethod.c
@@ -38,9 +38,11 @@ struct CFCMethod {
     CFCFunction function;
     char *macro_sym;
     char *full_override_sym;
+    char *host_alias;
     int is_final;
     int is_abstract;
     int is_novel;
+    int is_excluded;
 };
 
 static const CFCMeta CFCMETHOD_META = {
@@ -123,11 +125,12 @@ CFCMethod_init(CFCMethod *self, CFCParcel *parcel, const char *exposure,
         }
     }
 
-    self->macro_sym     = CFCUtil_strdup(macro_sym);
-    self->is_final      = is_final;
-    self->is_abstract   = is_abstract;
-
+    self->macro_sym         = CFCUtil_strdup(macro_sym);
     self->full_override_sym = NULL;
+    self->host_alias        = NULL;
+    self->is_final          = is_final;
+    self->is_abstract       = is_abstract;
+    self->is_excluded       = false;
 
     // Assume that this method is novel until we discover when applying
     // inheritance that it overrides another.
@@ -145,6 +148,7 @@ void
 CFCMethod_destroy(CFCMethod *self) {
     FREEMEM(self->macro_sym);
     FREEMEM(self->full_override_sym);
+    FREEMEM(self->host_alias);
     CFCFunction_destroy((CFCFunction*)self);
 }
 
@@ -228,6 +232,43 @@ CFCMethod_finalize(CFCMethod *self) {
     return finalized;
 }
 
+void
+CFCMethod_set_host_alias(CFCMethod *self, const char *alias) {
+    if (!alias || !alias[0]) {
+        CFCUtil_die("Missing required param 'alias'");
+    }
+    if (!self->is_novel) {
+        CFCUtil_die("Can't set_host_alias %s -- method %s not novel in %s",
+                    alias, self->macro_sym, CFCMethod_get_class_name(self));
+    }
+    if (self->host_alias) {
+        if (strcmp(self->host_alias, alias) == 0) { return; }
+        CFCUtil_die("Can't set_host_alias %s -- already set to %s for method"
+                    " %s in %s", alias, self->host_alias, self->macro_sym,
+                    CFCMethod_get_class_name(self));
+    }
+    self->host_alias = CFCUtil_strdup(alias);
+}
+
+const char*
+CFCMethod_get_host_alias(CFCMethod *self) {
+    return self->host_alias;
+}
+
+void
+CFCMethod_exclude_from_host(CFCMethod *self) {
+    if (!self->is_novel) {
+        CFCUtil_die("Can't exclude_from_host -- method %s not novel in %s",
+                    self->macro_sym, CFCMethod_get_class_name(self));
+    }
+    self->is_excluded = true;
+}
+
+int
+CFCMethod_excluded_from_host(CFCMethod *self) {
+    return self->is_excluded;
+}
+
 static char*
 S_short_method_sym(CFCMethod *self, CFCClass *invoker, const char *postfix) {
     const char *cnick;

http://git-wip-us.apache.org/repos/asf/lucy/blob/10c599b4/clownfish/compiler/src/CFCMethod.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMethod.h b/clownfish/compiler/src/CFCMethod.h
index cdceb6a..2835d55 100644
--- a/clownfish/compiler/src/CFCMethod.h
+++ b/clownfish/compiler/src/CFCMethod.h
@@ -188,6 +188,18 @@ CFCMethod_novel(CFCMethod *self);
 struct CFCType*
 CFCMethod_self_type(CFCMethod *self);
 
+void
+CFCMethod_set_host_alias(CFCMethod *self, const char *alias);
+
+const char*
+CFCMethod_get_host_alias(CFCMethod *self);
+
+void
+CFCMethod_exclude_from_host(CFCMethod *self);
+
+int
+CFCMethod_excluded_from_host(CFCMethod *self);
+
 struct CFCParcel*
 CFCMethod_get_parcel(CFCMethod *self);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/10c599b4/clownfish/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerlClass.c b/clownfish/compiler/src/CFCPerlClass.c
index 9c29429..c676fb2 100644
--- a/clownfish/compiler/src/CFCPerlClass.c
+++ b/clownfish/compiler/src/CFCPerlClass.c
@@ -43,11 +43,6 @@ struct CFCPerlClass {
     CFCClass *client;
     char *xs_code;
     CFCPerlPod *pod_spec;
-    char **meth_aliases;
-    char **meth_names;
-    size_t num_methods;
-    char **excluded;
-    size_t num_excluded;
     char **cons_aliases;
     char **cons_inits;
     size_t num_cons;
@@ -83,11 +78,6 @@ CFCPerlClass_init(CFCPerlClass *self, CFCParcel *parcel,
     self->client = CFCClass_fetch_singleton(parcel, class_name); 
     self->pod_spec          = NULL;
     self->xs_code           = NULL;
-    self->meth_aliases      = NULL;
-    self->meth_names        = NULL;
-    self->num_methods       = 0;
-    self->excluded          = NULL;
-    self->num_excluded      = 0;
     self->cons_aliases      = NULL;
     self->cons_inits        = NULL;
     self->num_cons          = 0;
@@ -104,16 +94,6 @@ CFCPerlClass_destroy(CFCPerlClass *self) {
     CFCBase_decref((CFCBase*)self->pod_spec);
     FREEMEM(self->class_name);
     FREEMEM(self->xs_code);
-    for (size_t i = 0; i < self->num_methods; i++) {
-        FREEMEM(self->meth_aliases[i]);
-        FREEMEM(self->meth_names[i]);
-    }
-    FREEMEM(self->meth_aliases);
-    FREEMEM(self->meth_names);
-    for (size_t i = 0; i < self->num_excluded; i++) {
-        FREEMEM(self->excluded[i]);
-    }
-    FREEMEM(self->excluded);
     for (size_t i = 0; i < self->num_cons; i++) {
         FREEMEM(self->cons_aliases[i]);
         FREEMEM(self->cons_inits[i]);
@@ -185,25 +165,39 @@ CFCPerlClass_clear_registry(void) {
 
 void
 CFCPerlClass_bind_method(CFCPerlClass *self, const char *alias,
-                         const char *method) {
-    size_t size = (self->num_methods + 1) * sizeof(char*);
-    self->meth_aliases = (char**)REALLOCATE(self->meth_aliases, size);
-    self->meth_names   = (char**)REALLOCATE(self->meth_names,   size);
-    self->meth_aliases[self->num_methods] = (char*)CFCUtil_strdup(alias);
-    self->meth_names[self->num_methods]   = (char*)CFCUtil_strdup(method);
-    self->num_methods++;
+                         const char *meth_name) {
     if (!self->client) {
         CFCUtil_die("Can't bind_method %s -- can't find client for %s",
                     alias, self->class_name);
     }
+    CFCMethod *method = CFCClass_method(self->client, meth_name);
+    if (!method) {
+        CFCUtil_die("Can't bind_method %s -- can't find method %s in %s",
+                    alias, meth_name, self->class_name);
+    }
+    if (strcmp(CFCMethod_get_class_name(method), self->class_name) != 0) {
+        CFCUtil_die("Can't bind_method %s -- method %s not fresh in %s",
+                    alias, meth_name, self->class_name);
+    }
+    CFCMethod_set_host_alias(method, alias);
 }
 
 void
-CFCPerlClass_exclude_method(CFCPerlClass *self, const char *method) {
-    size_t size = (self->num_excluded + 1) * sizeof(char*);
-    self->excluded = (char**)REALLOCATE(self->excluded, size);
-    self->excluded[self->num_excluded] = (char*)CFCUtil_strdup(method);
-    self->num_excluded++;
+CFCPerlClass_exclude_method(CFCPerlClass *self, const char *meth_name) {
+    if (!self->client) {
+        CFCUtil_die("Can't exclude_method %s -- can't find client for %s",
+                    meth_name, self->class_name);
+    }
+    CFCMethod *method = CFCClass_method(self->client, meth_name);
+    if (!method) {
+        CFCUtil_die("Can't exclude_method %s -- method not found in %s",
+                    meth_name, self->class_name);
+    }
+    if (strcmp(CFCMethod_get_class_name(method), self->class_name) != 0) {
+        CFCUtil_die("Can't exclude_method %s -- method not fresh in %s",
+                    meth_name, self->class_name);
+    }
+    CFCMethod_exclude_from_host(method);
 }
 
 void
@@ -261,7 +255,6 @@ CFCPerlClass_method_bindings(CFCPerlClass *self) {
      // Iterate over the class's fresh methods.
     for (size_t i = 0; fresh_methods[i] != NULL; i++) {
         CFCMethod  *method    = fresh_methods[i];
-        const char *alias     = CFCMethod_micro_sym(method);
         const char *meth_name = CFCMethod_get_macro_sym(method);
 
         // Only deal with methods when they are novel (i.e. first declared)
@@ -277,14 +270,9 @@ CFCPerlClass_method_bindings(CFCPerlClass *self) {
         if (CFCSymbol_private((CFCSymbol*)method)) { continue; }
 
         // Skip methods which have been explicitly excluded.
-        int is_excluded = 0;
-        for (size_t j = 0; j < self->num_excluded; j++) {
-            if (strcmp(self->excluded[j], meth_name) == 0) {
-                is_excluded = 1;
-                break;
-            }
+        if (CFCMethod_excluded_from_host(method)) {
+            continue;
         }
-        if (is_excluded) { continue; }
 
         // Skip methods with types which cannot be mapped automatically.
         CFCParamList *param_list  = CFCMethod_get_param_list(method);
@@ -294,13 +282,9 @@ CFCPerlClass_method_bindings(CFCPerlClass *self) {
         }
 
         // See if the user wants the method to have a specific alias.
-        for (size_t j = 0; j < self->num_methods; j++) {
-            const char *maybe = self->meth_names[j];
-            if (strcmp(maybe, meth_name) == 0) {
-                if (self->meth_aliases[j]) {
-                    alias = self->meth_aliases[j];
-                }
-            }
+        const char *alias = CFCMethod_get_host_alias(method);
+        if (!alias) {
+            alias = CFCMethod_micro_sym(method);
         }
 
         /* Create an XSub binding for each override.  Each of these directly

http://git-wip-us.apache.org/repos/asf/lucy/blob/10c599b4/clownfish/compiler/src/CFCTestMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestMethod.c b/clownfish/compiler/src/CFCTestMethod.c
index a805228..cde5d7e 100644
--- a/clownfish/compiler/src/CFCTestMethod.c
+++ b/clownfish/compiler/src/CFCTestMethod.c
@@ -42,7 +42,7 @@ S_run_final_tests(CFCTest *test);
 
 const CFCTestBatch CFCTEST_BATCH_METHOD = {
     "Clownfish::CFC::Model::Method",
-    70,
+    74,
     S_run_tests
 };
 
@@ -140,6 +140,31 @@ S_run_basic_tests(CFCTest *test) {
         CFCBase_decref((CFCBase*)self_differs);
     }
 
+    {
+        CFCMethod *aliased
+            = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
+                            "Aliased", return_type, param_list,
+                            NULL, 0, 0);
+        OK(test, !CFCMethod_get_host_alias(aliased),
+           "no host alias by default");
+        CFCMethod_set_host_alias(aliased, "Host_Alias");
+        STR_EQ(test, CFCMethod_get_host_alias(aliased), "Host_Alias",
+               "set/get host alias");
+        CFCBase_decref((CFCBase*)aliased);
+    }
+
+    {
+        CFCMethod *excluded
+            = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
+                            "Excluded", return_type, param_list,
+                            NULL, 0, 0);
+        OK(test, !CFCMethod_excluded_from_host(excluded),
+           "not excluded by default");
+        CFCMethod_exclude_from_host(excluded);
+        OK(test, CFCMethod_excluded_from_host(excluded), "exclude from host");
+        CFCBase_decref((CFCBase*)excluded);
+    }
+
     CFCBase_decref((CFCBase*)parser);
     CFCBase_decref((CFCBase*)neato_parcel);
     CFCBase_decref((CFCBase*)return_type);


[lucy-commits] [5/6] git commit: refs/heads/separate-clownfish-wip4 - Inherit metadata for Perl bindings from other parcels

Posted by nw...@apache.org.
Inherit metadata for Perl bindings from other parcels


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

Branch: refs/heads/separate-clownfish-wip4
Commit: 730c114a462f821a571c7d1b65ee3ab5092d88e6
Parents: a44bd32
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jun 15 19:27:11 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 15 20:39:30 2013 +0200

----------------------------------------------------------------------
 .../perl/lib/Clownfish/CFC/Perl/Build.pm        |  2 +-
 perl/buildlib/Lucy/Build.pm                     | 15 +++-------
 perl/buildlib/Lucy/Build/Binding/Misc.pm        | 30 +++++++++++++++++++-
 3 files changed, 34 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/730c114a/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm b/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
index 0243aad..8316c8e 100644
--- a/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
+++ b/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
@@ -240,7 +240,7 @@ sub _compile_clownfish {
         my $package_name = $pm_filepath;
         $package_name =~ s/buildlib\/(.*)\.pm$/$1/;
         $package_name =~ s/\//::/g;
-        $package_name->bind_all;
+        $package_name->bind_all($hierarchy);
     }
 
     my $binding = Clownfish::CFC::Binding::Perl->new(

http://git-wip-us.apache.org/repos/asf/lucy/blob/730c114a/perl/buildlib/Lucy/Build.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build.pm b/perl/buildlib/Lucy/Build.pm
index 97016ed..b7dfa29 100644
--- a/perl/buildlib/Lucy/Build.pm
+++ b/perl/buildlib/Lucy/Build.pm
@@ -20,6 +20,10 @@ use lib '../clownfish/compiler/perl/blib/arch';
 use lib '../clownfish/compiler/perl/blib/lib';
 use lib 'clownfish/compiler/perl/blib/arch';
 use lib 'clownfish/compiler/perl/blib/lib';
+use lib '../clownfish/runtime/perl/blib/arch';
+use lib '../clownfish/runtime/perl/blib/lib';
+use lib 'clownfish/runtime/perl/blib/arch';
+use lib 'clownfish/runtime/perl/blib/lib';
 
 package Lucy::Build;
 
@@ -166,17 +170,6 @@ sub ACTION_clownfish {
     $self->SUPER::ACTION_clownfish;
 }
 
-sub ACTION_test {
-    my $self = shift;
-
-    # Add blib dirs of Clownfish runtime to @INC
-    local @INC = @INC;
-    push( @INC, catdir( $CFR_DIR, qw( blib lib ) ) );
-    push( @INC, catdir( $CFR_DIR, qw( blib arch ) ) );
-
-    $self->SUPER::ACTION_test;
-}
-
 sub ACTION_suppressions {
     my $self       = shift;
     my $LOCAL_SUPP = 'local.supp';

http://git-wip-us.apache.org/repos/asf/lucy/blob/730c114a/perl/buildlib/Lucy/Build/Binding/Misc.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Misc.pm b/perl/buildlib/Lucy/Build/Binding/Misc.pm
index 2e6e0e7..3a779c0 100644
--- a/perl/buildlib/Lucy/Build/Binding/Misc.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Misc.pm
@@ -20,13 +20,41 @@ our $VERSION = '0.003000';
 $VERSION = eval $VERSION;
 
 sub bind_all {
-    my $class = shift;
+    my ($class, $hierarchy) = @_;
+    $class->inherit_metadata($hierarchy);
     $class->bind_lucy;
     $class->bind_test;
     $class->bind_testschema;
     $class->bind_bbsortex;
 }
 
+sub inherit_metadata {
+    my ($class, $hierarchy) = @_;
+
+    require Clownfish;
+
+    for my $class (@{ $hierarchy->ordered_classes }) {
+        next if $class->get_parcel->get_name ne 'Clownfish' || $class->inert;
+
+        my $class_name = $class->get_class_name;
+        my $vtable     = Clownfish::VTable->fetch_vtable($class_name);
+
+        for my $rt_method (@{ $vtable->get_methods }) {
+            if ($rt_method->is_excluded_from_host) {
+                my $method = $class->method($rt_method->get_name);
+                $method->exclude_from_host;
+            }
+            else {
+                my $alias = $rt_method->get_host_alias;
+                if (defined($alias)) {
+                    my $method = $class->method($rt_method->get_name);
+                    $method->set_host_alias($alias);
+                }
+            }
+        }
+    }
+}
+
 sub bind_lucy {
     my $xs_code = <<'END_XS_CODE';
 MODULE = Lucy    PACKAGE = Lucy


[lucy-commits] [2/6] git commit: refs/heads/separate-clownfish-wip4 - Add method aliases and excludes to runtime metadata

Posted by nw...@apache.org.
Add method aliases and excludes to runtime metadata

Also add a new method VTable_Get_Methods and Perl bindings for
Clownfish::Method and VTable_fetch_vtable.


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

Branch: refs/heads/separate-clownfish-wip4
Commit: 26ab0c9a1dbc84b6045f0083e1caab998e457eb9
Parents: c00d658
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Jun 12 21:21:31 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 15 20:39:29 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/Method.c       | 17 ++++++++
 clownfish/runtime/core/Clownfish/Method.cfh     | 11 +++++
 clownfish/runtime/core/Clownfish/VTable.c       | 46 ++++++++++++++++++++
 clownfish/runtime/core/Clownfish/VTable.cfh     | 10 +++++
 .../perl/buildlib/Clownfish/Build/Binding.pm    | 25 +++++++++++
 5 files changed, 109 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/26ab0c9a/clownfish/runtime/core/Clownfish/Method.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Method.c b/clownfish/runtime/core/Clownfish/Method.c
index 235226a..dafd60f 100644
--- a/clownfish/runtime/core/Clownfish/Method.c
+++ b/clownfish/runtime/core/Clownfish/Method.c
@@ -33,8 +33,10 @@ Method*
 Method_init(Method *self, const CharBuf *name, cfish_method_t callback_func,
             size_t offset) {
     self->name          = CB_Clone(name);
+    self->host_alias    = NULL;
     self->callback_func = callback_func;
     self->offset        = offset;
+    self->is_excluded   = false;
     return self;
 }
 
@@ -61,4 +63,19 @@ Method_get_refcount(Method *self) {
     return 1;
 }
 
+CharBuf*
+Method_get_name(Method *self) {
+    return self->name;
+}
+
+CharBuf*
+Method_get_host_alias(Method *self) {
+    return self->host_alias;
+}
+
+bool
+Method_is_excluded_from_host(Method *self) {
+    return self->is_excluded;
+}
+
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/26ab0c9a/clownfish/runtime/core/Clownfish/Method.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Method.cfh b/clownfish/runtime/core/Clownfish/Method.cfh
index 5cac0b2..9bd32e2 100644
--- a/clownfish/runtime/core/Clownfish/Method.cfh
+++ b/clownfish/runtime/core/Clownfish/Method.cfh
@@ -22,8 +22,10 @@ parcel Clownfish;
 class Clownfish::Method inherits Clownfish::Obj {
 
     CharBuf        *name;
+    CharBuf        *host_alias;
     cfish_method_t  callback_func;
     size_t          offset;
+    bool            is_excluded;
 
     inert Method*
     new(const CharBuf *name, cfish_method_t callback_func, size_t offset);
@@ -32,6 +34,15 @@ class Clownfish::Method inherits Clownfish::Obj {
     init(Method *self, const CharBuf *name, cfish_method_t callback_func,
          size_t offset);
 
+    CharBuf*
+    Get_Name(Method *self);
+
+    nullable CharBuf*
+    Get_Host_Alias(Method *self);
+
+    bool
+    Is_Excluded_From_Host(Method *self);
+
     incremented Obj*
     Inc_RefCount(Method *self);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/26ab0c9a/clownfish/runtime/core/Clownfish/VTable.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/VTable.c b/clownfish/runtime/core/Clownfish/VTable.c
index 8743d15..f278527 100644
--- a/clownfish/runtime/core/Clownfish/VTable.c
+++ b/clownfish/runtime/core/Clownfish/VTable.c
@@ -21,6 +21,8 @@
 #define CFISH_USE_SHORT_NAMES
 #define CHY_USE_SHORT_NAMES
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 
@@ -41,6 +43,9 @@ size_t VTable_offset_of_parent = offsetof(VTable, parent);
 static void
 S_scrunch_charbuf(CharBuf *source, CharBuf *target);
 
+static Method*
+S_find_method(VTable *self, const char *meth_name);
+
 LockFreeRegistry *VTable_registry = NULL;
 
 void
@@ -187,6 +192,11 @@ VTable_get_obj_alloc_size(VTable *self) {
     return self->obj_alloc_size;
 }
 
+VArray*
+VTable_get_methods(VTable *self) {
+    return self->methods;
+}
+
 void
 VTable_init_registry() {
     LockFreeRegistry *reg = LFReg_new(256);
@@ -346,4 +356,40 @@ VTable_fetch_vtable(const CharBuf *class_name) {
     return vtable;
 }
 
+void
+VTable_add_host_method_alias(VTable *self, const char *alias,
+                             const char *meth_name) {
+    Method *method = S_find_method(self, meth_name);
+    if (!method) {
+        fprintf(stderr, "Method %s not found\n", meth_name);
+        abort();
+    }
+    method->host_alias = CB_newf("%s", alias);
+}
+
+void
+VTable_exclude_host_method(VTable *self, const char *meth_name) {
+    Method *method = S_find_method(self, meth_name);
+    if (!method) {
+        fprintf(stderr, "Method %s not found\n", meth_name);
+        abort();
+    }
+    method->is_excluded = true;
+}
+
+static Method*
+S_find_method(VTable *self, const char *name) {
+    size_t   name_len = strlen(name);
+    uint32_t size     = VA_Get_Size(self->methods);
+
+    for (uint32_t i = 0; i < size; i++) {
+        Method *method = (Method*)VA_Fetch(self->methods, i);
+        if (CB_Equals_Str(method->name, name, name_len)) {
+            return method;
+        }
+    }
+
+    return NULL;
+}
+
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/26ab0c9a/clownfish/runtime/core/Clownfish/VTable.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/VTable.cfh b/clownfish/runtime/core/Clownfish/VTable.cfh
index 1325fd4..3c19d37 100644
--- a/clownfish/runtime/core/Clownfish/VTable.cfh
+++ b/clownfish/runtime/core/Clownfish/VTable.cfh
@@ -118,6 +118,13 @@ class Clownfish::VTable inherits Clownfish::Obj {
     Obj*
     Foster_Obj(VTable *self, void *host_obj);
 
+    void
+    Add_Host_Method_Alias(VTable *self, const char *alias,
+                          const char *meth_name);
+
+    void
+    Exclude_Host_Method(VTable *self, const char *meth_name);
+
     CharBuf*
     Get_Name(VTable *self);
 
@@ -127,6 +134,9 @@ class Clownfish::VTable inherits Clownfish::Obj {
     size_t
     Get_Obj_Alloc_Size(VTable *self);
 
+    VArray*
+    Get_Methods(VTable *self);
+
     public incremented VTable*
     Clone(VTable *self);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/26ab0c9a/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index 88847fc..66fa118 100644
--- a/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -33,6 +33,7 @@ sub bind_all {
     $class->bind_obj;
     $class->bind_varray;
     $class->bind_vtable;
+    $class->bind_method;
     $class->bind_stringhelper;
 }
 
@@ -599,6 +600,22 @@ CODE:
 OUTPUT: RETVAL
 
 SV*
+fetch_vtable(unused_sv, class_name_sv)
+    SV *unused_sv;
+    SV *class_name_sv;
+CODE:
+{
+    CHY_UNUSED_VAR(unused_sv);
+    STRLEN size;
+    char *ptr = SvPVutf8(class_name_sv, size);
+    cfish_ZombieCharBuf *class_name = CFISH_ZCB_WRAP_STR(ptr, size);
+    cfish_VTable *vtable
+        = cfish_VTable_fetch_vtable((cfish_CharBuf*)class_name);
+    RETVAL = vtable ? (SV*)Cfish_VTable_To_Host(vtable) : &PL_sv_undef;
+}
+OUTPUT: RETVAL
+
+SV*
 singleton(unused_sv, ...)
     SV *unused_sv;
 CODE:
@@ -640,6 +657,14 @@ END_XS_CODE
     Clownfish::CFC::Binding::Perl::Class->register($binding);
 }
 
+sub bind_method {
+    my $binding = Clownfish::CFC::Binding::Perl::Class->new(
+        parcel     => "Clownfish",
+        class_name => "Clownfish::Method",
+    );
+    Clownfish::CFC::Binding::Perl::Class->register($binding);
+}
+
 sub bind_stringhelper {
     my $xs_code = <<'END_XS_CODE';
 MODULE = Clownfish   PACKAGE = Clownfish::Util::StringHelper


[lucy-commits] [3/6] git commit: refs/heads/separate-clownfish-wip4 - Generate code to initialize runtime method metadata

Posted by nw...@apache.org.
Generate code to initialize runtime method metadata


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

Branch: refs/heads/separate-clownfish-wip4
Commit: b2d5dce6b49b525623ff3a582763234a970bf631
Parents: 10c599b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Jun 12 23:38:39 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jun 15 20:39:30 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCPerl.c      |  5 +++++
 clownfish/compiler/src/CFCPerlClass.c | 29 +++++++++++++++++++++++++++++
 clownfish/compiler/src/CFCPerlClass.h |  5 +++++
 3 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b2d5dce6/clownfish/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerl.c b/clownfish/compiler/src/CFCPerl.c
index 13dd0ee..d1d0dad 100644
--- a/clownfish/compiler/src/CFCPerl.c
+++ b/clownfish/compiler/src/CFCPerl.c
@@ -249,6 +249,11 @@ S_write_boot_c(CFCPerl *self) {
                 FREEMEM(alias_adds);
                 alias_adds = new_alias_adds;
             }
+
+            char *metadata_code
+                = CFCPerlClass_method_metadata_code(class_binding);
+            alias_adds = CFCUtil_cat(alias_adds, metadata_code, NULL);
+            FREEMEM(metadata_code);
         }
 
         CFCClass *parent = CFCClass_get_parent(klass);

http://git-wip-us.apache.org/repos/asf/lucy/blob/b2d5dce6/clownfish/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerlClass.c b/clownfish/compiler/src/CFCPerlClass.c
index c676fb2..f11b7d9 100644
--- a/clownfish/compiler/src/CFCPerlClass.c
+++ b/clownfish/compiler/src/CFCPerlClass.c
@@ -546,3 +546,32 @@ CFCPerlClass_get_class_aliases(CFCPerlClass *self) {
     return (const char **)self->class_aliases;
 }
 
+// Generate C code which initializes method metadata.
+char*
+CFCPerlClass_method_metadata_code(CFCPerlClass *self) {
+    const char *vtable_var = CFCClass_full_vtable_var(self->client);
+    CFCMethod **fresh_methods = CFCClass_fresh_methods(self->client);
+    char *code = CFCUtil_strdup("");
+
+    for (int i = 0; fresh_methods[i] != NULL; i++) {
+        CFCMethod *method = fresh_methods[i];
+        if (!CFCMethod_novel(method)) { continue; }
+
+        const char *macro_sym = CFCMethod_get_macro_sym(method);
+        const char *alias     = CFCMethod_get_host_alias(method);
+        if (alias) {
+            code = CFCUtil_cat(code, "    Cfish_VTable_Add_Host_Method_Alias(",
+                               vtable_var, ", \"", alias, "\", \"", macro_sym,
+                               "\");\n", NULL);
+        }
+        if (CFCMethod_excluded_from_host(method)) {
+            code = CFCUtil_cat(code, "    Cfish_VTable_Exclude_Host_Method(",
+                               vtable_var, ", \"", macro_sym, "\");\n", NULL);
+        }
+    }
+
+    FREEMEM(fresh_methods);
+    return code;
+}
+
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/b2d5dce6/clownfish/compiler/src/CFCPerlClass.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerlClass.h b/clownfish/compiler/src/CFCPerlClass.h
index d5fdda7..89fd1fe 100644
--- a/clownfish/compiler/src/CFCPerlClass.h
+++ b/clownfish/compiler/src/CFCPerlClass.h
@@ -162,6 +162,11 @@ CFCPerlClass_add_class_alias(CFCPerlClass *self, const char *alias);
 const char**
 CFCPerlClass_get_class_aliases(CFCPerlClass *self);
 
+/** Return C code which initializes method metadata.
+ */
+char*
+CFCPerlClass_method_metadata_code(CFCPerlClass *self);
+
 #ifdef __cplusplus
 }
 #endif