diff --git a/compiler/go.mod b/compiler/go.mod index 5f66983..482db81 100644 --- a/compiler/go.mod +++ b/compiler/go.mod @@ -9,6 +9,7 @@ require ( ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/compiler/go.sum b/compiler/go.sum index 96e990c..f1c3071 100644 --- a/compiler/go.sum +++ b/compiler/go.sum @@ -1,3 +1,5 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= diff --git a/compiler/testdata/coroutine.go b/compiler/testdata/coroutine.go index 49d8b25..45062fc 100644 --- a/compiler/testdata/coroutine.go +++ b/compiler/testdata/coroutine.go @@ -328,6 +328,19 @@ func Range10ClosureHeterogenousCapture() { n := 0 x := func() bool { + print("---", + "\n n = ", n, " @", &n, + "\n a = ", a, " @", &a, + "\n b = ", b, " @", &b, + "\n c = ", c, " @", &c, + "\n d = ", d, " @", &d, + "\n e = ", e, " @", &e, + "\n f = ", f, " @", &f, + "\n g = ", g, " @", &g, + "\n h = ", h, " @", &h, + "\n i = ", i, " @", &i, + "\n---\n", + ) var v int switch n { case 0: diff --git a/compiler/testdata/coroutine_durable.go b/compiler/testdata/coroutine_durable.go index 3956356..306b780 100644 --- a/compiler/testdata/coroutine_durable.go +++ b/compiler/testdata/coroutine_durable.go @@ -1526,6 +1526,7 @@ func Range10ClosureHeterogenousCapture() { _o9 = _f.Get(9).(int) _o10 = _f.Get(10).(func() bool) + _o11 = _f.Get(11).(int) } defer func() { @@ -1594,6 +1595,19 @@ func Range10ClosureHeterogenousCapture() { fallthrough case _f.IP < 12: _o10 = func() bool { + print("---", + "\n n = ", _o9, " @", &_o9, + "\n a = ", _o0, " @", &_o0, + "\n b = ", _o1, " @", &_o1, + "\n c = ", _o2, " @", &_o2, + "\n d = ", _o3, " @", &_o3, + "\n e = ", _o4, " @", &_o4, + "\n f = ", _o5, " @", &_o5, + "\n g = ", _o6, " @", &_o6, + "\n h = ", _o7, " @", &_o7, + "\n i = ", _o8, " @", &_o8, + "\n---\n", + ) switch _o9 { case 0: diff --git a/coroutine_durable.go b/coroutine_durable.go index 1f6cf37..5b7f039 100644 --- a/coroutine_durable.go +++ b/coroutine_durable.go @@ -2,7 +2,11 @@ package coroutine -import "github.com/stealthrocket/coroutine/internal/serde" +import ( + "fmt" + + "github.com/stealthrocket/coroutine/internal/serde" +) type serializedCoroutine struct { entry func() @@ -52,6 +56,7 @@ func (c *Context[R, S]) MarshalAppend(b []byte) ([]byte, error) { // the number of bytes that were read in order to reconstruct the // context. func (c *Context[R, S]) Unmarshal(b []byte) (int, error) { + fmt.Println("UNMARSHAL:", &b[0]) start := len(b) v, b := serde.Deserialize(b) s := v.(*serializedCoroutine) diff --git a/internal/serde/reflect.go b/internal/serde/reflect.go index af38c63..f077c52 100644 --- a/internal/serde/reflect.go +++ b/internal/serde/reflect.go @@ -7,6 +7,7 @@ import ( "reflect" "unsafe" + "github.com/davecgh/go-spew/spew" "github.com/stealthrocket/coroutine/types" ) @@ -288,6 +289,7 @@ func deserializePointedAt(d *Deserializer, t reflect.Type) reflect.Value { ep := e.UnsafePointer() d.store(id, ep) DeserializeAny(d, t, ep) + fmt.Printf("deserializePointedAt: %p => %v (%s)\n", ep, e.Elem().Interface(), t) return e } @@ -465,6 +467,11 @@ func serializeFunc(s *Serializer, t reflect.Type, p unsafe.Pointer) { if fn.Closure != nil { t := fn.Closure + v := reflect.NewAt(t, p) + + fmt.Println("SERIALIZE") + spew.Dump(v.Interface()) + serializeStructFields(s, p, t.NumField()-1, func(i int) reflect.StructField { return t.Field(i + 1) }) @@ -496,7 +503,8 @@ func deserializeFunc(d *Deserializer, t reflect.Type, p unsafe.Pointer) { deserializeStructFields(d, closure, t.NumField()-1, func(i int) reflect.StructField { return t.Field(i + 1) }) - //fmt.Printf("%#v\n", v.Interface()) + fmt.Print("DESERIALIZE") + spew.Dump(v.Interface()) *(*unsafe.Pointer)(p) = closure } else {