eface.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package x86_64
  2. import (
  3. `reflect`
  4. `unsafe`
  5. )
  6. type _GoType struct {
  7. size uintptr
  8. pdata uintptr
  9. hash uint32
  10. flags uint8
  11. align uint8
  12. falign uint8
  13. kflags uint8
  14. traits unsafe.Pointer
  15. gcdata *byte
  16. str int32
  17. ptrx int32
  18. }
  19. const (
  20. _KindMask = (1 << 5) - 1
  21. )
  22. func (self *_GoType) kind() reflect.Kind {
  23. return reflect.Kind(self.kflags & _KindMask)
  24. }
  25. type _GoSlice struct {
  26. ptr unsafe.Pointer
  27. len int
  28. cap int
  29. }
  30. type _GoEface struct {
  31. vt *_GoType
  32. ptr unsafe.Pointer
  33. }
  34. func (self *_GoEface) kind() reflect.Kind {
  35. if self.vt != nil {
  36. return self.vt.kind()
  37. } else {
  38. return reflect.Invalid
  39. }
  40. }
  41. func (self *_GoEface) toInt64() int64 {
  42. if self.vt.size == 8 {
  43. return *(*int64)(self.ptr)
  44. } else if self.vt.size == 4 {
  45. return int64(*(*int32)(self.ptr))
  46. } else if self.vt.size == 2 {
  47. return int64(*(*int16)(self.ptr))
  48. } else {
  49. return int64(*(*int8)(self.ptr))
  50. }
  51. }
  52. func efaceOf(v interface{}) _GoEface {
  53. return *(*_GoEface)(unsafe.Pointer(&v))
  54. }