Skip to content

Commit

Permalink
update readme, little lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kitech committed Feb 27, 2020
1 parent 703d101 commit 0f21338
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/t1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 34 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

2 changes: 1 addition & 1 deletion scripts/build-bysrc-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-bysrc-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions xgo/xos/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package xos
#include <fcntl.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <dirent.h>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0f21338

Please sign in to comment.