Skip to content

Commit 4923495

Browse files
authored
Merge pull request #2541 from xushiwei/proto
prototype: GopXXX => XGoXXX
2 parents 18629ff + 8acad9e commit 4923495

File tree

28 files changed

+307
-262
lines changed

28 files changed

+307
-262
lines changed

cl/_testgop/enumlines-rdr/in.xgo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import "io"
22

33
var r io.Reader
44

5-
for line <- lines(r) {
5+
for line in lines(r) {
66
println line
77
}

cl/_testgop/enumlines-rdr/out.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
var r io.Reader
1010

1111
func main() {
12-
for _xgo_it := osx.Lines(r).Gop_Enum(); ; {
12+
for _xgo_it := osx.Lines(r).XGo_Enum(); ; {
1313
var _xgo_ok bool
1414
line, _xgo_ok := _xgo_it.Next()
1515
if !_xgo_ok {

cl/_testgop/rangeexpr/out.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func main() {
99
fmt.Println(func() (_xgo_ret []int) {
10-
for _xgo_it := xgo.NewRange__0(0, 3, 1).Gop_Enum(); ; {
10+
for _xgo_it := xgo.NewRange__0(0, 3, 1).XGo_Enum(); ; {
1111
var _xgo_ok bool
1212
x, _xgo_ok := _xgo_it.Next()
1313
if !_xgo_ok {

cl/_testspx/execgsh/demo.gsh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
xgo "run", "./foo"
2+
exec "ls $HOME"
3+
ls ${HOME}

cl/_testspx/execgsh/out.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import "github.com/qiniu/x/gsh"
4+
5+
type demo struct {
6+
gsh.App
7+
}
8+
9+
func (this *demo) MainEntry() {
10+
this.XGo_Exec("xgo", "run", "./foo")
11+
this.Exec__1("ls $HOME")
12+
this.XGo_Exec("ls", this.XGo_Env("HOME"))
13+
}
14+
func (this *demo) Main() {
15+
gsh.XGot_App_Main(this)
16+
}
17+
func main() {
18+
new(demo).Main()
19+
}

cl/builtin.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ const (
8282
osxPkgPath = "github.com/qiniu/x/osx"
8383
)
8484

85+
func getXGo_ninteger(ng gogen.PkgRef) types.Object {
86+
scope := ng.Types.Scope()
87+
obj := scope.Lookup("XGo_ninteger")
88+
if obj == nil {
89+
obj = scope.Lookup("Gop_integer") // for backward compatibility
90+
}
91+
return obj
92+
}
93+
8594
func (ctx *pkgCtx) newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package {
8695
builtin := types.NewPackage("", "")
8796
fmt := pkg.Import("fmt")
@@ -97,7 +106,7 @@ func (ctx *pkgCtx) newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *ty
97106
if ng.Types != nil {
98107
initMathBig(pkg, conf, ng)
99108
if typesalias.Support {
100-
if obj := ng.Types.Scope().Lookup("Gop_ninteger"); obj != nil {
109+
if obj := getXGo_ninteger(ng); obj != nil {
101110
if _, ok := obj.Type().(*types.Basic); !ok {
102111
conf.EnableTypesalias = true
103112
ctx.featTypesAlias = true

cl/builtin_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ func TestCompileStmt(t *testing.T) {
176176
compileStmt(ctx, &ast.BadStmt{})
177177
}
178178

179-
func TestTryGopExec(t *testing.T) {
179+
func TestTryXGoExec(t *testing.T) {
180180
pkg := gogen.NewPackage("", "foo", goxConf)
181-
if tryGopExec(pkg.CB(), nil) {
182-
t.Fatal("tryGopExec")
181+
if tryXGoExec(pkg.CB(), nil) {
182+
t.Fatal("tryXGoExec")
183183
}
184184
}
185185

cl/classfile.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,15 @@ func (p *gmxProject) getGameClass(ctx *pkgCtx) string {
171171
return tname
172172
}
173173

174+
func isTestClass(pkg gogen.PkgRef) bool {
175+
scope := pkg.Types.Scope()
176+
return scope.Lookup("XGoTestClass") != nil || scope.Lookup("GopTestClass") != nil
177+
}
178+
174179
func (p *gmxProject) hasMain() bool {
175180
if !p.hasMain_ {
176181
imps := p.pkgImps
177-
p.hasMain_ = len(imps) > 0 && imps[0].TryRef("GopTestClass") != nil
182+
p.hasMain_ = len(imps) > 0 && isTestClass(imps[0])
178183
}
179184
return p.hasMain_
180185
}
@@ -293,7 +298,7 @@ func loadClass(ctx *pkgCtx, pkg *gogen.Package, file string, f *ast.File, conf *
293298
p.game, p.gameIsPtr = spxRef(spx, gt.Class)
294299
spriteFeatures(p.game, sprites)
295300
}
296-
if x := getStringConst(spx, "Gop_sched"); x != "" {
301+
if x := getStringConst(spx, "Gop_sched"); x != "" { // keep Gop_sched
297302
p.scheds, p.hasScheds = strings.SplitN(x, ",", 2), true
298303
}
299304
}

cl/cltest/cltest.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func LookupClass(ext string) (c *modfile.Project, ok bool) {
115115
{Ext: "_res.gox", Class: "Resource", Proto: "ResourceProto"},
116116
},
117117
PkgPaths: []string{"github.com/goplus/xgo/cl/internal/mcp"}}, true
118+
case ".gsh":
119+
return &modfile.Project{
120+
Ext: ".gsh", Class: "App",
121+
PkgPaths: []string{"github.com/qiniu/x/gsh", "math"},
122+
}, true
118123
}
119124
return
120125
}

cl/compile.go

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ type pkgCtx struct {
350350
overpos map[string]token.Pos // overload => pos
351351
fset *token.FileSet
352352
syms map[string]loader
353-
lbinames []any // names that should load before initGopPkg (can be string/func or *ast.Ident/type)
353+
lbinames []any // names that should load before initXGoPkg (can be string/func or *ast.Ident/type)
354354
inits []func()
355355
tylds []*typeLoader
356356
errs errors.List
@@ -387,7 +387,7 @@ type blockCtx struct {
387387
classRecv *ast.FieldList // available when isClass
388388
baseClass types.Object // available when isClass
389389

390-
fileScope *types.Scope // available when isGopFile
390+
fileScope *types.Scope // available when isXGoFile
391391
rec *goxRecorder
392392

393393
fileLine bool
@@ -661,7 +661,7 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gogen.Packag
661661
if rec := ctx.rec; rec != nil {
662662
rec.Scope(f.File, fileScope)
663663
}
664-
preloadGopFile(p, ctx, f.path, f.File, conf)
664+
preloadXGoFile(p, ctx, f.path, f.File, conf)
665665
}
666666

667667
proj, multi := gmxCheckProjs(p, ctx)
@@ -682,7 +682,7 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gogen.Packag
682682
preloadFile(p, ctx, f, skippingGoFile, false)
683683
}
684684

685-
initGopPkg(ctx, p, gopSyms)
685+
initXGoPkg(ctx, p, gopSyms)
686686

687687
// genMain = true if it is main package and no main func
688688
var genMain bool
@@ -741,7 +741,7 @@ func isOverloadFunc(name string) bool {
741741
return n > 3 && name[n-3:n-1] == "__"
742742
}
743743

744-
func initGopPkg(ctx *pkgCtx, pkg *gogen.Package, gopSyms map[string]bool) {
744+
func initXGoPkg(ctx *pkgCtx, pkg *gogen.Package, gopSyms map[string]bool) {
745745
for name, f := range ctx.syms {
746746
if gopSyms[name] {
747747
continue
@@ -759,7 +759,7 @@ func initGopPkg(ctx *pkgCtx, pkg *gogen.Package, gopSyms map[string]bool) {
759759
ctx.loadType(lbi.(*ast.Ident).Name)
760760
}
761761
}
762-
gogen.InitThisGopPkgEx(pkg.Types, ctx.overpos)
762+
gogen.InitXGoPackageEx(pkg.Types, ctx.overpos)
763763
}
764764

765765
func loadFile(ctx *pkgCtx, f *ast.File) {
@@ -805,7 +805,7 @@ func genGoFile(file string, goxTestFile bool) string {
805805
return defaultGoFile
806806
}
807807

808-
func preloadGopFile(p *gogen.Package, ctx *blockCtx, file string, f *ast.File, conf *Config) {
808+
func preloadXGoFile(p *gogen.Package, ctx *blockCtx, file string, f *ast.File, conf *Config) {
809809
var proj *gmxProject
810810
var c *gmxClass
811811
var classType, gameClass string
@@ -944,7 +944,7 @@ func preloadGopFile(p *gogen.Package, ctx *blockCtx, file string, f *ast.File, c
944944
parent.tylds = append(parent.tylds, ld)
945945
}
946946

947-
// bugfix: see TestGopxNoFunc
947+
// bugfix: see TestGoxNoFunc
948948
parent.lbinames = append(parent.lbinames, classType)
949949

950950
ctx.classRecv = &ast.FieldList{List: []*ast.Field{{
@@ -1042,7 +1042,7 @@ func preloadFile(p *gogen.Package, ctx *blockCtx, f *ast.File, goFile string, ge
10421042
log.Println("==> Preload func", fname)
10431043
}
10441044
if initLoader(parent, syms, name.Pos(), name.End(), fname, fn, genFnBody) {
1045-
if strings.HasPrefix(fname, "Gopx_") { // Gopx_xxx func
1045+
if strings.HasPrefix(fname, "XGox_") { // XGox_xxx func
10461046
ctx.lbinames = append(ctx.lbinames, fname)
10471047
}
10481048
}
@@ -1281,7 +1281,7 @@ func preloadFile(p *gogen.Package, ctx *blockCtx, f *ast.File, goFile string, ge
12811281
break LoopFunc
12821282
}
12831283
name1 := overloadFuncName(name.Name, idx)
1284-
onames = append(onames, "") // const Gopo_xxx = "xxxInt,,xxxFloat"
1284+
onames = append(onames, "") // const XGoo_xxx = "xxxInt,,xxxFloat"
12851285
ctx.lbinames = append(ctx.lbinames, name1)
12861286
id := &ast.Ident{NamePos: expr.Pos(), Name: name1}
12871287
if ctx.rec != nil {
@@ -1298,7 +1298,7 @@ func preloadFile(p *gogen.Package, ctx *blockCtx, f *ast.File, goFile string, ge
12981298
break LoopFunc
12991299
}
13001300
}
1301-
if exov { // need Gopo_xxx
1301+
if exov { // need XGoo_xxx
13021302
oname, err := overloadName(recv, name.Name, d.Operator)
13031303
if err != nil {
13041304
ctx.handleErrorf(name.Pos(), name.End(), "%v", err)
@@ -1356,7 +1356,7 @@ func overloadFuncName(name string, idx int) string {
13561356

13571357
func overloadName(recv *ast.Ident, name string, isOp bool) (string, error) {
13581358
if isOp {
1359-
if oname, ok := binaryGopNames[name]; ok {
1359+
if oname, ok := binaryXGoNames[name]; ok {
13601360
name = oname
13611361
} else {
13621362
return "", fmt.Errorf("invalid overload operator %v", name)
@@ -1370,15 +1370,15 @@ func overloadName(recv *ast.Ident, name string, isOp bool) (string, error) {
13701370
if recv != nil {
13711371
typ = recv.Name + sep
13721372
}
1373-
return "Gopo" + sep + typ + name, nil
1373+
return "XGoo" + sep + typ + name, nil
13741374
}
13751375

13761376
func staticMethod(tname, name string) string {
13771377
sep := "_"
13781378
if strings.ContainsRune(name, '_') || strings.ContainsRune(tname, '_') {
13791379
sep = "__"
13801380
}
1381-
return "Gops" + sep + tname + sep + name
1381+
return "XGos" + sep + tname + sep + name
13821382
}
13831383

13841384
func stringLit(val string) *ast.BasicLit {
@@ -1439,11 +1439,11 @@ func loadFunc(ctx *blockCtx, recv *types.Var, name string, d *ast.FuncDecl, genB
14391439
}
14401440
} else if d.Operator {
14411441
if recv != nil { // binary op
1442-
if v, ok := binaryGopNames[name]; ok {
1442+
if v, ok := binaryXGoNames[name]; ok {
14431443
name = v
14441444
}
14451445
} else { // unary op
1446-
if v, ok := unaryGopNames[name]; ok {
1446+
if v, ok := unaryXGoNames[name]; ok {
14471447
name = v
14481448
at := pkg.Types
14491449
arg1 := d.Type.Params.List[0]
@@ -1487,57 +1487,57 @@ func loadFunc(ctx *blockCtx, recv *types.Var, name string, d *ast.FuncDecl, genB
14871487
}
14881488
}
14891489

1490-
var binaryGopNames = map[string]string{
1491-
"+": "Gop_Add",
1492-
"-": "Gop_Sub",
1493-
"*": "Gop_Mul",
1494-
"/": "Gop_Quo",
1495-
"%": "Gop_Rem",
1496-
1497-
"&": "Gop_And",
1498-
"|": "Gop_Or",
1499-
"^": "Gop_Xor",
1500-
"<<": "Gop_Lsh",
1501-
">>": "Gop_Rsh",
1502-
"&^": "Gop_AndNot",
1503-
1504-
"+=": "Gop_AddAssign",
1505-
"-=": "Gop_SubAssign",
1506-
"*=": "Gop_MulAssign",
1507-
"/=": "Gop_QuoAssign",
1508-
"%=": "Gop_RemAssign",
1509-
1510-
"&=": "Gop_AndAssign",
1511-
"|=": "Gop_OrAssign",
1512-
"^=": "Gop_XorAssign",
1513-
"<<=": "Gop_LshAssign",
1514-
">>=": "Gop_RshAssign",
1515-
"&^=": "Gop_AndNotAssign",
1516-
1517-
"==": "Gop_EQ",
1518-
"!=": "Gop_NE",
1519-
"<=": "Gop_LE",
1520-
"<": "Gop_LT",
1521-
">=": "Gop_GE",
1522-
">": "Gop_GT",
1523-
1524-
"->": "Gop_PointTo",
1525-
"<>": "Gop_PointBi",
1526-
1527-
"&&": "Gop_LAnd",
1528-
"||": "Gop_LOr",
1529-
1530-
"<-": "Gop_Send",
1531-
}
1532-
1533-
var unaryGopNames = map[string]string{
1534-
"++": "Gop_Inc",
1535-
"--": "Gop_Dec",
1536-
"-": "Gop_Neg",
1537-
"+": "Gop_Dup",
1538-
"^": "Gop_Not",
1539-
"!": "Gop_LNot",
1540-
"<-": "Gop_Recv",
1490+
var binaryXGoNames = map[string]string{
1491+
"+": "XGo_Add",
1492+
"-": "XGo_Sub",
1493+
"*": "XGo_Mul",
1494+
"/": "XGo_Quo",
1495+
"%": "XGo_Rem",
1496+
1497+
"&": "XGo_And",
1498+
"|": "XGo_Or",
1499+
"^": "XGo_Xor",
1500+
"<<": "XGo_Lsh",
1501+
">>": "XGo_Rsh",
1502+
"&^": "XGo_AndNot",
1503+
1504+
"+=": "XGo_AddAssign",
1505+
"-=": "XGo_SubAssign",
1506+
"*=": "XGo_MulAssign",
1507+
"/=": "XGo_QuoAssign",
1508+
"%=": "XGo_RemAssign",
1509+
1510+
"&=": "XGo_AndAssign",
1511+
"|=": "XGo_OrAssign",
1512+
"^=": "XGo_XorAssign",
1513+
"<<=": "XGo_LshAssign",
1514+
">>=": "XGo_RshAssign",
1515+
"&^=": "XGo_AndNotAssign",
1516+
1517+
"==": "XGo_EQ",
1518+
"!=": "XGo_NE",
1519+
"<=": "XGo_LE",
1520+
"<": "XGo_LT",
1521+
">=": "XGo_GE",
1522+
">": "XGo_GT",
1523+
1524+
"->": "XGo_PointTo",
1525+
"<>": "XGo_PointBi",
1526+
1527+
"&&": "XGo_LAnd",
1528+
"||": "XGo_LOr",
1529+
1530+
"<-": "XGo_Send",
1531+
}
1532+
1533+
var unaryXGoNames = map[string]string{
1534+
"++": "XGo_Inc",
1535+
"--": "XGo_Dec",
1536+
"-": "XGo_Neg",
1537+
"+": "XGo_Dup",
1538+
"^": "XGo_Not",
1539+
"!": "XGo_LNot",
1540+
"<-": "XGo_Recv",
15411541
}
15421542

15431543
func loadFuncBody(ctx *blockCtx, fn *gogen.Func, body *ast.BlockStmt, sigBase *types.Signature, src ast.Node) {

0 commit comments

Comments
 (0)