Skip to content

Commit 168a089

Browse files
authored
Merge pull request #2296 from goplus/main
v1.4.0
2 parents db82816 + 951d06d commit 168a089

File tree

21 files changed

+173
-69
lines changed

21 files changed

+173
-69
lines changed

.github/workflows/go.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
with:
7373
go-version: ${{ matrix.go }}
7474

75+
- name: Set types alias env
76+
run: echo "GODEBUG=gotypesalias=1" >> $GITHUB_ENV
77+
7578
- name: Test Go+ installer
7679
run: |
7780
git config --global user.email "[email protected]"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module YourModulePath
116116

117117
go 1.21 // llgo 1.0
118118

119-
require github.com/goplus/llgo v0.9.9
119+
require github.com/goplus/lib v0.2.0
120120
```
121121

122122
Based on LLGo, Go+ can import libraries written in C/C++ and Python.
@@ -151,9 +151,9 @@ Here, `py"Hello world"` is a syntax supported by Go+, representing a Python stri
151151

152152
Here are more examples of Go+ calling C/C++ and Python libraries:
153153

154-
* [pytensor](demo/_llgo/pytensor/tensor.gop): a simple demo using [py/torch](https://pkg.go.dev/github.com/goplus/llgo/py/torch)
155-
* [tetris](demo/_llgo/tetris/tetris.gop): a tetris game based on [c/raylib](https://pkg.go.dev/github.com/goplus/llgo/c/raylib)
156-
* [sqlitedemo](demo/_llgo/sqlitedemo/sqlitedemo.gop): a demo using [c/sqlite](https://pkg.go.dev/github.com/goplus/llgo/c/sqlite)
154+
* [pytensor](demo/_llgo/pytensor/tensor.gop): a simple demo using [py/torch](https://pkg.go.dev/github.com/goplus/lib/py/torch)
155+
* [tetris](demo/_llgo/tetris/tetris.gop): a tetris game based on [c/raylib](https://pkg.go.dev/github.com/goplus/lib/c/raylib)
156+
* [sqlitedemo](demo/_llgo/sqlitedemo/sqlitedemo.gop): a demo using [c/sqlite](https://pkg.go.dev/github.com/goplus/lib/c/sqlite)
157157

158158
To find out more about LLGo/Go+'s support for C/C++ and Python in detail, please refer to homepage of [llgo](https://github.com/goplus/llgo).
159159

@@ -188,7 +188,7 @@ Sound a bit abstract? Let's see some Go+ classfiles.
188188
* Web Programming: [yaptest: A Go+ HTTP Test Framework](https://github.com/goplus/yap/tree/main/ytest)
189189
* Web Programming: [ydb: A Go+ Database Framework](https://github.com/goplus/yap/tree/main/ydb)
190190
* CLI Programming: [cobra: A Commander for modern Go+ CLI interactions](https://github.com/goplus/cobra)
191-
* CLI Programming: [gsh: An alternative to writing shell scripts](https://github.com/qiniu/x/tree/main/gsh)
191+
* CLI Programming: [gsh: An alternative to write shell scripts](https://github.com/qiniu/x/tree/main/gsh)
192192
* Unit Test: [test: Unit Test](https://github.com/goplus/gop/blob/main/doc/classfile.md#classfile-unit-test)
193193

194194

cl/_testc/hello/out.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import "github.com/goplus/llgo/c"
3+
import "github.com/goplus/lib/c"
44

55
func main() {
66
c.Printf(c.Str("Hello, world!\n"))

cl/_testpy/hello/out.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
"github.com/goplus/llgo/py"
5-
"github.com/goplus/llgo/py/std"
4+
"github.com/goplus/lib/py"
5+
"github.com/goplus/lib/py/std"
66
)
77

88
func main() {

cl/_testpy/pycall/out.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package main
22

33
import (
4-
"github.com/goplus/llgo/c"
5-
"github.com/goplus/llgo/py"
6-
"github.com/goplus/llgo/py/math"
4+
"github.com/goplus/lib/c"
5+
"github.com/goplus/lib/py"
6+
"github.com/goplus/lib/py/math"
77
)
88

99
func main() {

cl/builtin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ func TestGetGameClass(t *testing.T) {
7373
}
7474

7575
func TestSimplifyPkgPath(t *testing.T) {
76-
if simplifyPkgPath("c/lua") != "github.com/goplus/llgo/c/lua" {
76+
if simplifyPkgPath("c/lua") != "github.com/goplus/lib/c/lua" {
7777
t.Fatal("simplifyPkgPath: c/lua")
7878
}
79-
if simplifyPkgPath("cpp/std") != "github.com/goplus/llgo/cpp/std" {
79+
if simplifyPkgPath("cpp/std") != "github.com/goplus/lib/cpp/std" {
8080
t.Fatal("simplifyPkgPath: cpp/std")
8181
}
8282
}

cl/c.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323
// -----------------------------------------------------------------------------
2424

2525
const (
26-
pathLibc = "github.com/goplus/llgo/c"
27-
pathLibpy = "github.com/goplus/llgo/py"
28-
pathLibcpp = "github.com/goplus/llgo/cpp"
26+
pathLibc = "github.com/goplus/lib/c"
27+
pathLibpy = "github.com/goplus/lib/py"
28+
pathLibcpp = "github.com/goplus/lib/cpp"
2929
)
3030

3131
func simplifyGopPackage(pkgPath string) string {

cl/compile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ var unaryGopNames = map[string]string{
14331433

14341434
func loadFuncBody(ctx *blockCtx, fn *gogen.Func, body *ast.BlockStmt, sigBase *types.Signature, src ast.Node) {
14351435
cb := fn.BodyStart(ctx.pkg, body)
1436+
cb.SetComments(nil, false)
14361437
if sigBase != nil {
14371438
// this.Sprite.Main(...) or this.Game.MainEntry(...)
14381439
cb.VarVal("this").MemberVal(ctx.baseClass.Name()).MemberVal(fn.Name())

cl/compile_test.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,3 +4340,132 @@ func main() {
43404340
}
43414341
`)
43424342
}
4343+
4344+
func TestCommentFunc(t *testing.T) {
4345+
gopClTestEx(t, gblConfLine, "main", `
4346+
import (
4347+
"strconv"
4348+
)
4349+
4350+
func add(x, y string) (int, error) {
4351+
return strconv.atoi(x)? + strconv.atoi(y)?, nil
4352+
}
4353+
4354+
func addSafe(x, y string) int {
4355+
return strconv.atoi(x)?:0 + strconv.atoi(y)?:0
4356+
}
4357+
4358+
echo add("100", "23")!
4359+
4360+
sum, err := add("10", "abc")
4361+
echo sum, err
4362+
4363+
echo addSafe("10", "abc")
4364+
`, `package main
4365+
4366+
import (
4367+
"fmt"
4368+
"github.com/qiniu/x/errors"
4369+
"strconv"
4370+
)
4371+
//line /foo/bar.gop:6:1
4372+
func add(x string, y string) (int, error) {
4373+
//line /foo/bar.gop:7:1
4374+
var _autoGo_1 int
4375+
//line /foo/bar.gop:7:1
4376+
{
4377+
//line /foo/bar.gop:7:1
4378+
var _gop_err error
4379+
//line /foo/bar.gop:7:1
4380+
_autoGo_1, _gop_err = strconv.Atoi(x)
4381+
//line /foo/bar.gop:7:1
4382+
if _gop_err != nil {
4383+
//line /foo/bar.gop:7:1
4384+
_gop_err = errors.NewFrame(_gop_err, "strconv.atoi(x)", "/foo/bar.gop", 7, "main.add")
4385+
//line /foo/bar.gop:7:1
4386+
return 0, _gop_err
4387+
}
4388+
//line /foo/bar.gop:7:1
4389+
goto _autoGo_2
4390+
_autoGo_2:
4391+
//line /foo/bar.gop:7:1
4392+
}
4393+
//line /foo/bar.gop:7:1
4394+
var _autoGo_3 int
4395+
//line /foo/bar.gop:7:1
4396+
{
4397+
//line /foo/bar.gop:7:1
4398+
var _gop_err error
4399+
//line /foo/bar.gop:7:1
4400+
_autoGo_3, _gop_err = strconv.Atoi(y)
4401+
//line /foo/bar.gop:7:1
4402+
if _gop_err != nil {
4403+
//line /foo/bar.gop:7:1
4404+
_gop_err = errors.NewFrame(_gop_err, "strconv.atoi(y)", "/foo/bar.gop", 7, "main.add")
4405+
//line /foo/bar.gop:7:1
4406+
return 0, _gop_err
4407+
}
4408+
//line /foo/bar.gop:7:1
4409+
goto _autoGo_4
4410+
_autoGo_4:
4411+
//line /foo/bar.gop:7:1
4412+
}
4413+
//line /foo/bar.gop:7:1
4414+
return _autoGo_1 + _autoGo_3, nil
4415+
}
4416+
//line /foo/bar.gop:10:1
4417+
func addSafe(x string, y string) int {
4418+
//line /foo/bar.gop:11:1
4419+
return func() (_gop_ret int) {
4420+
//line /foo/bar.gop:11:1
4421+
var _gop_err error
4422+
//line /foo/bar.gop:11:1
4423+
_gop_ret, _gop_err = strconv.Atoi(x)
4424+
//line /foo/bar.gop:11:1
4425+
if _gop_err != nil {
4426+
//line /foo/bar.gop:11:1
4427+
return 0
4428+
}
4429+
//line /foo/bar.gop:11:1
4430+
return
4431+
}() + func() (_gop_ret int) {
4432+
//line /foo/bar.gop:11:1
4433+
var _gop_err error
4434+
//line /foo/bar.gop:11:1
4435+
_gop_ret, _gop_err = strconv.Atoi(y)
4436+
//line /foo/bar.gop:11:1
4437+
if _gop_err != nil {
4438+
//line /foo/bar.gop:11:1
4439+
return 0
4440+
}
4441+
//line /foo/bar.gop:11:1
4442+
return
4443+
}()
4444+
}
4445+
//line /foo/bar.gop:14
4446+
func main() {
4447+
//line /foo/bar.gop:14:1
4448+
fmt.Println(func() (_gop_ret int) {
4449+
//line /foo/bar.gop:14:1
4450+
var _gop_err error
4451+
//line /foo/bar.gop:14:1
4452+
_gop_ret, _gop_err = add("100", "23")
4453+
//line /foo/bar.gop:14:1
4454+
if _gop_err != nil {
4455+
//line /foo/bar.gop:14:1
4456+
_gop_err = errors.NewFrame(_gop_err, "add(\"100\", \"23\")", "/foo/bar.gop", 14, "main.main")
4457+
//line /foo/bar.gop:14:1
4458+
panic(_gop_err)
4459+
}
4460+
//line /foo/bar.gop:14:1
4461+
return
4462+
}())
4463+
//line /foo/bar.gop:16:1
4464+
sum, err := add("10", "abc")
4465+
//line /foo/bar.gop:17:1
4466+
fmt.Println(sum, err)
4467+
//line /foo/bar.gop:19:1
4468+
fmt.Println(addSafe("10", "abc"))
4469+
}
4470+
`)
4471+
}

cl/internal/llgo-hello/hello.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package hello
22

3-
import "github.com/goplus/llgo/c"
3+
import "github.com/goplus/lib/c"
44

55
func Main() {
66
c.Printf(c.Str("Hello world\n"))

0 commit comments

Comments
 (0)