lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [2/3] git commit: refs/heads/perl-method-bindings - Generate default constructor XSub for every class
Date Mon, 29 Jul 2013 12:58:45 GMT
Generate default constructor XSub for every class


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

Branch: refs/heads/perl-method-bindings
Commit: 1a0b43808a3e08a6436ee2f0864cb0ac21099d7d
Parents: f24927d
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Jul 29 14:14:57 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Jul 29 14:43:10 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/perl/lib/Clownfish/CFC.xs |  7 +--
 clownfish/compiler/src/CFCPerl.c             | 18 +++----
 clownfish/compiler/src/CFCPerlClass.c        | 64 ++++++++++++++---------
 clownfish/compiler/src/CFCPerlClass.h        |  2 +-
 4 files changed, 49 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/1a0b4380/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 9faba1f..eda22dc 100644
--- a/clownfish/compiler/perl/lib/Clownfish/CFC.xs
+++ b/clownfish/compiler/perl/lib/Clownfish/CFC.xs
@@ -2296,10 +2296,11 @@ CODE:
 OUTPUT: RETVAL
 
 SV*
-constructor_bindings(self)
-    CFCPerlClass *self;
+constructor_bindings(unused, klass)
+    SV *unused;
+    CFCClass *klass;
 CODE:
-    CFCPerlConstructor **bound = CFCPerlClass_constructor_bindings(self);
+    CFCPerlConstructor **bound = CFCPerlClass_constructor_bindings(klass);
     RETVAL = S_array_of_cfcbase_to_av((CFCBase**)bound);
     FREEMEM(bound);
 OUTPUT: RETVAL

http://git-wip-us.apache.org/repos/asf/lucy/blob/1a0b4380/clownfish/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerl.c b/clownfish/compiler/src/CFCPerl.c
index a1b961d..6612cd1 100644
--- a/clownfish/compiler/src/CFCPerl.c
+++ b/clownfish/compiler/src/CFCPerl.c
@@ -416,14 +416,13 @@ CFCPerl_write_bindings(CFCPerl *self) {
     }
     generated_xs = CFCUtil_cat(generated_xs, "\n", NULL);
 
-    // Constructors.
-    for (size_t i = 0; registry[i] != NULL; i++) {
-        CFCPerlClass *class_binding = registry[i];
-        CFCClass *client = CFCPerlClass_get_client(class_binding);
-        if (!client) { continue; }
+    for (size_t i = 0; ordered[i] != NULL; i++) {
+        CFCClass *klass = ordered[i];
+        if (CFCClass_included(klass)) { continue; }
 
+        // Constructors.
         CFCPerlConstructor **constructors
-            = CFCPerlClass_constructor_bindings(class_binding);
+            = CFCPerlClass_constructor_bindings(klass);
         for (size_t j = 0; constructors[j] != NULL; j++) {
             CFCPerlSub *xsub = (CFCPerlSub*)constructors[j];
 
@@ -437,13 +436,8 @@ CFCPerl_write_bindings(CFCPerl *self) {
             xs_init = S_add_xs_init(xs_init, xsub);
         }
         FREEMEM(constructors);
-    }
-
-    // Methods.
-    for (size_t i = 0; ordered[i] != NULL; i++) {
-        CFCClass *klass = ordered[i];
-        if (CFCClass_included(klass)) { continue; }
 
+        // Methods.
         CFCPerlMethod **methods = CFCPerlClass_method_bindings(klass);
         for (size_t j = 0; methods[j] != NULL; j++) {
             CFCPerlSub *xsub = (CFCPerlSub*)methods[j];

http://git-wip-us.apache.org/repos/asf/lucy/blob/1a0b4380/clownfish/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerlClass.c b/clownfish/compiler/src/CFCPerlClass.c
index e239fff..f90d5fa 100644
--- a/clownfish/compiler/src/CFCPerlClass.c
+++ b/clownfish/compiler/src/CFCPerlClass.c
@@ -311,10 +311,11 @@ CFCPerlClass_method_bindings(CFCClass *klass) {
 static const char NEW[] = "new";
 
 CFCPerlConstructor**
-CFCPerlClass_constructor_bindings(CFCPerlClass *self) {
-    CFCClass     *client    = self->client;
-    CFCFunction **functions = CFCClass_functions(self->client);
-    size_t        num_bound = 0;
+CFCPerlClass_constructor_bindings(CFCClass *klass) {
+    const char    *class_name = CFCClass_get_class_name(klass);
+    CFCPerlClass  *perl_class = CFCPerlClass_singleton(class_name);
+    CFCFunction  **functions  = CFCClass_functions(klass);
+    size_t         num_bound  = 0;
     CFCPerlConstructor **bound 
         = (CFCPerlConstructor**)CALLOCATE(1, sizeof(CFCPerlConstructor*));
 
@@ -327,31 +328,42 @@ CFCPerlClass_constructor_bindings(CFCPerlClass *self) {
         const char   *alias       = NULL;
 
         // Find user-specified alias.
-        for (size_t j = 0; j < self->num_cons; j++) {
-            if (strcmp(micro_sym, self->cons_inits[j]) == 0) {
-                alias = self->cons_aliases[j];
-                if (!S_can_be_bound(param_list, return_type)) {
-                    CFCUtil_die("Can't bind %s as %s -- types can't be mapped",
-                                micro_sym, alias);
-                }
-                break;
+        if (perl_class == NULL) {
+            // Bind init() to new() when possible.
+            if (strcmp(micro_sym, "init") == 0
+                && S_can_be_bound(param_list, return_type)
+               ) {
+                alias = NEW;
             }
         }
-
-        // Automatically bind init() to new() when possible.
-        if (!alias
-            && !self->exclude_cons
-            && strcmp(micro_sym, "init") == 0
-            && S_can_be_bound(param_list, return_type)
-           ) {
-            int saw_new = 0;
-            for (size_t j = 0; j < self->num_cons; j++) {
-                if (strcmp(self->cons_aliases[j], "new") == 0) {
-                    saw_new = 1;
+        else {
+            for (size_t j = 0; j < perl_class->num_cons; j++) {
+                if (strcmp(micro_sym, perl_class->cons_inits[j]) == 0) {
+                    alias = perl_class->cons_aliases[j];
+                    if (!S_can_be_bound(param_list, return_type)) {
+                        CFCUtil_die("Can't bind %s as %s"
+                                    " -- types can't be mapped",
+                                    micro_sym, alias);
+                    }
+                    break;
                 }
             }
-            if (!saw_new) {
-                alias = NEW;
+
+            // Automatically bind init() to new() when possible.
+            if (!alias
+                && !perl_class->exclude_cons
+                && strcmp(micro_sym, "init") == 0
+                && S_can_be_bound(param_list, return_type)
+               ) {
+                int saw_new = 0;
+                for (size_t j = 0; j < perl_class->num_cons; j++) {
+                    if (strcmp(perl_class->cons_aliases[j], "new") == 0) {
+                        saw_new = 1;
+                    }
+                }
+                if (!saw_new) {
+                    alias = NEW;
+                }
             }
         }
 
@@ -361,7 +373,7 @@ CFCPerlClass_constructor_bindings(CFCPerlClass *self) {
 
         // Create the binding, add it to the array.
         CFCPerlConstructor *cons_binding
-            = CFCPerlConstructor_new(client, alias, micro_sym);
+            = CFCPerlConstructor_new(klass, alias, micro_sym);
         size_t size = (num_bound + 2) * sizeof(CFCPerlConstructor*);
         bound = (CFCPerlConstructor**)REALLOCATE(bound, size);
         bound[num_bound] = cons_binding;

http://git-wip-us.apache.org/repos/asf/lucy/blob/1a0b4380/clownfish/compiler/src/CFCPerlClass.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerlClass.h b/clownfish/compiler/src/CFCPerlClass.h
index 88a73c6..7051b82 100644
--- a/clownfish/compiler/src/CFCPerlClass.h
+++ b/clownfish/compiler/src/CFCPerlClass.h
@@ -109,7 +109,7 @@ CFCPerlClass_method_bindings(struct CFCClass *klass);
  * representing all bound constructors.
  */
 struct CFCPerlConstructor**
-CFCPerlClass_constructor_bindings(CFCPerlClass *self);
+CFCPerlClass_constructor_bindings(struct CFCClass *klass);
 
 /** Auto-generate POD according to the spec supplied via set_pod_spec().  If
  * no spec was supplied, return NULL.


Mime
View raw message