Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ltzmaxwell committed Nov 26, 2024
1 parent 8b435e6 commit 0d2c203
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ func (m *Machine) RunDeclaration(d Decl) {
// package level, for which evaluations happen during
// preprocessing).
func (m *Machine) runDeclaration(d Decl) {
fmt.Println("---run declaration, d: ", d)
switch d := d.(type) {
case *FuncDecl:
// nothing to do.
Expand Down
15 changes: 14 additions & 1 deletion gnovm/pkg/gnolang/ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ type Object interface {
SetIsNewReal(bool)
GetLastNewEscapedRealm() PkgID
SetLastNewEscapedRealm(pkgID PkgID)
GetIsRef() bool
SetIsRef(bool)
GetIsNewEscaped() bool
SetIsNewEscaped(bool)
GetIsNewDeleted() bool
Expand Down Expand Up @@ -146,7 +148,7 @@ type ObjectInfo struct {
isDirty bool
isDeleted bool
isNewReal bool
isCrossRealm bool
isRef bool
isNewEscaped bool
isNewDeleted bool
lastNewRealEscapedRealm PkgID
Expand Down Expand Up @@ -323,6 +325,14 @@ func (oi *ObjectInfo) SetLastNewEscapedRealm(pkgId PkgID) {
oi.lastNewRealEscapedRealm = pkgId
}

func (oi *ObjectInfo) GetIsRef() bool {
return oi.isRef
}

func (oi *ObjectInfo) SetIsRef(isRef bool) {
oi.isRef = isRef
}

func (oi *ObjectInfo) GetIsNewEscaped() bool {
return oi.isNewEscaped
}
Expand Down Expand Up @@ -419,6 +429,9 @@ func (tv *TypedValue) GetFirstObject2(store Store) (obj Object, pkgId PkgID) {
return
case *SliceValue:
pkgId = PkgIDFromPkgPath(tv.T.Elem().GetPkgPath())
base := cv.GetBase(store)
fmt.Println("---base: ", base)
fmt.Println("---base.ID: ", base.ID)
return
case *FuncValue:
fmt.Println("---FuncValue")
Expand Down
20 changes: 14 additions & 6 deletions gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func (rlm *Realm) DidUpdate2(store Store, po, xo, co Object, refValue Value) {
}
}

if refValue != nil {
fmt.Printf("---SetIsRef, co: %v\n", co)
co.SetIsRef(true)
}

if po == nil || !po.GetIsReal() { // XXX, make sure po is attached
fmt.Println("---po(Base) not real, do nothing!!!")
return // do nothing.
Expand Down Expand Up @@ -566,13 +571,13 @@ func (rlm *Realm) FinalizeRealmTransaction(readonly bool, store Store) {
// All newly created objects become appended to .created,
// and get assigned ids.
func (rlm *Realm) processNewCreatedMarks(store Store) {
//fmt.Println("---processNewCreatedMarks---")
fmt.Println("---processNewCreatedMarks---")
//fmt.Println("---len of newCreated objects:", len(rlm.newCreated))
// Create new objects and their new descendants.
//for _, oo := range rlm.newCreated {
for i := 0; i < len(rlm.newCreated); i++ {
oo := rlm.newCreated[i]
//fmt.Printf("---oo[%d] is %v:\n", i, oo)
fmt.Printf("---oo[%d] is %v:\n", i, oo)
//if _, ok := oo.(*BoundMethodValue); ok {
// panic("should not happen persist bound method")
//}
Expand Down Expand Up @@ -605,7 +610,8 @@ func (rlm *Realm) processNewCreatedMarks(store Store) {
func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) {
//fmt.Println("---incRefCreatedDescendants, rlm.ID: ", rlm.ID)
//fmt.Println("---incRefCreatedDescendants oo.GetLastEscapedRealm: ", oo.GetLastNewEscapedRealm())
//fmt.Println("---incRefCreatedDescendants from oo: ", oo)
fmt.Println("---incRefCreatedDescendants from oo: ", oo)
//fmt.Println("---oo.GetRefCount: ", oo.GetRefCount())
//fmt.Println("---incRefCreatedDescendants, oo.GetObjectID: ", oo.GetObjectID())

if debug {
Expand All @@ -618,7 +624,9 @@ func (rlm *Realm) incRefCreatedDescendants(store Store, oo Object) {
}

// XXX, oo must be new real here, it's not escaped
if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID {
// if it's reference, all right
fmt.Println("---oo.GetIsRef: ", oo.GetIsRef())
if !oo.GetLastNewEscapedRealm().IsZero() && oo.GetLastNewEscapedRealm() != rlm.ID && !oo.GetIsRef() {
//fmt.Println("---oo.GetLastNewEscapedRealm: ", oo.GetLastNewEscapedRealm())
//fmt.Println("---rlm.ID: ", rlm.ID)
panic("should not happen while attempting to attach new real object from external realm")
Expand Down Expand Up @@ -980,9 +988,9 @@ func (rlm *Realm) saveUnsavedObjectRecursively(store Store, oo Object) {
}

func (rlm *Realm) saveObject(store Store, oo Object) {
//fmt.Println("---saveObject: ", oo)
fmt.Println("---saveObject: ", oo)
oid := oo.GetObjectID()
//fmt.Println("---saveObject: ", oid)
fmt.Println("---saveObject: ", oid)
if oid.IsZero() {
panic("unexpected zero object id")
}
Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/files/zrealm_crossrealm24.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
crossrealm "gno.land/r/demo/tests/crossrealm"
)

var b0 *crossrealm.Bar
var b0 *crossrealm.Bar // this is not attached, po is not real

func init() {
b0 = &crossrealm.Bar{A: 1}
b0 = &crossrealm.Bar{A: 22} // heapItem
}

func main() {
Expand Down
19 changes: 19 additions & 0 deletions gnovm/tests/files/zrealm_crossrealm24a.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// PKGPATH: gno.land/r/crossrealm_test
package crossrealm_test

import (
crossrealm "gno.land/r/demo/tests/crossrealm"
)

var b0 *crossrealm.Bar = &crossrealm.Bar{A: 11} // not attached here

func init() {
b0 = &crossrealm.Bar{A: 22}
}

func main() {
print(".")
}

// Output:
// .
13 changes: 8 additions & 5 deletions gnovm/tests/files/zrealm_crossrealm28.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ type foo struct {

func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) }

var fs []crossrealm.Fooer // panic
// XXX, consider this
var fs []crossrealm.Fooer

func init() {
fs = append(fs, foo{name: "1"}) // attached
fs = append(fs, foo{name: "1"})
fs = append(fs, foo{name: "2"})
}

func main() {
println("ok")
crossrealm.SetSlice(fs)
println("ok")
}

// Error:
// should not happen while attempting to attach new real object from external realm
// Output:
// (struct{("1" string)} gno.land/r/crossrealm_test.foo)
// (struct{("2" string)} gno.land/r/crossrealm_test.foo)
// ok
4 changes: 2 additions & 2 deletions gnovm/tests/files/zrealm_crossrealm28a.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func main() {
println(".")
}

// Error:
// should not happen while attempting to attach new real object from external realm
// Output:
// .
6 changes: 3 additions & 3 deletions gnovm/tests/files/zrealm_crossrealm28c.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ type foo struct {
func (foo) Foo() { println("hello " + std.CurrentRealm().PkgPath()) }

func main() {
var arr []crossrealm.Fooer // not attached here
var arr []crossrealm.Fooer // XXX, the array object should be in current realm
arr = append(arr, foo{name: "1"})
arr = append(arr, foo{name: "2"})
arr = append(arr, foo{name: "3"})

fs := arr[1:]
println("ok")
crossrealm.SetSlice(fs)
println("ok")
}

// Output:
// ok
// (struct{("2" string)} gno.land/r/crossrealm_test.foo)
// (struct{("3" string)} gno.land/r/crossrealm_test.foo)
// ok

0 comments on commit 0d2c203

Please sign in to comment.