Guest User

Untitled

a guest
Apr 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. // Tagged value 的 struct 定義
  2.  
  3. typedef LJ_ALIGN(8) union TValue {
  4. uint64_t u64; /* 64 bit pattern overlaps number. */
  5. lua_Number n; /* Number object overlaps split tag/value object. */
  6. struct {
  7. LJ_ENDIAN_LOHI(
  8. union {
  9. GCRef gcr; /* GCobj reference (if any). */
  10. int32_t i; /* Integer value. */
  11. };
  12. , uint32_t it; /* Internal object tag. Must overlap MSW of number. */
  13. )
  14. };
  15. struct {
  16. LJ_ENDIAN_LOHI(
  17. GCRef func; /* Function for next frame (or dummy L). */
  18. , FrameLink tp; /* Link to previous frame. */
  19. )
  20. } fr;
  21. struct {
  22. LJ_ENDIAN_LOHI(
  23. uint32_t lo; /* Lower 32 bits of number. */
  24. , uint32_t hi; /* Upper 32 bits of number. */
  25. )
  26. } u32;
  27. } TValue;
  28.  
  29. // Tag 的型別規格
  30. /* Internal object tags.
  31. **
  32. ** Internal tags overlap the MSW of a number object (must be a double).
  33. ** Interpreted as a double these are special NaNs. The FPU only generates
  34. ** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available
  35. ** for use as internal tags. Small negative numbers are used to shorten the
  36. ** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate).
  37. **
  38. ** ---MSW---.---LSW---
  39. ** primitive types | itype | |
  40. ** lightuserdata | itype | void * | (32 bit platforms)
  41. ** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers)
  42. ** GC objects | itype | GCRef |
  43. ** int (LJ_DUALNUM)| itype | int |
  44. ** number -------double------
  45. **
  46. ** ORDER LJ_T
  47. ** Primitive types nil/false/true must be first, lightuserdata next.
  48. ** GC objects are at the end, table/userdata must be lowest.
  49. ** Also check lj_ir.h for similar ordering constraints.
  50. */
  51. #define LJ_TNIL (~0u)
  52. #define LJ_TFALSE (~1u)
  53. #define LJ_TTRUE (~2u)
  54. #define LJ_TLIGHTUD (~3u)
  55. #define LJ_TSTR (~4u)
  56. #define LJ_TUPVAL (~5u)
  57. #define LJ_TTHREAD (~6u)
  58. #define LJ_TPROTO (~7u)
  59. #define LJ_TFUNC (~8u)
  60. #define LJ_TTRACE (~9u)
  61. #define LJ_TCDATA (~10u)
  62. #define LJ_TTAB (~11u)
  63. #define LJ_TUDATA (~12u)
  64. /* This is just the canonical number type used in some places. */
  65. #define LJ_TNUMX (~13u)
  66.  
  67. // 判斷型別的方式
  68. /* Macros to test types. */
  69. #define itype(o) ((o)->it)
  70. #define tvisnil(o) (itype(o) == LJ_TNIL)
  71. #define tvisfalse(o) (itype(o) == LJ_TFALSE)
  72. #define tvistrue(o) (itype(o) == LJ_TTRUE)
  73. #define tvisbool(o) (tvisfalse(o) || tvistrue(o))
  74. #if LJ_64
  75. #define tvislightud(o) (((int32_t)itype(o) >> 15) == -2)
  76. #else
  77. #define tvislightud(o) (itype(o) == LJ_TLIGHTUD)
  78. #endif
  79. #define tvisstr(o) (itype(o) == LJ_TSTR)
  80. #define tvisfunc(o) (itype(o) == LJ_TFUNC)
  81. #define tvisthread(o) (itype(o) == LJ_TTHREAD)
  82. #define tvisproto(o) (itype(o) == LJ_TPROTO)
  83. #define tviscdata(o) (itype(o) == LJ_TCDATA)
  84. #define tvistab(o) (itype(o) == LJ_TTAB)
  85. #define tvisudata(o) (itype(o) == LJ_TUDATA)
  86. #define tvisnumber(o) (itype(o) <= LJ_TISNUM)
  87. #define tvisint(o) (LJ_DUALNUM && itype(o) == LJ_TISNUM)
  88. #define tvisnum(o) (itype(o) < LJ_TISNUM)
  89.  
  90. #define tvistruecond(o) (itype(o) < LJ_TISTRUECOND)
  91. #define tvispri(o) (itype(o) >= LJ_TISPRI)
  92. #define tvistabud(o) (itype(o) <= LJ_TISTABUD) /* && !tvisnum() */
  93. #define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))
  94.  
  95. /* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */
  96. #define tvisnan(o) ((o)->n != (o)->n)
  97. #if LJ_64
  98. #define tviszero(o) (((o)->u64 << 1) == 0)
  99. #else
  100. #define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0)
  101. #endif
  102. #define tvispzero(o) ((o)->u64 == 0)
  103. #define tvismzero(o) ((o)->u64 == U64x(80000000,00000000))
  104. #define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000))
  105. #define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64)
Add Comment
Please, Sign In to add comment