Skip to content

Commit

Permalink
chore: jae's fix
Browse files Browse the repository at this point in the history
  • Loading branch information
albttx committed Oct 19, 2023
1 parent d3c3f6a commit a2d3416
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
24 changes: 24 additions & 0 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,30 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue) {
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

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#L1633-L1642

Added lines #L1633 - L1642 were not covered by tests
}
}
// Now check if it is an object.
obj, ok := recvv.(Object)
if ok {
recvOID := obj.GetObjectInfo().ID
if !recvOID.IsZero() {
recvPVOID := ObjectIDFromPkgID(recvOID.PkgID)
pv := m.Store.GetObject(recvPVOID).(*PackageValue)
rlm := pv.GetRealm()
m.Realm = rlm
}

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

View check run for this annotation

Codecov / codecov/patch

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

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

Expand Down
16 changes: 15 additions & 1 deletion gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,23 @@ func PkgIDFromPkgPath(path string) PkgID {
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)
return ObjectIDFromPkgID(pkgID)
}

// Returns the ObjectID of the PackageValue associated with pkgID.
func ObjectIDFromPkgID(pkgID PkgID) ObjectID {
return ObjectID{
PkgID: PkgIDFromPkgPath(path),
PkgID: pkgID,
NewTime: 1, // by realm logic.
}
}
Expand Down

0 comments on commit a2d3416

Please sign in to comment.