Map Hash to `map[string]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/a665132d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/a665132d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/a665132d
Branch: refs/heads/master
Commit: a665132d860925f4de24cd0182a0021a44a6a6ed
Parents: df02446
Author: Marvin Humphrey <[email protected]>
Authored: Thu Jul 30 18:20:06 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Fri Jul 31 11:06:32 2015 -0700
----------------------------------------------------------------------
compiler/src/CFCGoFunc.c | 9 ++++++++-
compiler/src/CFCGoTypeMap.c | 3 +++
runtime/go/build.go | 4 ++++
runtime/go/clownfish/clownfish.go | 8 ++++++++
4 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a665132d/compiler/src/CFCGoFunc.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoFunc.c b/compiler/src/CFCGoFunc.c
index 80a6e8d..2670034 100644
--- a/compiler/src/CFCGoFunc.c
+++ b/compiler/src/CFCGoFunc.c
@@ -91,6 +91,7 @@ S_prep_start(CFCParcel *parcel, const char *name, CFCClass
*invoker,
if (CFCType_cfish_string(type)) { convertible = "String"; }
else if (CFCType_cfish_vector(type)) { convertible = "Vector"; }
else if (CFCType_cfish_blob(type)) { convertible = "Blob"; }
+ else if (CFCType_cfish_hash(type)) { convertible = "Hash"; }
else { continue; }
char pattern[] =
"\t%sCF := (*C.cfish_%s)(%sGoTo%s(%s))\n";
@@ -174,7 +175,8 @@ S_prep_cfargs(CFCParcel *parcel, CFCClass *invoker,
}
else if ((CFCType_is_string_type(type)
|| CFCType_cfish_blob(type)
- || CFCType_cfish_vector(type))
+ || CFCType_cfish_vector(type)
+ || CFCType_cfish_hash(type))
// Don't convert an invocant.
&& (targ != IS_METHOD || i != 0)
) {
@@ -246,6 +248,11 @@ CFCGoFunc_return_statement(CFCParcel *parcel, CFCType
*return_type,
"%s\treturn %sVectorToGo(unsafe.Pointer(retvalCF))\n";
statement = CFCUtil_sprintf(pattern, maybe_decref, clownfish_dot);
}
+ else if (CFCType_cfish_hash(return_type)) {
+ char pattern[] =
+ "%s\treturn %sHashToGo(unsafe.Pointer(retvalCF))\n";
+ statement = CFCUtil_sprintf(pattern, maybe_decref, clownfish_dot);
+ }
else if (CFCType_is_object(return_type)) {
char *go_type_name = CFCGoTypeMap_go_type_name(return_type,
parcel);
char *struct_name = go_type_name;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a665132d/compiler/src/CFCGoTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoTypeMap.c b/compiler/src/CFCGoTypeMap.c
index afd5345..fbee678 100644
--- a/compiler/src/CFCGoTypeMap.c
+++ b/compiler/src/CFCGoTypeMap.c
@@ -102,6 +102,9 @@ CFCGoTypeMap_go_type_name(CFCType *type, CFCParcel
*current_parcel) {
else if (CFCType_cfish_vector(type)) {
return CFCUtil_strdup("[]interface{}");
}
+ else if (CFCType_cfish_hash(type)) {
+ return CFCUtil_strdup("map[string]interface{}");
+ }
else if (CFCType_is_object(type)) {
// Divide the specifier into prefix and struct name.
const char *specifier = CFCType_get_specifier(type);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a665132d/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index fd96fd1..71a8c6b 100644
--- a/runtime/go/build.go
+++ b/runtime/go/build.go
@@ -152,6 +152,10 @@ func specMethods(parcel *cfc.Parcel) {
vecBinding := cfc.NewGoClass(parcel, "Clownfish::Vector")
vecBinding.SetSuppressCtor(true)
vecBinding.Register()
+
+ hashBinding := cfc.NewGoClass(parcel, "Clownfish::Hash")
+ hashBinding.SetSuppressCtor(true)
+ hashBinding.Register()
}
func prep() {
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/a665132d/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go
b/runtime/go/clownfish/clownfish.go
index eefd831..d5e3190 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -138,6 +138,14 @@ func NewVector(size int) Vector {
return WRAPVector(unsafe.Pointer(cfObj))
}
+func NewHash(size int) Hash {
+ if (size < 0 || uint64(size) > ^uint64(0)) {
+ panic(NewErr(fmt.Sprintf("Param 'size' out of range: %d",
size)))
+ }
+ cfObj := C.cfish_Hash_new(C.size_t(size))
+ return WRAPHash(unsafe.Pointer(cfObj))
+}
+
func (o *ObjIMP) INITOBJ(ptr unsafe.Pointer) {
o.ref = uintptr(ptr)
runtime.SetFinalizer(o, ClearRef)