Skip to content

Commit

Permalink
latest jae fix from #1257
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon authored and tbruyelle committed Oct 19, 2023
1 parent a2d3416 commit 9cf2f47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 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
}
}

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

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/machine.go#L1644

Added line #L1644 was 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
13 changes: 6 additions & 7 deletions gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,11 @@ func (pid PkgID) Bytes() []byte {
}

func PkgIDFromPkgPath(path string) PkgID {
// fmt.Printf("PkgPath %s -> PkgID %v", path,
// PkgID{HashBytes([]byte(path))})
return PkgID{HashBytes([]byte(path))}
}

// func ObjectIDFromPkgPath(path string) ObjectID {
// return ObjectID{
// PkgID: PkgIDFromPkgPath(path),
// NewTime: 1, // by realm logic.
// }
// }

// Returns the ObjectID of the PackageValue associated with path.
func ObjectIDFromPkgPath(path string) ObjectID {
pkgID := PkgIDFromPkgPath(path)
Expand Down Expand Up @@ -159,6 +154,10 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) {
return // do nothing.
}
if po.GetObjectID().PkgID != rlm.ID {
// fmt.Println("PO", po.String())
// fmt.Println("PO.PKGID", po.GetObjectID().PkgID)
// fmt.Println("rlm", rlm)
// fmt.Println("rlm.ID", rlm.ID)

Check warning on line 160 in gnovm/pkg/gnolang/realm.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/realm.go#L157-L160

Added lines #L157 - L160 were not covered by tests
panic("cannot modify external-realm or non-realm object")
}
// From here on, po is real (not new-real).
Expand Down

0 comments on commit 9cf2f47

Please sign in to comment.