diff options
Diffstat (limited to 'src/lj_obj.h')
-rw-r--r-- | src/lj_obj.h | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/src/lj_obj.h b/src/lj_obj.h index 1bd50809..88289f3e 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h | |||
@@ -140,7 +140,10 @@ typedef LJ_ALIGN(8) union TValue { | |||
140 | lua_Number n; /* Number object overlaps split tag/value object. */ | 140 | lua_Number n; /* Number object overlaps split tag/value object. */ |
141 | struct { | 141 | struct { |
142 | LJ_ENDIAN_LOHI( | 142 | LJ_ENDIAN_LOHI( |
143 | GCRef gcr; /* GCobj reference (if any). */ | 143 | union { |
144 | GCRef gcr; /* GCobj reference (if any). */ | ||
145 | int32_t i; /* Integer value. */ | ||
146 | }; | ||
144 | , uint32_t it; /* Internal object tag. Must overlap MSW of number. */ | 147 | , uint32_t it; /* Internal object tag. Must overlap MSW of number. */ |
145 | ) | 148 | ) |
146 | }; | 149 | }; |
@@ -180,6 +183,7 @@ typedef const TValue cTValue; | |||
180 | ** lightuserdata | itype | void * | (32 bit platforms) | 183 | ** lightuserdata | itype | void * | (32 bit platforms) |
181 | ** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers) | 184 | ** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers) |
182 | ** GC objects | itype | GCRef | | 185 | ** GC objects | itype | GCRef | |
186 | ** int (LJ_DUALNUM)| itype | int | | ||
183 | ** number -------double------ | 187 | ** number -------double------ |
184 | ** | 188 | ** |
185 | ** ORDER LJ_T | 189 | ** ORDER LJ_T |
@@ -203,6 +207,7 @@ typedef const TValue cTValue; | |||
203 | /* This is just the canonical number type used in some places. */ | 207 | /* This is just the canonical number type used in some places. */ |
204 | #define LJ_TNUMX (~13u) | 208 | #define LJ_TNUMX (~13u) |
205 | 209 | ||
210 | /* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */ | ||
206 | #if LJ_64 | 211 | #if LJ_64 |
207 | #define LJ_TISNUM 0xfffeffffu | 212 | #define LJ_TISNUM 0xfffeffffu |
208 | #else | 213 | #else |
@@ -322,6 +327,8 @@ typedef struct GCproto { | |||
322 | gcref(mref((pt)->k, GCRef)[(idx)])) | 327 | gcref(mref((pt)->k, GCRef)[(idx)])) |
323 | #define proto_knum(pt, idx) \ | 328 | #define proto_knum(pt, idx) \ |
324 | check_exp((uintptr_t)(idx) < (pt)->sizekn, mref((pt)->k, lua_Number)[(idx)]) | 329 | check_exp((uintptr_t)(idx) < (pt)->sizekn, mref((pt)->k, lua_Number)[(idx)]) |
330 | #define proto_knumtv(pt, idx) \ | ||
331 | check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)]) | ||
325 | #define proto_bc(pt) ((BCIns *)((char *)(pt) + sizeof(GCproto))) | 332 | #define proto_bc(pt) ((BCIns *)((char *)(pt) + sizeof(GCproto))) |
326 | #define proto_bcpos(pt, pc) ((BCPos)((pc) - proto_bc(pt))) | 333 | #define proto_bcpos(pt, pc) ((BCPos)((pc) - proto_bc(pt))) |
327 | #define proto_uv(pt) (mref((pt)->uv, uint16_t)) | 334 | #define proto_uv(pt) (mref((pt)->uv, uint16_t)) |
@@ -650,7 +657,9 @@ typedef union GCobj { | |||
650 | #define tviscdata(o) (itype(o) == LJ_TCDATA) | 657 | #define tviscdata(o) (itype(o) == LJ_TCDATA) |
651 | #define tvistab(o) (itype(o) == LJ_TTAB) | 658 | #define tvistab(o) (itype(o) == LJ_TTAB) |
652 | #define tvisudata(o) (itype(o) == LJ_TUDATA) | 659 | #define tvisudata(o) (itype(o) == LJ_TUDATA) |
653 | #define tvisnum(o) (itype(o) <= LJ_TISNUM) | 660 | #define tvisnumber(o) (itype(o) <= LJ_TISNUM) |
661 | #define tvisint(o) (LJ_DUALNUM && itype(o) == LJ_TISNUM) | ||
662 | #define tvisnum(o) (itype(o) < LJ_TISNUM) | ||
654 | 663 | ||
655 | #define tvistruecond(o) (itype(o) < LJ_TISTRUECOND) | 664 | #define tvistruecond(o) (itype(o) < LJ_TISTRUECOND) |
656 | #define tvispri(o) (itype(o) >= LJ_TISPRI) | 665 | #define tvispri(o) (itype(o) >= LJ_TISPRI) |
@@ -659,6 +668,11 @@ typedef union GCobj { | |||
659 | 668 | ||
660 | /* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */ | 669 | /* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */ |
661 | #define tvisnan(o) ((o)->n != (o)->n) | 670 | #define tvisnan(o) ((o)->n != (o)->n) |
671 | #if LJ_64 | ||
672 | #define tviszero(o) (((o)->u64 << 1) == 0) | ||
673 | #else | ||
674 | #define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0) | ||
675 | #endif | ||
662 | #define tvispzero(o) ((o)->u64 == 0) | 676 | #define tvispzero(o) ((o)->u64 == 0) |
663 | #define tvismzero(o) ((o)->u64 == U64x(80000000,00000000)) | 677 | #define tvismzero(o) ((o)->u64 == U64x(80000000,00000000)) |
664 | #define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000)) | 678 | #define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000)) |
@@ -667,9 +681,9 @@ typedef union GCobj { | |||
667 | /* Macros to convert type ids. */ | 681 | /* Macros to convert type ids. */ |
668 | #if LJ_64 | 682 | #if LJ_64 |
669 | #define itypemap(o) \ | 683 | #define itypemap(o) \ |
670 | (tvisnum(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o)) | 684 | (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o)) |
671 | #else | 685 | #else |
672 | #define itypemap(o) (tvisnum(o) ? ~LJ_TNUMX : ~itype(o)) | 686 | #define itypemap(o) (tvisnumber(o) ? ~LJ_TNUMX : ~itype(o)) |
673 | #endif | 687 | #endif |
674 | 688 | ||
675 | /* Macros to get tagged values. */ | 689 | /* Macros to get tagged values. */ |
@@ -690,6 +704,7 @@ typedef union GCobj { | |||
690 | #define tabV(o) check_exp(tvistab(o), &gcval(o)->tab) | 704 | #define tabV(o) check_exp(tvistab(o), &gcval(o)->tab) |
691 | #define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud) | 705 | #define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud) |
692 | #define numV(o) check_exp(tvisnum(o), (o)->n) | 706 | #define numV(o) check_exp(tvisnum(o), (o)->n) |
707 | #define intV(o) check_exp(tvisint(o), (int32_t)(o)->i) | ||
693 | 708 | ||
694 | /* Macros to set tagged values. */ | 709 | /* Macros to set tagged values. */ |
695 | #define setitype(o, i) ((o)->it = (i)) | 710 | #define setitype(o, i) ((o)->it = (i)) |
@@ -741,7 +756,29 @@ define_setV(setudataV, GCudata, LJ_TUDATA) | |||
741 | #define setnanV(o) ((o)->u64 = U64x(fff80000,00000000)) | 756 | #define setnanV(o) ((o)->u64 = U64x(fff80000,00000000)) |
742 | #define setpinfV(o) ((o)->u64 = U64x(7ff00000,00000000)) | 757 | #define setpinfV(o) ((o)->u64 = U64x(7ff00000,00000000)) |
743 | #define setminfV(o) ((o)->u64 = U64x(fff00000,00000000)) | 758 | #define setminfV(o) ((o)->u64 = U64x(fff00000,00000000)) |
744 | #define setintV(o, i) ((o)->n = cast_num((int32_t)(i))) | 759 | |
760 | static LJ_AINLINE void setintV(TValue *o, int32_t i) | ||
761 | { | ||
762 | #if LJ_DUALNUM | ||
763 | o->i = (uint32_t)i; setitype(o, LJ_TISNUM); | ||
764 | #else | ||
765 | o->n = (lua_Number)i; | ||
766 | #endif | ||
767 | } | ||
768 | |||
769 | static LJ_AINLINE void setint64V(TValue *o, int64_t i) | ||
770 | { | ||
771 | if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i)) | ||
772 | setintV(o, (int32_t)i); | ||
773 | else | ||
774 | setnumV(o, (lua_Number)i); | ||
775 | } | ||
776 | |||
777 | #if LJ_64 | ||
778 | #define setintptrV(o, i) setint64V((o), (i)) | ||
779 | #else | ||
780 | #define setintptrV(o, i) setintV((o), (i)) | ||
781 | #endif | ||
745 | 782 | ||
746 | /* Copy tagged values. */ | 783 | /* Copy tagged values. */ |
747 | static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2) | 784 | static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2) |
@@ -774,6 +811,22 @@ static LJ_AINLINE uint64_t lj_num2u64(lua_Number n) | |||
774 | return (uint64_t)n; | 811 | return (uint64_t)n; |
775 | } | 812 | } |
776 | 813 | ||
814 | static LJ_AINLINE int32_t numberVint(cTValue *o) | ||
815 | { | ||
816 | if (LJ_LIKELY(tvisint(o))) | ||
817 | return intV(o); | ||
818 | else | ||
819 | return lj_num2int(numV(o)); | ||
820 | } | ||
821 | |||
822 | static LJ_AINLINE lua_Number numberVnum(cTValue *o) | ||
823 | { | ||
824 | if (LJ_UNLIKELY(tvisint(o))) | ||
825 | return (lua_Number)intV(o); | ||
826 | else | ||
827 | return numV(o); | ||
828 | } | ||
829 | |||
777 | /* -- Miscellaneous object handling --------------------------------------- */ | 830 | /* -- Miscellaneous object handling --------------------------------------- */ |
778 | 831 | ||
779 | /* Names and maps for internal and external object tags. */ | 832 | /* Names and maps for internal and external object tags. */ |