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

cl: fix compileIdent check class SelectorExpr #1548

Merged
merged 2 commits into from
Nov 20, 2023
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
61 changes: 61 additions & 0 deletions cl/compile_spx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,64 @@ func (this *Kai) onMsg(msg string) {
}
`, "Game.tgmx", "Kai.tspx")
}

func TestSpxSelection(t *testing.T) {
gopSpxTestEx(t, `
println "hi"
`, `
import "fmt"
func onMsg(msg string) {
fmt.println msg
this.position.add 100,200
position.add 100,200
position.X += 100
println position.X
this.vector.add 100,200
vector.add 100,200
vector.X += 100
vector.self.X += 100
vector.self.Y += 200
vector.self.add position.X,position.Y
println vector.X
println vector.self.self
}
`, `package main

import (
"fmt"
"github.com/goplus/gop/cl/internal/spx"
)

type Game struct {
*spx.MyGame
}

func (this *Game) MainEntry() {
fmt.Println("hi")
}
func main() {
spx.Gopt_MyGame_Main(new(Game))
}

type Kai struct {
spx.Sprite
*Game
}

func (this *Kai) onMsg(msg string) {
fmt.Println(msg)
this.Position().Add__0(100, 200)
this.Position().Add__0(100, 200)
this.Position().X += 100
fmt.Println(this.Position().X)
this.Vector().Add__0(100, 200)
this.Vector().Add__0(100, 200)
this.Vector().X += 100
this.Vector().Self().X += 100
this.Vector().Self().Y += 200
this.Vector().Self().Add__0(this.Position().X, this.Position().Y)
fmt.Println(this.Vector().X)
fmt.Println(this.Vector().Self().Self())
}
`, "Game.tgmx", "Kai.tspx")
}
6 changes: 5 additions & 1 deletion cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg *gox.PkgRef,
sig := fn.Ancestor().Type().(*types.Signature)
if recv := sig.Recv(); recv != nil {
ctx.cb.Val(recv)
if compileMember(ctx, ident, name, flags&^clCommandWithoutArgs) == nil { // class member object
chkFlag := flags &^ clCommandWithoutArgs
if chkFlag&clIdentSelectorExpr != 0 {
chkFlag = clIdentCanAutoCall
}
if compileMember(ctx, ident, name, chkFlag) == nil { // class member object
return
}
ctx.cb.InternalStack().PopN(1)
Expand Down
14 changes: 9 additions & 5 deletions cl/internal/spx/pkg/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ var (
)

type Vector struct {
x int
y int
X int
Y int
}

func NewVector(x, y int) *Vector {
return &Vector{x, y}
}

func (v *Vector) Add__0(x int, y int) {
v.x += x
v.y += y
v.X += x
v.Y += y
}

func (v *Vector) Add__1(o *Vector) {
v.Add__0(o.x, o.y)
v.Add__0(o.X, o.Y)
}

func (v *Vector) Self() *Vector {
return v
}
9 changes: 9 additions & 0 deletions cl/internal/spx/sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ import (

type Sprite struct {
pos pkg.Vector
Entry
}

type Entry struct {
vec pkg.Vector
}

func (p *Entry) Vector() *pkg.Vector {
return &p.vec
}

func (p *Sprite) SetCostume(costume interface{}) {
Expand Down