github.com/DQNEO/babygo@v0.0.3/src/reflect/reflect.go (about)

     1  package reflect
     2  
     3  import "unsafe"
     4  
     5  type Type struct {
     6  	typ *rtype
     7  }
     8  
     9  type emptyInterface struct {
    10  	typ  *rtype         // dynamic type
    11  	data unsafe.Pointer // pointer to the actual data of the dynamic type
    12  }
    13  
    14  type rtype struct {
    15  	id   int
    16  	name string // string representation of type
    17  }
    18  
    19  func TypeOf(x interface{}) *Type {
    20  	eface := (*emptyInterface)(unsafe.Pointer(&x))
    21  	return &Type{
    22  		typ: eface.typ,
    23  	}
    24  }
    25  
    26  func (t *Type) String() string {
    27  	return t.typ.String()
    28  }
    29  
    30  func (t *rtype) String() string {
    31  	return t.name
    32  }