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/08/17 22:25:59 UTC
[1/6] lucy-clownfish git commit: Handle nil args in Go method
wrappers.
Repository: lucy-clownfish
Updated Branches:
refs/heads/master d28ce6ee4 -> 2e66aac98
Handle nil args in Go method wrappers.
Parameters which have a default value of `NULL` map to a `nil` value in
Go. We can't call TOPTR() on them, so we need to use `UnwrapClownfish`.
To prevent the generated invocation statement from getting ridiculously
long, convert/unwrap *all* object types to temp variables.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/f3ed7660
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/f3ed7660
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/f3ed7660
Branch: refs/heads/master
Commit: f3ed7660fb43abc67c3f7025b067115e9362517e
Parents: 8172d40
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 20:01:20 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Aug 14 15:36:17 2015 -0700
----------------------------------------------------------------------
compiler/src/CFCGoFunc.c | 92 +++++++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/f3ed7660/compiler/src/CFCGoFunc.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoFunc.c b/compiler/src/CFCGoFunc.c
index a1e3bb5..34d3d48 100644
--- a/compiler/src/CFCGoFunc.c
+++ b/compiler/src/CFCGoFunc.c
@@ -58,6 +58,7 @@ S_prep_start(CFCParcel *parcel, const char *name, CFCClass *invoker,
const char *clownfish_dot = CFCParcel_is_cfish(parcel)
? "" : "clownfish.";
CFCVariable **param_vars = CFCParamList_get_variables(param_list);
+ const char **default_values = CFCParamList_get_initial_values(param_list);
char *invocant;
char go_name[GO_NAME_BUF_SIZE];
@@ -84,10 +85,39 @@ S_prep_start(CFCParcel *parcel, const char *name, CFCClass *invoker,
}
params = CFCUtil_cat(params, go_name, " ", go_type_name, NULL);
FREEMEM(go_type_name);
+ }
+
+ // Convert certain types and defer their destruction until after the
+ // Clownfish call returns.
+ for (int i = 0; param_vars[i] != NULL; i++) {
+ CFCVariable *var = param_vars[i];
+ CFCType *type = CFCVariable_get_type(var);
+ if (!CFCType_is_object(type)) {
+ continue;
+ }
- // Convert certain types and defer their destruction until after the
- // Clownfish call returns.
- const char *class_var;
+ if (targ == IS_METHOD && i == 0) {
+ CFCGoTypeMap_go_meth_receiever(CFCClass_get_struct_sym(invoker),
+ param_list, go_name,
+ GO_NAME_BUF_SIZE);
+ }
+ else {
+ CFCGoTypeMap_go_arg_name(param_list, i, go_name, GO_NAME_BUF_SIZE);
+ }
+
+ // A parameter may be marked with the nullable modifier. It may also
+ // be nullable if it has a default value of "NULL". (Since Go does
+ // not support default values for method parameters, this is the only
+ // default value we care about.)
+ const char *nullable = CFCType_nullable(type) ? "true" : "false";
+ if (default_values[i] != NULL
+ && strcmp(default_values[i], "NULL") == 0
+ ) {
+ nullable = "true";
+ }
+
+ const char *class_var = NULL;
+ const char *struct_name = CFCType_get_specifier(type);
if (CFCType_cfish_obj(type)) {
class_var = "CFISH_OBJ";
}
@@ -103,11 +133,26 @@ S_prep_start(CFCParcel *parcel, const char *name, CFCClass *invoker,
else if (CFCType_cfish_hash(type)) {
class_var = "CFISH_HASH";
}
- else {
+
+ if (class_var == NULL || (targ == IS_METHOD && i == 0)) {
+ // Just unwrap -- don't convert.
+ char *pattern;
+ if (CFCType_decremented(type)) {
+ pattern =
+ "\t%sCF := (*C.%s)(unsafe.Pointer(C.cfish_incref(%sUnwrapClownfish(%s, \"%s\", %s))))\n";
+ }
+ else {
+ pattern =
+ "\t%sCF := (*C.%s)(%sUnwrapClownfish(%s, \"%s\", %s))\n";
+ }
+ char *conversion = CFCUtil_sprintf(pattern, go_name, struct_name,
+ clownfish_dot, go_name,
+ go_name, nullable);
+ converted = CFCUtil_cat(converted, conversion, NULL);
+ FREEMEM(conversion);
continue;
}
- const char *struct_name = CFCType_get_specifier(type);
- const char *nullable = CFCType_nullable(type) ? "true" : "false";
+
char pattern[] =
"\t%sCF := (*C.%s)(%sGoToClownfish(%s, unsafe.Pointer(C.%s), %s))\n";
char *conversion = CFCUtil_sprintf(pattern, go_name, struct_name,
@@ -188,29 +233,8 @@ S_prep_cfargs(CFCParcel *parcel, CFCClass *invoker,
cfargs = CFCUtil_cat(cfargs, "C.", CFCType_get_specifier(type),
"(", go_name, ")", NULL);
}
- else if ((CFCType_cfish_obj(type)
- || CFCType_cfish_string(type)
- || CFCType_cfish_blob(type)
- || CFCType_cfish_vector(type)
- || CFCType_cfish_hash(type))
- // Don't convert an invocant.
- && (targ != IS_METHOD || i != 0)
- ) {
- cfargs = CFCUtil_cat(cfargs, go_name, "CF", NULL);
- }
else if (CFCType_is_object(type)) {
-
- char *obj_pattern;
- if (CFCType_decremented(type)) {
- obj_pattern = "(*C.%s)(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(%s.TOPTR()))))";
- }
- else {
- obj_pattern = "(*C.%s)(unsafe.Pointer(%s.TOPTR()))";
- }
- char *temp = CFCUtil_sprintf(obj_pattern,
- CFCType_get_specifier(type), go_name);
- cfargs = CFCUtil_cat(cfargs, temp, NULL);
- FREEMEM(temp);
+ cfargs = CFCUtil_cat(cfargs, go_name, "CF", NULL);
}
}
return cfargs;
@@ -276,15 +300,6 @@ CFCGoFunc_return_statement(CFCParcel *parcel, CFCType *return_type,
}
else if (CFCType_is_object(return_type)) {
char *go_type_name = CFCGoTypeMap_go_type_name(return_type, parcel);
- char *struct_name = go_type_name;
- char *go_package = CFCUtil_strdup(go_type_name);
- for (int i = strlen(go_package) - 1; i >= 0; i--) {
- if (go_package[i] == '.') {
- struct_name += i + 1;
- break;
- }
- go_package[i] = '\0';
- }
char *pattern;
if (CFCType_incremented(return_type)) {
pattern = "\treturn %sWRAPAny(unsafe.Pointer(retvalCF)).(%s)\n";
@@ -292,9 +307,8 @@ CFCGoFunc_return_statement(CFCParcel *parcel, CFCType *return_type,
else {
pattern = "\treturn %sWRAPAny(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(retvalCF)))).(%s)\n";
}
- statement = CFCUtil_sprintf(pattern, go_package, struct_name);
+ statement = CFCUtil_sprintf(pattern, clownfish_dot, go_type_name);
FREEMEM(go_type_name);
- FREEMEM(go_package);
}
else {
CFCUtil_die("Unexpected type: %s", CFCType_to_c(return_type));
[3/6] lucy-clownfish git commit: Add Go binding for Obj_get_class.
Posted by ma...@apache.org.
Add Go binding for Obj_get_class.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/e2152ee5
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/e2152ee5
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/e2152ee5
Branch: refs/heads/master
Commit: e2152ee531a5b7cfbaad33b12a138e91851cf7ec
Parents: d28ce6e
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Aug 11 12:43:39 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Aug 14 15:36:17 2015 -0700
----------------------------------------------------------------------
runtime/go/clownfish/clownfish.go | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e2152ee5/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 1d0f40c..6fa8919 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -123,6 +123,12 @@ type ObjIMP struct {
ref uintptr
}
+func GetClass(o Obj) Class {
+ objCF := (*C.cfish_Obj)(unsafe.Pointer(o.TOPTR()))
+ classCF := C.cfish_Obj_get_class(objCF)
+ return WRAPClass(unsafe.Pointer(classCF))
+}
+
func FetchClass(className string) Class {
nameCF := (*C.cfish_String)(GoToString(className))
defer C.cfish_decref(unsafe.Pointer(nameCF))
[5/6] lucy-clownfish git commit: Add a missing incref.
Posted by ma...@apache.org.
Add a missing incref.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/81ce545d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/81ce545d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/81ce545d
Branch: refs/heads/master
Commit: 81ce545d140dc7bd0a1336a64c87f5c09ab961ed
Parents: 37aefb5
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 19:59:01 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Aug 14 15:36:17 2015 -0700
----------------------------------------------------------------------
runtime/go/clownfish/clownfish.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/81ce545d/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 6fa8919..14f07ed 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -533,7 +533,7 @@ func ToGo(ptr unsafe.Pointer) interface{} {
return float64(val)
} else {
// Don't convert to a native Go type, but wrap in a Go struct.
- return WRAPAny(ptr)
+ return WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(ptr))))
}
}
[4/6] lucy-clownfish git commit: Ensure proper Go wrapper for return
vals.
Posted by ma...@apache.org.
Ensure proper Go wrapper for return vals.
Access to the capabilities of a Clownfish object wrapped in a Go object
depends on the Go wrapper being class-specific. For instance, it does
not suffice to wrap a `*C.cfish_Hash` inside a `clownfish.ObjIMP`,
because you cannot invoke Hash operations on it.
Therefore, use WRAPAny for return values, so that the most specific
wrapper struct gets chosen.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/37aefb59
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/37aefb59
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/37aefb59
Branch: refs/heads/master
Commit: 37aefb596c9967103fb1efb084e53da58fbd20f1
Parents: e2152ee
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Aug 11 12:44:19 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Aug 14 15:36:17 2015 -0700
----------------------------------------------------------------------
compiler/src/CFCGoFunc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/37aefb59/compiler/src/CFCGoFunc.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoFunc.c b/compiler/src/CFCGoFunc.c
index d8a33c8..a1e3bb5 100644
--- a/compiler/src/CFCGoFunc.c
+++ b/compiler/src/CFCGoFunc.c
@@ -287,10 +287,10 @@ CFCGoFunc_return_statement(CFCParcel *parcel, CFCType *return_type,
}
char *pattern;
if (CFCType_incremented(return_type)) {
- pattern = "\treturn %sWRAP%s(unsafe.Pointer(retvalCF))\n";
+ pattern = "\treturn %sWRAPAny(unsafe.Pointer(retvalCF)).(%s)\n";
}
else {
- pattern = "\treturn %sWRAP%s(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(retvalCF))))\n";
+ pattern = "\treturn %sWRAPAny(unsafe.Pointer(C.cfish_inc_refcount(unsafe.Pointer(retvalCF)))).(%s)\n";
}
statement = CFCUtil_sprintf(pattern, go_package, struct_name);
FREEMEM(go_type_name);
[2/6] lucy-clownfish git commit: Add simple Go unwrapping function.
Posted by ma...@apache.org.
Add simple Go unwrapping function.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/8172d407
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/8172d407
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/8172d407
Branch: refs/heads/master
Commit: 8172d40724759806bba44af34e1fd2883d89e8f8
Parents: 81ce545
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 19:59:47 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Aug 14 15:36:17 2015 -0700
----------------------------------------------------------------------
runtime/go/clownfish/clownfish.go | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8172d407/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 14f07ed..bae8b3d 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -354,6 +354,17 @@ func GoToClownfish(value interface{}, class unsafe.Pointer, nullable bool) unsaf
panic(NewErr(fmt.Sprintf("Can't convert a %T to %s", value, className)))
}
+func UnwrapClownfish(value Obj, name string, nullable bool) unsafe.Pointer {
+ if value == nil {
+ if nullable {
+ return nil
+ } else {
+ panic(NewErr(fmt.Sprintf("%s cannot be nil", name)))
+ }
+ }
+ return unsafe.Pointer(value.TOPTR())
+}
+
func GoToString(value interface{}) unsafe.Pointer {
switch v := value.(type) {
case string:
[6/6] lucy-clownfish git commit: Merge branch
'CLOWNFISH-59-tune-go-conv'
Posted by ma...@apache.org.
Merge branch 'CLOWNFISH-59-tune-go-conv'
Fix some bugs and suboptimal behaviors in the Go conversion routines.
This closes #35.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/2e66aac9
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/2e66aac9
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/2e66aac9
Branch: refs/heads/master
Commit: 2e66aac987f77e61c59bfb951f4eaac8b841c1a3
Parents: d28ce6e f3ed766
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Aug 17 13:24:38 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Aug 17 13:24:38 2015 -0700
----------------------------------------------------------------------
compiler/src/CFCGoFunc.c | 96 +++++++++++++++++++---------------
runtime/go/clownfish/clownfish.go | 19 ++++++-
2 files changed, 73 insertions(+), 42 deletions(-)
----------------------------------------------------------------------