From 0f213381f06116d0f6f2ca6bf2ccbe70ab088882 Mon Sep 17 00:00:00 2001 From: drswinghead Date: Thu, 27 Feb 2020 08:09:26 +0800 Subject: [PATCH] update readme, little lib --- .github/workflows/t1.yml | 2 +- readme.md | 37 ++++++++++++++++++++++++++++++++--- scripts/build-bysrc-linux.sh | 2 +- scripts/build-bysrc-macos.sh | 2 +- xgo/xos/os.go | 38 ++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/.github/workflows/t1.yml b/.github/workflows/t1.yml index b76012f..552ef97 100644 --- a/.github/workflows/t1.yml +++ b/.github/workflows/t1.yml @@ -65,7 +65,7 @@ jobs: #server: ${{ secrets.IRCSRV }} #port: ${{ secrets.IRCPORT }} tls: true - channel: "#vknuts" + channel: "#cygo" nickname: gareport message: status ${{ matrix.platform }} ${{ job.status }} https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks?check_suite_id= https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks/0/logs diff --git a/readme.md b/readme.md index f5793db..913291a 100644 --- a/readme.md +++ b/readme.md @@ -1,13 +1,40 @@ -Go compiler to C, with a generic library contains Go core features, like goroutine,channel,GC. +Compile Go to C, with a generic library contains Go core features, like goroutine,channel,GC. That's will generate minimal binary. The farther plan is compile any Go package to C. +### The pain of Go +* Too large binary size +* Not friendly with C +* Builtin string/array/map no methods +* Too verbosity error handling, not like the Go2 `try` error handling proposal + ### Features * goroutine * channel +* defer * GC * CGO * interface +* closure +* string/array/map with lot builtin methods +* `catch` statement error handling + +### Install + +``` +cd $GOPATH +git clone https://github.com/kitech/cygo +cd cygo/bysrc +go build -o cygo +``` + +### Example + +``` +./cygo ./tpkgs/hello +cmake . +make +``` ### Supported important syntax * defer @@ -17,12 +44,16 @@ That's will generate minimal binary. The farther plan is compile any Go package ### Todos * [ ] dynamic stack resize * [ ] correct and more safe point for GC +* [ ] support more OS/platforms +* [ ] so much to do ### Supported original Go packages * unsafe * errors ### 资料 -* [ ] Let's Build A Simple Interpreter https://github.com/rspivak/lsbasi -* [ ] dwarf https://github.com/gimli-rs/gimli +* minigo +* tinygo +* Let's Build A Simple Interpreter https://github.com/rspivak/lsbasi +* dwarf https://github.com/gimli-rs/gimli diff --git a/scripts/build-bysrc-linux.sh b/scripts/build-bysrc-linux.sh index 5091c7d..107a1ee 100755 --- a/scripts/build-bysrc-linux.sh +++ b/scripts/build-bysrc-linux.sh @@ -20,7 +20,7 @@ cp -a $GOPATH/src/github.com/kitech/goplusplus $GOPATH/src/gopp cp -a $PWD $GOPATH/src/ ln -sv $PWD/xgo $GOPATH/src/ -cd $GOPATH/src/cxrt/bysrc +cd $GOPATH/src/cygo/bysrc pwd go env diff --git a/scripts/build-bysrc-macos.sh b/scripts/build-bysrc-macos.sh index 5091c7d..107a1ee 100755 --- a/scripts/build-bysrc-macos.sh +++ b/scripts/build-bysrc-macos.sh @@ -20,7 +20,7 @@ cp -a $GOPATH/src/github.com/kitech/goplusplus $GOPATH/src/gopp cp -a $PWD $GOPATH/src/ ln -sv $PWD/xgo $GOPATH/src/ -cd $GOPATH/src/cxrt/bysrc +cd $GOPATH/src/cygo/bysrc pwd go env diff --git a/xgo/xos/os.go b/xgo/xos/os.go index 98df589..0ac7008 100644 --- a/xgo/xos/os.go +++ b/xgo/xos/os.go @@ -9,6 +9,7 @@ package xos #include #include #include +#include #include #include @@ -280,6 +281,43 @@ func Wkdir() string { } return s } +func Tmpdir() string { + var s string + s = Getenv("TMPDIR") + s = ifelse(s.len == 0, "/tmp", s) + return s +} + +type Utsname struct { + sysname string + nodename string + release string + version string + machine string + domainname string +} + +func (uto *Utsname) String() string { + return uto.sysname + " " + uto.nodename + " " + + uto.release + " " + uto.version + " " + uto.machine +} + +func Uname() string { + uts := &C.struct_utsname{} + rv := C.uname(&uts) + if rv != 0 { + println(Errmsg()) + return "" + } + uto := &Utsname{} + uto.sysname = gostring(uts.sysname) + uto.nodename = gostring(uts.nodename) + uto.release = gostring(uts.release) + uto.version = gostring(uts.version) + uto.machine = gostring(uts.machine) + // uto.domainname = gostring(uts.domainname) + return uto.String() +} func Umask(mask int) int { rv := C.umask(0)