mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Turn TValue setter macros into inline functions.
This commit is contained in:
parent
41379126a2
commit
28cfccf748
@ -235,7 +235,7 @@ LJLIB_CF(jit_util_funck)
|
||||
} else {
|
||||
if (~idx < (ptrdiff_t)pt->sizekgc) {
|
||||
GCobj *gc = proto_kgc(pt, idx);
|
||||
setgcV(L, L->top-1, &gc->gch, ~gc->gch.gct);
|
||||
setgcV(L, L->top-1, gc, ~gc->gch.gct);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)
|
||||
} else {
|
||||
if (ir->o == IR_KGC) {
|
||||
lua_assert(irt_isgcv(ir->t));
|
||||
setgcV(L, tv, &ir_kgc(ir)->gch, irt_toitype(ir->t));
|
||||
setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t));
|
||||
} else {
|
||||
lua_assert(ir->o == IR_KPTR || ir->o == IR_KNULL);
|
||||
setlightudV(tv, mref(ir->ptr, void));
|
||||
|
@ -226,9 +226,9 @@ TValue *lj_meta_cat(lua_State *L, TValue *top, int left)
|
||||
** after mm: [...][CAT stack ...] <--push-- [result]
|
||||
** next step: [...][CAT stack .............]
|
||||
*/
|
||||
copyTV(L, top+2, top) /* Careful with the order of stack copies! */
|
||||
copyTV(L, top+1, top-1)
|
||||
copyTV(L, top, mo)
|
||||
copyTV(L, top+2, top); /* Careful with the order of stack copies! */
|
||||
copyTV(L, top+1, top-1);
|
||||
copyTV(L, top, mo);
|
||||
setcont(top-1, lj_cont_cat);
|
||||
return top+1; /* Trigger metamethod call. */
|
||||
} else if (strV(top)->len == 0) { /* Shortcut. */
|
||||
@ -295,8 +295,8 @@ TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)
|
||||
setcont(top, ne ? lj_cont_condf : lj_cont_condt);
|
||||
copyTV(L, top+1, mo);
|
||||
it = ~(uint32_t)o1->gch.gct;
|
||||
setgcV(L, top+2, &o1->gch, it);
|
||||
setgcV(L, top+3, &o2->gch, it);
|
||||
setgcV(L, top+2, o1, it);
|
||||
setgcV(L, top+3, o2, it);
|
||||
return top+2; /* Trigger metamethod call. */
|
||||
}
|
||||
return cast(TValue *, (intptr_t)ne);
|
||||
|
229
src/lj_obj.h
229
src/lj_obj.h
@ -211,111 +211,6 @@ typedef const TValue cTValue;
|
||||
#define LJ_TISGCV (LJ_TSTR+1)
|
||||
#define LJ_TISTABUD LJ_TTAB
|
||||
|
||||
/* -- TValue getters/setters ---------------------------------------------- */
|
||||
|
||||
/* Macros to test types. */
|
||||
#define itype(o) ((o)->it)
|
||||
#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) (((int32_t)itype(o) >> 15) == -2)
|
||||
#else
|
||||
#define tvislightud(o) (itype(o) == LJ_TLIGHTUD)
|
||||
#endif
|
||||
#define tvisstr(o) (itype(o) == LJ_TSTR)
|
||||
#define tvisfunc(o) (itype(o) == LJ_TFUNC)
|
||||
#define tvisthread(o) (itype(o) == LJ_TTHREAD)
|
||||
#define tvisproto(o) (itype(o) == LJ_TPROTO)
|
||||
#define tvistab(o) (itype(o) == LJ_TTAB)
|
||||
#define tvisudata(o) (itype(o) == LJ_TUDATA)
|
||||
#define tvisnum(o) (itype(o) <= LJ_TISNUM)
|
||||
|
||||
#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)
|
||||
#define tvispzero(o) ((o)->u64 == 0)
|
||||
#define tvismzero(o) ((o)->u64 == U64x(80000000,00000000))
|
||||
#define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000))
|
||||
#define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64)
|
||||
|
||||
/* Macros to convert type ids. */
|
||||
#if LJ_64
|
||||
#define itypemap(o) \
|
||||
(tvisnum(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o))
|
||||
#else
|
||||
#define itypemap(o) (tvisnum(o) ? ~LJ_TNUMX : ~itype(o))
|
||||
#endif
|
||||
|
||||
/* Macros to get tagged values. */
|
||||
#define gcval(o) (gcref((o)->gcr))
|
||||
#define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - (o)->it))
|
||||
#if LJ_64
|
||||
#define lightudV(o) check_exp(tvislightud(o), \
|
||||
(void *)((o)->u64 & U64x(00007fff,ffffffff)))
|
||||
#else
|
||||
#define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void))
|
||||
#endif
|
||||
#define gcV(o) check_exp(tvisgcv(o), gcval(o))
|
||||
#define strV(o) check_exp(tvisstr(o), &gcval(o)->str)
|
||||
#define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn)
|
||||
#define threadV(o) check_exp(tvisthread(o), &gcval(o)->th)
|
||||
#define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt)
|
||||
#define tabV(o) check_exp(tvistab(o), &gcval(o)->tab)
|
||||
#define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud)
|
||||
#define numV(o) check_exp(tvisnum(o), (o)->n)
|
||||
|
||||
/* Macros to set tagged values. */
|
||||
#define setitype(o, i) ((o)->it = (i))
|
||||
#define setnilV(o) ((o)->it = LJ_TNIL)
|
||||
#define setboolV(o, x) ((o)->it = LJ_TFALSE-(x))
|
||||
|
||||
#if LJ_64
|
||||
#define checklightudptr(L, p) \
|
||||
(((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p))
|
||||
#define setlightudV(o, x) \
|
||||
((o)->u64 = (uint64_t)(x) | (((uint64_t)0xffff) << 48))
|
||||
#define setcont(o, x) \
|
||||
((o)->u64 = (uint64_t)(x) - (uint64_t)lj_vm_asm_begin)
|
||||
#else
|
||||
#define checklightudptr(L, p) (p)
|
||||
#define setlightudV(o, x) \
|
||||
{ TValue *i_o = (o); \
|
||||
setgcrefp(i_o->gcr, (x)); i_o->it = LJ_TLIGHTUD; }
|
||||
#define setcont(o, x) \
|
||||
{ TValue *i_o = (o); \
|
||||
setgcrefp(i_o->gcr, (x)); i_o->it = LJ_TLIGHTUD; }
|
||||
#endif
|
||||
|
||||
#define tvchecklive(g, o) \
|
||||
lua_assert(!tvisgcv(o) || \
|
||||
((~itype(o) == gcval(o)->gch.gct) && !isdead(g, gcval(o))))
|
||||
|
||||
#define setgcV(L, o, x, itype) \
|
||||
{ TValue *i_o = (o); \
|
||||
setgcrefp(i_o->gcr, &(x)->nextgc); i_o->it = itype; \
|
||||
tvchecklive(G(L), i_o); }
|
||||
#define setstrV(L, o, x) setgcV(L, o, x, LJ_TSTR)
|
||||
#define setthreadV(L, o, x) setgcV(L, o, x, LJ_TTHREAD)
|
||||
#define setprotoV(L, o, x) setgcV(L, o, x, LJ_TPROTO)
|
||||
#define setfuncV(L, o, x) setgcV(L, o, &(x)->l, LJ_TFUNC)
|
||||
#define settabV(L, o, x) setgcV(L, o, x, LJ_TTAB)
|
||||
#define setudataV(L, o, x) setgcV(L, o, x, LJ_TUDATA)
|
||||
|
||||
#define setnumV(o, x) ((o)->n = (x))
|
||||
#define setnanV(o) ((o)->u64 = U64x(fff80000,00000000))
|
||||
#define setintV(o, i) ((o)->n = cast_num((int32_t)(i)))
|
||||
|
||||
/* Copy tagged values. */
|
||||
#define copyTV(L, o1, o2) \
|
||||
{ cTValue *i_o2 = (o2); TValue *i_o1 = (o1); \
|
||||
*i_o1 = *i_o2; tvchecklive(G(L), i_o1); }
|
||||
|
||||
/* -- String object ------------------------------------------------------- */
|
||||
|
||||
/* String object header. String payload follows. */
|
||||
@ -694,7 +589,125 @@ typedef union GCobj {
|
||||
#define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud)
|
||||
|
||||
/* Macro to convert any collectable object into a GCobj pointer. */
|
||||
#define obj2gco(v) (cast(GCobj *, (v)))
|
||||
#define obj2gco(v) ((GCobj *)(v))
|
||||
|
||||
/* -- TValue getters/setters ---------------------------------------------- */
|
||||
|
||||
#ifdef LUA_USE_ASSERT
|
||||
#include "lj_gc.h"
|
||||
#endif
|
||||
|
||||
/* Macros to test types. */
|
||||
#define itype(o) ((o)->it)
|
||||
#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) (((int32_t)itype(o) >> 15) == -2)
|
||||
#else
|
||||
#define tvislightud(o) (itype(o) == LJ_TLIGHTUD)
|
||||
#endif
|
||||
#define tvisstr(o) (itype(o) == LJ_TSTR)
|
||||
#define tvisfunc(o) (itype(o) == LJ_TFUNC)
|
||||
#define tvisthread(o) (itype(o) == LJ_TTHREAD)
|
||||
#define tvisproto(o) (itype(o) == LJ_TPROTO)
|
||||
#define tvistab(o) (itype(o) == LJ_TTAB)
|
||||
#define tvisudata(o) (itype(o) == LJ_TUDATA)
|
||||
#define tvisnum(o) (itype(o) <= LJ_TISNUM)
|
||||
|
||||
#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)
|
||||
#define tvispzero(o) ((o)->u64 == 0)
|
||||
#define tvismzero(o) ((o)->u64 == U64x(80000000,00000000))
|
||||
#define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000))
|
||||
#define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64)
|
||||
|
||||
/* Macros to convert type ids. */
|
||||
#if LJ_64
|
||||
#define itypemap(o) \
|
||||
(tvisnum(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o))
|
||||
#else
|
||||
#define itypemap(o) (tvisnum(o) ? ~LJ_TNUMX : ~itype(o))
|
||||
#endif
|
||||
|
||||
/* Macros to get tagged values. */
|
||||
#define gcval(o) (gcref((o)->gcr))
|
||||
#define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - (o)->it))
|
||||
#if LJ_64
|
||||
#define lightudV(o) \
|
||||
check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff)))
|
||||
#else
|
||||
#define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void))
|
||||
#endif
|
||||
#define gcV(o) check_exp(tvisgcv(o), gcval(o))
|
||||
#define strV(o) check_exp(tvisstr(o), &gcval(o)->str)
|
||||
#define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn)
|
||||
#define threadV(o) check_exp(tvisthread(o), &gcval(o)->th)
|
||||
#define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt)
|
||||
#define tabV(o) check_exp(tvistab(o), &gcval(o)->tab)
|
||||
#define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud)
|
||||
#define numV(o) check_exp(tvisnum(o), (o)->n)
|
||||
|
||||
/* Macros to set tagged values. */
|
||||
#define setitype(o, i) ((o)->it = (i))
|
||||
#define setnilV(o) ((o)->it = LJ_TNIL)
|
||||
#define setboolV(o, x) ((o)->it = LJ_TFALSE-(uint32_t)(x))
|
||||
|
||||
static LJ_AINLINE void setlightudV(TValue *o, void *p)
|
||||
{
|
||||
#if LJ_64
|
||||
o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48);
|
||||
#else
|
||||
setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LJ_64
|
||||
#define checklightudptr(L, p) \
|
||||
(((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p))
|
||||
#define setcont(o, f) \
|
||||
((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin)
|
||||
#else
|
||||
#define checklightudptr(L, p) (p)
|
||||
#define setcont(o, f) setlightudV((o), (void *)(f))
|
||||
#endif
|
||||
|
||||
#define tvchecklive(L, o) \
|
||||
UNUSED(L), lua_assert(!tvisgcv(o) || \
|
||||
((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o))))
|
||||
|
||||
static LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t itype)
|
||||
{
|
||||
setgcref(o->gcr, v); setitype(o, itype); tvchecklive(L, o);
|
||||
}
|
||||
|
||||
#define define_setV(name, type, tag) \
|
||||
static LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \
|
||||
{ \
|
||||
setgcV(L, o, obj2gco(v), tag); \
|
||||
}
|
||||
define_setV(setstrV, GCstr, LJ_TSTR)
|
||||
define_setV(setthreadV, lua_State, LJ_TTHREAD)
|
||||
define_setV(setprotoV, GCproto, LJ_TPROTO)
|
||||
define_setV(setfuncV, GCfunc, LJ_TFUNC)
|
||||
define_setV(settabV, GCtab, LJ_TTAB)
|
||||
define_setV(setudataV, GCudata, LJ_TUDATA)
|
||||
|
||||
#define setnumV(o, x) ((o)->n = (x))
|
||||
#define setnanV(o) ((o)->u64 = U64x(fff80000,00000000))
|
||||
#define setintV(o, i) ((o)->n = cast_num((int32_t)(i)))
|
||||
|
||||
/* Copy tagged values. */
|
||||
static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2)
|
||||
{
|
||||
*o1 = *o2; tvchecklive(L, o1);
|
||||
}
|
||||
|
||||
/* -- Number to integer conversion ---------------------------------------- */
|
||||
|
||||
@ -722,8 +735,4 @@ LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1];
|
||||
/* Compare two objects without calling metamethods. */
|
||||
LJ_FUNC int lj_obj_equal(cTValue *o1, cTValue *o2);
|
||||
|
||||
#ifdef LUA_USE_ASSERT
|
||||
#include "lj_gc.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -188,7 +188,7 @@ static BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype)
|
||||
{
|
||||
lua_State *L = fs->L;
|
||||
TValue o, *val;
|
||||
setgcV(L, &o, &gc->gch, itype);
|
||||
setgcV(L, &o, gc, itype);
|
||||
/* NOBARRIER: the key is new or kept alive. */
|
||||
val = lj_tab_set(L, fs->kt, &o);
|
||||
if (tvisnum(val))
|
||||
|
Loading…
Reference in New Issue
Block a user