Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goplus/gox#333 #1715

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cl

import (
"fmt"
"go/constant"
"go/types"
"log"
"reflect"
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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] == "__"
Expand All @@ -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)
}

Expand Down
19 changes: 19 additions & 0 deletions cl/compile_gop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ println 10 * a
import "fmt"
const GopPackage = true
type foo struct {
}
Expand Down Expand Up @@ -226,6 +228,8 @@ var d = a.mul(c)
import "fmt"
const GopPackage = true
type foo struct {
}
Expand Down Expand Up @@ -263,6 +267,8 @@ println add("Hello", "World")
import "fmt"
const GopPackage = true
func add__0(a int, b int) int {
return a + b
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -557,6 +564,8 @@ n.onKey ["a"], nil, key => {
n.onKey 100, 200
`, `package main
const GopPackage = true
type Mesh struct {
}
Expand Down Expand Up @@ -709,6 +718,8 @@ a += b
a += c
`, `package main
const GopPackage = true
var a Vector3
var b int
var c float64
Expand Down Expand Up @@ -775,6 +786,8 @@ i.onKey ["1","2"], key => {
import "fmt"
const GopPackage = true
func main() {
n := &N[int]{}
n.OnKey__0("1", func() {
Expand Down Expand Up @@ -817,6 +830,8 @@ n.test
n.test 100
`, `package main
const GopPackage = true
func main() {
Test__0()
Test__1(100)
Expand Down Expand Up @@ -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 {
}]
Expand Down Expand Up @@ -1125,6 +1142,8 @@ tbl.col string, "foo"
tbl.col int, 100
`, `package main
const GopPackage = true
var tbl *Table
func main() {
Expand Down
2 changes: 1 addition & 1 deletion cl/internal/spx/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package spx

const (
GopPackage = true
GopPackage = "github.com/goplus/gop/cl/internal/spx/pkg"
Gop_sched = "Sched,SchedNow"
)

Expand Down
2 changes: 1 addition & 1 deletion cl/internal/spx/pkg/pkg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

var (
const (
GopPackage = true
)

Expand Down
4 changes: 0 additions & 4 deletions cl/outline/outline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
27 changes: 10 additions & 17 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions x/typesutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down