Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 9a5dd08d7 -> 3764af037


Stop forcing invocant to "self" in codegen.

Use the original invocant name in generated method invocation function
and method 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/9cec34f4
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/9cec34f4
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/9cec34f4

Branch: refs/heads/master
Commit: 9cec34f49c237e37438d8d740d63278ce24275d5
Parents: 9a5dd08
Author: Marvin Humphrey <[email protected]>
Authored: Wed May 20 15:35:14 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Wed May 27 14:29:38 2015 -0700

----------------------------------------------------------------------
 compiler/src/CFCBindMethod.c | 37 +++++++++++++++++--------------------
 compiler/src/CFCParamList.c  | 19 +++++++++++++++++++
 compiler/src/CFCParamList.h  | 11 +++++++++++
 3 files changed, 47 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9cec34f4/compiler/src/CFCBindMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindMethod.c b/compiler/src/CFCBindMethod.c
index 3f7bccd..0b37408 100644
--- a/compiler/src/CFCBindMethod.c
+++ b/compiler/src/CFCBindMethod.c
@@ -76,23 +76,20 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
     CFCParamList *param_list = CFCMethod_get_param_list(method);
     const char *PREFIX         = CFCClass_get_PREFIX(klass);
     const char *invoker_struct = CFCClass_full_struct_sym(klass);
+    const char *self_name      = CFCParamList_param_name(param_list, 0);
 
     char *full_meth_sym   = CFCMethod_full_method_sym(method, klass);
     char *full_offset_sym = CFCMethod_full_offset_sym(method, klass);
     char *full_typedef    = CFCMethod_full_typedef(method, klass);
 
-    // Prepare parameter lists, minus invoker.  The invoker gets forced to
-    // "self" later.
+    // Prepare parameter lists, minus the type of the invoker.
     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 != ',') {
-        arg_names_minus_invoker++;
-    }
-    while (*params_minus_invoker && *params_minus_invoker != ',') {
-        params_minus_invoker++;
+    const char *arg_names  = CFCParamList_name_list(param_list);
+    const char *params_end = CFCParamList_to_c(param_list);
+    while (*params_end && *params_end != '*') {
+        params_end++;
     }
 
     // Prepare a return statement... or not.
@@ -103,15 +100,15 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
     const char pattern[] =
         "extern %sVISIBLE size_t %s;\n"
         "static CFISH_INLINE %s\n"
-        "%s(%s *self%s) {\n"
-        "    const %s method = (%s)cfish_obj_method(self, %s);\n"
-        "    %smethod(self%s);\n"
+        "%s(%s%s) {\n"
+        "    const %s method = (%s)cfish_obj_method(%s, %s);\n"
+        "    %smethod(%s);\n"
         "}\n";
     char *method_def
         = CFCUtil_sprintf(pattern, PREFIX, full_offset_sym, ret_type_str,
-                          full_meth_sym, invoker_struct, params_minus_invoker,
-                          full_typedef, full_typedef, full_offset_sym,
-                          maybe_return, arg_names_minus_invoker);
+                          full_meth_sym, invoker_struct, params_end,
+                          full_typedef, full_typedef, self_name, 
full_offset_sym,
+                          maybe_return, arg_names);
 
     FREEMEM(full_offset_sym);
     FREEMEM(full_meth_sym);
@@ -121,17 +118,17 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
 
 char*
 CFCBindMeth_typedef_dec(struct CFCMethod *method, CFCClass *klass) {
-    const char *params_minus_invoker
+    const char *params_end
         = CFCParamList_to_c(CFCMethod_get_param_list(method));
-    while (*params_minus_invoker && *params_minus_invoker != ',') {
-        params_minus_invoker++;
+    while (*params_end && *params_end != '*') {
+        params_end++;
     }
     const char *self_struct = CFCClass_full_struct_sym(klass);
     const char *ret_type = CFCType_to_c(CFCMethod_get_return_type(method));
     char *full_typedef = CFCMethod_full_typedef(method, klass);
-    char *buf = CFCUtil_sprintf("typedef %s\n(*%s)(%s *self%s);\n", ret_type,
+    char *buf = CFCUtil_sprintf("typedef %s\n(*%s)(%s%s);\n", ret_type,
                                 full_typedef, self_struct,
-                                params_minus_invoker);
+                                params_end);
     FREEMEM(full_typedef);
     return buf;
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9cec34f4/compiler/src/CFCParamList.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParamList.c b/compiler/src/CFCParamList.c
index 897a7db..281de73 100644
--- a/compiler/src/CFCParamList.c
+++ b/compiler/src/CFCParamList.c
@@ -20,6 +20,7 @@
 #include "CFCBase.h"
 #include "CFCParamList.h"
 #include "CFCVariable.h"
+#include "CFCType.h"
 #include "CFCSymbol.h"
 #include "CFCUtil.h"
 
@@ -176,3 +177,21 @@ CFCParamList_name_list(CFCParamList *self) {
     return self->name_list;
 }
 
+const char*
+CFCParamList_param_name(CFCParamList *self, int tick) {
+    if (tick >= self->num_vars) {
+        CFCUtil_die("No var at position %d for ParamList (%s)", tick,
+                    CFCParamList_to_c(self));
+    }
+    return CFCVariable_get_name(self->variables[tick]);
+}
+
+CFCType*
+CFCParamList_param_type(CFCParamList *self, int tick) {
+    if (tick >= self->num_vars) {
+        CFCUtil_die("No var at position %d for ParamList (%s)", tick,
+                    CFCParamList_to_c(self));
+    }
+    return CFCVariable_get_type(self->variables[tick]);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9cec34f4/compiler/src/CFCParamList.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParamList.h b/compiler/src/CFCParamList.h
index 2aaae6d..cbc2b15 100644
--- a/compiler/src/CFCParamList.h
+++ b/compiler/src/CFCParamList.h
@@ -27,6 +27,7 @@ extern "C" {
 typedef struct CFCParamList CFCParamList;
 struct CFCClass;
 struct CFCVariable;
+struct CFCType;
 
 /**
  * @param variadic Should be true if the function is variadic.
@@ -87,6 +88,16 @@ CFCParamList_to_c(CFCParamList *self);
 const char*
 CFCParamList_name_list(CFCParamList *self);
 
+/** Return the name of the parameter at position `tick`.
+ */
+const char*
+CFCParamList_param_name(CFCParamList *self, int tick);
+
+/** Return the type of the parameter at position `tick`.
+ */
+struct CFCType*
+CFCParamList_param_type(CFCParamList *self, int tick);
+
 #ifdef __cplusplus
 }
 #endif

Reply via email to