Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fix(gnovm): PoC of inter-realm spec #2958

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2dcdfd5
naive fix
ltzmaxwell Jun 24, 2024
3056bcd
Merge branch 'master' of https://github.com/gnolang/gno
ltzmaxwell Jul 26, 2024
e69dfc0
Merge branch 'master' of github.com:gnolang/gno
ltzmaxwell Aug 13, 2024
9d05216
Merge branch 'master' of https://github.com/gnolang/gno
ltzmaxwell Aug 22, 2024
fb2f408
fix untyped bool
ltzmaxwell Aug 22, 2024
22f973f
revert un-intentional change
ltzmaxwell Aug 27, 2024
2926b3d
test files
ltzmaxwell Sep 22, 2024
c3e3bdd
debug
ltzmaxwell Sep 23, 2024
72b28d7
debug
ltzmaxwell Sep 27, 2024
00a59e7
save
ltzmaxwell Oct 7, 2024
71c6fed
external type
ltzmaxwell Oct 8, 2024
07d9029
save
ltzmaxwell Oct 10, 2024
8fdc399
save
ltzmaxwell Oct 14, 2024
a604cdc
more test
ltzmaxwell Oct 16, 2024
2e6a97c
save
ltzmaxwell Nov 6, 2024
7bedb54
save
ltzmaxwell Nov 6, 2024
eeb5bd8
more obj info
ltzmaxwell Nov 8, 2024
9175b85
test
ltzmaxwell Nov 9, 2024
c41caa3
make test pass
ltzmaxwell Nov 12, 2024
48eb8b9
fixup
ltzmaxwell Nov 12, 2024
0bef907
fixup
ltzmaxwell Nov 12, 2024
585b370
test array
ltzmaxwell Nov 13, 2024
c8b24f5
add test
ltzmaxwell Nov 13, 2024
ff95ddc
debug
ltzmaxwell Nov 16, 2024
ecad113
more embede tests
ltzmaxwell Nov 22, 2024
e2670cc
start refactor
ltzmaxwell Nov 24, 2024
e28a2ba
save
ltzmaxwell Nov 25, 2024
696e6da
save
ltzmaxwell Nov 25, 2024
675355d
clean
ltzmaxwell Nov 25, 2024
4af9d45
save
ltzmaxwell Nov 25, 2024
588b9dd
change api
ltzmaxwell Nov 26, 2024
928bda2
fixup
ltzmaxwell Nov 26, 2024
35927e6
fixup
ltzmaxwell Nov 26, 2024
8b435e6
fixup
ltzmaxwell Nov 26, 2024
0d2c203
debug
ltzmaxwell Nov 26, 2024
e0a040e
add test
ltzmaxwell Nov 28, 2024
3ec7a2e
fixup
ltzmaxwell Dec 30, 2024
fd7f8c8
refactor test
ltzmaxwell Dec 31, 2024
453554b
fixup
ltzmaxwell Jan 1, 2025
30883f0
debug
ltzmaxwell Jan 4, 2025
b0241aa
fixup
ltzmaxwell Jan 5, 2025
926e6e9
fixup
ltzmaxwell Jan 6, 2025
bff5b19
fixup
ltzmaxwell Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/gno.land/p/demo/tests/tests2.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tests

type Foo struct{ name string }

var F = Foo{"p"}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (ls *LocalStruct) String() string {
var local *LocalStruct

func init() {
local = &LocalStruct{A: 123}
local = &LocalStruct{A: 123} // this is attached first
}

// Make1 returns a local object wrapped by a p struct
Expand Down
44 changes: 44 additions & 0 deletions examples/gno.land/r/demo/tests/crossrealm/func/crossrealm_func.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package crossrealm_func

type F func() bool

var f F

func SetCallback(ff F) {
f = ff
}

func ExecuteCallback() {
f()
}

var ff = func() string { return "a" } // parent object already escaped

// XXX, this is special case, for ff, it's closure is referenced,
// so need to check all embedded items attached?
// see zrealm_crossrealm38.gno
func GetFunc() func() string {
return ff
}

func GetFunc2() func() string {
return func() string {
return "b"
}
}

type MyStruct struct{}

func (sv *MyStruct) M() string { return "a" }

var mysv *MyStruct = &MyStruct{}

//var f_local func() string
//
//func init() {
// f_local = mysv.M
//}

func GetMethod() func() string {
return mysv.M
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package iface

// XXX, how about not interface
type Fooer interface{ Foo() }

var fooer Fooer

func SetFooer(f Fooer) Fooer {
fooer = f
return fooer
}

func CallFoo() { fooer.Foo() }

// container in external realm
type Container struct {
name string
f Fooer
}

var container Container // attached

func SetContainer(f Fooer) {
container.f = f // update
}

func SetContainer2(f Fooer) {
ff := f // associate to non-attached object
SetContainer(ff) // attach container, while ff is not attached
}
12 changes: 12 additions & 0 deletions examples/gno.land/r/demo/tests/crossrealm/map/crossrealm_map.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package crossrealm_map

var m map[string]int

func init() {
m = make(map[string]int)
m["a"] = 1
}

func GetMap() map[string]int {
return m
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package crossrealm_slice

import "gno.land/p/demo/tests/p_crossrealm"

type Fooer interface{ Foo() }

var S []Fooer

func SetSlice(fs []Fooer) {
S = fs
for _, f := range fs {
println(f)
}
}

// -------------------------------------
type XYZ struct{ name string }

var s1 []XYZ
var s3 []XYZ

// var s4 []XYZ
var s4 = make([]XYZ, 1, 2)

// NOTE that if new list allocated, XYZ{"4"} will be copied, and it's a new object
// var s4 = make([]XYZ, 1)
var s5 []*XYZ
var s6 = make([]*XYZ, 2)

var s7 [2]XYZ

func init() {
s1 = append(s1, XYZ{"1"})
s1 = append(s1, XYZ{"2"})

s3 = append(s3, XYZ{"3"})
//s4 = append(s4, XYZ{"4"})
s4[0] = XYZ{"4"}

s5 = append(s5, &XYZ{"5"})

s6[0] = &XYZ{"6"}

s7[0] = XYZ{"7"}
s7[1] = XYZ{"7.1"} // should be real after this
}

func GetSlice() []XYZ {
return s1[1:]
}

// -------------------------------------------------------
var e1 = XYZ{"1"}
var e2 = XYZ{"2"}

func GetSlice2() []XYZ {
var s2 []XYZ
s2 = append(s2, e1)
s2 = append(s2, e2)
return s2
}

// ------------------------------------------------------
func GetSlice3() []XYZ {
s3 = append(s3, XYZ{"0"}) // this is real after function
return s3
}

func GetSlice4(f func(s []XYZ)) {
s4 = append(s4, XYZ{"0"}) // this is real after this function
f(s4) // XYZ{"0"} is floating
}

func GetSlice5() []*XYZ { // TODO, unwrap
return s5
}

func GetSlice6(f func(s []*XYZ)) {
s6[1] = &XYZ{"6.1"}
f(s6) // not real now
}

func GetSlice7(f func(s [2]XYZ)) {
//s7[1] = XYZ{"7.1"}
f(s7)
}

var s8 [1]p_crossrealm.Stringer

func GetSlice8(f p_crossrealm.Stringer) [1]p_crossrealm.Stringer {
s8[0] = f
return s8
}

func GetSlice9(f p_crossrealm.Stringer) [1]p_crossrealm.Stringer {
var s9 [1]p_crossrealm.Stringer
s9[0] = f
return s9
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package crossrealm_slice

type XYZ struct{ name string }

var s4 = make([]XYZ, 1)

func init() {
s4[0] = XYZ{"4"} // TODO; is it owned by array
}

func GetSlice4(f func(s []XYZ)) {
s4 = append(s4, XYZ{"0"}) // this is real after this function
f(s4) // XYZ{"0"} is floating
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package crossrealm_struct

type Bar struct {
A int
}

var bar *Bar

// TODO: deprovision this
var Bar2 *Bar = &Bar{A: 22} // exported
var Bar3 Bar = Bar{A: 22}

func (b *Bar) String() {
println("b.A: ", b.A)
}

func SetBar(b *Bar) *Bar {
bar = b
return bar
}

func ChangeBar() {
Bar2.A += 1
//println(Bar2.A)
}

func (b *Bar) ModifyBar() {
b.A += 1
}

// -------------------------------------------------
type A struct {
name string
}

type B struct {
name string
}

type D struct {
name string
}

type C struct {
A
B
D
}

var a A = A{name: "a"}
var b B = B{name: "b"}

var c *C

func init() {
c = &C{}
c.A = a
c.B = b
}

func GetStruct(cb func(v *C)) *C {
c.D = D{name: "d"} // this is not attached before return
cb(c)
return c
}

func GetStruct2(cb func(v *C)) *C {
var e = &C{}
e.A = a
e.B = b
cb(e)
return e
}
12 changes: 12 additions & 0 deletions gnovm/pkg/gnolang/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ func init() {

var enabled bool = true

func (debugging) Println2(args ...interface{}) {
if debug2 {
fmt.Println(append([]interface{}{"DEBUG:"}, args...)...)
}
}

func (debugging) Printf2(format string, args ...interface{}) {
if debug2 {
fmt.Printf("DEBUG: "+format, args...)
}
}

func (debugging) Println(args ...interface{}) {
if debug {
if enabled {
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/debug_false.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
package gnolang

const debug debugging = false

const debug2 debugging = false
1 change: 0 additions & 1 deletion gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ func BenchmarkIfStatement(b *testing.B) {
func main() {
for i:=0; i<10000; i++ {
if i > 10 {

}
}
}`
Expand Down
Loading
Loading