57 lines
939 B
Go
57 lines
939 B
Go
package main
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"github.com/goplus/llgo/runtime/abi"
|
|
)
|
|
|
|
type T struct {
|
|
p *T
|
|
t *abi.Type
|
|
n uintptr
|
|
a []T
|
|
}
|
|
|
|
type eface struct {
|
|
typ *abi.Type
|
|
data unsafe.Pointer
|
|
}
|
|
|
|
func toEface(i any) *eface {
|
|
return (*eface)(unsafe.Pointer(&i))
|
|
}
|
|
|
|
func main() {
|
|
e := toEface(T{})
|
|
e2 := toEface(abi.Type{})
|
|
|
|
println(e.typ)
|
|
println(e.typ.PtrToThis_)
|
|
println(e2.typ)
|
|
println(e2.typ.PtrToThis_)
|
|
|
|
f0 := e.typ.StructType().Fields[0]
|
|
if f0.Typ != e.typ.PtrToThis_ {
|
|
panic("error field 0")
|
|
}
|
|
if f0.Typ.Elem() != e.typ {
|
|
panic("error field 0 elem")
|
|
}
|
|
f1 := e.typ.StructType().Fields[1]
|
|
if f1.Typ != e2.typ.PtrToThis_ {
|
|
panic("error field 1")
|
|
}
|
|
if f1.Typ.Elem() != e2.typ {
|
|
panic("error field 1 elem")
|
|
}
|
|
f2 := e.typ.StructType().Fields[2]
|
|
if f2.Typ != e2.typ.StructType().Fields[0].Typ {
|
|
panic("error field 2")
|
|
}
|
|
f3 := e.typ.StructType().Fields[3]
|
|
if f3.Typ.Elem() != e.typ {
|
|
panic("error field 3")
|
|
}
|
|
}
|