Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Oct 19, 2023
1 parent bc47c25 commit ec4d717
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
36 changes: 14 additions & 22 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,33 +1627,25 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) {
}
m.Package = pv
rlm := pv.GetRealm()
if rlm != nil && m.Realm != rlm {
m.Realm = rlm // enter new realm
} else if rlm == nil && recv.V != nil { // XXX maybe improve this part.
// maybe this is a bound method of a recv of a realm.
// in that case, inherit the realm of the receiver.
recvv := recv.V
// deref if pointer.
// XXX I guess we want to deref as much as possible.
for {
if pv, ok := recvv.(PointerValue); ok {
recvv = pv.Deref().V
} else {
break
}
}
// Now check if it is an object.
obj, ok := recvv.(Object)
if ok {
if rlm == nil && recv.IsDefined() {
// if bound method, get realm from receiver.
obj := recv.GetFirstObject(m.Store)
if obj == nil {
// panic("XXX not sure why this would be")
fmt.Println("XXX XXX", recv.String())
} else {
recvOID := obj.GetObjectInfo().ID
if !recvOID.IsZero() {
recvPVOID := ObjectIDFromPkgID(recvOID.PkgID)
pv := m.Store.GetObject(recvPVOID).(*PackageValue)
rlm := pv.GetRealm()
m.Realm = rlm
recvPkgOID := ObjectIDFromPkgID(recvOID.PkgID)
pv := m.Store.GetObject(recvPkgOID).(*PackageValue)
rlm = pv.GetRealm() // done
}

Check warning on line 1642 in gnovm/pkg/gnolang/machine.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/machine.go#L1631-L1642

Added lines #L1631 - L1642 were not covered by tests
}
}
if rlm != nil && m.Realm != rlm {
// enter new realm
m.Realm = rlm

Check warning on line 1647 in gnovm/pkg/gnolang/machine.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/machine.go#L1646-L1647

Added lines #L1646 - L1647 were not covered by tests
}
}

func (m *Machine) PushFrameGoNative(cx *CallExpr, fv *NativeValue) {
Expand Down
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func (tv *TypedValue) GetFirstObject(store Store) Object {
// something in it; in that case, ignore the base. That will
// likely require maybe a preparation step in persistence
// ( or unlikely, a second type of ref-counting).
// XXX is there an issue with Base=nil pointers here cross realm?

Check warning on line 335 in gnovm/pkg/gnolang/ownership.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/ownership.go#L335

Added line #L335 was not covered by tests
if cv.Base != nil {
return cv.Base.(Object)
} else {
Expand Down

0 comments on commit ec4d717

Please sign in to comment.