From 766e6b27235567e45e20ec15ff8930d53f7a28f7 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 8 Mar 2024 18:12:12 +0800 Subject: [PATCH 1/7] this.Sprite.Main(...) or this.Game.MainEntry(...) --- cl/classfile.go | 28 ++++++++++++++++++++++--- cl/compile.go | 45 ++++++++++++++++++++++++++++++++-------- cl/compile_spx_test.go | 3 ++- cl/expr.go | 2 +- cl/internal/spx3/spx3.go | 4 ++-- 5 files changed, 66 insertions(+), 16 deletions(-) diff --git a/cl/classfile.go b/cl/classfile.go index c19d16ef2..ad9c56823 100644 --- a/cl/classfile.go +++ b/cl/classfile.go @@ -298,16 +298,38 @@ func gmxMainNarg(sig *types.Signature) int { } func hasMethod(o types.Object, name string) bool { + return findMethod(o, name) != nil +} + +func findMethod(o types.Object, name string) *types.Func { if obj, ok := o.(*types.TypeName); ok { if t, ok := obj.Type().(*types.Named); ok { for i, n := 0, t.NumMethods(); i < n; i++ { - if t.Method(i).Name() == name { - return true + f := t.Method(i) + if f.Name() == name { + return f } } } } - return false + return nil +} + +func makeMainSig(recv *types.Var, f *types.Func) *types.Signature { + const ( + paramNameTempl = "_gop_arg0" + ) + sig := f.Type().(*types.Signature) + in := sig.Params() + nin := in.Len() + pkg := recv.Pkg() + params := make([]*types.Var, nin) + paramName := []byte(paramNameTempl) + for i := 0; i < nin; i++ { + paramName[len(paramNameTempl)-1] = byte('0' + i) + params[i] = types.NewParam(token.NoPos, pkg, string(paramName), in.At(i).Type()) + } + return types.NewSignatureType(recv, nil, nil, types.NewTuple(params...), nil, false) } // ----------------------------------------------------------------------------- diff --git a/cl/compile.go b/cl/compile.go index 846c0564a..52d0d57c2 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -369,9 +369,12 @@ type blockCtx struct { tlookup *typeParamLookup c2goBase string // default is `github.com/goplus/` relBaseDir string - classRecv *ast.FieldList // available when gmxSettings != nil - fileScope *types.Scope // only valid when isGopFile - rec *goxRecorder + + classRecv *ast.FieldList // available when isClass + baseClass types.Object // available when isClass + + fileScope *types.Scope // available when isGopFile + rec *goxRecorder fileLine bool isClass bool @@ -742,12 +745,14 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con } if f.IsProj { o := proj.game + ctx.baseClass = o baseTypeName, baseType = o.Name(), o.Type() if proj.gameIsPtr { baseType = types.NewPointer(baseType) } } else { o := proj.sprite[c.ext] + ctx.baseClass = o baseTypeName, baseType, spxClass = o.Name(), o.Type(), true } } @@ -1215,8 +1220,17 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) { log.Printf("==> Load method %v.%s\n", recv.Type(), name) } } - pkg := ctx.pkg - if d.Operator { + var pkg = ctx.pkg + var sigBase *types.Signature + if d.Shadow { + if recv != nil { + if base := ctx.baseClass; base != nil { + if f := findMethod(base, name); f != nil { + sigBase = makeMainSig(recv, f) + } + } + } + } else if d.Operator { if recv != nil { // binary op if v, ok := binaryGopNames[name]; ok { name = v @@ -1232,7 +1246,10 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) { } } } - sig := toFuncType(ctx, d.Type, recv, d) + sig := sigBase + if sig == nil { + sig = toFuncType(ctx, d.Type, recv, d) + } fn, err := pkg.NewFuncWith(d.Name.Pos(), name, sig, func() token.Pos { return d.Recv.List[0].Type.Pos() }) @@ -1253,11 +1270,11 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) { file := pkg.CurFile() ctx.inits = append(ctx.inits, func() { // interface issue: #795 old := pkg.RestoreCurFile(file) - loadFuncBody(ctx, fn, body, d) + loadFuncBody(ctx, fn, body, sigBase, d) pkg.RestoreCurFile(old) }) } else { - loadFuncBody(ctx, fn, body, d) + loadFuncBody(ctx, fn, body, nil, d) } } } @@ -1316,8 +1333,18 @@ var unaryGopNames = map[string]string{ "<-": "Gop_Recv", } -func loadFuncBody(ctx *blockCtx, fn *gox.Func, body *ast.BlockStmt, src ast.Node) { +func loadFuncBody(ctx *blockCtx, fn *gox.Func, body *ast.BlockStmt, sigBase *types.Signature, src ast.Node) { cb := fn.BodyStart(ctx.pkg, body) + if sigBase != nil { + // this.Sprite.Main(...) or this.Game.MainEntry(...) + cb.VarVal("this").MemberVal(ctx.baseClass.Name()).MemberVal(fn.Name()) + params := sigBase.Params() + n := params.Len() + for i := 0; i < n; i++ { + cb.Val(params.At(i)) + } + cb.Call(n).EndStmt() + } compileStmts(ctx, body.List) if rec := ctx.recorder(); rec != nil { switch fn := src.(type) { diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go index c76895995..4fbf4faa6 100644 --- a/cl/compile_spx_test.go +++ b/cl/compile_spx_test.go @@ -486,7 +486,8 @@ func (this *Game) MainEntry() { func main() { spx3.Gopt_Game_Main(new(Game), new(Kai)) } -func (this *Kai) Main() { +func (this *Kai) Main(_gop_arg0 string) { + this.Sprite.Main(_gop_arg0) fmt.Println(jwt.Token("Hi")) } `, "main_spx.gox", "Kai_spx.gox") diff --git a/cl/expr.go b/cl/expr.go index 8ffc3b124..735c3a5bb 100644 --- a/cl/expr.go +++ b/cl/expr.go @@ -904,7 +904,7 @@ func compileFuncLit(ctx *blockCtx, v *ast.FuncLit) { } fn := cb.NewClosureWith(sig) if body := v.Body; body != nil { - loadFuncBody(ctx, fn, body, v) + loadFuncBody(ctx, fn, body, nil, v) cb.SetComments(comments, once) } } diff --git a/cl/internal/spx3/spx3.go b/cl/internal/spx3/spx3.go index 8f1d8574b..551fcdb16 100644 --- a/cl/internal/spx3/spx3.go +++ b/cl/internal/spx3/spx3.go @@ -38,7 +38,7 @@ func (p *Sprite) Name() string { return "sprite" } -func (p *Sprite) initSprite(name string) {} +func (p *Sprite) Main(name string) {} -func Gopt_Game_Main(game interface{ initGame() }, workers ...interface{ initSprite(name string) }) { +func Gopt_Game_Main(game interface{ initGame() }, workers ...interface{ Main(name string) }) { } From 998c3e4fb2b2a5ee0fdfffed740af3a1ac1a24de Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 8 Mar 2024 18:35:07 +0800 Subject: [PATCH 2/7] ClassNameAndExt: remove :. --- cl/builtin_test.go | 6 +++++- cl/classfile.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cl/builtin_test.go b/cl/builtin_test.go index cdb95b972..3c0d18eec 100644 --- a/cl/builtin_test.go +++ b/cl/builtin_test.go @@ -288,7 +288,11 @@ func TestMarkAutogen(t *testing.T) { func TestClassNameAndExt(t *testing.T) { name, ext := ClassNameAndExt("/foo/bar.abc_yap.gox") - if name != "bar" || ext != "_yap.gox" { + if name != "bar_abc" || ext != "_yap.gox" { + t.Fatal("classNameAndExt:", name, ext) + } + name, ext = ClassNameAndExt("/foo/get_bar_:id.yap") + if name != "get_bar_id" || ext != ".yap" { t.Fatal("classNameAndExt:", name, ext) } } diff --git a/cl/classfile.go b/cl/classfile.go index ad9c56823..84332e55f 100644 --- a/cl/classfile.go +++ b/cl/classfile.go @@ -73,8 +73,8 @@ func (p *gmxProject) getScheds(cb *gox.CodeBuilder) []goast.Stmt { func ClassNameAndExt(file string) (name, ext string) { fname := filepath.Base(file) name, ext = modfile.SplitFname(fname) - if idx := strings.Index(name, "."); idx > 0 { - name = name[:idx] + if strings.ContainsAny(name, ":.") { + name = strings.NewReplacer(":", "", ".", "_").Replace(name) } return } From 1abc2bc0e89fe60bdda80981b720c7c8d007e221 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 8 Mar 2024 19:43:36 +0800 Subject: [PATCH 3/7] spxClass: Classfname() string --- cl/builtin_test.go | 10 +++--- cl/classfile.go | 16 ++++++---- cl/compile.go | 34 +++++++++++++++++--- cl/compile_spx_test.go | 72 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 16 deletions(-) diff --git a/cl/builtin_test.go b/cl/builtin_test.go index 3c0d18eec..99e269c0f 100644 --- a/cl/builtin_test.go +++ b/cl/builtin_test.go @@ -287,12 +287,12 @@ func TestMarkAutogen(t *testing.T) { } func TestClassNameAndExt(t *testing.T) { - name, ext := ClassNameAndExt("/foo/bar.abc_yap.gox") - if name != "bar_abc" || ext != "_yap.gox" { + name, clsfile, ext := ClassNameAndExt("/foo/bar.abc_yap.gox") + if name != "bar_abc" || clsfile != "bar.abc" || ext != "_yap.gox" { t.Fatal("classNameAndExt:", name, ext) } - name, ext = ClassNameAndExt("/foo/get_bar_:id.yap") - if name != "get_bar_id" || ext != ".yap" { + name, clsfile, ext = ClassNameAndExt("/foo/get_bar_:id.yap") + if name != "get_bar_id" || clsfile != "get_bar_:id" || ext != ".yap" { t.Fatal("classNameAndExt:", name, ext) } } @@ -451,7 +451,7 @@ func TestGmxProject(t *testing.T) { pkg := gox.NewPackage("", "foo", goxConf) ctx := &pkgCtx{ projs: make(map[string]*gmxProject), - classes: make(map[*ast.File]gmxClass), + classes: make(map[*ast.File]*gmxClass), } gmx := loadClass(ctx, pkg, "main.t2gmx", &ast.File{IsProj: true}, &Config{ LookupClass: lookupClass, diff --git a/cl/classfile.go b/cl/classfile.go index 84332e55f..6645b70b2 100644 --- a/cl/classfile.go +++ b/cl/classfile.go @@ -33,9 +33,10 @@ import ( // ----------------------------------------------------------------------------- type gmxClass struct { - tname string // class type - ext string - proj *gmxProject + tname string // class type + clsfile string + ext string + proj *gmxProject } type gmxProject struct { @@ -70,9 +71,10 @@ func (p *gmxProject) getScheds(cb *gox.CodeBuilder) []goast.Stmt { return p.schedStmts } -func ClassNameAndExt(file string) (name, ext string) { +func ClassNameAndExt(file string) (name, clsfile, ext string) { fname := filepath.Base(file) - name, ext = modfile.SplitFname(fname) + clsfile, ext = modfile.SplitFname(fname) + name = clsfile if strings.ContainsAny(name, ":.") { name = strings.NewReplacer(":", "", ".", "_").Replace(name) } @@ -84,7 +86,7 @@ func isGoxTestFile(ext string) bool { } func loadClass(ctx *pkgCtx, pkg *gox.Package, file string, f *ast.File, conf *Config) *gmxProject { - tname, ext := ClassNameAndExt(file) + tname, clsfile, ext := ClassNameAndExt(file) gt, ok := conf.LookupClass(ext) if !ok { panic("TODO: class not found") @@ -138,7 +140,7 @@ func loadClass(ctx *pkgCtx, pkg *gox.Package, file string, f *ast.File, conf *Co } else { p.sptypes = append(p.sptypes, tname) } - ctx.classes[f] = gmxClass{tname, ext, p} + ctx.classes[f] = &gmxClass{tname, clsfile, ext, p} if debugLoad { log.Println("==> InitClass", tname, "isProj:", f.IsProj) } diff --git a/cl/compile.go b/cl/compile.go index 52d0d57c2..7cc31aeb0 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -338,7 +338,7 @@ func doInitMethods(ld *typeLoader) { type pkgCtx struct { *nodeInterp projs map[string]*gmxProject // .gmx => project - classes map[*ast.File]gmxClass + classes map[*ast.File]*gmxClass fset *token.FileSet cpkgs *cpackages.Importer syms map[string]loader @@ -491,7 +491,7 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package, fset: fset, nodeInterp: interp, projs: make(map[string]*gmxProject), - classes: make(map[*ast.File]gmxClass), + classes: make(map[*ast.File]*gmxClass), syms: make(map[string]loader), generics: make(map[string]bool), } @@ -718,6 +718,7 @@ func genGoFile(file string, goxTestFile bool) string { func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, conf *Config) { var proj *gmxProject + var c *gmxClass var classType string var testType string var baseTypeName string @@ -727,12 +728,12 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con var parent = ctx.pkgCtx if f.IsClass { if f.IsNormalGox { - classType, _ = ClassNameAndExt(file) + classType, _, _ = ClassNameAndExt(file) if classType == "main" { classType = "_main" } } else { - c := parent.classes[f] + c = parent.classes[f] classType = c.tname proj, ctx.proj = c.proj, c.proj ctx.autoimps = proj.autoimps @@ -851,6 +852,31 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con X: &ast.Ident{Name: classType}, }, }}} + // func Classfname() string + if spxClass { + f.Decls = append(f.Decls, &ast.FuncDecl{ + Name: &ast.Ident{ + Name: "Classfname", + }, + Type: &ast.FuncType{ + Params: &ast.FieldList{}, + Results: &ast.FieldList{ + List: []*ast.Field{ + {Type: &ast.Ident{Name: "string"}}, + }, + }, + }, + Body: &ast.BlockStmt{ + List: []ast.Stmt{ + &ast.ReturnStmt{ + Results: []ast.Expr{ + &ast.BasicLit{Kind: token.STRING, Value: strconv.Quote(c.clsfile)}, + }, + }, + }, + }, + }) + } } if d := f.ShadowEntry; d != nil { d.Name.Name = getEntrypoint(f) diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go index 4fbf4faa6..8892aae16 100644 --- a/cl/compile_spx_test.go +++ b/cl/compile_spx_test.go @@ -206,6 +206,9 @@ func (this *Kai) onMsg(msg string) { this.Say("Hi") } } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -250,6 +253,9 @@ func (this *index) onInit() { this.bar() fmt.Println("Hi") } +func (this *bar) Classfname() string { + return "bar" +} `) } @@ -278,6 +284,9 @@ func (this *index) MainEntry() { func main() { spx.Gopt_MyGame_Main(new(index)) } +func (this *bar) Classfname() string { + return "bar" +} `) } @@ -314,6 +323,9 @@ func (this *index) MainEntry() { func main() { spx.Gopt_MyGame_Main(new(index)) } +func (this *bar) Classfname() string { + return "bar" +} `) } @@ -359,6 +371,9 @@ func (this *bar) onInit() { this.Say("Where do you come from?", 2) this.Broadcast__0("msg2") } +func (this *bar) Classfname() string { + return "bar" +} `, "Game.tgmx", "bar.tspx") } @@ -408,6 +423,9 @@ func (this *Kai) onInit() { func (this *Kai) onCloned() { this.Say("Hi") } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -451,6 +469,9 @@ func main() { func (this *Kai) Main() { fmt.Println("Hi") } +func (this *Kai) Classfname() string { + return "Kai" +} `, "index.tgmx", "Kai.tspx") } @@ -490,6 +511,9 @@ func (this *Kai) Main(_gop_arg0 string) { this.Sprite.Main(_gop_arg0) fmt.Println(jwt.Token("Hi")) } +func (this *Kai) Classfname() string { + return "Kai" +} `, "main_spx.gox", "Kai_spx.gox") } @@ -523,6 +547,9 @@ func (this *Game) MainEntry() { func main() { spx3.Gopt_Game_Main(new(Game), new(Kai)) } +func (this *Kai) Classfname() string { + return "Kai" +} `, "main_spx.gox", "Kai_spx.gox") } @@ -555,6 +582,9 @@ func main() { } func (this *Kai) onMsg(msg string) { } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.t2gmx", "Kai.t2spx") } @@ -587,6 +617,9 @@ func main() { } func (this *Kai) onMsg(msg string) { } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.t2gmx", "Kai.t2spx2") } @@ -613,8 +646,14 @@ type Kai struct { func (this *Dog) Main() { fmt.Println("Hi, Sprite") } +func (this *Dog) Classfname() string { + return "Dog" +} func (this *Kai) onMsg(msg string) { } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Dog_t3spx.gox", "Kai.t3spx2") } @@ -642,6 +681,9 @@ func (this *Game) MainEntry() { func main() { new(Game).Main() } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.t2gmx", "Kai.t2spx", "") gopSpxTestExConf(t, "OnlyGmx", &conf, ` var ( @@ -666,6 +708,9 @@ func (this *Game) MainEntry() { func main() { new(Game).Main() } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.t2gmx", "Kai.t2spx", "") gopSpxTestExConf(t, "KaiAndGmx", &conf, ` @@ -708,6 +753,9 @@ func (this *Kai) Main() { } func (this *Kai) onMsg(msg string) { } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.t2gmx", "Kai.t2spx", "") } @@ -746,6 +794,9 @@ func (this *Kai) onMsg(msg string) { this.Say("Hi") } } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -810,6 +861,9 @@ func (this *Kai) onInit() { func (this *Kai) onCloned() { this.Say("Hi") } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -847,6 +901,9 @@ func main() { } func (this *Kai) onMsg(msg string) { } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -881,6 +938,9 @@ func main() { func (this *Kai) onMsg(msg string) { this.Position().Add__0(100, 200) } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -940,6 +1000,9 @@ func (this *Kai) onMsg(msg string) { fmt.Println(this.Vector().X) fmt.Println(this.Vector().Self().Self()) } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -1041,6 +1104,9 @@ func (this *Kai) Main() { spx.Gopt_Sprite_OnKey2(this, "hello", func(key string) { }) } +func (this *Kai) Classfname() string { + return "Kai" +} `, "Game.tgmx", "Kai.tspx") } @@ -1077,6 +1143,9 @@ func (this *caseFoo) Main() { t.Fatal("failed") }) } +func (this *caseFoo) Classfname() string { + return "Foo" +} func TestFoo(t *testing.T) { test.Gopt_Case_TestMain(new(caseFoo), t) } @@ -1105,6 +1174,9 @@ type case_foo struct { func (this *case_foo) Main() { this.T().Log("Hi") } +func (this *case_foo) Classfname() string { + return "foo" +} func Test_foo(t *testing.T) { test.Gopt_Case_TestMain(new(case_foo), t) } From 49921b85e50ae1536a958ad6e8b13e9c4147d548 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 8 Mar 2024 19:49:33 +0800 Subject: [PATCH 4/7] commentStmt: skip noPos --- cl/stmt.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cl/stmt.go b/cl/stmt.go index 359f54811..7d9b1eca5 100644 --- a/cl/stmt.go +++ b/cl/stmt.go @@ -53,6 +53,10 @@ func commentStmt(ctx *blockCtx, stmt ast.Stmt) { func commentStmtEx(cb *gox.CodeBuilder, ctx *pkgCtx, stmt ast.Stmt) { start := stmt.Pos() + if start == token.NoPos { + cb.SetComments(nil, false) + return + } if doc := checkStmtDoc(stmt); doc != nil { start = doc.Pos() } From 60dfd5b6231a21fe26ae162f80f16fd703663e70 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 8 Mar 2024 20:20:58 +0800 Subject: [PATCH 5/7] ClassNameAndExt: :-. --- cl/builtin_test.go | 4 ++-- cl/classfile.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cl/builtin_test.go b/cl/builtin_test.go index 99e269c0f..ffa51f465 100644 --- a/cl/builtin_test.go +++ b/cl/builtin_test.go @@ -291,8 +291,8 @@ func TestClassNameAndExt(t *testing.T) { if name != "bar_abc" || clsfile != "bar.abc" || ext != "_yap.gox" { t.Fatal("classNameAndExt:", name, ext) } - name, clsfile, ext = ClassNameAndExt("/foo/get_bar_:id.yap") - if name != "get_bar_id" || clsfile != "get_bar_:id" || ext != ".yap" { + name, clsfile, ext = ClassNameAndExt("/foo/get-bar_:id.yap") + if name != "get_bar_id" || clsfile != "get-bar_:id" || ext != ".yap" { t.Fatal("classNameAndExt:", name, ext) } } diff --git a/cl/classfile.go b/cl/classfile.go index 6645b70b2..527500dab 100644 --- a/cl/classfile.go +++ b/cl/classfile.go @@ -75,8 +75,8 @@ func ClassNameAndExt(file string) (name, clsfile, ext string) { fname := filepath.Base(file) clsfile, ext = modfile.SplitFname(fname) name = clsfile - if strings.ContainsAny(name, ":.") { - name = strings.NewReplacer(":", "", ".", "_").Replace(name) + if strings.ContainsAny(name, ":-.") { + name = strings.NewReplacer(":", "", "-", "_", ".", "_").Replace(name) } return } From 8e2f55033d557bd8e8521cbf13e10d210a44677b Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 8 Mar 2024 21:25:46 +0800 Subject: [PATCH 6/7] x/typesutil --- x/typesutil/info_test.go | 86 +++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/x/typesutil/info_test.go b/x/typesutil/info_test.go index 86faca944..22a288550 100644 --- a/x/typesutil/info_test.go +++ b/x/typesutil/info_test.go @@ -1623,53 +1623,57 @@ func onCloned() { say("Hi") } `, `== types == -000: 0: 0 | Kai *ast.Ident | type : main.Kai | type -001: 3: 4 | int *ast.Ident | type : int | type -002: 6:11 | struct { +000: 0: 0 | "Kai" *ast.BasicLit | value : untyped string = "Kai" | constant +001: 0: 0 | Kai *ast.Ident | type : main.Kai | type +002: 0: 0 | string *ast.Ident | type : string | type +003: 3: 4 | int *ast.Ident | type : int | type +004: 6:11 | struct { x int y int } *ast.StructType | type : struct{x int; y int} | type -003: 7: 4 | int *ast.Ident | type : int | type -004: 8: 4 | int *ast.Ident | type : int | type -005: 12: 2 | a *ast.Ident | var : int | variable -006: 12: 6 | 1 *ast.BasicLit | value : untyped int = 1 | constant -007: 13: 2 | clone *ast.Ident | value : func(sprite interface{}) | value -008: 14: 2 | clone *ast.Ident | value : func(sprite interface{}, data interface{}) | value -009: 14: 2 | clone info{1, 2} *ast.CallExpr | void : () | no value -010: 14: 8 | info *ast.Ident | type : main.info | type -011: 14: 8 | info{1, 2} *ast.CompositeLit | value : main.info | value -012: 14:13 | 1 *ast.BasicLit | value : untyped int = 1 | constant -013: 14:15 | 2 *ast.BasicLit | value : untyped int = 2 | constant -014: 15: 2 | clone *ast.Ident | value : func(sprite interface{}, data interface{}) | value -015: 15: 2 | clone &info{1, 2} *ast.CallExpr | void : () | no value -016: 15: 8 | &info{1, 2} *ast.UnaryExpr | value : *main.info | value -017: 15: 9 | info *ast.Ident | type : main.info | type -018: 15: 9 | info{1, 2} *ast.CompositeLit | value : main.info | value -019: 15:14 | 1 *ast.BasicLit | value : untyped int = 1 | constant -020: 15:16 | 2 *ast.BasicLit | value : untyped int = 2 | constant -021: 19: 2 | say *ast.Ident | value : func(msg string, secs ...float64) | value -022: 19: 2 | say("Hi") *ast.CallExpr | void : () | no value -023: 19: 6 | "Hi" *ast.BasicLit | value : untyped string = "Hi" | constant +005: 7: 4 | int *ast.Ident | type : int | type +006: 8: 4 | int *ast.Ident | type : int | type +007: 12: 2 | a *ast.Ident | var : int | variable +008: 12: 6 | 1 *ast.BasicLit | value : untyped int = 1 | constant +009: 13: 2 | clone *ast.Ident | value : func(sprite interface{}) | value +010: 14: 2 | clone *ast.Ident | value : func(sprite interface{}, data interface{}) | value +011: 14: 2 | clone info{1, 2} *ast.CallExpr | void : () | no value +012: 14: 8 | info *ast.Ident | type : main.info | type +013: 14: 8 | info{1, 2} *ast.CompositeLit | value : main.info | value +014: 14:13 | 1 *ast.BasicLit | value : untyped int = 1 | constant +015: 14:15 | 2 *ast.BasicLit | value : untyped int = 2 | constant +016: 15: 2 | clone *ast.Ident | value : func(sprite interface{}, data interface{}) | value +017: 15: 2 | clone &info{1, 2} *ast.CallExpr | void : () | no value +018: 15: 8 | &info{1, 2} *ast.UnaryExpr | value : *main.info | value +019: 15: 9 | info *ast.Ident | type : main.info | type +020: 15: 9 | info{1, 2} *ast.CompositeLit | value : main.info | value +021: 15:14 | 1 *ast.BasicLit | value : untyped int = 1 | constant +022: 15:16 | 2 *ast.BasicLit | value : untyped int = 2 | constant +023: 19: 2 | say *ast.Ident | value : func(msg string, secs ...float64) | value +024: 19: 2 | say("Hi") *ast.CallExpr | void : () | no value +025: 19: 6 | "Hi" *ast.BasicLit | value : untyped string = "Hi" | constant == defs == -000: 0: 0 | this | var this *main.Kai -001: 3: 2 | a | field a int -002: 6: 6 | info | type main.info struct{x int; y int} -003: 7: 2 | x | field x int -004: 8: 2 | y | field y int -005: 11: 6 | onInit | func (*main.Kai).onInit() -006: 18: 6 | onCloned | func (*main.Kai).onCloned() +000: 0: 0 | Classfname | func (*main.Kai).Classfname() string +001: 0: 0 | this | var this *main.Kai +002: 3: 2 | a | field a int +003: 6: 6 | info | type main.info struct{x int; y int} +004: 7: 2 | x | field x int +005: 8: 2 | y | field y int +006: 11: 6 | onInit | func (*main.Kai).onInit() +007: 18: 6 | onCloned | func (*main.Kai).onCloned() == uses == 000: 0: 0 | Kai | type main.Kai struct{github.com/goplus/gop/cl/internal/spx.Sprite; a int} -001: 3: 4 | int | type int -002: 7: 4 | int | type int -003: 8: 4 | int | type int -004: 12: 2 | a | field a int -005: 13: 2 | clone | func github.com/goplus/gop/cl/internal/spx.Gopt_Sprite_Clone__0(sprite interface{}) -006: 14: 2 | clone | func github.com/goplus/gop/cl/internal/spx.Gopt_Sprite_Clone__1(sprite interface{}, data interface{}) -007: 14: 8 | info | type main.info struct{x int; y int} -008: 15: 2 | clone | func github.com/goplus/gop/cl/internal/spx.Gopt_Sprite_Clone__1(sprite interface{}, data interface{}) -009: 15: 9 | info | type main.info struct{x int; y int} -010: 19: 2 | say | func (*github.com/goplus/gop/cl/internal/spx.Sprite).Say(msg string, secs ...float64)`) +001: 0: 0 | string | type string +002: 3: 4 | int | type int +003: 7: 4 | int | type int +004: 8: 4 | int | type int +005: 12: 2 | a | field a int +006: 13: 2 | clone | func github.com/goplus/gop/cl/internal/spx.Gopt_Sprite_Clone__0(sprite interface{}) +007: 14: 2 | clone | func github.com/goplus/gop/cl/internal/spx.Gopt_Sprite_Clone__1(sprite interface{}, data interface{}) +008: 14: 8 | info | type main.info struct{x int; y int} +009: 15: 2 | clone | func github.com/goplus/gop/cl/internal/spx.Gopt_Sprite_Clone__1(sprite interface{}, data interface{}) +010: 15: 9 | info | type main.info struct{x int; y int} +011: 19: 2 | say | func (*github.com/goplus/gop/cl/internal/spx.Sprite).Say(msg string, secs ...float64)`) } func TestScopesInfo(t *testing.T) { From acf0a7d5ffb45da28cdda24f538c89f91a0a7971 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 8 Mar 2024 21:29:55 +0800 Subject: [PATCH 7/7] x/build --- x/build/build_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/build/build_test.go b/x/build/build_test.go index 8e2f621f0..fed51751a 100644 --- a/x/build/build_test.go +++ b/x/build/build_test.go @@ -401,6 +401,9 @@ func main() { func (this *Cat) Main() { fmt.Println("hi") } +func (this *Cat) Classfname() string { + return "Cat" +} `) }