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 2014/11/30 06:08:58 UTC

[01/20] lucy-clownfish git commit: Start Go bindings for CFC.

Repository: lucy-clownfish
Updated Branches:
  refs/heads/go_bindings_2 [created] 80154f6b8


Start Go bindings for CFC.


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

Branch: refs/heads/go_bindings_2
Commit: db4f76ec4b29933933375ec2c53bbfabccecd8e4
Parents: b7c1ca4
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 16:23:25 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:54 2014 -0800

----------------------------------------------------------------------
 compiler/go/build.go        | 158 +++++++++++++++++++++++++++++++++++++++
 compiler/go/cfc/cfc.go      |  51 +++++++++++++
 compiler/go/cfc/cfc_test.go |  26 +++++++
 3 files changed, 235 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/db4f76ec/compiler/go/build.go
----------------------------------------------------------------------
diff --git a/compiler/go/build.go b/compiler/go/build.go
new file mode 100644
index 0000000..d4a585b
--- /dev/null
+++ b/compiler/go/build.go
@@ -0,0 +1,158 @@
+/* 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.
+ */
+
+/* Build "script" for cfc (Apache Clownfish compiler).
+ */
+package main
+
+import "flag"
+import "fmt"
+import "io/ioutil"
+import "log"
+import "os"
+import "os/exec"
+import "path"
+import "runtime"
+
+var packageName string = "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/compiler/go/cfc"
+var charmonizerC string = "../common/charmonizer.c"
+var charmonizerEXE string = "charmonizer"
+var charmonyH string = "charmony.h"
+var buildDir string
+var buildGO string
+var configGO string
+
+func init() {
+	_, buildGO, _, _ = runtime.Caller(1)
+	buildDir = path.Dir(buildGO)
+	configGO = path.Join(buildDir, "cfc", "config.go")
+}
+
+func main() {
+	os.Chdir(buildDir)
+	flag.Parse()
+	action := "build"
+	args := flag.Args()
+	if len(args) > 0 {
+		action = args[0]
+	}
+	switch action {
+	case "build":
+		build()
+	case "clean":
+		clean()
+	case "test":
+		test()
+	case "install":
+		install()
+	default:
+		log.Fatalf("Unrecognized action specified: %s", action)
+	}
+}
+
+func current(orig, dest string) bool {
+	destInfo, err := os.Stat(dest)
+	if err != nil {
+		if os.IsNotExist(err) {
+			// If dest doesn't exist, we're not current.
+			return false
+		} else {
+			log.Fatalf("Unexpected stat err: %s", err)
+		}
+	}
+
+	// If source is newer than dest, we're not current.
+	origInfo, err := os.Stat(orig)
+	if err != nil {
+		log.Fatalf("Unexpected: %s", err)
+	}
+	return destInfo.ModTime().Before(origInfo.ModTime())
+}
+
+func runCommand(name string, args ...string) {
+	command := exec.Command(name, args...)
+	command.Stdout = os.Stdout
+	command.Stderr = os.Stderr
+	err := command.Run()
+	if err != nil {
+		log.Fatal(err)
+	}
+}
+
+func configure() {
+	if !current(charmonizerC, charmonizerEXE) {
+		runCommand("cc", "-o", charmonizerEXE, charmonizerC)
+	}
+	if !current(charmonizerEXE, charmonyH) {
+		runCommand("./charmonizer", "--cc=cc", "--enable-c", "--host=go",
+			"--enable-makefile", "--", "-std=gnu99", "-O2")
+	}
+}
+
+func prep() {
+	configure()
+	runCommand("make", "-j", "static")
+	writeConfigGO()
+}
+
+func build() {
+	prep()
+	runCommand("go", "build", packageName)
+}
+
+func test() {
+	prep()
+	runCommand("go", "test", packageName)
+}
+
+func install() {
+	prep()
+	runCommand("go", "install", packageName)
+}
+
+func writeConfigGO() {
+	if current(buildGO, configGO) {
+		return
+	}
+	libPath := path.Join(buildDir, "libcfc.a")
+	content := fmt.Sprintf(
+		"// Auto-generated by build.go, specifying absolute path to static lib.\n"+
+			"package cfc\n"+
+			"// #cgo CFLAGS: -I%s/../include -I%s/../src -I%s\n"+
+			"// #cgo LDFLAGS: %s\n"+
+			"import \"C\"\n",
+		buildDir, buildDir, buildDir, libPath)
+	ioutil.WriteFile(configGO, []byte(content), 0666)
+}
+
+func clean() {
+	if _, err := os.Stat(charmonizerEXE); os.IsNotExist(err) {
+		return
+	}
+	fmt.Println("Cleaning")
+	if _, err := os.Stat("Makefile"); !os.IsNotExist(err) {
+		runCommand("make", "clean")
+	}
+	cleanables := []string{charmonizerEXE, charmonyH, "Makefile", configGO}
+	for _, file := range cleanables {
+		err := os.Remove(file)
+		if err == nil {
+			fmt.Println("Removing", file)
+		} else if !os.IsNotExist(err) {
+			log.Fatal(err)
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/db4f76ec/compiler/go/cfc/cfc.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go
new file mode 100644
index 0000000..b46fafe
--- /dev/null
+++ b/compiler/go/cfc/cfc.go
@@ -0,0 +1,51 @@
+/* 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.
+ */
+
+/* Package cfc provides a compiler for Apache Clownfish.
+ */
+package cfc
+
+// #include "CFC.h"
+// #include <stdlib.h>
+import "C"
+
+import "runtime"
+import "unsafe"
+
+func DoStuff() {
+	hierarchy := NewHierarchy("autogen")
+	hierarchy.Build()
+}
+
+type Hierarchy struct {
+	ref *C.CFCHierarchy
+}
+
+func NewHierarchy(dest string) Hierarchy {
+	destCString := C.CString(dest)
+	defer C.free(unsafe.Pointer(destCString))
+	obj := Hierarchy{C.CFCHierarchy_new(destCString)}
+	runtime.SetFinalizer(&obj, (*Hierarchy).RunDecRef)
+	return obj
+}
+
+func (obj *Hierarchy) RunDecRef() {
+	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
+}
+
+func (obj *Hierarchy) Build() {
+	C.CFCHierarchy_build(obj.ref)
+}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/db4f76ec/compiler/go/cfc/cfc_test.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc_test.go b/compiler/go/cfc/cfc_test.go
new file mode 100644
index 0000000..1bfc6f6
--- /dev/null
+++ b/compiler/go/cfc/cfc_test.go
@@ -0,0 +1,26 @@
+/* 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.
+ */
+
+package cfc_test
+
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/compiler/go/cfc"
+import "testing"
+
+func TestStuff(t *testing.T) {
+	hierarchy := cfc.NewHierarchy("autogen")
+	hierarchy.Build()
+}
+


[19/20] lucy-clownfish git commit: Adapt charmonizer for Go bindings.

Posted by ma...@apache.org.
Adapt charmonizer for Go bindings.

*   Add "host" CLI arg.
*   Only build static lib when "static" Makefile target is run.
*   Select correct dir for host-specific C files.


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

Branch: refs/heads/go_bindings_2
Commit: b5bd3522ae33c5398cbd734b96b1ff8064b24634
Parents: 8e24d26
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 20:53:43 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/common/charmonizer.main | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b5bd3522/runtime/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main
index 4c2bcd5..8d9b9d1 100644
--- a/runtime/common/charmonizer.main
+++ b/runtime/common/charmonizer.main
@@ -97,12 +97,17 @@ int main(int argc, const char **argv) {
     /* Initialize. */
     chaz_CLI *cli
         = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment");
+    chaz_CLI_register(cli, "host", "specify host binding language",
+                      CHAZ_CLI_ARG_REQUIRED);
     chaz_CLI_register(cli, "disable-threads", "whether to disable threads",
                       CHAZ_CLI_NO_ARG);
     chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]");
     if (!chaz_Probe_parse_cli_args(argc, argv, cli)) {
         chaz_Probe_die_usage();
     }
+    if (!chaz_CLI_defined(cli, "host")) {
+        chaz_CLI_set(cli, "host", "c");
+    }
     chaz_Probe_init(cli);
     S_add_compiler_flags(cli);
 
@@ -235,7 +240,16 @@ cfish_MakeFile_new(chaz_CLI *cli) {
     self->autogen_target
         = chaz_Util_join(dir_sep, "autogen", "hierarchy.json", NULL);
 
-    if (chaz_CLI_defined(cli, "enable-perl")) {
+    if (strcmp(chaz_CLI_strval(cli, "host"), "go") == 0) {
+        static const char *go_autogen_src_files[] = {
+            "cfish_parcel",
+            "testcfish_parcel",
+            NULL
+        };
+        self->host_src_dir = "ext";
+        self->autogen_src_files = go_autogen_src_files;
+    }
+    else if (chaz_CLI_defined(cli, "enable-perl")) {
         static const char *perl_autogen_src_files[] = {
             "boot",
             "callbacks",
@@ -258,7 +272,7 @@ cfish_MakeFile_new(chaz_CLI *cli) {
 
     self->shared_lib = chaz_Lib_new("cfish", chaz_Lib_SHARED, cfish_version,
                                     cfish_major_version);
-    self->static_lib = chaz_Lib_new("cfish", chaz_Lib_STATIC, cfish_version,
+    self->static_lib = chaz_Lib_new("clownfish", chaz_Lib_STATIC, cfish_version,
                                     cfish_major_version);
     self->shared_lib_filename = chaz_Lib_filename(self->shared_lib);
     self->static_lib_filename = chaz_Lib_filename(self->static_lib);
@@ -350,12 +364,10 @@ cfish_MakeFile_write(cfish_MakeFile *self) {
 
     /* Rules */
 
-    scratch = chaz_Util_join(" ", self->shared_lib_filename,
-                             self->static_lib_filename, NULL);
-    chaz_MakeFile_add_rule(self->makefile, "all", scratch);
-    free(scratch);
+    chaz_MakeFile_add_rule(self->makefile, "all", self->shared_lib_filename);
+    chaz_MakeFile_add_rule(self->makefile, "static", self->static_lib_filename);
 
-    if (!chaz_CLI_defined(self->cli, "enable-perl")) {
+    if (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) {
         cfish_MakeFile_write_c_cfc_rules(self);
     }
 


[20/20] lucy-clownfish git commit: Use custom C code for fleshing out Go bindings.

Posted by ma...@apache.org.
Use custom C code for fleshing out Go bindings.

Instead of wrapping the C version of the Clownfish shared library,
prepare to custom-code Go-specific behaviors for the host-specific
portions of Clownfish.

Content copied from c/src/**.c


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

Branch: refs/heads/go_bindings_2
Commit: 5ff4b913a56cf13d5738326802f812d2301425f5
Parents: 28c6365
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Nov 14 18:46:27 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/go/build.go        |   2 +-
 runtime/go/ext/clownfish.c | 223 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 224 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5ff4b913/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index d05113d..8f19e4d 100644
--- a/runtime/go/build.go
+++ b/runtime/go/build.go
@@ -45,7 +45,7 @@ var installedLibPath string
 func init() {
 	_, buildGO, _, _ = runtime.Caller(1)
 	buildDir = path.Dir(buildGO)
-	hostSrcDir = path.Join(buildDir, "../c/src")
+	hostSrcDir = path.Join(buildDir, "ext")
 	configGO = path.Join(buildDir, "clownfish", "config.go")
 	var err error
 	installedLibPath, err = cfc.InstalledLibPath(packageName)

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5ff4b913/runtime/go/ext/clownfish.c
----------------------------------------------------------------------
diff --git a/runtime/go/ext/clownfish.c b/runtime/go/ext/clownfish.c
new file mode 100644
index 0000000..a66d0a6
--- /dev/null
+++ b/runtime/go/ext/clownfish.c
@@ -0,0 +1,223 @@
+/* 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.
+ */
+
+#define CFISH_USE_SHORT_NAMES
+#define C_CFISH_OBJ
+#define C_CFISH_CLASS
+#define C_CFISH_METHOD
+#define C_CFISH_ERR
+#define C_CFISH_LOCKFREEREGISTRY
+
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "charmony.h"
+
+#include "Clownfish/Obj.h"
+#include "Clownfish/Class.h"
+#include "Clownfish/Method.h"
+#include "Clownfish/Err.h"
+#include "Clownfish/Util/Memory.h"
+#include "Clownfish/String.h"
+#include "Clownfish/VArray.h"
+#include "Clownfish/LockFreeRegistry.h"
+
+/******************************** Obj **************************************/
+
+uint32_t
+Obj_Get_RefCount_IMP(Obj *self) {
+    return self->refcount;
+}
+
+Obj*
+Obj_Inc_RefCount_IMP(Obj *self) {
+    self->refcount++;
+    return self;
+}
+
+uint32_t
+Obj_Dec_RefCount_IMP(Obj *self) {
+    uint32_t modified_refcount = INT32_MAX;
+    switch (self->refcount) {
+        case 0:
+            THROW(ERR, "Illegal refcount of 0");
+            break; // useless
+        case 1:
+            modified_refcount = 0;
+            Obj_Destroy(self);
+            break;
+        default:
+            modified_refcount = --self->refcount;
+            break;
+    }
+    return modified_refcount;
+}
+
+void*
+Obj_To_Host_IMP(Obj *self) {
+    UNUSED_VAR(self);
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(void*);
+}
+
+/******************************* Class *************************************/
+
+Obj*
+Class_Make_Obj_IMP(Class *self) {
+    Obj *obj = (Obj*)Memory_wrapped_calloc(self->obj_alloc_size, 1);
+    obj->klass = self;
+    obj->refcount = 1;
+    return obj;
+}
+
+Obj*
+Class_Init_Obj_IMP(Class *self, void *allocation) {
+    Obj *obj = (Obj*)allocation;
+    obj->klass = self;
+    obj->refcount = 1;
+    return obj;
+}
+
+Obj*
+Class_Foster_Obj_IMP(Class *self, void *host_obj) {
+    UNUSED_VAR(self);
+    UNUSED_VAR(host_obj);
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(Obj*);
+}
+
+void
+Class_register_with_host(Class *singleton, Class *parent) {
+    UNUSED_VAR(singleton);
+    UNUSED_VAR(parent);
+}
+
+VArray*
+Class_fresh_host_methods(String *class_name) {
+    UNUSED_VAR(class_name);
+    return VA_new(0);
+}
+
+String*
+Class_find_parent_class(String *class_name) {
+    UNUSED_VAR(class_name);
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(String*);
+}
+
+void*
+Class_To_Host_IMP(Class *self) {
+    UNUSED_VAR(self);
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(void*);
+}
+
+/******************************* Method ************************************/
+
+String*
+Method_Host_Name_IMP(Method *self) {
+    return (String*)INCREF(self->name);
+}
+
+/******************************** Err **************************************/
+
+/* TODO: Thread safety */
+static Err *current_error;
+static Err *thrown_error;
+static jmp_buf  *current_env;
+
+void
+Err_init_class(void) {
+}
+
+Err*
+Err_get_error() {
+    return current_error;
+}
+
+void
+Err_set_error(Err *error) {
+    if (current_error) {
+        DECREF(current_error);
+    }
+    current_error = error;
+}
+
+void
+Err_do_throw(Err *error) {
+    if (current_env) {
+        thrown_error = error;
+        longjmp(*current_env, 1);
+    }
+    else {
+        String *message = Err_Get_Mess(error);
+        char *utf8 = Str_To_Utf8(message);
+        fprintf(stderr, "%s", utf8);
+        FREEMEM(utf8);
+        exit(EXIT_FAILURE);
+    }
+}
+
+void*
+Err_To_Host_IMP(Err *self) {
+    UNUSED_VAR(self);
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(void*);
+}
+
+void
+Err_throw_mess(Class *klass, String *message) {
+    UNUSED_VAR(klass);
+    Err *err = Err_new(message);
+    Err_do_throw(err);
+}
+
+void
+Err_warn_mess(String *message) {
+    char *utf8 = Str_To_Utf8(message);
+    fprintf(stderr, "%s", utf8);
+    FREEMEM(utf8);
+    DECREF(message);
+}
+
+Err*
+Err_trap(Err_Attempt_t routine, void *context) {
+    jmp_buf  env;
+    jmp_buf *prev_env = current_env;
+    current_env = &env;
+
+    if (!setjmp(env)) {
+        routine(context);
+    }
+
+    current_env = prev_env;
+
+    Err *error = thrown_error;
+    thrown_error = NULL;
+    return error;
+}
+
+/************************** LockFreeRegistry *******************************/
+
+void*
+LFReg_To_Host_IMP(LockFreeRegistry *self) {
+    UNUSED_VAR(self);
+    THROW(ERR, "TODO");
+    UNREACHABLE_RETURN(void*);
+}
+
+


[05/20] lucy-clownfish git commit: Separate executable from common test objects.

Posted by ma...@apache.org.
Separate executable from common test objects.


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

Branch: refs/heads/go_bindings_2
Commit: f013755b6008750e03ed60a4de8b022a5fedeb64
Parents: 95c7e8a
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 12:29:27 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:54 2014 -0800

----------------------------------------------------------------------
 compiler/common/charmonizer.main | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/f013755b/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main
index 9111e2f..5df4536 100644
--- a/compiler/common/charmonizer.main
+++ b/compiler/common/charmonizer.main
@@ -26,6 +26,7 @@
 typedef struct SourceFileContext {
     chaz_MakeVar *common_objs;
     chaz_MakeVar *test_cfc_objs;
+    chaz_MakeVar *common_test_objs;
 } SourceFileContext;
 
 static void
@@ -181,6 +182,7 @@ S_write_makefile(struct chaz_CLI *cli) {
 
     sfc.common_objs   = chaz_MakeFile_add_var(makefile, "COMMON_OBJS", NULL);
     sfc.test_cfc_objs = chaz_MakeFile_add_var(makefile, "TEST_CFC_OBJS", NULL);
+    sfc.common_test_objs = chaz_MakeFile_add_var(makefile, "COMMON_TEST_OBJS", NULL);
 
     chaz_Make_list_files(src_dir, "c", S_source_file_callback, &sfc);
 
@@ -221,7 +223,8 @@ S_write_makefile(struct chaz_CLI *cli) {
     chaz_MakeFile_add_exe(makefile, cfc_exe, "$(COMMON_OBJS) $(CFC_OBJS)",
                           link_flags);
     chaz_MakeFile_add_exe(makefile, test_cfc_exe,
-                          "$(COMMON_OBJS) $(TEST_CFC_OBJS)", link_flags);
+                          "$(COMMON_OBJS) $(COMMON_TEST_OBJS) $(TEST_CFC_OBJS)",
+                          link_flags);
     chaz_CFlags_destroy(link_flags);
 
     rule = chaz_MakeFile_add_rule(makefile, "test", test_cfc_exe);
@@ -251,6 +254,7 @@ S_write_makefile(struct chaz_CLI *cli) {
     clean_rule = chaz_MakeFile_clean_rule(makefile);
 
     chaz_MakeRule_add_rm_command(clean_rule, "$(COMMON_OBJS)");
+    chaz_MakeRule_add_rm_command(clean_rule, "$(COMMON_TEST_OBJS)");
     chaz_MakeRule_add_rm_command(clean_rule, "$(CFC_OBJS)");
     chaz_MakeRule_add_rm_command(clean_rule, "$(TEST_CFC_OBJS)");
 
@@ -293,7 +297,7 @@ S_source_file_callback(const char *dir, char *file, void *context) {
 
     obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL);
     if (strlen(file) >= 7 && memcmp(file, "CFCTest", 7) == 0) {
-        chaz_MakeVar_append(sfc->test_cfc_objs, obj_file);
+        chaz_MakeVar_append(sfc->common_test_objs, obj_file);
     }
     else {
         chaz_MakeVar_append(sfc->common_objs, obj_file);


[11/20] lucy-clownfish git commit: Implement error handling in terms of Go panic.

Posted by ma...@apache.org.
Implement error handling in terms of Go panic.

*   Clownfish `THROW` calls Go `panic`.
*   Clownfish `trap` utilizes Go `recover`.


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

Branch: refs/heads/go_bindings_2
Commit: 045b2e48c56e9dfc0616e27418ecc6c0cfd14079
Parents: 5ff4b91
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 15 19:45:17 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/go/clownfish/clownfish.go | 84 ++++++++++++++++++++++++++++++++++
 runtime/go/clownfish/err_test.go  | 42 +++++++++++++++++
 runtime/go/ext/clownfish.c        | 42 ++++++-----------
 3 files changed, 141 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/045b2e48/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index aee0f8e..1ad7195 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -31,12 +31,40 @@ package clownfish
 #include "Clownfish/LockFreeRegistry.h"
 #include "Clownfish/Method.h"
 
+extern void
+GoCfish_PanicErr_internal(cfish_Err *error);
+typedef void
+(*cfish_Err_do_throw_t)(cfish_Err *error);
+extern cfish_Err_do_throw_t GoCfish_PanicErr;
+
+extern cfish_Err*
+GoCfish_TrapErr_internal(CFISH_Err_Attempt_t routine, void *context);
+typedef cfish_Err*
+(*cfish_Err_trap_t)(CFISH_Err_Attempt_t routine, void *context);
+extern cfish_Err_trap_t GoCfish_TrapErr;
+
+// C symbols linked into a Go-built package archive are not visible to
+// external C code -- but internal code *can* see symbols from outside.
+// This allows us to fake up symbol export by assigning values only known
+// interally to external symbols during Go package initialization.
+static CHY_INLINE void
+GoCfish_glue_exported_symbols() {
+	GoCfish_PanicErr = GoCfish_PanicErr_internal;
+	GoCfish_TrapErr  = GoCfish_TrapErr_internal;
+}
+
+static CHY_INLINE void
+GoCfish_RunRoutine(CFISH_Err_Attempt_t routine, void *context) {
+	routine(context);
+}
+
 */
 import "C"
 import "runtime"
 import "unsafe"
 
 func init() {
+	C.GoCfish_glue_exported_symbols()
 	C.cfish_bootstrap_parcel()
 }
 
@@ -108,3 +136,59 @@ func CFStringToGo(ptr unsafe.Pointer) string {
 	size := C.int(C.CFISH_Str_Get_Size(cfString))
 	return C.GoStringN(data, size)
 }
+
+// TODO: Err should be an interface.
+func NewError(mess string) error {
+	str := C.CString(mess)
+	len := C.size_t(len(mess))
+	messC := C.cfish_Str_new_steal_utf8(str, len)
+	obj := &Err{C.cfish_Err_new(messC)}
+	runtime.SetFinalizer(obj, (*Err).callDecRef)
+	return obj
+}
+
+func (obj *Err) callDecRef() {
+	C.CFISH_Err_Dec_RefCount(obj.ref)
+	obj.ref = nil
+}
+
+func (obj *Err) Error() string {
+	return CFStringToGo(unsafe.Pointer(C.CFISH_Err_Get_Mess(obj.ref)))
+}
+
+//export GoCfish_PanicErr_internal
+func GoCfish_PanicErr_internal(cfErr *C.cfish_Err) {
+	goErr := &Err{cfErr}
+	C.CFISH_Err_Inc_RefCount(cfErr)
+	runtime.SetFinalizer(goErr, (*Err).callDecRef)
+	panic(goErr)
+}
+
+//export GoCfish_TrapErr_internal
+func GoCfish_TrapErr_internal(routine C.CFISH_Err_Attempt_t,
+	context unsafe.Pointer) *C.cfish_Err {
+	err := TrapErr(func() { C.GoCfish_RunRoutine(routine, context) } )
+	if err != nil {
+		return (err.(*Err)).ref
+	}
+	return nil
+}
+
+// Run the supplied routine, and if it panics with a *clownfish.Err, trap and
+// return it.
+func TrapErr(routine func()) (trapped error) {
+	defer func() {
+		if r := recover(); r != nil {
+			// TODO: pass whitelist of Err types to trap.
+			myErr, ok := r.(*Err)
+			if ok {
+				trapped = myErr
+			} else {
+				// re-panic
+				panic(r)
+			}
+		}
+	}()
+	routine()
+	return trapped
+}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/045b2e48/runtime/go/clownfish/err_test.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/err_test.go b/runtime/go/clownfish/err_test.go
new file mode 100644
index 0000000..060cf1e
--- /dev/null
+++ b/runtime/go/clownfish/err_test.go
@@ -0,0 +1,42 @@
+/* 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.
+ */
+
+package clownfish_test
+
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+import "testing"
+import "errors"
+
+func TestTrapErr(t *testing.T) {
+	err := clownfish.TrapErr(
+		func() { panic(clownfish.NewError("mistakes were made")) },
+	)
+	if err == nil {
+		t.Error("Failed to trap *clownfish.Err")
+	}
+}
+
+func TestTrapErr_no_trap_string(t *testing.T) {
+	defer func() { recover() }()
+	clownfish.TrapErr(func() { panic("foo") })
+	t.Error("Trapped plain string") // shouldn't reach here
+}
+
+func TestTrapErr_no_trap_error(t *testing.T) {
+	defer func() { recover() }()
+	clownfish.TrapErr(func() { panic(errors.New("foo")) })
+	t.Error("Trapped non-clownfish.Error error type") // shouldn't reach here
+}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/045b2e48/runtime/go/ext/clownfish.c
----------------------------------------------------------------------
diff --git a/runtime/go/ext/clownfish.c b/runtime/go/ext/clownfish.c
index a66d0a6..1ae5c76 100644
--- a/runtime/go/ext/clownfish.c
+++ b/runtime/go/ext/clownfish.c
@@ -21,7 +21,6 @@
 #define C_CFISH_ERR
 #define C_CFISH_LOCKFREEREGISTRY
 
-#include <setjmp.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -36,6 +35,11 @@
 #include "Clownfish/VArray.h"
 #include "Clownfish/LockFreeRegistry.h"
 
+/* These symbols must be assigned real values during Go initialization,
+ * which we'll confirm in Err_init().  */
+void (*GoCfish_PanicErr)(Err *error);
+Err* (*GoCfish_TrapErr)(Err_Attempt_t routine, void *context);
+
 /******************************** Obj **************************************/
 
 uint32_t
@@ -137,11 +141,17 @@ Method_Host_Name_IMP(Method *self) {
 
 /* TODO: Thread safety */
 static Err *current_error;
-static Err *thrown_error;
-static jmp_buf  *current_env;
 
 void
 Err_init_class(void) {
+    if (GoCfish_PanicErr == NULL
+        || GoCfish_TrapErr == NULL
+       ) {
+        fprintf(stderr, "Error at file %s line %d: Unexpected internal "
+            "failure to initialize functions during bootstrapping\n",
+            __FILE__, __LINE__);
+        exit(1);
+    }
 }
 
 Err*
@@ -159,17 +169,7 @@ Err_set_error(Err *error) {
 
 void
 Err_do_throw(Err *error) {
-    if (current_env) {
-        thrown_error = error;
-        longjmp(*current_env, 1);
-    }
-    else {
-        String *message = Err_Get_Mess(error);
-        char *utf8 = Str_To_Utf8(message);
-        fprintf(stderr, "%s", utf8);
-        FREEMEM(utf8);
-        exit(EXIT_FAILURE);
-    }
+    GoCfish_PanicErr(error);
 }
 
 void*
@@ -196,19 +196,7 @@ Err_warn_mess(String *message) {
 
 Err*
 Err_trap(Err_Attempt_t routine, void *context) {
-    jmp_buf  env;
-    jmp_buf *prev_env = current_env;
-    current_env = &env;
-
-    if (!setjmp(env)) {
-        routine(context);
-    }
-
-    current_env = prev_env;
-
-    Err *error = thrown_error;
-    thrown_error = NULL;
-    return error;
+    return GoCfish_TrapErr(routine, context);
 }
 
 /************************** LockFreeRegistry *******************************/


[09/20] lucy-clownfish git commit: Provide Go access to CFCBindCore and CFCC.

Posted by ma...@apache.org.
Provide Go access to CFCBindCore and CFCC.


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

Branch: refs/heads/go_bindings_2
Commit: d196ffdee24256a7a214275f7e2779d46a990ec3
Parents: db4f76e
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 17:09:55 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:55 2014 -0800

----------------------------------------------------------------------
 compiler/go/cfc/cfc.go | 72 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d196ffde/compiler/go/cfc/cfc.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go
index b46fafe..6533a0a 100644
--- a/compiler/go/cfc/cfc.go
+++ b/compiler/go/cfc/cfc.go
@@ -34,6 +34,14 @@ type Hierarchy struct {
 	ref *C.CFCHierarchy
 }
 
+type BindCore struct {
+	ref *C.CFCBindCore
+}
+
+type BindC struct {
+	ref *C.CFCC
+}
+
 func NewHierarchy(dest string) Hierarchy {
 	destCString := C.CString(dest)
 	defer C.free(unsafe.Pointer(destCString))
@@ -49,3 +57,67 @@ func (obj *Hierarchy) RunDecRef() {
 func (obj *Hierarchy) Build() {
 	C.CFCHierarchy_build(obj.ref)
 }
+
+func (obj Hierarchy) AddSourceDir(dir string) {
+	dirCString := C.CString(dir)
+	defer C.free(unsafe.Pointer(dirCString))
+	C.CFCHierarchy_add_source_dir(obj.ref, dirCString)
+}
+
+func (obj Hierarchy) AddIncludeDir(dir string) {
+	dirCString := C.CString(dir)
+	defer C.free(unsafe.Pointer(dirCString))
+	C.CFCHierarchy_add_include_dir(obj.ref, dirCString)
+}
+
+func (obj Hierarchy) WriteLog() {
+	C.CFCHierarchy_write_log(obj.ref)
+}
+
+func NewBindCore(hierarchy Hierarchy, header string, footer string) BindCore {
+	headerCString := C.CString(header)
+	footerCString := C.CString(footer)
+	defer C.free(unsafe.Pointer(headerCString))
+	defer C.free(unsafe.Pointer(footerCString))
+	obj := BindCore{
+		C.CFCBindCore_new(hierarchy.ref, headerCString, footerCString),
+	}
+	runtime.SetFinalizer(&obj, (*BindCore).RunDecRef)
+	return obj
+}
+
+func (obj BindCore) RunDecRef() {
+	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
+}
+
+func (obj BindCore) WriteAllModified(modified bool) bool {
+	var mod C.int = 0
+	if modified {
+		mod = 1
+	}
+	return C.CFCBindCore_write_all_modified(obj.ref, mod) != 0
+}
+
+func NewBindC(hierarchy Hierarchy, header string, footer string) BindC {
+	headerCString := C.CString(header)
+	footerCString := C.CString(footer)
+	defer C.free(unsafe.Pointer(headerCString))
+	defer C.free(unsafe.Pointer(footerCString))
+	obj := BindC{
+		C.CFCC_new(hierarchy.ref, headerCString, footerCString),
+	}
+	runtime.SetFinalizer(&obj, (*BindC).RunDecRef)
+	return obj
+}
+
+func (obj BindC) RunDecRef() {
+	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
+}
+
+func (obj BindC) WriteCallbacks() {
+	C.CFCC_write_callbacks(obj.ref)
+}
+
+func (obj BindC) WriteHostDefs() {
+	C.CFCC_write_hostdefs(obj.ref)
+}


[13/20] lucy-clownfish git commit: Regen Charmonizer for Go bindings.

Posted by ma...@apache.org.
Regen Charmonizer 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/53b7c28a
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/53b7c28a
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/53b7c28a

Branch: refs/heads/go_bindings_2
Commit: 53b7c28acf3bad68b4863396ef113f0d9cc2f649
Parents: b5bd352
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 20:56:37 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/common/charmonizer.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/53b7c28a/runtime/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.c b/runtime/common/charmonizer.c
index 133494b..ebae413 100644
--- a/runtime/common/charmonizer.c
+++ b/runtime/common/charmonizer.c
@@ -7777,12 +7777,17 @@ int main(int argc, const char **argv) {
     /* Initialize. */
     chaz_CLI *cli
         = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment");
+    chaz_CLI_register(cli, "host", "specify host binding language",
+                      CHAZ_CLI_ARG_REQUIRED);
     chaz_CLI_register(cli, "disable-threads", "whether to disable threads",
                       CHAZ_CLI_NO_ARG);
     chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]");
     if (!chaz_Probe_parse_cli_args(argc, argv, cli)) {
         chaz_Probe_die_usage();
     }
+    if (!chaz_CLI_defined(cli, "host")) {
+        chaz_CLI_set(cli, "host", "c");
+    }
     chaz_Probe_init(cli);
     S_add_compiler_flags(cli);
 
@@ -7915,7 +7920,16 @@ cfish_MakeFile_new(chaz_CLI *cli) {
     self->autogen_target
         = chaz_Util_join(dir_sep, "autogen", "hierarchy.json", NULL);
 
-    if (chaz_CLI_defined(cli, "enable-perl")) {
+    if (strcmp(chaz_CLI_strval(cli, "host"), "go") == 0) {
+        static const char *go_autogen_src_files[] = {
+            "cfish_parcel",
+            "testcfish_parcel",
+            NULL
+        };
+        self->host_src_dir = "ext";
+        self->autogen_src_files = go_autogen_src_files;
+    }
+    else if (chaz_CLI_defined(cli, "enable-perl")) {
         static const char *perl_autogen_src_files[] = {
             "boot",
             "callbacks",
@@ -7938,7 +7952,7 @@ cfish_MakeFile_new(chaz_CLI *cli) {
 
     self->shared_lib = chaz_Lib_new("cfish", chaz_Lib_SHARED, cfish_version,
                                     cfish_major_version);
-    self->static_lib = chaz_Lib_new("cfish", chaz_Lib_STATIC, cfish_version,
+    self->static_lib = chaz_Lib_new("clownfish", chaz_Lib_STATIC, cfish_version,
                                     cfish_major_version);
     self->shared_lib_filename = chaz_Lib_filename(self->shared_lib);
     self->static_lib_filename = chaz_Lib_filename(self->static_lib);
@@ -8030,12 +8044,10 @@ cfish_MakeFile_write(cfish_MakeFile *self) {
 
     /* Rules */
 
-    scratch = chaz_Util_join(" ", self->shared_lib_filename,
-                             self->static_lib_filename, NULL);
-    chaz_MakeFile_add_rule(self->makefile, "all", scratch);
-    free(scratch);
+    chaz_MakeFile_add_rule(self->makefile, "all", self->shared_lib_filename);
+    chaz_MakeFile_add_rule(self->makefile, "static", self->static_lib_filename);
 
-    if (!chaz_CLI_defined(self->cli, "enable-perl")) {
+    if (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) {
         cfish_MakeFile_write_c_cfc_rules(self);
     }
 


[08/20] lucy-clownfish git commit: Add INSTALL doc for Go CFC bindings.

Posted by ma...@apache.org.
Add INSTALL doc for Go CFC 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/8e24d26e
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/8e24d26e
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/8e24d26e

Branch: refs/heads/go_bindings_2
Commit: 8e24d26e7c95cd55813b512380848572eca9d10d
Parents: d196ffd
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 17:13:55 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:55 2014 -0800

----------------------------------------------------------------------
 compiler/go/INSTALL | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8e24d26e/compiler/go/INSTALL
----------------------------------------------------------------------
diff --git a/compiler/go/INSTALL b/compiler/go/INSTALL
new file mode 100644
index 0000000..3d44031
--- /dev/null
+++ b/compiler/go/INSTALL
@@ -0,0 +1,20 @@
+Apache Clownfish symbiotic object system -- CFC compiler Go bindings
+--------------------------------------------------------------------
+
+These are temporary installation instructions for developers working on the
+Apache Clownfish Go (golang) bindings.
+
+Make sure you have your GOPATH set, then clone the Clownfish git repository.
+
+    mkdir -p $GOPATH/src/git-wip-us.apache.org/repos/asf
+    cd $GOPATH/src/git-wip-us.apache.org/repos/asf
+    git clone https://git-wip-us.apache.org/repos/asf/lucy-clownfish.git lucy-clownfish.git
+    cd lucy-clownfish.git/compiler/go
+
+From the `compiler/go` directory within the checkout, run `build.go`:
+
+    go run build.go
+    go run build.go test
+    go run build.go install
+    go run build.go clean
+


[16/20] lucy-clownfish git commit: Remove unnecessary hostSrcDir from build.go.

Posted by ma...@apache.org.
Remove unnecessary hostSrcDir from build.go.

This commit will be consolidated away before merging to master.


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

Branch: refs/heads/go_bindings_2
Commit: 80154f6b853ec3e7c5cb3b10e7acaee603e8fdce
Parents: e7c9382
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 21:04:53 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/go/build.go | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/80154f6b/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index 8f19e4d..a82cc36 100644
--- a/runtime/go/build.go
+++ b/runtime/go/build.go
@@ -37,7 +37,6 @@ var charmonizerC string = "../common/charmonizer.c"
 var charmonizerEXE string = "charmonizer"
 var charmonyH string = "charmony.h"
 var buildDir string
-var hostSrcDir string
 var buildGO string
 var configGO string
 var installedLibPath string
@@ -45,7 +44,6 @@ var installedLibPath string
 func init() {
 	_, buildGO, _, _ = runtime.Caller(1)
 	buildDir = path.Dir(buildGO)
-	hostSrcDir = path.Join(buildDir, "ext")
 	configGO = path.Join(buildDir, "clownfish", "config.go")
 	var err error
 	installedLibPath, err = cfc.InstalledLibPath(packageName)
@@ -111,8 +109,7 @@ func configure() {
 	}
 	if !current(charmonizerEXE, charmonyH) {
 		runCommand("./charmonizer", "--cc=cc", "--enable-c", "--host=go",
-			"--host-src=" + hostSrcDir, "--enable-makefile",
-			"--", "-std=gnu99", "-O2")
+			"--enable-makefile", "--", "-std=gnu99", "-O2")
 	}
 }
 


[03/20] lucy-clownfish git commit: Add a missing incref.

Posted by ma...@apache.org.
Add a missing incref.

This fixes a potential segfault at teardown, when the class registry is
being emptied.


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

Branch: refs/heads/go_bindings_2
Commit: 87b63a8cc8acb015834469b18d4956bca396eebf
Parents: 93ce926
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 11 15:08:42 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:54 2014 -0800

----------------------------------------------------------------------
 compiler/src/CFCMethod.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87b63a8c/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCMethod.c b/compiler/src/CFCMethod.c
index 2a1bba1..ee5cb29 100644
--- a/compiler/src/CFCMethod.c
+++ b/compiler/src/CFCMethod.c
@@ -255,7 +255,8 @@ CFCMethod_finalize(CFCMethod *self) {
                         self->function.param_list,
                         self->function.docucomment, true,
                         self->is_abstract);
-    finalized->novel_method = self->novel_method;
+    finalized->novel_method
+        = (CFCMethod*)CFCBase_incref((CFCBase*)self->novel_method);
     finalized->is_novel     = self->is_novel;
     return finalized;
 }


[12/20] lucy-clownfish git commit: Install .cfh and static lib under $GOPATH/pkg.

Posted by ma...@apache.org.
Install .cfh and static lib under $GOPATH/pkg.

*   Install C static archive into $GOPATH/pkg/$PACKAGE/_lib/
*   Install .cfh headers into a main include directory, also under `pkg`.


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

Branch: refs/heads/go_bindings_2
Commit: 20fa9e7c9b21bab2db5a3a4b686b4d2ada298efd
Parents: b1ba382
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Nov 10 09:11:03 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 compiler/go/build.go   | 59 ++++++++++++++++++++++++++++++++++----
 compiler/go/cfc/cfc.go | 38 +++++++++++++++++++++++++
 runtime/go/build.go    | 69 +++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 158 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/20fa9e7c/compiler/go/build.go
----------------------------------------------------------------------
diff --git a/compiler/go/build.go b/compiler/go/build.go
index d4a585b..80612f5 100644
--- a/compiler/go/build.go
+++ b/compiler/go/build.go
@@ -20,11 +20,13 @@ package main
 
 import "flag"
 import "fmt"
+import "io"
 import "io/ioutil"
 import "log"
 import "os"
 import "os/exec"
 import "path"
+import "path/filepath"
 import "runtime"
 
 var packageName string = "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/compiler/go/cfc"
@@ -34,11 +36,24 @@ var charmonyH string = "charmony.h"
 var buildDir string
 var buildGO string
 var configGO string
+var installDir string
+var cfIncludeDir string
 
 func init() {
 	_, buildGO, _, _ = runtime.Caller(1)
 	buildDir = path.Dir(buildGO)
 	configGO = path.Join(buildDir, "cfc", "config.go")
+
+	// Compute include dir for clownfish headers.
+	goPathDirs := filepath.SplitList(os.Getenv("GOPATH"))
+	if len(goPathDirs) == 0 {
+		log.Fatal("GOPATH environment variable not set")
+	}
+	commonDir := path.Join(goPathDirs[0], "pkg",
+		runtime.GOOS+"_"+runtime.GOARCH, "git-wip-us.apache.org", "repos",
+		"asf", "lucy-clownfish.git")
+	cfIncludeDir = path.Join(commonDir, "_include")
+	installDir = path.Join(commonDir, "compiler", "go", "cfc")
 }
 
 func main() {
@@ -118,23 +133,57 @@ func test() {
 	runCommand("go", "test", packageName)
 }
 
+func makePath(dir string) {
+	if _, err := os.Stat(dir); os.IsNotExist(err) {
+		err = os.MkdirAll(dir, 0755)
+		if err != nil {
+			log.Fatalf("Can't create dir '%s': %s", dir, err)
+		}
+	}
+}
+
+func copyFile(source, dest string) {
+	sourceFH, err := os.Open(source)
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer sourceFH.Close()
+	destFH, err := os.Create(dest)
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer destFH.Close()
+	_, err = io.Copy(destFH, sourceFH)
+	if err != nil {
+		log.Fatalf("io.Copy from %s to %s failed: %s", source, dest, err)
+	}
+}
+
 func install() {
 	prep()
 	runCommand("go", "install", packageName)
+	makePath(cfIncludeDir)
+	installedLibDir := path.Join(installDir, "_lib")
+	makePath(installedLibDir)
+	installedLibPath := path.Join(installedLibDir, "libcfc.a")
+	copyFile("libcfc.a", installedLibPath)
 }
 
 func writeConfigGO() {
 	if current(buildGO, configGO) {
 		return
 	}
-	libPath := path.Join(buildDir, "libcfc.a")
+	installedLibDir := path.Join(installDir, "_lib")
 	content := fmt.Sprintf(
-		"// Auto-generated by build.go, specifying absolute path to static lib.\n"+
+		"// Auto-generated by build.go\n"+
 			"package cfc\n"+
 			"// #cgo CFLAGS: -I%s/../include -I%s/../src -I%s\n"+
-			"// #cgo LDFLAGS: %s\n"+
-			"import \"C\"\n",
-		buildDir, buildDir, buildDir, libPath)
+			"// #cgo LDFLAGS: -L%s\n"+
+			"// #cgo LDFLAGS: -L%s\n"+
+			"// #cgo LDFLAGS: -lcfc\n"+
+			"import \"C\"\n"+
+			"var mainIncDir string = \"%s\"\n",
+		buildDir, buildDir, buildDir, buildDir, installedLibDir, cfIncludeDir)
 	ioutil.WriteFile(configGO, []byte(content), 0666)
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/20fa9e7c/compiler/go/cfc/cfc.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go
index 6533a0a..fb38bfb 100644
--- a/compiler/go/cfc/cfc.go
+++ b/compiler/go/cfc/cfc.go
@@ -22,9 +22,46 @@ package cfc
 // #include <stdlib.h>
 import "C"
 
+import "os"
+import "path"
+import "path/filepath"
 import "runtime"
+import "strings"
 import "unsafe"
 
+// Return the path of the main include directory holding clownfish parcel and
+// header files.
+func MainIncludeDir() string {
+	return mainIncDir
+}
+
+type CFCError struct {
+	mess string
+}
+
+func (e CFCError) Error() string {
+	return e.mess
+}
+
+// Given a package name for a Clownfish parcel with Go bindings, return the
+// install path for its C static archive.
+//
+// TODO: It would be better if we could embed the C archive contents within
+// the installed Go archive.
+func InstalledLibPath(packageName string) (string, error) {
+	goPathDirs := filepath.SplitList(os.Getenv("GOPATH"))
+	if len(goPathDirs) == 0 {
+		return "", CFCError{"GOPATH environment variable not set"}
+	}
+	packageParts := strings.Split(packageName, "/")
+	filename := "lib" + packageParts[len(packageParts)-1] + ".a"
+	parts := []string{goPathDirs[0], "pkg"}
+	parts = append(parts, runtime.GOOS+"_"+runtime.GOARCH)
+	parts = append(parts, packageParts...)
+	parts = append(parts, "_lib", filename)
+	return path.Join(parts...), nil
+}
+
 func DoStuff() {
 	hierarchy := NewHierarchy("autogen")
 	hierarchy.Build()
@@ -46,6 +83,7 @@ func NewHierarchy(dest string) Hierarchy {
 	destCString := C.CString(dest)
 	defer C.free(unsafe.Pointer(destCString))
 	obj := Hierarchy{C.CFCHierarchy_new(destCString)}
+	obj.AddIncludeDir(mainIncDir)
 	runtime.SetFinalizer(&obj, (*Hierarchy).RunDecRef)
 	return obj
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/20fa9e7c/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index 1b24831..d05113d 100644
--- a/runtime/go/build.go
+++ b/runtime/go/build.go
@@ -20,11 +20,14 @@ package main
 
 import "flag"
 import "fmt"
+import "io"
 import "io/ioutil"
 import "log"
 import "os"
 import "os/exec"
 import "path"
+import "path/filepath"
+import "strings"
 import "runtime"
 
 import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/compiler/go/cfc"
@@ -37,12 +40,18 @@ var buildDir string
 var hostSrcDir string
 var buildGO string
 var configGO string
+var installedLibPath string
 
 func init() {
 	_, buildGO, _, _ = runtime.Caller(1)
 	buildDir = path.Dir(buildGO)
 	hostSrcDir = path.Join(buildDir, "../c/src")
 	configGO = path.Join(buildDir, "clownfish", "config.go")
+	var err error
+	installedLibPath, err = cfc.InstalledLibPath(packageName)
+	if err != nil {
+		log.Fatal(err)
+	}
 }
 
 func main() {
@@ -127,6 +136,7 @@ func prep() {
 	runCFC()
 	runCommand("make", "-j", "static")
 	writeConfigGO()
+	runCommand("go", "build", packageName)
 }
 
 func build() {
@@ -139,25 +149,78 @@ func test() {
 	runCommand("go", "test", packageName)
 }
 
+func copyFile(source, dest string) {
+	sourceFH, err := os.Open(source)
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer sourceFH.Close()
+	destFH, err := os.Create(dest)
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer destFH.Close()
+	_, err = io.Copy(destFH, sourceFH)
+	if err != nil {
+		log.Fatalf("io.Copy from %s to %s failed: %s", source, dest, err)
+	}
+}
+
+func installHeaders() {
+	coreDir := "../core"
+	incDir := cfc.MainIncludeDir()
+	doInstall := func(source string, info os.FileInfo, err error) error {
+		if strings.HasSuffix(source, ".cfp") || strings.HasSuffix(source, ".cfh") {
+			dest := path.Join(incDir, strings.TrimPrefix(source, coreDir))
+			destDir := path.Dir(dest)
+			if _, err := os.Stat(destDir); os.IsNotExist(err) {
+				err = os.MkdirAll(destDir, 0755)
+				if err != nil {
+					log.Fatalf("Can't create dir '%s': %s", destDir, err)
+				}
+			}
+			os.Remove(dest)
+			copyFile(source, dest)
+		}
+		return nil
+	}
+	filepath.Walk("../core", doInstall)
+}
+
+func installStaticLib() {
+	tempLibPath := path.Join(buildDir, "libclownfish.a")
+	destDir := path.Dir(installedLibPath)
+	if _, err := os.Stat(destDir); os.IsNotExist(err) {
+		err = os.MkdirAll(destDir, 0755)
+		if err != nil {
+			log.Fatalf("Can't create dir '%s': %s", destDir, err)
+		}
+	}
+	os.Remove(installedLibPath)
+	copyFile(tempLibPath, installedLibPath)
+}
+
 func install() {
 	prep()
 	runCommand("go", "install", packageName)
+	installHeaders()
+	installStaticLib()
 }
 
 func writeConfigGO() {
 	if current(buildGO, configGO) {
 		return
 	}
-	libPath := path.Join(buildDir, "libcfish.a")
 	content := fmt.Sprintf(
 		"// Auto-generated by build.go, specifying absolute path to static lib.\n"+
 			"package clownfish\n"+
 			"// #cgo CFLAGS: -I%s/../core\n"+
 			"// #cgo CFLAGS: -I%s\n"+
 			"// #cgo CFLAGS: -I%s/autogen/include\n"+
-			"// #cgo LDFLAGS: %s\n"+
+			"// #cgo LDFLAGS: -L%s\n"+
+			"// #cgo LDFLAGS: -lclownfish\n"+
 			"import \"C\"\n",
-		buildDir, buildDir, buildDir, libPath)
+		buildDir, buildDir, buildDir, buildDir)
 	ioutil.WriteFile(configGO, []byte(content), 0666)
 }
 


[06/20] lucy-clownfish git commit: Regen charmonizer for CFC static lib.

Posted by ma...@apache.org.
Regen charmonizer for CFC static lib.


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

Branch: refs/heads/go_bindings_2
Commit: 93ce926d51ed6654537a47e8a8fa3fa02f1b328a
Parents: 783e852
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 14:07:12 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:54 2014 -0800

----------------------------------------------------------------------
 compiler/common/charmonizer.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/93ce926d/compiler/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.c b/compiler/common/charmonizer.c
index 2a24d21..7d0f18c 100644
--- a/compiler/common/charmonizer.c
+++ b/compiler/common/charmonizer.c
@@ -7706,8 +7706,12 @@ chaz_VariadicMacros_run(void) {
 typedef struct SourceFileContext {
     chaz_MakeVar *common_objs;
     chaz_MakeVar *test_cfc_objs;
+    chaz_MakeVar *common_test_objs;
 } SourceFileContext;
 
+static const char cfc_version[]       = "0.4.0";
+static const char cfc_major_version[] = "0.4";
+
 static void
 S_add_compiler_flags(struct chaz_CLI *cli);
 
@@ -7721,6 +7725,8 @@ int main(int argc, const char **argv) {
     /* Initialize. */
     chaz_CLI *cli
         = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment");
+    chaz_CLI_register(cli, "host", "specify host binding language",
+                      CHAZ_CLI_ARG_REQUIRED);
     chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]");
     {
         int result = chaz_Probe_parse_cli_args(argc, argv, cli);
@@ -7796,6 +7802,17 @@ S_add_compiler_flags(struct chaz_CLI *cli) {
 }
 
 static void
+S_add_staticlib_makefile_target(chaz_MakeFile *makefile) {
+    chaz_Lib *static_lib = chaz_Lib_new("cfc", chaz_Lib_STATIC, cfc_version,
+                                        cfc_major_version);
+    char *static_lib_filename = chaz_Lib_filename(static_lib);
+    chaz_MakeFile_add_rule(makefile, "static", static_lib_filename);
+    chaz_MakeFile_add_static_lib(makefile, static_lib, "$(COMMON_OBJS)");
+    free(static_lib_filename);
+    chaz_Lib_destroy(static_lib);
+}
+
+static void
 S_write_makefile(struct chaz_CLI *cli) {
     SourceFileContext sfc;
 
@@ -7859,6 +7876,7 @@ S_write_makefile(struct chaz_CLI *cli) {
 
     sfc.common_objs   = chaz_MakeFile_add_var(makefile, "COMMON_OBJS", NULL);
     sfc.test_cfc_objs = chaz_MakeFile_add_var(makefile, "TEST_CFC_OBJS", NULL);
+    sfc.common_test_objs = chaz_MakeFile_add_var(makefile, "COMMON_TEST_OBJS", NULL);
 
     chaz_Make_list_files(src_dir, "c", S_source_file_callback, &sfc);
 
@@ -7877,6 +7895,7 @@ S_write_makefile(struct chaz_CLI *cli) {
     /* Rules */
 
     chaz_MakeFile_add_rule(makefile, "all", cfc_exe);
+    S_add_staticlib_makefile_target(makefile);
 
     chaz_MakeFile_add_lemon_exe(makefile, lemon_dir);
     chaz_MakeFile_add_lemon_grammar(makefile, parse_header);
@@ -7899,7 +7918,8 @@ S_write_makefile(struct chaz_CLI *cli) {
     chaz_MakeFile_add_exe(makefile, cfc_exe, "$(COMMON_OBJS) $(CFC_OBJS)",
                           link_flags);
     chaz_MakeFile_add_exe(makefile, test_cfc_exe,
-                          "$(COMMON_OBJS) $(TEST_CFC_OBJS)", link_flags);
+                          "$(COMMON_OBJS) $(COMMON_TEST_OBJS) $(TEST_CFC_OBJS)",
+                          link_flags);
     chaz_CFlags_destroy(link_flags);
 
     rule = chaz_MakeFile_add_rule(makefile, "test", test_cfc_exe);
@@ -7929,6 +7949,7 @@ S_write_makefile(struct chaz_CLI *cli) {
     clean_rule = chaz_MakeFile_clean_rule(makefile);
 
     chaz_MakeRule_add_rm_command(clean_rule, "$(COMMON_OBJS)");
+    chaz_MakeRule_add_rm_command(clean_rule, "$(COMMON_TEST_OBJS)");
     chaz_MakeRule_add_rm_command(clean_rule, "$(CFC_OBJS)");
     chaz_MakeRule_add_rm_command(clean_rule, "$(TEST_CFC_OBJS)");
 
@@ -7971,7 +7992,7 @@ S_source_file_callback(const char *dir, char *file, void *context) {
 
     obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL);
     if (strlen(file) >= 7 && memcmp(file, "CFCTest", 7) == 0) {
-        chaz_MakeVar_append(sfc->test_cfc_objs, obj_file);
+        chaz_MakeVar_append(sfc->common_test_objs, obj_file);
     }
     else {
         chaz_MakeVar_append(sfc->common_objs, obj_file);


[02/20] lucy-clownfish git commit: Add headers for C bindings to CFC.h.

Posted by ma...@apache.org.
Add headers for C bindings to CFC.h.


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

Branch: refs/heads/go_bindings_2
Commit: b7c1ca4b21d03caec24d6e11f5a9392ca866fca3
Parents: 87b63a8
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 15:13:35 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:54 2014 -0800

----------------------------------------------------------------------
 compiler/include/CFC.h | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b7c1ca4b/compiler/include/CFC.h
----------------------------------------------------------------------
diff --git a/compiler/include/CFC.h b/compiler/include/CFC.h
index 9a13607..d1eda29 100644
--- a/compiler/include/CFC.h
+++ b/compiler/include/CFC.h
@@ -34,6 +34,9 @@
 #include "CFCVariable.h"
 #include "CFCVersion.h"
 
+#include "CFCC.h"
+#include "CFCCClass.h"
+
 #include "CFCBindCore.h"
 #include "CFCBindAliases.h"
 #include "CFCBindClass.h"


[10/20] lucy-clownfish git commit: Add INSTALL for the Go runtime bindings.

Posted by ma...@apache.org.
Add INSTALL for the Go runtime 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/b1ba3821
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b1ba3821
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b1ba3821

Branch: refs/heads/go_bindings_2
Commit: b1ba38211c9b126384be82210e68963ced318ce2
Parents: 26a9f65
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 8 15:43:05 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/go/INSTALL | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b1ba3821/runtime/go/INSTALL
----------------------------------------------------------------------
diff --git a/runtime/go/INSTALL b/runtime/go/INSTALL
new file mode 100644
index 0000000..c5db488
--- /dev/null
+++ b/runtime/go/INSTALL
@@ -0,0 +1,19 @@
+Apache Clownfish symbiotic object system -- runtime Go bindings
+---------------------------------------------------------------
+
+These are temporary installation instructions for developers working on the
+Apache Clownfish Go bindings.
+
+As a prerequisite, install the Go bindings for the Clownfish compiler (CFC).
+This will entail cloning the Git repository which is shared by the runtime.
+
+    # After installing CFC, switch to the runtime/go directory.
+    cd $GOPATH/src/git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go
+
+From the `runtime/go` directory within the checkout, run `build.go`:
+
+    go run build.go
+    go run build.go test
+    go run build.go install
+    go run build.go clean
+


[17/20] lucy-clownfish git commit: Use `finalize` for finalizers.

Posted by ma...@apache.org.
Use `finalize` for finalizers.

*   Be consistent about defaulting to non-exported name.
*   Finalizers may do more than decref, so RunDecRef is misleading.


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

Branch: refs/heads/go_bindings_2
Commit: e7c9382ea56c2af02decf1770af8f73d804b194a
Parents: 045b2e4
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sun Nov 16 21:18:36 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 compiler/go/cfc/cfc.go            | 12 ++++++------
 runtime/go/clownfish/clownfish.go | 10 +++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e7c9382e/compiler/go/cfc/cfc.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go
index 92f0094..7c12a6c 100644
--- a/compiler/go/cfc/cfc.go
+++ b/compiler/go/cfc/cfc.go
@@ -84,11 +84,11 @@ func NewHierarchy(dest string) *Hierarchy {
 	defer C.free(unsafe.Pointer(destCString))
 	obj := &Hierarchy{C.CFCHierarchy_new(destCString)}
 	obj.AddIncludeDir(mainIncDir)
-	runtime.SetFinalizer(obj, (*Hierarchy).RunDecRef)
+	runtime.SetFinalizer(obj, (*Hierarchy).finalize)
 	return obj
 }
 
-func (obj *Hierarchy) RunDecRef() {
+func (obj *Hierarchy) finalize() {
 	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
 }
 
@@ -120,11 +120,11 @@ func NewBindCore(hierarchy *Hierarchy, header string, footer string) *BindCore {
 	obj := &BindCore{
 		C.CFCBindCore_new(hierarchy.ref, headerCString, footerCString),
 	}
-	runtime.SetFinalizer(obj, (*BindCore).RunDecRef)
+	runtime.SetFinalizer(obj, (*BindCore).finalize)
 	return obj
 }
 
-func (obj *BindCore) RunDecRef() {
+func (obj *BindCore) finalize() {
 	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
 }
 
@@ -144,11 +144,11 @@ func NewBindC(hierarchy *Hierarchy, header string, footer string) *BindC {
 	obj := &BindC{
 		C.CFCC_new(hierarchy.ref, headerCString, footerCString),
 	}
-	runtime.SetFinalizer(obj, (*BindC).RunDecRef)
+	runtime.SetFinalizer(obj, (*BindC).finalize)
 	return obj
 }
 
-func (obj *BindC) RunDecRef() {
+func (obj *BindC) finalize() {
 	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e7c9382e/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 1ad7195..c8860c1 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -110,11 +110,11 @@ func NewString(goString string) *String {
 	obj := &String{
 		C.cfish_Str_new_steal_utf8(str, len),
 	}
-	runtime.SetFinalizer(obj, (*String).callDecRef)
+	runtime.SetFinalizer(obj, (*String).finalize)
 	return obj
 }
 
-func (obj *String) callDecRef() {
+func (obj *String) finalize() {
 	C.CFISH_Str_Dec_RefCount(obj.ref)
 	obj.ref = nil
 }
@@ -143,11 +143,11 @@ func NewError(mess string) error {
 	len := C.size_t(len(mess))
 	messC := C.cfish_Str_new_steal_utf8(str, len)
 	obj := &Err{C.cfish_Err_new(messC)}
-	runtime.SetFinalizer(obj, (*Err).callDecRef)
+	runtime.SetFinalizer(obj, (*Err).finalize)
 	return obj
 }
 
-func (obj *Err) callDecRef() {
+func (obj *Err) finalize() {
 	C.CFISH_Err_Dec_RefCount(obj.ref)
 	obj.ref = nil
 }
@@ -160,7 +160,7 @@ func (obj *Err) Error() string {
 func GoCfish_PanicErr_internal(cfErr *C.cfish_Err) {
 	goErr := &Err{cfErr}
 	C.CFISH_Err_Inc_RefCount(cfErr)
-	runtime.SetFinalizer(goErr, (*Err).callDecRef)
+	runtime.SetFinalizer(goErr, (*Err).finalize)
 	panic(goErr)
 }
 


[15/20] lucy-clownfish git commit: Add Go wrappers for Clownfish basic types.

Posted by ma...@apache.org.
Add Go wrappers for Clownfish basic types.


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

Branch: refs/heads/go_bindings_2
Commit: 26a9f65f617ab2711eba6dba186fb32bae824a53
Parents: 047d52d
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Nov 5 10:58:27 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/go/clownfish/clownfish.go      | 73 +++++++++++++++++++++++++++--
 runtime/go/clownfish/clownfish_test.go |  6 ++-
 2 files changed, 74 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/26a9f65f/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 5ed0b8c..7f4db15 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -33,13 +33,78 @@ package clownfish
 
 */
 import "C"
+import "runtime"
+import "unsafe"
 
 func init() {
 	C.cfish_bootstrap_parcel()
 }
 
-// Temporary test-only routine.
-func DoStuff() {
-	hash := C.cfish_Hash_new(C.uint32_t(0))
-	C.CFISH_Hash_Dec_RefCount(hash)
+type Obj interface {
+	ToPtr() unsafe.Pointer
+}
+
+type Err struct {
+	ref *C.cfish_Err
+}
+
+type String struct {
+	ref *C.cfish_String
+}
+
+type ByteBuf struct {
+	ref *C.cfish_ByteBuf
+}
+
+type Hash struct {
+	ref *C.cfish_Hash
+}
+
+type VArray struct {
+	ref *C.cfish_VArray
+}
+
+type Class struct {
+	ref *C.cfish_Class
+}
+
+type Method struct {
+	ref *C.cfish_Method
+}
+
+type LockFreeRegistry struct {
+	ref *C.cfish_LockFreeRegistry
+}
+
+func NewString(goString string) String {
+	str := C.CString(goString)
+	len := C.size_t(len(goString))
+	obj := String{
+		C.cfish_Str_new_steal_utf8(str, len),
+	}
+	runtime.SetFinalizer(&obj, (*String).callDecRef)
+	return obj
+}
+
+func (obj *String) callDecRef() {
+	C.CFISH_Str_Dec_RefCount(obj.ref)
+	obj.ref = nil
+}
+
+func (obj *String) ToPtr() unsafe.Pointer {
+	return unsafe.Pointer(obj.ref)
+}
+
+func CFStringToGo(ptr unsafe.Pointer) string {
+	cfString := (*C.cfish_String)(ptr);
+	if cfString == nil {
+		return ""
+	}
+	if !C.CFISH_Str_Is_A(cfString, C.CFISH_STRING) {
+		cfString := C.CFISH_Str_To_String(cfString)
+		defer C.CFISH_Str_Dec_RefCount(cfString)
+	}
+	data := C.CFISH_Str_Get_Ptr8(cfString)
+	size := C.int(C.CFISH_Str_Get_Size(cfString))
+	return C.GoStringN(data, size)
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/26a9f65f/runtime/go/clownfish/clownfish_test.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish_test.go b/runtime/go/clownfish/clownfish_test.go
index 3872b92..1709dfc 100644
--- a/runtime/go/clownfish/clownfish_test.go
+++ b/runtime/go/clownfish/clownfish_test.go
@@ -20,5 +20,9 @@ import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
 import "testing"
 
 func TestStuff(t *testing.T) {
-	clownfish.DoStuff()
+	cfString := clownfish.NewString("foo")
+	goString := clownfish.CFStringToGo(cfString.ToPtr())
+	if goString != "foo" {
+		t.Error("Round-tripping strings failed")
+	}
 }


[14/20] lucy-clownfish git commit: Use struct pointers for Clownfish Go host objects.

Posted by ma...@apache.org.
Use struct pointers for Clownfish Go host objects.

Be consistent about passing around Clownfish Go host objects by
reference rather than by value.


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

Branch: refs/heads/go_bindings_2
Commit: 28c63650151f284d599849824b60a8cbfe7dd455
Parents: 20fa9e7
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Nov 12 17:23:34 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 compiler/go/cfc/cfc.go            | 34 +++++++++++++++++-----------------
 runtime/go/clownfish/clownfish.go |  6 +++---
 2 files changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/28c63650/compiler/go/cfc/cfc.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go
index fb38bfb..92f0094 100644
--- a/compiler/go/cfc/cfc.go
+++ b/compiler/go/cfc/cfc.go
@@ -79,12 +79,12 @@ type BindC struct {
 	ref *C.CFCC
 }
 
-func NewHierarchy(dest string) Hierarchy {
+func NewHierarchy(dest string) *Hierarchy {
 	destCString := C.CString(dest)
 	defer C.free(unsafe.Pointer(destCString))
-	obj := Hierarchy{C.CFCHierarchy_new(destCString)}
+	obj := &Hierarchy{C.CFCHierarchy_new(destCString)}
 	obj.AddIncludeDir(mainIncDir)
-	runtime.SetFinalizer(&obj, (*Hierarchy).RunDecRef)
+	runtime.SetFinalizer(obj, (*Hierarchy).RunDecRef)
 	return obj
 }
 
@@ -96,39 +96,39 @@ func (obj *Hierarchy) Build() {
 	C.CFCHierarchy_build(obj.ref)
 }
 
-func (obj Hierarchy) AddSourceDir(dir string) {
+func (obj *Hierarchy) AddSourceDir(dir string) {
 	dirCString := C.CString(dir)
 	defer C.free(unsafe.Pointer(dirCString))
 	C.CFCHierarchy_add_source_dir(obj.ref, dirCString)
 }
 
-func (obj Hierarchy) AddIncludeDir(dir string) {
+func (obj *Hierarchy) AddIncludeDir(dir string) {
 	dirCString := C.CString(dir)
 	defer C.free(unsafe.Pointer(dirCString))
 	C.CFCHierarchy_add_include_dir(obj.ref, dirCString)
 }
 
-func (obj Hierarchy) WriteLog() {
+func (obj *Hierarchy) WriteLog() {
 	C.CFCHierarchy_write_log(obj.ref)
 }
 
-func NewBindCore(hierarchy Hierarchy, header string, footer string) BindCore {
+func NewBindCore(hierarchy *Hierarchy, header string, footer string) *BindCore {
 	headerCString := C.CString(header)
 	footerCString := C.CString(footer)
 	defer C.free(unsafe.Pointer(headerCString))
 	defer C.free(unsafe.Pointer(footerCString))
-	obj := BindCore{
+	obj := &BindCore{
 		C.CFCBindCore_new(hierarchy.ref, headerCString, footerCString),
 	}
-	runtime.SetFinalizer(&obj, (*BindCore).RunDecRef)
+	runtime.SetFinalizer(obj, (*BindCore).RunDecRef)
 	return obj
 }
 
-func (obj BindCore) RunDecRef() {
+func (obj *BindCore) RunDecRef() {
 	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
 }
 
-func (obj BindCore) WriteAllModified(modified bool) bool {
+func (obj *BindCore) WriteAllModified(modified bool) bool {
 	var mod C.int = 0
 	if modified {
 		mod = 1
@@ -136,26 +136,26 @@ func (obj BindCore) WriteAllModified(modified bool) bool {
 	return C.CFCBindCore_write_all_modified(obj.ref, mod) != 0
 }
 
-func NewBindC(hierarchy Hierarchy, header string, footer string) BindC {
+func NewBindC(hierarchy *Hierarchy, header string, footer string) *BindC {
 	headerCString := C.CString(header)
 	footerCString := C.CString(footer)
 	defer C.free(unsafe.Pointer(headerCString))
 	defer C.free(unsafe.Pointer(footerCString))
-	obj := BindC{
+	obj := &BindC{
 		C.CFCC_new(hierarchy.ref, headerCString, footerCString),
 	}
-	runtime.SetFinalizer(&obj, (*BindC).RunDecRef)
+	runtime.SetFinalizer(obj, (*BindC).RunDecRef)
 	return obj
 }
 
-func (obj BindC) RunDecRef() {
+func (obj *BindC) RunDecRef() {
 	C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
 }
 
-func (obj BindC) WriteCallbacks() {
+func (obj *BindC) WriteCallbacks() {
 	C.CFCC_write_callbacks(obj.ref)
 }
 
-func (obj BindC) WriteHostDefs() {
+func (obj *BindC) WriteHostDefs() {
 	C.CFCC_write_hostdefs(obj.ref)
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/28c63650/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 7f4db15..aee0f8e 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -76,13 +76,13 @@ type LockFreeRegistry struct {
 	ref *C.cfish_LockFreeRegistry
 }
 
-func NewString(goString string) String {
+func NewString(goString string) *String {
 	str := C.CString(goString)
 	len := C.size_t(len(goString))
-	obj := String{
+	obj := &String{
 		C.cfish_Str_new_steal_utf8(str, len),
 	}
-	runtime.SetFinalizer(&obj, (*String).callDecRef)
+	runtime.SetFinalizer(obj, (*String).callDecRef)
 	return obj
 }
 


[18/20] lucy-clownfish git commit: Start Go bindings for runtime.

Posted by ma...@apache.org.
Start Go bindings for runtime.


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

Branch: refs/heads/go_bindings_2
Commit: 047d52dc67ed91fb1e009e4f46173f7fe7a580a0
Parents: 53b7c28
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Nov 5 10:51:41 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 21:07:53 2014 -0800

----------------------------------------------------------------------
 runtime/go/build.go                    | 179 ++++++++++++++++++++++++++++
 runtime/go/clownfish/clownfish.go      |  45 +++++++
 runtime/go/clownfish/clownfish_test.go |  24 ++++
 3 files changed, 248 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/047d52dc/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
new file mode 100644
index 0000000..1b24831
--- /dev/null
+++ b/runtime/go/build.go
@@ -0,0 +1,179 @@
+/* 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.
+ */
+
+/* Build "script" for Apache Clownfish runtime.
+ */
+package main
+
+import "flag"
+import "fmt"
+import "io/ioutil"
+import "log"
+import "os"
+import "os/exec"
+import "path"
+import "runtime"
+
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/compiler/go/cfc"
+
+var packageName string = "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+var charmonizerC string = "../common/charmonizer.c"
+var charmonizerEXE string = "charmonizer"
+var charmonyH string = "charmony.h"
+var buildDir string
+var hostSrcDir string
+var buildGO string
+var configGO string
+
+func init() {
+	_, buildGO, _, _ = runtime.Caller(1)
+	buildDir = path.Dir(buildGO)
+	hostSrcDir = path.Join(buildDir, "../c/src")
+	configGO = path.Join(buildDir, "clownfish", "config.go")
+}
+
+func main() {
+	os.Chdir(buildDir)
+	flag.Parse()
+	action := "build"
+	args := flag.Args()
+	if len(args) > 0 {
+		action = args[0]
+	}
+	switch action {
+	case "build":
+		build()
+	case "clean":
+		clean()
+	case "test":
+		test()
+	case "install":
+		install()
+	default:
+		log.Fatalf("Unrecognized action specified: %s", action)
+	}
+}
+
+func current(orig, dest string) bool {
+	destInfo, err := os.Stat(dest)
+	if err != nil {
+		if os.IsNotExist(err) {
+			// If dest doesn't exist, we're not current.
+			return false
+		} else {
+			log.Fatalf("Unexpected stat err: %s", err)
+		}
+	}
+
+	// If source is newer than dest, we're not current.
+	origInfo, err := os.Stat(orig)
+	if err != nil {
+		log.Fatalf("Unexpected: %s", err)
+	}
+	return origInfo.ModTime().Before(destInfo.ModTime())
+}
+
+func runCommand(name string, args ...string) {
+	command := exec.Command(name, args...)
+	command.Stdout = os.Stdout
+	command.Stderr = os.Stderr
+	err := command.Run()
+	if err != nil {
+		log.Fatal(err)
+	}
+}
+
+func configure() {
+	if !current(charmonizerC, charmonizerEXE) {
+		runCommand("cc", "-o", charmonizerEXE, charmonizerC)
+	}
+	if !current(charmonizerEXE, charmonyH) {
+		runCommand("./charmonizer", "--cc=cc", "--enable-c", "--host=go",
+			"--host-src=" + hostSrcDir, "--enable-makefile",
+			"--", "-std=gnu99", "-O2")
+	}
+}
+
+func runCFC() {
+	hierarchy := cfc.NewHierarchy("autogen")
+	hierarchy.AddSourceDir("../core")
+	hierarchy.Build()
+	autogenHeader := "/* Auto-generated by build.go. */\n"
+	coreBinding := cfc.NewBindCore(hierarchy, autogenHeader, "")
+	modified := coreBinding.WriteAllModified(false)
+	if modified {
+		cBinding := cfc.NewBindC(hierarchy, autogenHeader, "")
+		cBinding.WriteCallbacks()
+		cBinding.WriteHostDefs()
+		hierarchy.WriteLog()
+	}
+}
+
+func prep() {
+	configure()
+	runCFC()
+	runCommand("make", "-j", "static")
+	writeConfigGO()
+}
+
+func build() {
+	prep()
+	runCommand("go", "build", packageName)
+}
+
+func test() {
+	prep()
+	runCommand("go", "test", packageName)
+}
+
+func install() {
+	prep()
+	runCommand("go", "install", packageName)
+}
+
+func writeConfigGO() {
+	if current(buildGO, configGO) {
+		return
+	}
+	libPath := path.Join(buildDir, "libcfish.a")
+	content := fmt.Sprintf(
+		"// Auto-generated by build.go, specifying absolute path to static lib.\n"+
+			"package clownfish\n"+
+			"// #cgo CFLAGS: -I%s/../core\n"+
+			"// #cgo CFLAGS: -I%s\n"+
+			"// #cgo CFLAGS: -I%s/autogen/include\n"+
+			"// #cgo LDFLAGS: %s\n"+
+			"import \"C\"\n",
+		buildDir, buildDir, buildDir, libPath)
+	ioutil.WriteFile(configGO, []byte(content), 0666)
+}
+
+func clean() {
+	if _, err := os.Stat(charmonizerEXE); os.IsNotExist(err) {
+		return
+	}
+	fmt.Println("Cleaning")
+	runCommand("make", "clean")
+	cleanables := []string{charmonizerEXE, charmonyH, "Makefile", configGO}
+	for _, file := range cleanables {
+		err := os.Remove(file)
+		if err == nil {
+			fmt.Println("Removing", file)
+		} else if !os.IsNotExist(err) {
+			log.Fatal(err)
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/047d52dc/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
new file mode 100644
index 0000000..5ed0b8c
--- /dev/null
+++ b/runtime/go/clownfish/clownfish.go
@@ -0,0 +1,45 @@
+/* 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.
+ */
+
+package clownfish
+
+/*
+
+#include "charmony.h"
+
+#include "Clownfish/Obj.h"
+#include "Clownfish/Err.h"
+#include "Clownfish/Class.h"
+#include "Clownfish/String.h"
+#include "Clownfish/Hash.h"
+#include "Clownfish/VArray.h"
+#include "Clownfish/String.h"
+#include "Clownfish/Util/Memory.h"
+#include "Clownfish/LockFreeRegistry.h"
+#include "Clownfish/Method.h"
+
+*/
+import "C"
+
+func init() {
+	C.cfish_bootstrap_parcel()
+}
+
+// Temporary test-only routine.
+func DoStuff() {
+	hash := C.cfish_Hash_new(C.uint32_t(0))
+	C.CFISH_Hash_Dec_RefCount(hash)
+}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/047d52dc/runtime/go/clownfish/clownfish_test.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish_test.go b/runtime/go/clownfish/clownfish_test.go
new file mode 100644
index 0000000..3872b92
--- /dev/null
+++ b/runtime/go/clownfish/clownfish_test.go
@@ -0,0 +1,24 @@
+/* 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.
+ */
+
+package clownfish_test
+
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+import "testing"
+
+func TestStuff(t *testing.T) {
+	clownfish.DoStuff()
+}


[07/20] lucy-clownfish git commit: Add a static library target for CFC.

Posted by ma...@apache.org.
Add a static library target for CFC.


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

Branch: refs/heads/go_bindings_2
Commit: 783e8522d23fc25c6998fe5b4ece57efed5143a9
Parents: f013755
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 14:02:14 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:54 2014 -0800

----------------------------------------------------------------------
 compiler/common/charmonizer.main | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/783e8522/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main
index 5df4536..9cc6bfc 100644
--- a/compiler/common/charmonizer.main
+++ b/compiler/common/charmonizer.main
@@ -29,6 +29,9 @@ typedef struct SourceFileContext {
     chaz_MakeVar *common_test_objs;
 } SourceFileContext;
 
+static const char cfc_version[]       = "0.4.0";
+static const char cfc_major_version[] = "0.4";
+
 static void
 S_add_compiler_flags(struct chaz_CLI *cli);
 
@@ -119,6 +122,17 @@ S_add_compiler_flags(struct chaz_CLI *cli) {
 }
 
 static void
+S_add_staticlib_makefile_target(chaz_MakeFile *makefile) {
+    chaz_Lib *static_lib = chaz_Lib_new("cfc", chaz_Lib_STATIC, cfc_version,
+                                        cfc_major_version);
+    char *static_lib_filename = chaz_Lib_filename(static_lib);
+    chaz_MakeFile_add_rule(makefile, "static", static_lib_filename);
+    chaz_MakeFile_add_static_lib(makefile, static_lib, "$(COMMON_OBJS)");
+    free(static_lib_filename);
+    chaz_Lib_destroy(static_lib);
+}
+
+static void
 S_write_makefile(struct chaz_CLI *cli) {
     SourceFileContext sfc;
 
@@ -201,6 +215,7 @@ S_write_makefile(struct chaz_CLI *cli) {
     /* Rules */
 
     chaz_MakeFile_add_rule(makefile, "all", cfc_exe);
+    S_add_staticlib_makefile_target(makefile);
 
     chaz_MakeFile_add_lemon_exe(makefile, lemon_dir);
     chaz_MakeFile_add_lemon_grammar(makefile, parse_header);


[04/20] lucy-clownfish git commit: Add "host" CLI argument to CFC charmonizer.

Posted by ma...@apache.org.
Add "host" CLI argument to CFC charmonizer.


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

Branch: refs/heads/go_bindings_2
Commit: 95c7e8abc1fd0b90e20a9cf75f712afbcf031557
Parents: ed813dc
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 10:36:33 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Nov 29 14:07:54 2014 -0800

----------------------------------------------------------------------
 compiler/common/charmonizer.main | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/95c7e8ab/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main
index 2c5a376..9111e2f 100644
--- a/compiler/common/charmonizer.main
+++ b/compiler/common/charmonizer.main
@@ -41,6 +41,8 @@ int main(int argc, const char **argv) {
     /* Initialize. */
     chaz_CLI *cli
         = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment");
+    chaz_CLI_register(cli, "host", "specify host binding language",
+                      CHAZ_CLI_ARG_REQUIRED);
     chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]");
     {
         int result = chaz_Probe_parse_cli_args(argc, argv, cli);