eface.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // Copyright 2024 CloudWeGo Authors
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package x86_64
  17. import (
  18. `reflect`
  19. `unsafe`
  20. )
  21. type _GoType struct {
  22. size uintptr
  23. pdata uintptr
  24. hash uint32
  25. flags uint8
  26. align uint8
  27. falign uint8
  28. kflags uint8
  29. traits unsafe.Pointer
  30. gcdata *byte
  31. str int32
  32. ptrx int32
  33. }
  34. const (
  35. _KindMask = (1 << 5) - 1
  36. )
  37. func (self *_GoType) kind() reflect.Kind {
  38. return reflect.Kind(self.kflags & _KindMask)
  39. }
  40. type _GoSlice struct {
  41. ptr unsafe.Pointer
  42. len int
  43. cap int
  44. }
  45. type _GoEface struct {
  46. vt *_GoType
  47. ptr unsafe.Pointer
  48. }
  49. func (self *_GoEface) kind() reflect.Kind {
  50. if self.vt != nil {
  51. return self.vt.kind()
  52. } else {
  53. return reflect.Invalid
  54. }
  55. }
  56. func (self *_GoEface) toInt64() int64 {
  57. if self.vt.size == 8 {
  58. return *(*int64)(self.ptr)
  59. } else if self.vt.size == 4 {
  60. return int64(*(*int32)(self.ptr))
  61. } else if self.vt.size == 2 {
  62. return int64(*(*int16)(self.ptr))
  63. } else {
  64. return int64(*(*int8)(self.ptr))
  65. }
  66. }
  67. func efaceOf(v interface{}) _GoEface {
  68. return *(*_GoEface)(unsafe.Pointer(&v))
  69. }