mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Treat the tag of a TValue as unsigned everywhere.
This commit is contained in:
parent
f396f3d192
commit
41379126a2
@ -224,7 +224,7 @@ LJLIB_ASM(tostring) LJLIB_REC(.)
|
||||
if (tvisnum(o)) {
|
||||
s = lj_str_fromnum(L, &o->n);
|
||||
} else if (tvispri(o)) {
|
||||
s = strV(lj_lib_upvalue(L, -itype(o)));
|
||||
s = strV(lj_lib_upvalue(L, -(int32_t)itype(o)));
|
||||
} else {
|
||||
if (tvisfunc(o) && isffunc(funcV(o)))
|
||||
lua_pushfstring(L, "function: fast#%d", funcV(o)->c.ffid);
|
||||
|
@ -195,9 +195,10 @@ LUA_API int lua_type(lua_State *L, int idx)
|
||||
} else if (o == niltv(L)) {
|
||||
return LUA_TNONE;
|
||||
} else { /* Magic internal/external tag conversion. ORDER LJ_T */
|
||||
int t = ~itype(o);
|
||||
lua_assert(itype(o) != LJ_TUPVAL);
|
||||
return (int)(((t < 8 ? 0x98042110 : 0x7506) >> 4*(t&7)) & 15u);
|
||||
uint32_t t = ~itype(o);
|
||||
int tt = (int)(((t < 8 ? 0x98042110 : 0x7506) >> 4*(t&7)) & 15u);
|
||||
lua_assert(tt != LUA_TNIL || tvisnil(o));
|
||||
return tt;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,11 +386,11 @@ static LJ_AINLINE IRType itype2irt(const TValue *tv)
|
||||
return IRT_LIGHTUD;
|
||||
#endif
|
||||
else
|
||||
return cast(IRType, ~uitype(tv));
|
||||
return cast(IRType, ~itype(tv));
|
||||
}
|
||||
|
||||
#define irt_toitype(t) \
|
||||
check_exp(!(LJ_64 && irt_islightud((t))), (int32_t)~(uint32_t)irt_type((t)))
|
||||
check_exp(!(LJ_64 && irt_islightud((t))), ~(uint32_t)irt_type((t)))
|
||||
|
||||
#define irt_isguard(t) ((t).irt & IRT_GUARD)
|
||||
#define irt_ismarked(t) ((t).irt & IRT_MARK)
|
||||
|
@ -285,7 +285,7 @@ TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)
|
||||
cTValue *mo = lj_meta_fast(L, tabref(o1->gch.metatable), MM_eq);
|
||||
if (mo) {
|
||||
TValue *top;
|
||||
int it;
|
||||
uint32_t it;
|
||||
if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) {
|
||||
cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq);
|
||||
if (mo2 == NULL || !lj_obj_equal(mo, mo2))
|
||||
@ -294,7 +294,7 @@ TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)
|
||||
top = curr_top(L);
|
||||
setcont(top, ne ? lj_cont_condf : lj_cont_condt);
|
||||
copyTV(L, top+1, mo);
|
||||
it = ~(int32_t)o1->gch.gct;
|
||||
it = ~(uint32_t)o1->gch.gct;
|
||||
setgcV(L, top+2, &o1->gch, it);
|
||||
setgcV(L, top+3, &o2->gch, it);
|
||||
return top+2; /* Trigger metamethod call. */
|
||||
|
54
src/lj_obj.h
54
src/lj_obj.h
@ -141,7 +141,7 @@ typedef LJ_ALIGN(8) union TValue {
|
||||
struct {
|
||||
LJ_ENDIAN_LOHI(
|
||||
GCRef gcr; /* GCobj reference (if any). */
|
||||
, int32_t it; /* Internal object tag. Must overlap MSW of number. */
|
||||
, uint32_t it; /* Internal object tag. Must overlap MSW of number. */
|
||||
)
|
||||
};
|
||||
struct {
|
||||
@ -186,42 +186,41 @@ typedef const TValue cTValue;
|
||||
** GC objects are at the end, table/userdata must be lowest.
|
||||
** Also check lj_ir.h for similar ordering constraints.
|
||||
*/
|
||||
#define LJ_TNIL (-1)
|
||||
#define LJ_TFALSE (-2)
|
||||
#define LJ_TTRUE (-3)
|
||||
#define LJ_TLIGHTUD (-4)
|
||||
#define LJ_TSTR (-5)
|
||||
#define LJ_TUPVAL (-6)
|
||||
#define LJ_TTHREAD (-7)
|
||||
#define LJ_TPROTO (-8)
|
||||
#define LJ_TFUNC (-9)
|
||||
#define LJ_TTRACE (-10)
|
||||
#define LJ_TTAB (-11)
|
||||
#define LJ_TUDATA (-12)
|
||||
#define LJ_TNIL (~0u)
|
||||
#define LJ_TFALSE (~1u)
|
||||
#define LJ_TTRUE (~2u)
|
||||
#define LJ_TLIGHTUD (~3u)
|
||||
#define LJ_TSTR (~4u)
|
||||
#define LJ_TUPVAL (~5u)
|
||||
#define LJ_TTHREAD (~6u)
|
||||
#define LJ_TPROTO (~7u)
|
||||
#define LJ_TFUNC (~8u)
|
||||
#define LJ_TTRACE (~9u)
|
||||
#define LJ_TTAB (~10u)
|
||||
#define LJ_TUDATA (~11u)
|
||||
/* This is just the canonical number type used in some places. */
|
||||
#define LJ_TNUMX (-13)
|
||||
#define LJ_TNUMX (~12u)
|
||||
|
||||
#if LJ_64
|
||||
#define LJ_TISNUM ((uint32_t)0xfffeffff)
|
||||
#define LJ_TISNUM 0xfffeffffu
|
||||
#else
|
||||
#define LJ_TISNUM ((uint32_t)LJ_TNUMX)
|
||||
#define LJ_TISNUM LJ_TNUMX
|
||||
#endif
|
||||
#define LJ_TISTRUECOND ((uint32_t)LJ_TFALSE)
|
||||
#define LJ_TISPRI ((uint32_t)LJ_TTRUE)
|
||||
#define LJ_TISGCV ((uint32_t)(LJ_TSTR+1))
|
||||
#define LJ_TISTABUD ((uint32_t)LJ_TTAB)
|
||||
#define LJ_TISTRUECOND LJ_TFALSE
|
||||
#define LJ_TISPRI LJ_TTRUE
|
||||
#define LJ_TISGCV (LJ_TSTR+1)
|
||||
#define LJ_TISTABUD LJ_TTAB
|
||||
|
||||
/* -- TValue getters/setters ---------------------------------------------- */
|
||||
|
||||
/* Macros to test types. */
|
||||
#define itype(o) ((o)->it)
|
||||
#define uitype(o) ((uint32_t)itype(o))
|
||||
#define tvisnil(o) (itype(o) == LJ_TNIL)
|
||||
#define tvisfalse(o) (itype(o) == LJ_TFALSE)
|
||||
#define tvistrue(o) (itype(o) == LJ_TTRUE)
|
||||
#define tvisbool(o) (tvisfalse(o) || tvistrue(o))
|
||||
#if LJ_64
|
||||
#define tvislightud(o) ((itype(o) >> 15) == -2)
|
||||
#define tvislightud(o) (((int32_t)itype(o) >> 15) == -2)
|
||||
#else
|
||||
#define tvislightud(o) (itype(o) == LJ_TLIGHTUD)
|
||||
#endif
|
||||
@ -231,13 +230,12 @@ typedef const TValue cTValue;
|
||||
#define tvisproto(o) (itype(o) == LJ_TPROTO)
|
||||
#define tvistab(o) (itype(o) == LJ_TTAB)
|
||||
#define tvisudata(o) (itype(o) == LJ_TUDATA)
|
||||
#define tvisnum(o) (uitype(o) <= LJ_TISNUM)
|
||||
#define tvisnum(o) (itype(o) <= LJ_TISNUM)
|
||||
|
||||
#define tvistruecond(o) (uitype(o) < LJ_TISTRUECOND)
|
||||
#define tvispri(o) (uitype(o) >= LJ_TISPRI)
|
||||
#define tvistabud(o) (uitype(o) <= LJ_TISTABUD) /* && !tvisnum() */
|
||||
#define tvisgcv(o) \
|
||||
((uitype(o) - LJ_TISGCV) > ((uint32_t)LJ_TNUMX - LJ_TISGCV))
|
||||
#define tvistruecond(o) (itype(o) < LJ_TISTRUECOND)
|
||||
#define tvispri(o) (itype(o) >= LJ_TISPRI)
|
||||
#define tvistabud(o) (itype(o) <= LJ_TISTABUD) /* && !tvisnum() */
|
||||
#define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))
|
||||
|
||||
/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */
|
||||
#define tvisnan(o) ((o)->n != (o)->n)
|
||||
|
@ -184,7 +184,7 @@ static BCReg const_num(FuncState *fs, ExpDesc *e)
|
||||
}
|
||||
|
||||
/* Add a GC object constant. */
|
||||
static BCReg const_gc(FuncState *fs, GCobj *gc, int itype)
|
||||
static BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype)
|
||||
{
|
||||
lua_State *L = fs->L;
|
||||
TValue o, *val;
|
||||
@ -1294,10 +1294,10 @@ static void expr_bracket(LexState *ls, ExpDesc *v)
|
||||
static void expr_kvalue(TValue *v, ExpDesc *e)
|
||||
{
|
||||
if (e->k <= VKTRUE) {
|
||||
v->it = ~(int32_t)e->k;
|
||||
setitype(v, ~(uint32_t)e->k);
|
||||
} else if (e->k == VKSTR) {
|
||||
setgcref(v->gcr, obj2gco(e->u.sval));
|
||||
v->it = LJ_TSTR;
|
||||
setitype(v, LJ_TSTR);
|
||||
} else {
|
||||
lua_assert(e->k == VKNUM);
|
||||
setnumV(v, expr_numV(e));
|
||||
|
@ -1969,7 +1969,7 @@ void lj_record_ins(jit_State *J)
|
||||
switch (bcmode_c(op)) {
|
||||
case BCMvar:
|
||||
copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break;
|
||||
case BCMpri: setitype(rcv, (int32_t)~rc); rc = TREF_PRI(IRT_NIL+rc); break;
|
||||
case BCMpri: setitype(rcv, ~rc); rc = TREF_PRI(IRT_NIL+rc); break;
|
||||
case BCMnum: { lua_Number n = proto_knum(J->pt, rc);
|
||||
setnumV(rcv, n); ix.key = rc = lj_ir_knumint(J, n); } break;
|
||||
case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc));
|
||||
|
Loading…
Reference in New Issue
Block a user