lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [5/9] lucy-clownfish git commit: Stub out module for Go bindings.
Date Tue, 07 Apr 2015 00:03:50 GMT
Stub out module for Go bindings.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/b2cc905f
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b2cc905f
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b2cc905f

Branch: refs/heads/master
Commit: b2cc905f63f4f4d71e57315e86632b76552870f1
Parents: fbd9d54
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Sun Mar 15 10:46:26 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Mon Apr 6 09:08:19 2015 -0700

----------------------------------------------------------------------
 compiler/go/cfc/cfc.go | 35 ++++++++++++++++
 compiler/include/CFC.h |  2 +
 compiler/src/CFCGo.c   | 98 +++++++++++++++++++++++++++++++++++++++++++++
 compiler/src/CFCGo.h   | 63 +++++++++++++++++++++++++++++
 runtime/go/build.go    |  5 +++
 5 files changed, 203 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b2cc905f/compiler/go/cfc/cfc.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go
index 930aba8..1f30cd2 100644
--- a/compiler/go/cfc/cfc.go
+++ b/compiler/go/cfc/cfc.go
@@ -83,6 +83,10 @@ type BindC struct {
 	ref *C.CFCC
 }
 
+type BindGo struct {
+	ref *C.CFCGo
+}
+
 func FetchParcel(name string) *Parcel {
 	nameC := C.CString(name)
 	defer C.free(unsafe.Pointer(nameC))
@@ -179,3 +183,34 @@ func (obj *BindC) WriteCallbacks() {
 func (obj *BindC) WriteHostDefs() {
 	C.CFCC_write_hostdefs(obj.ref)
 }
+
+func NewBindGo(hierarchy *Hierarchy) *BindGo {
+	obj := &BindGo{
+		C.CFCGo_new(hierarchy.ref),
+	}
+	runtime.SetFinalizer(obj, (*BindGo).finalize)
+	return obj
+}
+
+func (obj *BindGo) finalize() {
+	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
+}
+
+func (obj *BindGo) SetHeader(header string) {
+	headerCString := C.CString(header)
+	defer C.free(unsafe.Pointer(headerCString))
+	C.CFCGo_set_header(obj.ref, headerCString)
+}
+
+func (obj *BindGo) SetFooter(header string) {
+	headerCString := C.CString(header)
+	defer C.free(unsafe.Pointer(headerCString))
+	C.CFCGo_set_header(obj.ref, headerCString)
+}
+
+func (obj *BindGo) WriteBindings(parcel *Parcel, dest string) {
+	destC := C.CString(dest)
+	defer C.free(unsafe.Pointer(destC))
+	C.CFCGo_write_bindings(obj.ref, parcel.ref, destC)
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b2cc905f/compiler/include/CFC.h
----------------------------------------------------------------------
diff --git a/compiler/include/CFC.h b/compiler/include/CFC.h
index 0fc047b..2cc85f4 100644
--- a/compiler/include/CFC.h
+++ b/compiler/include/CFC.h
@@ -43,6 +43,8 @@
 #include "CFCBindFunction.h"
 #include "CFCBindMethod.h"
 
+#include "CFCGo.h"
+
 #include "CFCPerl.h"
 #include "CFCPerlSub.h"
 #include "CFCPerlMethod.h"

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b2cc905f/compiler/src/CFCGo.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGo.c b/compiler/src/CFCGo.c
new file mode 100644
index 0000000..8625664
--- /dev/null
+++ b/compiler/src/CFCGo.c
@@ -0,0 +1,98 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "charmony.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#define CFC_NEED_BASE_STRUCT_DEF
+#include "CFCBase.h"
+#include "CFCGo.h"
+#include "CFCParcel.h"
+#include "CFCClass.h"
+#include "CFCMethod.h"
+#include "CFCHierarchy.h"
+#include "CFCUtil.h"
+#include "CFCGoTypeMap.h"
+
+static void
+S_CFCGo_destroy(CFCGo *self);
+
+struct CFCGo {
+    CFCBase base;
+    CFCHierarchy *hierarchy;
+    char *header;
+    char *footer;
+    char *c_header;
+    char *c_footer;
+};
+
+static const CFCMeta CFCGO_META = {
+    "Clownfish::CFC::Binding::Go",
+    sizeof(CFCGo),
+    (CFCBase_destroy_t)S_CFCGo_destroy
+};
+
+CFCGo*
+CFCGo_new(CFCHierarchy *hierarchy) {
+    CFCUTIL_NULL_CHECK(hierarchy);
+    CFCGo *self = (CFCGo*)CFCBase_allocate(&CFCGO_META);
+    self->hierarchy  = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
+    self->header     = CFCUtil_strdup("");
+    self->footer     = CFCUtil_strdup("");
+    self->c_header   = CFCUtil_strdup("");
+    self->c_footer   = CFCUtil_strdup("");
+    return self;
+}
+
+static void
+S_CFCGo_destroy(CFCGo *self) {
+    CFCBase_decref((CFCBase*)self->hierarchy);
+    FREEMEM(self->header);
+    FREEMEM(self->footer);
+    FREEMEM(self->c_header);
+    FREEMEM(self->c_footer);
+    CFCBase_destroy((CFCBase*)self);
+}
+
+void
+CFCGo_set_header(CFCGo *self, const char *header) {
+    CFCUTIL_NULL_CHECK(header);
+    free(self->header);
+    self->header = CFCUtil_strdup(header);
+    free(self->c_header);
+    self->c_header = CFCUtil_make_c_comment(header);
+}
+
+void
+CFCGo_set_footer(CFCGo *self, const char *footer) {
+    CFCUTIL_NULL_CHECK(footer);
+    free(self->footer);
+    self->footer = CFCUtil_strdup(footer);
+    free(self->c_footer);
+    self->c_footer = CFCUtil_make_c_comment(footer);
+}
+
+void
+CFCGo_write_bindings(CFCGo *self, CFCParcel *parcel, const char *dest) {
+    CHY_UNUSED_VAR(self);
+    CHY_UNUSED_VAR(parcel);
+    CHY_UNUSED_VAR(dest);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b2cc905f/compiler/src/CFCGo.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGo.h b/compiler/src/CFCGo.h
new file mode 100644
index 0000000..0953236
--- /dev/null
+++ b/compiler/src/CFCGo.h
@@ -0,0 +1,63 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_CFCGO
+#define H_CFCGO
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct CFCGo CFCGo;
+struct CFCParcel;
+struct CFCHierarchy;
+
+/** Clownfish::CFC::Binding::Go - Go bindings for a
+ * Clownfish::CFC::Model::Hierarchy.
+ *
+ * Clownfish::CFC::Binding::Go presents an interface for auto-generating CGO
+ * code to bind C code for a Clownfish parcel to Go.
+ */
+
+/**
+ * @param hierarchy A CFCHierarchy.
+ */
+
+CFCGo*
+CFCGo_new(struct CFCHierarchy *hierarchy);
+
+/** Set the text which will be prepended to generated CGO files -- for
+ * instance, an "autogenerated file" warning.
+ */
+void
+CFCGo_set_header(CFCGo *self, const char *header);
+
+/** Set the text which will be appended to the end of generated CGO files.
+ */
+void
+CFCGo_set_footer(CFCGo *self, const char *footer);
+
+/** Generate CGO bindings for the specified parcel.
+ */
+void
+CFCGo_write_bindings(CFCGo *self, struct CFCParcel *parcel, const char *dest);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CFCGO */
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b2cc905f/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index 51f4662..c746537 100644
--- a/runtime/go/build.go
+++ b/runtime/go/build.go
@@ -123,6 +123,11 @@ func runCFC() {
 	if modified {
 		cBinding := cfc.NewBindC(hierarchy, autogenHeader, "")
 		cBinding.WriteHostDefs()
+		goBinding := cfc.NewBindGo(hierarchy)
+		goBinding.SetHeader(autogenHeader)
+		parcel := cfc.FetchParcel("Clownfish")
+		packageDir := path.Join(buildDir, "clownfish")
+		goBinding.WriteBindings(parcel, packageDir)
 		hierarchy.WriteLog()
 	}
 }


Mime
View raw message