github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xruntime/interface.go (about) 1 package xruntime 2 3 import ( 4 "unsafe" 5 ) 6 7 type TypeFlag uint8 8 type NameOffset int32 9 type TypeOffset int32 10 11 type Type struct { 12 Size uintptr 13 PtrData uintptr // Size of memory prefix holding all pointers 14 Hash uint32 15 TypeFlag TypeFlag 16 Align uint8 17 FieldAlign uint8 18 Kind uint8 19 // function for comparing objects of this type 20 // (ptr to object A, ptr to object B) -> ==? 21 Equal func(unsafe.Pointer, unsafe.Pointer) bool 22 // Gcdata stores the GC type data for the garbage collector. 23 // If the KindGCProg bit is set in Kind, Gcdata is a GC program. 24 // Otherwise it is a ptrmask bitmap. See mbitmap.go for details. 25 Gcdata *byte 26 Str NameOffset 27 PtrToThis TypeOffset 28 } 29 30 type Name struct { 31 Bytes *byte 32 } 33 34 type Method struct { 35 Name NameOffset 36 Type TypeOffset 37 } 38 39 type InterfaceType struct { 40 Type Type 41 PkgPath Name 42 Methods []Method 43 } 44 45 type VTable struct { 46 IType *InterfaceType 47 Type *Type 48 Hash uint32 // copy of _type.Hash. Used for type switches. 49 _ [4]byte 50 Fun [1]uintptr // variable sized. Fun[0]==0 means _type does not implement IType. 51 } 52 53 type Interface struct { 54 VTable *VTable 55 Data unsafe.Pointer 56 } 57 58 type EmptyInterface struct { 59 Type *Type 60 Data unsafe.Pointer 61 } 62 63 func InterfaceData(v interface{}) *Interface { 64 return (*Interface)(unsafe.Pointer(&v)) 65 } 66 67 func EmptyInterfaceData(v interface{}) *EmptyInterface { 68 return (*EmptyInterface)(unsafe.Pointer(&v)) 69 }