Repository: goplus/gop
Pull request #1715 (2024-02-09 13:25:27)

goplus/gox#333


Patch:
diff --git a/cl/compile.go b/cl/compile.go
index 617bbc38..709739b1 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -19,7 +19,6 @@ package cl
 
 import (
 	"fmt"
-	"go/constant"
 	"go/types"
 	"log"
 	"reflect"
@@ -175,9 +174,6 @@ type Config struct {
 	// Fset provides source position information for syntax trees and types (required).
 	Fset *token.FileSet
 
-	// Context represents all things between packages (optional).
-	Context *gox.Context
-
 	// RelativeBase is the root directory of relative path.
 	RelativeBase string
 
@@ -193,9 +189,6 @@ type Config struct {
 	// See (*github.com/goplus/mod/gopmod.Module).LookupClass.
 	LookupClass func(ext string) (c *Project, ok bool)
 
-	// IsPkgtStandard checks a pkgPath is a Go standard package or not.
-	IsPkgtStandard func(pkgPath string) bool
-
 	// An Importer resolves import paths to Packages (optional).
 	Importer types.Importer
 
@@ -491,8 +484,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
 	confGox := &gox.Config{
 		Types:           conf.Types,
 		Fset:            fset,
-		Context:         conf.Context,
-		IsPkgtStandard:  conf.IsPkgtStandard,
 		Importer:        conf.Importer,
 		LoadNamed:       ctx.loadNamed,
 		HandleErr:       ctx.handleErr,
@@ -625,10 +616,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
 	return
 }
 
-const (
-	gopPackage = "GopPackage"
-)
-
 func isOverloadFunc(name string) bool {
 	n := len(name)
 	return n > 3 && name[n-3:n-1] == "__"
@@ -652,9 +639,6 @@ func initGopPkg(ctx *pkgCtx, pkg *gox.Package, gopSyms map[string]bool) {
 			ctx.loadType(lbi.(*ast.Ident).Name)
 		}
 	}
-	if scope := pkg.Types.Scope(); scope.Lookup(gopPackage) == nil {
-		scope.Insert(types.NewConst(token.NoPos, pkg.Types, gopPackage, types.Typ[types.UntypedBool], constant.MakeBool(true)))
-	}
 	gox.InitThisGopPkg(pkg.Types)
 }
 
diff --git a/cl/internal/spx/game.go b/cl/internal/spx/game.go
index e7b1f1c1..0b7123f9 100644
--- a/cl/internal/spx/game.go
+++ b/cl/internal/spx/game.go
@@ -17,7 +17,7 @@
 package spx
 
 const (
-	GopPackage = true
+	GopPackage = "github.com/goplus/gop/cl/internal/spx/pkg"
 	Gop_sched  = "Sched,SchedNow"
 )
 
diff --git a/cl/internal/spx/pkg/pkg.go b/cl/internal/spx/pkg/pkg.go
index 9c77e7e7..bd2ff494 100644
--- a/cl/internal/spx/pkg/pkg.go
+++ b/cl/internal/spx/pkg/pkg.go
@@ -1,6 +1,6 @@
 package pkg
 
-var (
+const (
 	GopPackage = true
 )
 
diff --git a/cl/outline/outline.go b/cl/outline/outline.go
index 9e97dadd..7adab5ac 100644
--- a/cl/outline/outline.go
+++ b/cl/outline/outline.go
@@ -47,9 +47,6 @@ type Config struct {
 	// LookupClass lookups a class by specified file extension.
 	LookupClass func(ext string) (c *Project, ok bool)
 
-	// IsPkgtStandard checks a pkgPath is a Go standard package or not.
-	IsPkgtStandard func(pkgPath string) bool
-
 	// An Importer resolves import paths to Packages.
 	Importer types.Importer
 }
@@ -66,7 +63,6 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (_ Package, err
 		C2goBase:       conf.C2goBase,
 		LookupPub:      conf.LookupPub,
 		LookupClass:    conf.LookupClass,
-		IsPkgtStandard: conf.IsPkgtStandard,
 		Importer:       conf.Importer,
 		NoFileLine:     true,
 		NoAutoGenMain:  true,
diff --git a/go.mod b/go.mod
index 6b72d104..1f9ce88f 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.18
 require (
 	github.com/fsnotify/fsnotify v1.7.0
 	github.com/goplus/c2go v0.7.21
-	github.com/goplus/gox v1.14.7
+	github.com/goplus/gox v1.14.9
 	github.com/goplus/mod v0.13.0
 	github.com/qiniu/x v1.13.3
 	golang.org/x/tools v0.17.0
diff --git a/go.sum b/go.sum
index d133e80d..9d1c3a36 100644
--- a/go.sum
+++ b/go.sum
@@ -7,8 +7,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
 github.com/goplus/c2go v0.7.21 h1:bRWda6KtQdY0ph+tnPEOGzZMq3OUkAI9cJBzrr5N6AM=
 github.com/goplus/c2go v0.7.21/go.mod h1:45zjbWGW8NDuGfTOrFchCIpH9TbiH7TPg8/zF6EdEyk=
 github.com/goplus/gox v1.14.2/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
-github.com/goplus/gox v1.14.7 h1:C70XxjEVRjrmkblNkbM5oSZOJTOgimsXRtK6/XVlk5s=
-github.com/goplus/gox v1.14.7/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
+github.com/goplus/gox v1.14.9 h1:BXbO79ac0t5jPZ1NVAShPwl+UKVkKyM0cue2Y8idFyY=
+github.com/goplus/gox v1.14.9/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
 github.com/goplus/mod v0.13.0 h1:M/VsI/NWTcs2+vtWBG7793zmlCimKlSMY5LXaiztXV8=
 github.com/goplus/mod v0.13.0/go.mod h1:Qin2SxKoK+3cNFwtg4Jnk1F9Qn5vR6Kwlvr6lTCRJNI=
 github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
diff --git a/load.go b/load.go
index 79890fb4..17990ce4 100644
--- a/load.go
+++ b/load.go
@@ -121,9 +121,6 @@ type Config struct {
 	Filter   func(fs.FileInfo) bool
 	Importer types.Importer
 
-	// Context represents all things between packages (optional).
-	Context *gox.Context
-
 	IgnoreNotatedError bool
 }
 
@@ -186,13 +183,11 @@ func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (ou
 
 	var pkgTest *ast.Package
 	var clConf = &cl.Config{
-		Fset:           fset,
-		Context:        conf.Context,
-		RelativeBase:   relativeBaseOf(mod),
-		Importer:       imp,
-		IsPkgtStandard: mod.IsPkgtStandard,
-		LookupClass:    mod.LookupClass,
-		LookupPub:      c2go.LookupPub(mod),
+		Fset:         fset,
+		RelativeBase: relativeBaseOf(mod),
+		Importer:     imp,
+		LookupClass:  mod.LookupClass,
+		LookupPub:    c2go.LookupPub(mod),
 	}
 
 	for name, pkg := range pkgs {
@@ -272,13 +267,11 @@ func LoadFiles(dir string, files []string, conf *Config) (out *gox.Package, err
 			imp = NewImporter(mod, gop, fset)
 		}
 		clConf := &cl.Config{
-			Fset:           fset,
-			Context:        conf.Context,
-			RelativeBase:   relativeBaseOf(mod),
-			Importer:       imp,
-			LookupClass:    mod.LookupClass,
-			IsPkgtStandard: mod.IsPkgtStandard,
-			LookupPub:      c2go.LookupPub(mod),
+			Fset:         fset,
+			RelativeBase: relativeBaseOf(mod),
+			Importer:     imp,
+			LookupClass:  mod.LookupClass,
+			LookupPub:    c2go.LookupPub(mod),
 		}
 		out, err = cl.NewPackage("", pkg, clConf)
 		if err != nil {
diff --git a/x/typesutil/check.go b/x/typesutil/check.go
index f6803f47..dad82567 100644
--- a/x/typesutil/check.go
+++ b/x/typesutil/check.go
@@ -69,9 +69,6 @@ type Config struct {
 	// Fset provides source position information for syntax trees and types (required).
 	Fset *token.FileSet
 
-	// Context represents all things between packages (optional).
-	Context *gox.Context
-
 	// WorkingDir is the directory in which to run gop compiler (optional).
 	// If WorkingDir is not set, os.Getwd() is used.
 	WorkingDir string
@@ -147,11 +144,9 @@ func (p *Checker) Files(goFiles []*goast.File, gopFiles []*ast.File) (err error)
 	_, err = cl.NewPackage(pkgTypes.Path(), pkg, &cl.Config{
 		Types:          pkgTypes,
 		Fset:           fset,
-		Context:        opts.Context,
 		C2goBase:       opts.C2goBase,
 		LookupPub:      c2go.LookupPub(mod),
 		LookupClass:    mod.LookupClass,
-		IsPkgtStandard: mod.IsPkgtStandard,
 		Importer:       newImporter(conf.Importer, mod, nil, fset),
 		Recorder:       gopRecorder{p.gopInfo},
 		NoFileLine:     true,


Test patch:
diff --git a/cl/compile_gop_test.go b/cl/compile_gop_test.go
index d5e5384a..ce1c1125 100644
--- a/cl/compile_gop_test.go
+++ b/cl/compile_gop_test.go
@@ -174,6 +174,8 @@ println 10 * a
 
 import "fmt"
 
+const GopPackage = true
+
 type foo struct {
 }
 
@@ -226,6 +228,8 @@ var d = a.mul(c)
 
 import "fmt"
 
+const GopPackage = true
+
 type foo struct {
 }
 
@@ -263,6 +267,8 @@ println add("Hello", "World")
 
 import "fmt"
 
+const GopPackage = true
+
 func add__0(a int, b int) int {
 	return a + b
 }
@@ -297,6 +303,7 @@ println mul(1.2, 3.14)
 
 import "fmt"
 
+const GopPackage = true
 const Gopo_mul = "mulInt,mulFloat"
 
 func mulInt(a int, b int) int {
@@ -557,6 +564,8 @@ n.onKey ["a"], nil, key => {
 n.onKey 100, 200
 `, `package main
 
+const GopPackage = true
+
 type Mesh struct {
 }
 
@@ -709,6 +718,8 @@ a += b
 a += c
 `, `package main
 
+const GopPackage = true
+
 var a Vector3
 var b int
 var c float64
@@ -775,6 +786,8 @@ i.onKey ["1","2"], key => {
 
 import "fmt"
 
+const GopPackage = true
+
 func main() {
 	n := &N[int]{}
 	n.OnKey__0("1", func() {
@@ -817,6 +830,8 @@ n.test
 n.test 100
 `, `package main
 
+const GopPackage = true
+
 func main() {
 	Test__0()
 	Test__1(100)
@@ -882,6 +897,8 @@ c := Var(string)
 d := Var(M)
 `, `package main
 
+const GopPackage = true
+
 var a Var__0[int]
 var b Var__1[map[string]interface {
 }]
@@ -1125,6 +1142,8 @@ tbl.col string, "foo"
 tbl.col int, 100
 `, `package main
 
+const GopPackage = true
+
 var tbl *Table
 
 func main() {