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:38 UTC
[12/23] lucy-clownfish git commit: Flesh out Go interfaces.
Flesh out Go interfaces.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/6002adcb
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/6002adcb
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/6002adcb
Branch: refs/heads/master
Commit: 6002adcbc9a3f58326910506f65e5753cdfd48b7
Parents: 3dc0240
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Apr 3 11:37:48 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed May 6 14:28:15 2015 -0700
----------------------------------------------------------------------
compiler/src/CFCGoClass.c | 23 ++++++++++++++++++++++-
compiler/src/CFCGoMethod.c | 37 +++++++++++++++++++++++++++++++++++++
compiler/src/CFCGoMethod.h | 6 ++++++
3 files changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6002adcb/compiler/src/CFCGoClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoClass.c b/compiler/src/CFCGoClass.c
index 44884ec..21e6075 100644
--- a/compiler/src/CFCGoClass.c
+++ b/compiler/src/CFCGoClass.c
@@ -198,16 +198,37 @@ CFCGoClass_go_typing(CFCGoClass *self) {
temp_hack_iface_methods = CFCUtil_strdup("");
}
+ char *novel_iface = CFCUtil_strdup("");
+ S_lazy_init_method_bindings(self);
+ for (int i = 0; self->method_bindings[i] != NULL; i++) {
+ CFCGoMethod *meth_binding = self->method_bindings[i];
+ CFCMethod *method = CFCGoMethod_get_client(meth_binding);
+ if (!CFCMethod_novel(method)) {
+ continue;
+ }
+ const char *sym = CFCMethod_get_macro_sym(method);
+ if (!CFCClass_fresh_method(self->client, sym)) {
+ continue;
+ }
+
+ char *iface_sig = CFCGoMethod_iface_sig(meth_binding);
+ novel_iface
+ = CFCUtil_cat(novel_iface, "\t", iface_sig, "\n", NULL);
+ FREEMEM(iface_sig);
+ }
+
char pattern[] =
"type %s interface {\n"
"%s"
"%s"
+ "%s"
"}\n"
"\n"
"%s"
;
content = CFCUtil_sprintf(pattern, short_struct, parent_iface,
- temp_hack_iface_methods, go_struct_def);
+ temp_hack_iface_methods, novel_iface,
+ go_struct_def);
FREEMEM(temp_hack_iface_methods);
FREEMEM(go_struct_def);
FREEMEM(parent_iface);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6002adcb/compiler/src/CFCGoMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoMethod.c b/compiler/src/CFCGoMethod.c
index 92cc3c5..05ac230 100644
--- a/compiler/src/CFCGoMethod.c
+++ b/compiler/src/CFCGoMethod.c
@@ -67,6 +67,43 @@ S_CFCGoMethod_destroy(CFCGoMethod *self) {
CFCBase_destroy((CFCBase*)self);
}
+CFCMethod*
+CFCGoMethod_get_client(CFCGoMethod *self) {
+ return self->method;
+}
+
+char*
+CFCGoMethod_iface_sig(CFCGoMethod *self) {
+ CFCMethod *method = self->method;
+ CFCParcel *parcel = CFCMethod_get_parcel(method);
+ CFCType *return_type = CFCMethod_get_return_type(method);
+ char *name = CFCGoFunc_go_meth_name(CFCMethod_get_macro_sym(method));
+ char *go_ret_type = CFCType_is_void(return_type)
+ ? CFCUtil_strdup("")
+ : CFCGoTypeMap_go_type_name(return_type, parcel);
+
+ // Assemble list of argument types.
+ char *args = CFCUtil_strdup("");
+ CFCParamList *param_list = CFCMethod_get_param_list(method);
+ CFCVariable **vars = CFCParamList_get_variables(param_list);
+ for (int i = 1; vars[i] != NULL; i++) {
+ CFCType *type = CFCVariable_get_type(vars[i]);
+ if (i > 1) {
+ args = CFCUtil_cat(args, ", ", NULL);
+ }
+ char *go_type = CFCGoTypeMap_go_type_name(type, parcel);
+ args = CFCUtil_cat(args, go_type, NULL);
+ FREEMEM(go_type);
+ }
+
+ char *sig = CFCUtil_sprintf("%s(%s) %s", name, args, go_ret_type);
+
+ FREEMEM(args);
+ FREEMEM(go_ret_type);
+ FREEMEM(name);
+ return sig;
+}
+
static char*
S_prep_cfargs(CFCParamList *param_list) {
CFCVariable **vars = CFCParamList_get_variables(param_list);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6002adcb/compiler/src/CFCGoMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoMethod.h b/compiler/src/CFCGoMethod.h
index 7b61c28..55314d8 100644
--- a/compiler/src/CFCGoMethod.h
+++ b/compiler/src/CFCGoMethod.h
@@ -31,6 +31,12 @@ struct CFCClass;
CFCGoMethod*
CFCGoMethod_new(struct CFCMethod *method);
+struct CFCMethod*
+CFCGoMethod_get_client(CFCGoMethod *self);
+
+char*
+CFCGoMethod_iface_sig(CFCGoMethod *self);
+
char*
CFCGoMethod_func_def(CFCGoMethod *self, struct CFCClass *invoker);