aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2010-04-25 23:21:15 +0200
committerMike Pall <mike>2010-04-25 23:21:15 +0200
commit41379126a2e41179068800f5ab791cc84f740228 (patch)
treed973dc7a6e89b3f67b0438e2bdae7c46fe24a26a
parentf396f3d192eb635b3b3a3d074e45e6b810689918 (diff)
downloadluajit-41379126a2e41179068800f5ab791cc84f740228.tar.gz
luajit-41379126a2e41179068800f5ab791cc84f740228.tar.bz2
luajit-41379126a2e41179068800f5ab791cc84f740228.zip
Treat the tag of a TValue as unsigned everywhere.
-rw-r--r--src/lib_base.c2
-rw-r--r--src/lj_api.c7
-rw-r--r--src/lj_ir.h4
-rw-r--r--src/lj_meta.c4
-rw-r--r--src/lj_obj.h54
-rw-r--r--src/lj_parse.c6
-rw-r--r--src/lj_record.c2
7 files changed, 39 insertions, 40 deletions
diff --git a/src/lib_base.c b/src/lib_base.c
index 1fa26d0a..66b514dc 100644
--- a/src/lib_base.c
+++ b/src/lib_base.c
@@ -224,7 +224,7 @@ LJLIB_ASM(tostring) LJLIB_REC(.)
224 if (tvisnum(o)) { 224 if (tvisnum(o)) {
225 s = lj_str_fromnum(L, &o->n); 225 s = lj_str_fromnum(L, &o->n);
226 } else if (tvispri(o)) { 226 } else if (tvispri(o)) {
227 s = strV(lj_lib_upvalue(L, -itype(o))); 227 s = strV(lj_lib_upvalue(L, -(int32_t)itype(o)));
228 } else { 228 } else {
229 if (tvisfunc(o) && isffunc(funcV(o))) 229 if (tvisfunc(o) && isffunc(funcV(o)))
230 lua_pushfstring(L, "function: fast#%d", funcV(o)->c.ffid); 230 lua_pushfstring(L, "function: fast#%d", funcV(o)->c.ffid);
diff --git a/src/lj_api.c b/src/lj_api.c
index 2b99c267..b9bac1d4 100644
--- a/src/lj_api.c
+++ b/src/lj_api.c
@@ -195,9 +195,10 @@ LUA_API int lua_type(lua_State *L, int idx)
195 } else if (o == niltv(L)) { 195 } else if (o == niltv(L)) {
196 return LUA_TNONE; 196 return LUA_TNONE;
197 } else { /* Magic internal/external tag conversion. ORDER LJ_T */ 197 } else { /* Magic internal/external tag conversion. ORDER LJ_T */
198 int t = ~itype(o); 198 uint32_t t = ~itype(o);
199 lua_assert(itype(o) != LJ_TUPVAL); 199 int tt = (int)(((t < 8 ? 0x98042110 : 0x7506) >> 4*(t&7)) & 15u);
200 return (int)(((t < 8 ? 0x98042110 : 0x7506) >> 4*(t&7)) & 15u); 200 lua_assert(tt != LUA_TNIL || tvisnil(o));
201 return tt;
201 } 202 }
202} 203}
203 204
diff --git a/src/lj_ir.h b/src/lj_ir.h
index 60366049..4c72d88f 100644
--- a/src/lj_ir.h
+++ b/src/lj_ir.h
@@ -386,11 +386,11 @@ static LJ_AINLINE IRType itype2irt(const TValue *tv)
386 return IRT_LIGHTUD; 386 return IRT_LIGHTUD;
387#endif 387#endif
388 else 388 else
389 return cast(IRType, ~uitype(tv)); 389 return cast(IRType, ~itype(tv));
390} 390}
391 391
392#define irt_toitype(t) \ 392#define irt_toitype(t) \
393 check_exp(!(LJ_64 && irt_islightud((t))), (int32_t)~(uint32_t)irt_type((t))) 393 check_exp(!(LJ_64 && irt_islightud((t))), ~(uint32_t)irt_type((t)))
394 394
395#define irt_isguard(t) ((t).irt & IRT_GUARD) 395#define irt_isguard(t) ((t).irt & IRT_GUARD)
396#define irt_ismarked(t) ((t).irt & IRT_MARK) 396#define irt_ismarked(t) ((t).irt & IRT_MARK)
diff --git a/src/lj_meta.c b/src/lj_meta.c
index ab8ae8fe..dc6756c6 100644
--- a/src/lj_meta.c
+++ b/src/lj_meta.c
@@ -285,7 +285,7 @@ TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)
285 cTValue *mo = lj_meta_fast(L, tabref(o1->gch.metatable), MM_eq); 285 cTValue *mo = lj_meta_fast(L, tabref(o1->gch.metatable), MM_eq);
286 if (mo) { 286 if (mo) {
287 TValue *top; 287 TValue *top;
288 int it; 288 uint32_t it;
289 if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) { 289 if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) {
290 cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq); 290 cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq);
291 if (mo2 == NULL || !lj_obj_equal(mo, mo2)) 291 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)
294 top = curr_top(L); 294 top = curr_top(L);
295 setcont(top, ne ? lj_cont_condf : lj_cont_condt); 295 setcont(top, ne ? lj_cont_condf : lj_cont_condt);
296 copyTV(L, top+1, mo); 296 copyTV(L, top+1, mo);
297 it = ~(int32_t)o1->gch.gct; 297 it = ~(uint32_t)o1->gch.gct;
298 setgcV(L, top+2, &o1->gch, it); 298 setgcV(L, top+2, &o1->gch, it);
299 setgcV(L, top+3, &o2->gch, it); 299 setgcV(L, top+3, &o2->gch, it);
300 return top+2; /* Trigger metamethod call. */ 300 return top+2; /* Trigger metamethod call. */
diff --git a/src/lj_obj.h b/src/lj_obj.h
index defb2088..819930c6 100644
--- a/src/lj_obj.h
+++ b/src/lj_obj.h
@@ -141,7 +141,7 @@ typedef LJ_ALIGN(8) union TValue {
141 struct { 141 struct {
142 LJ_ENDIAN_LOHI( 142 LJ_ENDIAN_LOHI(
143 GCRef gcr; /* GCobj reference (if any). */ 143 GCRef gcr; /* GCobj reference (if any). */
144 , int32_t it; /* Internal object tag. Must overlap MSW of number. */ 144 , uint32_t it; /* Internal object tag. Must overlap MSW of number. */
145 ) 145 )
146 }; 146 };
147 struct { 147 struct {
@@ -186,42 +186,41 @@ typedef const TValue cTValue;
186** GC objects are at the end, table/userdata must be lowest. 186** GC objects are at the end, table/userdata must be lowest.
187** Also check lj_ir.h for similar ordering constraints. 187** Also check lj_ir.h for similar ordering constraints.
188*/ 188*/
189#define LJ_TNIL (-1) 189#define LJ_TNIL (~0u)
190#define LJ_TFALSE (-2) 190#define LJ_TFALSE (~1u)
191#define LJ_TTRUE (-3) 191#define LJ_TTRUE (~2u)
192#define LJ_TLIGHTUD (-4) 192#define LJ_TLIGHTUD (~3u)
193#define LJ_TSTR (-5) 193#define LJ_TSTR (~4u)
194#define LJ_TUPVAL (-6) 194#define LJ_TUPVAL (~5u)
195#define LJ_TTHREAD (-7) 195#define LJ_TTHREAD (~6u)
196#define LJ_TPROTO (-8) 196#define LJ_TPROTO (~7u)
197#define LJ_TFUNC (-9) 197#define LJ_TFUNC (~8u)
198#define LJ_TTRACE (-10) 198#define LJ_TTRACE (~9u)
199#define LJ_TTAB (-11) 199#define LJ_TTAB (~10u)
200#define LJ_TUDATA (-12) 200#define LJ_TUDATA (~11u)
201/* This is just the canonical number type used in some places. */ 201/* This is just the canonical number type used in some places. */
202#define LJ_TNUMX (-13) 202#define LJ_TNUMX (~12u)
203 203
204#if LJ_64 204#if LJ_64
205#define LJ_TISNUM ((uint32_t)0xfffeffff) 205#define LJ_TISNUM 0xfffeffffu
206#else 206#else
207#define LJ_TISNUM ((uint32_t)LJ_TNUMX) 207#define LJ_TISNUM LJ_TNUMX
208#endif 208#endif
209#define LJ_TISTRUECOND ((uint32_t)LJ_TFALSE) 209#define LJ_TISTRUECOND LJ_TFALSE
210#define LJ_TISPRI ((uint32_t)LJ_TTRUE) 210#define LJ_TISPRI LJ_TTRUE
211#define LJ_TISGCV ((uint32_t)(LJ_TSTR+1)) 211#define LJ_TISGCV (LJ_TSTR+1)
212#define LJ_TISTABUD ((uint32_t)LJ_TTAB) 212#define LJ_TISTABUD LJ_TTAB
213 213
214/* -- TValue getters/setters ---------------------------------------------- */ 214/* -- TValue getters/setters ---------------------------------------------- */
215 215
216/* Macros to test types. */ 216/* Macros to test types. */
217#define itype(o) ((o)->it) 217#define itype(o) ((o)->it)
218#define uitype(o) ((uint32_t)itype(o))
219#define tvisnil(o) (itype(o) == LJ_TNIL) 218#define tvisnil(o) (itype(o) == LJ_TNIL)
220#define tvisfalse(o) (itype(o) == LJ_TFALSE) 219#define tvisfalse(o) (itype(o) == LJ_TFALSE)
221#define tvistrue(o) (itype(o) == LJ_TTRUE) 220#define tvistrue(o) (itype(o) == LJ_TTRUE)
222#define tvisbool(o) (tvisfalse(o) || tvistrue(o)) 221#define tvisbool(o) (tvisfalse(o) || tvistrue(o))
223#if LJ_64 222#if LJ_64
224#define tvislightud(o) ((itype(o) >> 15) == -2) 223#define tvislightud(o) (((int32_t)itype(o) >> 15) == -2)
225#else 224#else
226#define tvislightud(o) (itype(o) == LJ_TLIGHTUD) 225#define tvislightud(o) (itype(o) == LJ_TLIGHTUD)
227#endif 226#endif
@@ -231,13 +230,12 @@ typedef const TValue cTValue;
231#define tvisproto(o) (itype(o) == LJ_TPROTO) 230#define tvisproto(o) (itype(o) == LJ_TPROTO)
232#define tvistab(o) (itype(o) == LJ_TTAB) 231#define tvistab(o) (itype(o) == LJ_TTAB)
233#define tvisudata(o) (itype(o) == LJ_TUDATA) 232#define tvisudata(o) (itype(o) == LJ_TUDATA)
234#define tvisnum(o) (uitype(o) <= LJ_TISNUM) 233#define tvisnum(o) (itype(o) <= LJ_TISNUM)
235 234
236#define tvistruecond(o) (uitype(o) < LJ_TISTRUECOND) 235#define tvistruecond(o) (itype(o) < LJ_TISTRUECOND)
237#define tvispri(o) (uitype(o) >= LJ_TISPRI) 236#define tvispri(o) (itype(o) >= LJ_TISPRI)
238#define tvistabud(o) (uitype(o) <= LJ_TISTABUD) /* && !tvisnum() */ 237#define tvistabud(o) (itype(o) <= LJ_TISTABUD) /* && !tvisnum() */
239#define tvisgcv(o) \ 238#define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))
240 ((uitype(o) - LJ_TISGCV) > ((uint32_t)LJ_TNUMX - LJ_TISGCV))
241 239
242/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */ 240/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */
243#define tvisnan(o) ((o)->n != (o)->n) 241#define tvisnan(o) ((o)->n != (o)->n)
diff --git a/src/lj_parse.c b/src/lj_parse.c
index b5bd7baf..c881aa91 100644
--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -184,7 +184,7 @@ static BCReg const_num(FuncState *fs, ExpDesc *e)
184} 184}
185 185
186/* Add a GC object constant. */ 186/* Add a GC object constant. */
187static BCReg const_gc(FuncState *fs, GCobj *gc, int itype) 187static BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype)
188{ 188{
189 lua_State *L = fs->L; 189 lua_State *L = fs->L;
190 TValue o, *val; 190 TValue o, *val;
@@ -1294,10 +1294,10 @@ static void expr_bracket(LexState *ls, ExpDesc *v)
1294static void expr_kvalue(TValue *v, ExpDesc *e) 1294static void expr_kvalue(TValue *v, ExpDesc *e)
1295{ 1295{
1296 if (e->k <= VKTRUE) { 1296 if (e->k <= VKTRUE) {
1297 v->it = ~(int32_t)e->k; 1297 setitype(v, ~(uint32_t)e->k);
1298 } else if (e->k == VKSTR) { 1298 } else if (e->k == VKSTR) {
1299 setgcref(v->gcr, obj2gco(e->u.sval)); 1299 setgcref(v->gcr, obj2gco(e->u.sval));
1300 v->it = LJ_TSTR; 1300 setitype(v, LJ_TSTR);
1301 } else { 1301 } else {
1302 lua_assert(e->k == VKNUM); 1302 lua_assert(e->k == VKNUM);
1303 setnumV(v, expr_numV(e)); 1303 setnumV(v, expr_numV(e));
diff --git a/src/lj_record.c b/src/lj_record.c
index b5e35076..440db6c6 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1969,7 +1969,7 @@ void lj_record_ins(jit_State *J)
1969 switch (bcmode_c(op)) { 1969 switch (bcmode_c(op)) {
1970 case BCMvar: 1970 case BCMvar:
1971 copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break; 1971 copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break;
1972 case BCMpri: setitype(rcv, (int32_t)~rc); rc = TREF_PRI(IRT_NIL+rc); break; 1972 case BCMpri: setitype(rcv, ~rc); rc = TREF_PRI(IRT_NIL+rc); break;
1973 case BCMnum: { lua_Number n = proto_knum(J->pt, rc); 1973 case BCMnum: { lua_Number n = proto_knum(J->pt, rc);
1974 setnumV(rcv, n); ix.key = rc = lj_ir_knumint(J, n); } break; 1974 setnumV(rcv, n); ix.key = rc = lj_ir_knumint(J, n); } break;
1975 case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc)); 1975 case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc));