Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ltzmaxwell committed Dec 13, 2024
1 parent 210d003 commit f3aa400
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/op_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (m *Machine) doOpEval() {
fmt.Println("---v.T: ", v.T)
fmt.Println("---v.V: ", v.V)

SetPointerValueOrigin(&v.V, nx.AbsPath)
SetOriginForPointerValue(&v.V, nx.AbsPath)
m.PushValue(v)
return
}
Expand Down
20 changes: 10 additions & 10 deletions gnovm/pkg/gnolang/op_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (m *Machine) doOpIndex1() {
if exists {
*xv = vv // reuse as result
fmt.Println("---xv1: ", *xv)
SetPointerValueOrigin(&xv.V, abs)
SetOriginForPointerValue(&xv.V, abs)
} else {
vt := ct.Value

Expand All @@ -45,15 +45,15 @@ func (m *Machine) doOpIndex1() {
V: defaultValue(m.Alloc, vt),
}
fmt.Println("---xv2: ", *xv)
SetPointerValueOrigin(&xv.V, abs)
SetOriginForPointerValue(&xv.V, abs)
}
default:
println("---default")
res := xv.GetPointerAtIndex(m.Alloc, m.Store, iv)
*xv = res.Deref() // reuse as result
fmt.Println("---xv: ", *xv)

SetPointerValueOrigin(&xv.V, abs)
SetOriginForPointerValue(&xv.V, abs)

fmt.Println("---*xv: ", *xv)
}
Expand Down Expand Up @@ -84,21 +84,21 @@ func (m *Machine) doOpIndex2() {
T: vt,
V: defaultValue(m.Alloc, vt),
}
SetPointerValueOrigin(&xv.V, abs)
SetOriginForPointerValue(&xv.V, abs)
*iv = untypedBool(false) // reuse as result
} else {
mv := xv.V.(*MapValue)
vv, exists := mv.GetValueForKey(m.Store, iv)
if exists {
*xv = vv // reuse as result
SetPointerValueOrigin(&xv.V, abs)
SetOriginForPointerValue(&xv.V, abs)
*iv = untypedBool(true) // reuse as result
} else {
*xv = TypedValue{ // reuse as result
T: vt,
V: defaultValue(m.Alloc, vt),
}
SetPointerValueOrigin(&xv.V, abs)
SetOriginForPointerValue(&xv.V, abs)
*iv = untypedBool(false) // reuse as result
}
}
Expand All @@ -121,7 +121,7 @@ func (m *Machine) doOpSelector() {
m.Printf("+v[S] %v\n", res)
}
*xv = res // reuse as result
SetPointerValueOrigin(&xv.V, sx.AbsPath)
SetOriginForPointerValue(&xv.V, sx.AbsPath)
//xv.SetPath(sx.AbsPath)
}

Expand Down Expand Up @@ -198,14 +198,14 @@ func (m *Machine) doOpStar() {
// TODO: check this
if pv, ok := xv.V.(PointerValue); ok {
origin := pv.Origin
SetPointerValueOrigin(&refv.V, origin)
SetOriginForPointerValue(&refv.V, origin)
}
m.PushValue(refv)
} else {
v2 := pv.TV.V
if pv, ok := xv.V.(PointerValue); ok {
origin := pv.Origin
SetPointerValueOrigin(&v2, origin)
SetOriginForPointerValue(&v2, origin)
}
m.PushValue(*pv.TV)
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func (m *Machine) doOpRef() {
//}
if pather, ok := rx.X.(AbsPather); ok {
println("---pather")
SetPointerValueOrigin(&tv.V, pather.GetAbsPath())
SetOriginForPointerValue(&tv.V, pather.GetAbsPath())
}
m.PushValue(tv)
}
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,7 @@ func signOfUnsignedBytes(n [8]byte) int {
return 1
}

func SetPointerValueOrigin(v *Value, origin string) {
func SetOriginForPointerValue(v *Value, origin string) {
fmt.Println("---SetPointerValueOrigin, v: ", *v)
fmt.Println("---origin: ", origin)
if pv, ok := (*v).(PointerValue); ok {
Expand Down
8 changes: 7 additions & 1 deletion gnovm/tests/files/ptrmap_3.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ type Foo struct {
var root *Foo

var f = &Foo{name: "a"}
var f2 = &Foo{name: "a2"}

func init() {
root = f
root = f // origin of root is set as f's
}

func main() {
f.name = "b"
println(root == f)

root = f2 // root has new origin(and pointer value)
println(root == f2)
}

// Output:
// true
// true

0 comments on commit f3aa400

Please sign in to comment.