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 2015/05/07 00:18:36 UTC
[10/23] lucy-clownfish git commit: Brute normalization of method
signatures for Go.
Brute normalization of method signatures for Go.
* Pass invoker to Go method glue generation.
* Use novel method invocation function.
* For co-variant return types, the Go bindings always return the
lowest common denominator from the novel method. This is
necessary because a method with a co-variant return type does not
satisfy a Go interface.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/3dc02407
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/3dc02407
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/3dc02407
Branch: refs/heads/master
Commit: 3dc02407e573356a1b929ac96be49d5bc319afdc
Parents: 8f15e5a
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 1 16:57:58 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed May 6 14:28:15 2015 -0700
----------------------------------------------------------------------
compiler/src/CFCGoClass.c | 3 ++-
compiler/src/CFCGoFunc.c | 11 ++++-------
compiler/src/CFCGoFunc.h | 2 ++
compiler/src/CFCGoMethod.c | 28 ++++++++++++++--------------
compiler/src/CFCGoMethod.h | 3 ++-
5 files changed, 24 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3dc02407/compiler/src/CFCGoClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoClass.c b/compiler/src/CFCGoClass.c
index 50e512c..44884ec 100644
--- a/compiler/src/CFCGoClass.c
+++ b/compiler/src/CFCGoClass.c
@@ -295,7 +295,8 @@ CFCGoClass_gen_meth_glue(CFCGoClass *self) {
char *meth_defs = CFCUtil_strdup("");
for (size_t i = 0; self->method_bindings[i] != NULL; i++) {
CFCGoMethod *meth_binding = self->method_bindings[i];
- char *method_def = CFCGoMethod_func_def(meth_binding);
+ char *method_def
+ = CFCGoMethod_func_def(meth_binding, self->client);
meth_defs = CFCUtil_cat(meth_defs, method_def, "\n", NULL);
FREEMEM(method_def);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3dc02407/compiler/src/CFCGoFunc.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoFunc.c b/compiler/src/CFCGoFunc.c
index db540aa..88a887e 100644
--- a/compiler/src/CFCGoFunc.c
+++ b/compiler/src/CFCGoFunc.c
@@ -20,6 +20,7 @@
#include "CFCGoFunc.h"
#include "CFCGoTypeMap.h"
#include "CFCBase.h"
+#include "CFCClass.h"
#include "CFCFunction.h"
#include "CFCUtil.h"
#include "CFCParcel.h"
@@ -44,18 +45,14 @@ CFCGoFunc_go_meth_name(const char *orig) {
}
char*
-CFCGoFunc_func_start(CFCParcel *parcel, const char *name,
+CFCGoFunc_func_start(CFCParcel *parcel, const char *name, CFCClass *invoker,
CFCParamList *param_list, CFCType *return_type,
int is_method) {
CFCVariable **param_vars = CFCParamList_get_variables(param_list);
char *invocant;
if (is_method) {
- CFCVariable *var = param_vars[0];
- CFCType *type = CFCVariable_get_type(var);
- char *go_type_name = CFCGoTypeMap_go_type_name(type, parcel);
- invocant = CFCUtil_sprintf("(%s *%sIMP) ", CFCVariable_micro_sym(var),
- go_type_name);
- FREEMEM(go_type_name);
+ invocant = CFCUtil_sprintf("(self *%sIMP) ",
+ CFCClass_get_struct_sym(invoker));
}
else {
invocant = CFCUtil_strdup("");
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3dc02407/compiler/src/CFCGoFunc.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoFunc.h b/compiler/src/CFCGoFunc.h
index d9ee98b..a8a47c3 100644
--- a/compiler/src/CFCGoFunc.h
+++ b/compiler/src/CFCGoFunc.h
@@ -25,6 +25,7 @@ extern "C" {
struct CFCFunction;
struct CFCParcel;
struct CFCType;
+struct CFCClass;
struct CFCParamList;
char*
@@ -32,6 +33,7 @@ CFCGoFunc_go_meth_name(const char *orig);
char*
CFCGoFunc_func_start(struct CFCParcel *parcel, const char *name,
+ struct CFCClass *invoker,
struct CFCParamList *param_list,
struct CFCType *return_type, int is_method);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3dc02407/compiler/src/CFCGoMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoMethod.c b/compiler/src/CFCGoMethod.c
index 7aef897..92cc3c5 100644
--- a/compiler/src/CFCGoMethod.c
+++ b/compiler/src/CFCGoMethod.c
@@ -85,30 +85,30 @@ S_prep_cfargs(CFCParamList *param_list) {
else if (CFCType_is_object(type)) {
char *obj_pattern;
if (CFCType_decremented(type)) {
- obj_pattern = "%s(*C.%s)(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(%s.TOPTR()))))";
+ obj_pattern = "(*C.%s)(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(%s.TOPTR()))))";
}
else {
- obj_pattern = "%s(*C.%s)(unsafe.Pointer(%s.TOPTR()))";
+ obj_pattern = "(*C.%s)(unsafe.Pointer(%s.TOPTR()))";
}
- char *temp = CFCUtil_sprintf(obj_pattern, cfargs,
+ char *temp = CFCUtil_sprintf(obj_pattern,
CFCType_get_specifier(type), name);
- FREEMEM(cfargs);
- cfargs = temp;
+ cfargs = CFCUtil_cat(cfargs, temp, NULL);
+ FREEMEM(temp);
}
}
return cfargs;
}
char*
-CFCGoMethod_func_def(CFCGoMethod *self) {
- CFCMethod *method = self->method;
- CFCParcel *parcel = CFCMethod_get_parcel(method);
- CFCParamList *param_list = CFCMethod_get_param_list(method);
- CFCType *ret_type = CFCMethod_get_return_type(method);
- char *name = CFCGoFunc_go_meth_name(CFCMethod_get_macro_sym(method));
- char *first_line = CFCGoFunc_func_start(parcel, name, param_list,
- ret_type, true);
- char *full_meth_sym = CFCMethod_full_method_sym(method, NULL);
+CFCGoMethod_func_def(CFCGoMethod *self, CFCClass *invoker) {
+ CFCMethod *novel_method = CFCMethod_find_novel_method(self->method);
+ CFCParcel *parcel = CFCClass_get_parcel(invoker);
+ CFCParamList *param_list = CFCMethod_get_param_list(novel_method);
+ CFCType *ret_type = CFCMethod_get_return_type(novel_method);
+ char *name = CFCGoFunc_go_meth_name(CFCMethod_get_macro_sym(novel_method));
+ char *first_line = CFCGoFunc_func_start(parcel, name, invoker,
+ param_list, ret_type, true);
+ char *full_meth_sym = CFCMethod_full_method_sym(novel_method, NULL);
char *cfargs = S_prep_cfargs(param_list);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3dc02407/compiler/src/CFCGoMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoMethod.h b/compiler/src/CFCGoMethod.h
index b94529e..7b61c28 100644
--- a/compiler/src/CFCGoMethod.h
+++ b/compiler/src/CFCGoMethod.h
@@ -26,12 +26,13 @@ extern "C" {
typedef struct CFCGoMethod CFCGoMethod;
struct CFCMethod;
+struct CFCClass;
CFCGoMethod*
CFCGoMethod_new(struct CFCMethod *method);
char*
-CFCGoMethod_func_def(CFCGoMethod *self);
+CFCGoMethod_func_def(CFCGoMethod *self, struct CFCClass *invoker);
#ifdef __cplusplus
}