You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/03/19 01:09:21 UTC
[01/19] lucy-clownfish git commit: Separate executable from common
test objects.
Repository: lucy-clownfish
Updated Branches:
refs/heads/master 5646bf057 -> d0babb78c
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/b0042957
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b0042957
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b0042957
Branch: refs/heads/master
Commit: b004295717ac976df0fa59b739651dfd19208f3b
Parents: 5646bf0
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 12:29:27 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Mar 2 18:28:29 2015 -0800
----------------------------------------------------------------------
compiler/common/charmonizer.main | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b0042957/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main
index 74ff7b6..9174d72 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
@@ -198,6 +199,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);
chaz_Make_list_files(cmark_dir, "c", S_source_file_callback, &sfc);
@@ -239,7 +241,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);
@@ -269,6 +272,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)");
@@ -311,7 +315,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);
[08/19] 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/dc2b8d4c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/dc2b8d4c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/dc2b8d4c
Branch: refs/heads/master
Commit: dc2b8d4c77b949100a1214e12c21325cce2c58f7
Parents: 827a528
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 14:07:12 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:43 2015 -0700
----------------------------------------------------------------------
compiler/common/charmonizer.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dc2b8d4c/compiler/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.c b/compiler/common/charmonizer.c
index 47563a6..217e318 100644
--- a/compiler/common/charmonizer.c
+++ b/compiler/common/charmonizer.c
@@ -7769,8 +7769,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);
@@ -7875,6 +7879,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;
@@ -7941,6 +7956,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);
chaz_Make_list_files(cmark_dir, "c", S_source_file_callback, &sfc);
@@ -7960,6 +7976,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);
@@ -7979,10 +7996,13 @@ S_write_makefile(struct chaz_CLI *cli) {
if (chaz_CLI_defined(cli, "enable-coverage")) {
chaz_CFlags_enable_code_coverage(link_flags);
}
- 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);
+ if (strcmp(chaz_CLI_strval(cli, "host"), "c") == 0) {
+ chaz_MakeFile_add_exe(makefile, cfc_exe, "$(COMMON_OBJS) $(CFC_OBJS)",
+ link_flags);
+ chaz_MakeFile_add_exe(makefile, test_cfc_exe,
+ "$(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);
@@ -8012,6 +8032,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)");
@@ -8054,7 +8075,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);
[05/19] 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/13ca2780
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/13ca2780
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/13ca2780
Branch: refs/heads/master
Commit: 13ca27800021bd42a0f1698f8f9298f777f36f00
Parents: dc2b8d4
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 15:13:35 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:43 2015 -0700
----------------------------------------------------------------------
compiler/include/CFC.h | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/13ca2780/compiler/include/CFC.h
----------------------------------------------------------------------
diff --git a/compiler/include/CFC.h b/compiler/include/CFC.h
index 9a13607..0fc047b 100644
--- a/compiler/include/CFC.h
+++ b/compiler/include/CFC.h
@@ -34,6 +34,8 @@
#include "CFCVariable.h"
#include "CFCVersion.h"
+#include "CFCC.h"
+
#include "CFCBindCore.h"
#include "CFCBindAliases.h"
#include "CFCBindClass.h"
[14/19] 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/063b499e
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/063b499e
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/063b499e
Branch: refs/heads/master
Commit: 063b499ec701883acffac02f8db9a2b42ae679b3
Parents: cd5158c
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Nov 10 09:11:03 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 19:01:11 2015 -0700
----------------------------------------------------------------------
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/063b499e/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/063b499e/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/063b499e/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index 269290b..8411504 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"
@@ -36,11 +39,17 @@ var charmonyH string = "charmony.h"
var buildDir string
var buildGO string
var configGO string
+var installedLibPath string
func init() {
_, buildGO, _, _ = runtime.Caller(1)
buildDir = path.Dir(buildGO)
configGO = path.Join(buildDir, "clownfish", "config.go")
+ var err error
+ installedLibPath, err = cfc.InstalledLibPath(packageName)
+ if err != nil {
+ log.Fatal(err)
+ }
}
func main() {
@@ -124,6 +133,7 @@ func prep() {
runCFC()
runCommand("make", "-j", "static")
writeConfigGO()
+ runCommand("go", "build", packageName)
}
func build() {
@@ -136,25 +146,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)
}
[09/19] lucy-clownfish git commit: Only build cfc and test_cfc exe's
under C.
Posted by ma...@apache.org.
Only build cfc and test_cfc exe's under C.
As a side effect, don't add them to the 'clean' target. This solves a
problem because `rm -f cfc` failes under the Go bindings errors out when
`cfc` is a directory.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/827a528d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/827a528d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/827a528d
Branch: refs/heads/master
Commit: 827a528d3ec28d52e3edcadce60ddf08bfb5d06b
Parents: 3d5934c
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sun Mar 15 17:59:00 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:43 2015 -0700
----------------------------------------------------------------------
compiler/common/charmonizer.main | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/827a528d/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main
index 801c954..52f52ef 100644
--- a/compiler/common/charmonizer.main
+++ b/compiler/common/charmonizer.main
@@ -253,11 +253,13 @@ S_write_makefile(struct chaz_CLI *cli) {
if (chaz_CLI_defined(cli, "enable-coverage")) {
chaz_CFlags_enable_code_coverage(link_flags);
}
- chaz_MakeFile_add_exe(makefile, cfc_exe, "$(COMMON_OBJS) $(CFC_OBJS)",
- link_flags);
- chaz_MakeFile_add_exe(makefile, test_cfc_exe,
- "$(COMMON_OBJS) $(COMMON_TEST_OBJS) $(TEST_CFC_OBJS)",
- link_flags);
+ if (strcmp(chaz_CLI_strval(cli, "host"), "c") == 0) {
+ chaz_MakeFile_add_exe(makefile, cfc_exe, "$(COMMON_OBJS) $(CFC_OBJS)",
+ link_flags);
+ chaz_MakeFile_add_exe(makefile, test_cfc_exe,
+ "$(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);
[18/19] 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/0efb7721
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/0efb7721
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/0efb7721
Branch: refs/heads/master
Commit: 0efb7721b3ae24038e583b5225649b6427ec59e1
Parents: c320f1f
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sun Nov 16 21:18:36 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 19:02:11 2015 -0700
----------------------------------------------------------------------
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/0efb7721/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/0efb7721/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 5b9b515..fe68e49 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_dec_refcount(unsafe.Pointer(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_dec_refcount(unsafe.Pointer(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_inc_refcount(unsafe.Pointer(cfErr))
- runtime.SetFinalizer(goErr, (*Err).callDecRef)
+ runtime.SetFinalizer(goErr, (*Err).finalize)
panic(goErr)
}
[10/19] 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/0a181fe3
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/0a181fe3
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/0a181fe3
Branch: refs/heads/master
Commit: 0a181fe378e7a7d20c9389453e906419a78b113d
Parents: e1e9a0f
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 20:56:37 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:44 2015 -0700
----------------------------------------------------------------------
runtime/common/charmonizer.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/0a181fe3/runtime/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.c b/runtime/common/charmonizer.c
index 08e5ed3..706cf7c 100644
--- a/runtime/common/charmonizer.c
+++ b/runtime/common/charmonizer.c
@@ -7851,6 +7851,9 @@ int main(int argc, const char **argv) {
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);
@@ -7985,7 +7988,16 @@ cfish_MakeFile_new(chaz_CLI *cli) {
self->autogen_target
= chaz_Util_join(dir_sep, "autogen", "hierarchy.json", NULL);
- if (strcmp(chaz_CLI_strval(self->cli, "host"), "perl") == 0) {
+ 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 (strcmp(chaz_CLI_strval(cli, "host"), "perl") == 0) {
static const char *perl_autogen_src_files[] = {
"boot",
"callbacks",
@@ -8008,7 +8020,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);
@@ -8100,10 +8112,8 @@ 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 (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) {
cfish_MakeFile_write_c_cfc_rules(self);
[12/19] 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/56636641
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/56636641
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/56636641
Branch: refs/heads/master
Commit: 56636641d9447c779da5ed661f3f60e2af32aae6
Parents: 3d11dea
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Nov 5 10:58:27 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 19:01:11 2015 -0700
----------------------------------------------------------------------
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/56636641/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 7859709..0165223 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_dec_refcount(unsafe.Pointer(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_dec_refcount(unsafe.Pointer(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_dec_refcount(unsafe.Pointer(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/56636641/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")
+ }
}
[02/19] 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/3d5934cb
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/3d5934cb
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/3d5934cb
Branch: refs/heads/master
Commit: 3d5934cb575f92f4213e08ba25eacccca6ecc312
Parents: b004295
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 14:02:14 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Mar 2 18:28:49 2015 -0800
----------------------------------------------------------------------
compiler/common/charmonizer.main | 15 +++++++++++++++
1 file changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3d5934cb/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main
index 9174d72..801c954 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);
@@ -133,6 +136,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;
@@ -219,6 +233,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/19] lucy-clownfish git commit: Start Go bindings for CFC.
Posted by ma...@apache.org.
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/77d82947
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/77d82947
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/77d82947
Branch: refs/heads/master
Commit: 77d82947741d1c2cefc425b7df0f017608f72bc7
Parents: 13ca278
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 16:23:25 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:43 2015 -0700
----------------------------------------------------------------------
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/77d82947/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/77d82947/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/77d82947/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()
+}
+
[15/19] 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/56d26bc1
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/56d26bc1
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/56d26bc1
Branch: refs/heads/master
Commit: 56d26bc159fb97d8efb1f67f67f1d7b61a186aab
Parents: a255977
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Nov 14 18:46:27 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 19:01:11 2015 -0700
----------------------------------------------------------------------
runtime/go/ext/clownfish.c | 285 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 285 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/56d26bc1/runtime/go/ext/clownfish.c
----------------------------------------------------------------------
diff --git a/runtime/go/ext/clownfish.c b/runtime/go/ext/clownfish.c
index e69de29..196f90c 100644
--- a/runtime/go/ext/clownfish.c
+++ b/runtime/go/ext/clownfish.c
@@ -0,0 +1,285 @@
+/* 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 **************************************/
+
+static CFISH_INLINE bool
+SI_immortal(cfish_Class *klass) {
+ if (klass == CFISH_CLASS
+ || klass == CFISH_METHOD
+ || klass == CFISH_BOOLNUM
+ || klass == CFISH_HASHTOMBSTONE
+ ){
+ return true;
+ }
+ return false;
+}
+
+static CFISH_INLINE bool
+SI_is_string_type(cfish_Class *klass) {
+ if (klass == CFISH_STRING || klass == CFISH_STACKSTRING) {
+ return true;
+ }
+ return false;
+}
+
+static CFISH_INLINE bool
+SI_threadsafe_but_not_immortal(cfish_Class *klass) {
+ if (klass == CFISH_LOCKFREEREGISTRY) {
+ return true;
+ }
+ return false;
+}
+
+uint32_t
+cfish_get_refcount(void *vself) {
+ cfish_Obj *self = (cfish_Obj*)vself;
+ return self->refcount;
+}
+
+Obj*
+cfish_inc_refcount(void *vself) {
+ Obj *self = (Obj*)vself;
+
+ // Handle special cases.
+ cfish_Class *const klass = self->klass;
+ if (klass->flags & CFISH_fREFCOUNTSPECIAL) {
+ if (SI_is_string_type(klass)) {
+ // Only copy-on-incref Strings get special-cased. Ordinary
+ // strings fall through to the general case.
+ if (CFISH_Str_Is_Copy_On_IncRef((cfish_String*)self)) {
+ const char *utf8 = CFISH_Str_Get_Ptr8((cfish_String*)self);
+ size_t size = CFISH_Str_Get_Size((cfish_String*)self);
+ return (cfish_Obj*)cfish_Str_new_from_trusted_utf8(utf8, size);
+ }
+ }
+ else if (SI_immortal(klass)) {
+ return self;
+ }
+ else if (SI_threadsafe_but_not_immortal(klass)) {
+ // TODO: use atomic operation
+ }
+ }
+
+ self->refcount++;
+ return self;
+}
+
+uint32_t
+cfish_dec_refcount(void *vself) {
+ cfish_Obj *self = (Obj*)vself;
+ cfish_Class *klass = self->klass;
+ if (klass->flags & CFISH_fREFCOUNTSPECIAL) {
+ if (SI_immortal(klass)) {
+ return self->refcount;
+ }
+ else if (SI_threadsafe_but_not_immortal(klass)) {
+ // TODO: use atomic operation
+ }
+ }
+
+ 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*);
+}
+
+
[16/19] 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/a2559770
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/a2559770
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/a2559770
Branch: refs/heads/master
Commit: a255977090098de619ad298cc5c6fd9f7958ea9a
Parents: 063b499
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Nov 12 17:23:34 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 19:01:11 2015 -0700
----------------------------------------------------------------------
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/a2559770/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/a2559770/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 0165223..75a3314 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
}
[13/19] 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/cd5158c2
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/cd5158c2
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/cd5158c2
Branch: refs/heads/master
Commit: cd5158c251cb8d31661870ee9c6d75a41ea0ddd8
Parents: 5663664
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 8 15:43:05 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 19:01:11 2015 -0700
----------------------------------------------------------------------
runtime/go/INSTALL | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd5158c2/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
+
[07/19] lucy-clownfish git commit: Adapt charmonizer for Go bindings.
Posted by ma...@apache.org.
Adapt charmonizer for Go bindings.
* Add behaviors when "host" CLI arg is "go".
* Default "host" CLI arg to "c".
* Only build static lib when "static" Makefile target is run.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/e1e9a0fc
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/e1e9a0fc
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/e1e9a0fc
Branch: refs/heads/master
Commit: e1e9a0fcc6fdd8d5dd78bf6f9b57fac67cd0a5b1
Parents: 56048a5
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 29 20:53:43 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:43 2015 -0700
----------------------------------------------------------------------
runtime/common/charmonizer.main | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e1e9a0fc/runtime/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main
index 9ef16dc..2f6fe86 100644
--- a/runtime/common/charmonizer.main
+++ b/runtime/common/charmonizer.main
@@ -108,6 +108,9 @@ int main(int argc, const char **argv) {
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);
@@ -242,7 +245,16 @@ cfish_MakeFile_new(chaz_CLI *cli) {
self->autogen_target
= chaz_Util_join(dir_sep, "autogen", "hierarchy.json", NULL);
- if (strcmp(chaz_CLI_strval(self->cli, "host"), "perl") == 0) {
+ 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 (strcmp(chaz_CLI_strval(cli, "host"), "perl") == 0) {
static const char *perl_autogen_src_files[] = {
"boot",
"callbacks",
@@ -265,7 +277,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);
@@ -357,10 +369,8 @@ 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 (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) {
cfish_MakeFile_write_c_cfc_rules(self);
[03/19] 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/56048a54
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/56048a54
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/56048a54
Branch: refs/heads/master
Commit: 56048a542466ea95b8feb80dfb586613352e5d6f
Parents: d70fa60
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 17:13:55 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:43 2015 -0700
----------------------------------------------------------------------
compiler/go/INSTALL | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/56048a54/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
+
[17/19] 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/c320f1fd
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c320f1fd
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c320f1fd
Branch: refs/heads/master
Commit: c320f1fd5a65b971a496787b59309ef82d8f4845
Parents: 56d26bc
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Nov 15 19:45:17 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 19:02:11 2015 -0700
----------------------------------------------------------------------
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/c320f1fd/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go
index 75a3314..5b9b515 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_dec_refcount(unsafe.Pointer(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_inc_refcount(unsafe.Pointer(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/c320f1fd/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/c320f1fd/runtime/go/ext/clownfish.c
----------------------------------------------------------------------
diff --git a/runtime/go/ext/clownfish.c b/runtime/go/ext/clownfish.c
index 196f90c..851012b 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 **************************************/
static CFISH_INLINE bool
@@ -199,11 +203,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*
@@ -221,17 +231,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*
@@ -258,19 +258,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 *******************************/
[06/19] 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/d70fa601
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d70fa601
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d70fa601
Branch: refs/heads/master
Commit: d70fa6012b734541a8413e1f0a71e256768a270b
Parents: 77d8294
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Nov 4 17:09:55 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:05:43 2015 -0700
----------------------------------------------------------------------
compiler/go/cfc/cfc.go | 72 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d70fa601/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)
+}
[11/19] 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/3d11dea1
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/3d11dea1
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/3d11dea1
Branch: refs/heads/master
Commit: 3d11dea1f974a9403a459c4bb91c4ff09ea858b7
Parents: 0a181fe
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Nov 5 10:51:41 2014 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sun Mar 15 18:28:47 2015 -0700
----------------------------------------------------------------------
runtime/go/build.go | 176 ++++++++++++++++++++++++++++
runtime/go/clownfish/clownfish.go | 45 +++++++
runtime/go/clownfish/clownfish_test.go | 24 ++++
runtime/go/ext/clownfish.c | 0
4 files changed, 245 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3d11dea1/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
new file mode 100644
index 0000000..269290b
--- /dev/null
+++ b/runtime/go/build.go
@@ -0,0 +1,176 @@
+/* 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 buildGO string
+var configGO string
+
+func init() {
+ _, buildGO, _, _ = runtime.Caller(1)
+ buildDir = path.Dir(buildGO)
+ 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",
+ "--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/3d11dea1/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..7859709
--- /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_dec_refcount(unsafe.Pointer(hash))
+}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3d11dea1/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()
+}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3d11dea1/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..e69de29
[19/19] lucy-clownfish git commit: Merge branch
'CLOWNFISH-28-POC-Go-bindings'
Posted by ma...@apache.org.
Merge branch 'CLOWNFISH-28-POC-Go-bindings'
Use mostly hand-rolled glue code for binding Go to limited portions of the
Clownfish runtime. A more extensible code-generation approach can follow
later, but the early version helps to flesh out the design.
This fixes CLOWNFISH-28.
This closes #4.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d0babb78
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d0babb78
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d0babb78
Branch: refs/heads/master
Commit: d0babb78c858438ff47ce9eb6313051cf2e5f66e
Parents: 5646bf0 0efb772
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Mar 18 17:08:20 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Mar 18 17:08:20 2015 -0700
----------------------------------------------------------------------
compiler/common/charmonizer.c | 31 +++-
compiler/common/charmonizer.main | 31 +++-
compiler/go/INSTALL | 20 ++
compiler/go/build.go | 207 +++++++++++++++++++++
compiler/go/cfc/cfc.go | 161 ++++++++++++++++
compiler/go/cfc/cfc_test.go | 26 +++
compiler/include/CFC.h | 2 +
runtime/common/charmonizer.c | 22 ++-
runtime/common/charmonizer.main | 22 ++-
runtime/go/INSTALL | 19 ++
runtime/go/build.go | 239 ++++++++++++++++++++++++
runtime/go/clownfish/clownfish.go | 194 ++++++++++++++++++++
runtime/go/clownfish/clownfish_test.go | 28 +++
runtime/go/clownfish/err_test.go | 42 +++++
runtime/go/ext/clownfish.c | 273 ++++++++++++++++++++++++++++
15 files changed, 1295 insertions(+), 22 deletions(-)
----------------------------------------------------------------------