You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2012/01/14 03:08:56 UTC

[lucy-commits] svn commit: r1231434 - in /incubator/lucy/trunk/clownfish/src: CFCBindClass.c CFCClass.c CFCClass.h

Author: marvin
Date: Sat Jan 14 02:08:56 2012
New Revision: 1231434

URL: http://svn.apache.org/viewvc?rev=1231434&view=rev
Log:
Don't generate redundant callback support.

CFC generates routines and metadata which support calling back to the host
from C.  Callback code generated off of novel CFCMethods is functionally
equivalent to the callback code generated off of overrider CFCMethods --
therefore, limit generation to novel methods, shrinking the compiled size of
parcel.c by about 15-20%.

Modified:
    incubator/lucy/trunk/clownfish/src/CFCBindClass.c
    incubator/lucy/trunk/clownfish/src/CFCClass.c
    incubator/lucy/trunk/clownfish/src/CFCClass.h

Modified: incubator/lucy/trunk/clownfish/src/CFCBindClass.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindClass.c?rev=1231434&r1=1231433&r2=1231434&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindClass.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCBindClass.c Sat Jan 14 02:08:56 2012
@@ -349,8 +349,7 @@ CFCBindClass_to_c(CFCBindClass *self) {
         // Define callbacks for methods that can be overridden via the
         // host.
         if (CFCMethod_public(method) || CFCMethod_abstract(method)) {
-            const char *full_cb_sym = CFCMethod_full_callback_sym(method);
-            if (method_is_fresh) {
+            if (method_is_fresh && CFCMethod_novel(method)) {
                 char *cb_def = CFCBindMeth_callback_def(method);
                 char *cb_obj_def
                     = CFCBindMeth_callback_obj_def(method, offset_str);
@@ -359,6 +358,10 @@ CFCBindClass_to_c(CFCBindClass *self) {
                 FREEMEM(cb_def);
                 FREEMEM(cb_obj_def);
             }
+            CFCMethod *novel
+                = CFCClass_find_novel_method(client,
+                                             CFCMethod_micro_sym(method));
+            const char *full_cb_sym = CFCMethod_full_callback_sym(novel);
             cb_var = CFCUtil_cat(cb_var, "&", full_cb_sym, ",\n    ", NULL);
         }
 

Modified: incubator/lucy/trunk/clownfish/src/CFCClass.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCClass.c?rev=1231434&r1=1231433&r2=1231434&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCClass.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCClass.c Sat Jan 14 02:08:56 2012
@@ -671,6 +671,21 @@ CFCClass_fresh_member_vars(CFCClass *sel
     return (CFCVariable**)S_fresh_syms(self, (CFCSymbol**)self->member_vars);
 }
 
+CFCMethod*
+CFCClass_find_novel_method(CFCClass *self, const char *sym) {
+    if (!self->tree_grown) {
+        CFCUtil_die("Can't call original_method before grow_tree");
+    }
+    CFCClass *ancestor = self;
+    do {
+        CFCMethod *method = CFCClass_method(ancestor, sym);
+        if (method && CFCMethod_novel(method)) {
+            return method;
+        }
+    } while (NULL != (ancestor = CFCClass_get_parent(ancestor)));
+    return NULL;
+}
+
 CFCClass**
 CFCClass_children(CFCClass *self) {
     return self->children;

Modified: incubator/lucy/trunk/clownfish/src/CFCClass.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCClass.h?rev=1231434&r1=1231433&r2=1231434&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCClass.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCClass.h Sat Jan 14 02:08:56 2012
@@ -141,6 +141,12 @@ CFCClass_method(CFCClass *self, const ch
 struct CFCMethod*
 CFCClass_fresh_method(CFCClass *self, const char *sym);
 
+/** Traverse all ancestors to find the first class which declared the method
+ * and return it.  Cannot be called before grow_tree().
+ */
+struct CFCMethod*
+CFCClass_find_novel_method(CFCClass *self, const char *sym);
+
 /** Bequeath all inherited methods and members to children.
  */
 void