Repository: goplus/gop
Pull request #1051 (2021-12-10 19:31:06)

gox v1.8.6


Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index ea06a35a..5052546c 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -21,9 +21,6 @@ jobs:
       with:
         go-version: ${{ matrix.go-version }}
 
-    - name: Test Go+ installer
-      run: go test -v cmd/make_test.go
-
     - name: Compile gop and related tools
       run: go install ./...
 
diff --git a/README.md b/README.md
index d7afc11c..5fe28f26 100644
--- a/README.md
+++ b/README.md
@@ -87,10 +87,10 @@ It's for Go, and it's also for Go+.
 
 ## Playground
 
-Go+ Playground based on Docker:
+Go+ Playground based on Docker (recommended):
 * https://play.goplus.org/
 
-Go+ Playground based on GopherJS:
+Go+ Playground based on GopherJS (currently only available in v0.7.x):
 * https://jsplay.goplus.org/
 
 
diff --git a/cl/expr.go b/cl/expr.go
index 9c68d4b2..342afe8e 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -322,18 +322,10 @@ func compileSelectorExpr(ctx *blockCtx, v *ast.SelectorExpr, flags int) {
 	}
 }
 
-func isFunc(typ types.Type) bool {
-	switch typ.(type) {
-	case *types.Signature:
-		return true
-	}
-	return false
-}
-
 func pkgRef(at *gox.PkgRef, name string) (o types.Object, alias bool) {
 	if c := name[0]; c >= 'a' && c <= 'z' {
 		name = string(rune(c)+('A'-'a')) + name[1:]
-		if v := at.TryRef(name); v != nil && isFunc(v.Type()) {
+		if v := at.TryRef(name); v != nil && gox.IsFunc(v.Type()) {
 			return v, true
 		}
 		return
@@ -365,7 +357,7 @@ func compilePkgRef(ctx *blockCtx, at *gox.PkgRef, x *ast.Ident, flags int) bool
 			cb.VarRef(v, x)
 		} else {
 			autoprop := alias && (flags&clIdentAutoCall) != 0
-			if autoprop && !canAutoProperty(v.Type()) {
+			if autoprop && !gox.HasAutoProperty(v.Type()) {
 				return false
 			}
 			cb.Val(v, x)
@@ -378,14 +370,6 @@ func compilePkgRef(ctx *blockCtx, at *gox.PkgRef, x *ast.Ident, flags int) bool
 	return false
 }
 
-func canAutoProperty(typ types.Type) bool {
-	switch v := typ.(type) {
-	case *types.Signature:
-		return v.Params().Len() == 0
-	}
-	return false
-}
-
 type fnType struct {
 	params   *types.Tuple
 	n1       int
diff --git a/cl/internal/spx/game.go b/cl/internal/spx/game.go
index f2f8c356..9162dea9 100644
--- a/cl/internal/spx/game.go
+++ b/cl/internal/spx/game.go
@@ -52,6 +52,14 @@ func Sched() {
 func SchedNow() {
 }
 
+func Rand__0(int) int {
+	return 0
+}
+
+func Rand__1(float64) float64 {
+	return 0
+}
+
 var (
 	TestIntValue int
 )
diff --git a/cl/stmt.go b/cl/stmt.go
index 6381083d..d8bc695a 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -86,7 +86,7 @@ func compileStmt(ctx *blockCtx, stmt ast.Stmt) {
 			ctx.cb.Call(0)
 		} else {
 			compileExpr(ctx, v.X)
-			if canAutoCall(v.X) && isFunc(ctx.cb.InternalStack().Get(-1).Type) {
+			if canAutoCall(v.X) && gox.IsFunc(ctx.cb.InternalStack().Get(-1).Type) {
 				ctx.cb.Call(0)
 			}
 		}
diff --git a/cmd/make.go b/cmd/make.go
index 7d8506d3..1760318f 100644
--- a/cmd/make.go
+++ b/cmd/make.go
@@ -83,8 +83,8 @@ const (
 )
 
 func init() {
-	if inWindows {
-		for index, file := range gopBinFiles {
+	for index, file := range gopBinFiles {
+		if inWindows {
 			file += ".exe"
 			gopBinFiles[index] = file
 		}
@@ -233,9 +233,6 @@ func buildGoplusTools(useGoProxy bool) {
 	}
 	print(buildOutput)
 
-	// Clear gop run cache
-	cleanGopRunCache()
-
 	installPath := linkGoplusToLocalBin()
 
 	println("\nGo+ tools installed successfully!")
@@ -296,22 +293,6 @@ func clean() {
 			log.Fatalln(err)
 		}
 	}
-
-	cleanGopRunCache()
-}
-
-func cleanGopRunCache() {
-	homeDir, _ := os.UserHomeDir()
-	runCacheDir := filepath.Join(homeDir, ".gop", "run")
-	files := []string{"go.mod", "go.sum"}
-	for _, file := range files {
-		fullPath := filepath.Join(runCacheDir, file)
-		if checkPathExist(fullPath, false) {
-			if err := os.Remove(fullPath); err != nil {
-				log.Fatalln(err)
-			}
-		}
-	}
 }
 
 func uninstall() {
diff --git a/go.mod b/go.mod
index 9458a26c..7e5c7c1a 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/goplus/gop
 go 1.16
 
 require (
-	github.com/goplus/gox v1.8.5
+	github.com/goplus/gox v1.8.6
 	github.com/qiniu/x v1.11.5
 	golang.org/x/mod v0.5.1
 	golang.org/x/tools v0.1.8
diff --git a/go.sum b/go.sum
index e204e55e..9bbd40ca 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/goplus/gox v1.8.5 h1:2rvB6mwrwIxXHGisxA7HHbtrP8iWfazW+tL5Q8Fb4YM=
-github.com/goplus/gox v1.8.5/go.mod h1:XWqV75HImeysI8+Q9gAdYyvwlP8jds24xsgYRwTO3JI=
+github.com/goplus/gox v1.8.6 h1:2Nm++uPwQe9vMWWLS5fXhV7A/P+amwTtexUKtzv1YvI=
+github.com/goplus/gox v1.8.6/go.mod h1:XWqV75HImeysI8+Q9gAdYyvwlP8jds24xsgYRwTO3JI=
 github.com/qiniu/x v1.11.5 h1:TYr5cl4g2yoHAZeDK4MTjKF6CMoG+IHlCDvvM5qym6U=
 github.com/qiniu/x v1.11.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
 github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=


Test patch:
diff --git a/cl/builtin_test.go b/cl/builtin_test.go
index 59cbf821..045c08e6 100644
--- a/cl/builtin_test.go
+++ b/cl/builtin_test.go
@@ -36,12 +36,6 @@ func TestCompileErrWrapExpr(t *testing.T) {
 	compileErrWrapExpr(ctx, &ast.ErrWrapExpr{Tok: token.QUESTION})
 }
 
-func TestCanAutoProperty(t *testing.T) {
-	if canAutoProperty(nil) {
-		t.Fatal("canAutoProperty?")
-	}
-}
-
 func TestToString(t *testing.T) {
 	defer func() {
 		if e := recover(); e == nil {
@@ -63,12 +57,6 @@ func TestGetTypeName(t *testing.T) {
 	getTypeName(types.NewSlice(types.Typ[types.Int]))
 }
 
-func TestIsFunc(t *testing.T) {
-	if isFunc(nil) {
-		t.Fatal("TestIsFunc failed")
-	}
-}
-
 func TestHandleRecover(t *testing.T) {
 	var ctx pkgCtx
 	ctx.handleRecover("hello")
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index 48a26f9a..032ea2f0 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -301,6 +301,8 @@ var (
 	t   Sound
 )
 
+var x float64 = rand(1.2)
+
 run "hzip://open.qiniu.us/weather/res.zip"
 `, `
 println "Hi"
@@ -311,6 +313,8 @@ import (
 	spx "github.com/goplus/gop/cl/internal/spx"
 )
 
+var x float64 = spx.Rand__1(1.2)
+
 type index struct {
 	*spx.MyGame
 	Kai Kai
diff --git a/cmd/make_test.go b/cmd/make_test.go
deleted file mode 100644
index b63bb311..00000000
--- a/cmd/make_test.go
+++ /dev/null
@@ -1,104 +0,0 @@
-//go:build ignore
-// +build ignore
-
-package make_test
-
-import (
-	"os"
-	"os/exec"
-	"path/filepath"
-	"runtime"
-	"testing"
-)
-
-const (
-	inWindows = (runtime.GOOS == "windows")
-)
-
-var script = "all.bash"
-var gopRoot = ""
-var gopBinFiles = []string{"gop", "gopfmt"}
-
-func checkPathExist(path string, isDir bool) bool {
-	stat, err := os.Stat(path)
-	isExists := !os.IsNotExist(err)
-	if isDir {
-		return isExists && stat.IsDir()
-	}
-	return isExists && !stat.IsDir()
-}
-
-func detectGoBinPath() string {
-	goBin, ok := os.LookupEnv("GOBIN")
-	if ok {
-		return goBin
-	}
-
-	goPath, ok := os.LookupEnv("GOPATH")
-	if ok {
-		list := filepath.SplitList(goPath)
-		if len(list) > 0 {
-			// Put in first directory of $GOPATH.
-			return filepath.Join(list[0], "bin")
-		}
-	}
-
-	homeDir, _ := os.UserHomeDir()
-	return filepath.Join(homeDir, "go", "bin")
-}
-
-func init() {
-	pwd, _ := os.Getwd()
-	gopRoot = filepath.Join(pwd, "..")
-	if inWindows {
-		script = "all.bat"
-		for index, file := range gopBinFiles {
-			file += ".exe"
-			gopBinFiles[index] = file
-		}
-	}
-}
-
-func TestAllScript(t *testing.T) {
-	os.Chdir(gopRoot)
-	cmd := exec.Command(filepath.Join(gopRoot, script))
-	if output, err := cmd.CombinedOutput(); err != nil {
-		t.Fatalf("Failed: %v:\nOut: %s\n", err, output)
-	}
-
-	goBinPath := detectGoBinPath()
-
-	for _, file := range gopBinFiles {
-		if !checkPathExist(filepath.Join(gopRoot, "bin", file), false) {
-			t.Fatalf("Failed: %s not found in ./bin directory\n", file)
-		}
-		if !checkPathExist(filepath.Join(goBinPath, file), false) {
-			t.Fatalf("Failed: %s not found in %s/bin directory\n", file, goBinPath)
-		}
-	}
-
-	cmd = exec.Command(filepath.Join(gopRoot, "bin", gopBinFiles[0]), "version")
-	if output, err := cmd.CombinedOutput(); err != nil {
-		t.Fatalf("Failed: %v:\nOut: %s\n", err, output)
-	}
-}
-
-func TestHandleMultiFlags(t *testing.T) {
-	os.Chdir(gopRoot)
-	cmd := exec.Command("go", "run", filepath.Join(gopRoot, "cmd/make.go"), "--install", "--test", "--uninstall")
-	if output, err := cmd.CombinedOutput(); err != nil {
-		t.Fatalf("Failed: %v:\nOut: %s\n", err, output)
-	}
-
-	goBinPath := detectGoBinPath()
-
-	// Uninstall will be the last action to run, test if all build assets being cleared.
-	for _, file := range gopBinFiles {
-		if checkPathExist(filepath.Join(gopRoot, "bin", file), false) {
-			t.Fatalf("Failed: %s found in ./bin directory\n", file)
-		}
-		if checkPathExist(filepath.Join(goBinPath, file), false) {
-			t.Fatalf("Failed: %s found in %s/bin directory\n", file, goBinPath)
-		}
-	}
-}