Cleanup of TValue setters. No functional changes.

This commit is contained in:
Mike Pall 2014-12-20 00:59:16 +01:00
parent 6e9145a882
commit 5cb6e2eaaf
11 changed files with 26 additions and 21 deletions

View File

@ -1101,7 +1101,7 @@ LUA_API int lua_yield(lua_State *L, int nresults)
top->u64 = cframe_multres(cf);
setcont(top+1, lj_cont_hook);
setframe_pc(top+1, cframe_pc(cf)-1);
setframe_gc(top+2, obj2gco(L));
setframe_gc(top+2, obj2gco(L), LJ_TTHREAD);
setframe_ftsz(top+2, ((char *)(top+3)-(char *)L->base)+FRAME_CONT);
L->top = L->base = top+3;
#if LJ_TARGET_X64

View File

@ -192,7 +192,7 @@ static void bcread_ktabk(LexState *ls, TValue *o)
o->u32.hi = bcread_uleb128(ls);
} else {
lua_assert(tp <= BCDUMP_KTAB_TRUE);
setitype(o, ~tp);
setpriV(o, ~tp);
}
}

View File

@ -411,6 +411,7 @@ static void callback_conv_args(CTState *cts, lua_State *L)
int gcsteps = 0;
CType *ct;
GCfunc *fn;
int fntp;
MSize ngpr = 0, nsp = 0, maxgpr = CCALL_NARG_GPR;
#if CCALL_NARG_FPR
MSize nfpr = 0;
@ -423,15 +424,17 @@ static void callback_conv_args(CTState *cts, lua_State *L)
ct = ctype_get(cts, id);
rid = ctype_cid(ct->info);
fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot));
fntp = LJ_TFUNC;
} else { /* Must set up frame first, before throwing the error. */
ct = NULL;
rid = 0;
fn = (GCfunc *)L;
fntp = LJ_TTHREAD;
}
o->u32.lo = LJ_CONT_FFI_CALLBACK; /* Continuation returns from callback. */
o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */
o++;
setframe_gc(o, obj2gco(fn));
setframe_gc(o, obj2gco(fn), fntp);
setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT);
L->top = L->base = ++o;
if (!ct)

View File

@ -631,7 +631,7 @@ LJ_NOINLINE void lj_err_optype_call(lua_State *L, TValue *o)
if (((ptrdiff_t)pc & FRAME_TYPE) != FRAME_LUA) {
const char *tname = lj_typename(o);
setframe_pc(o, pc);
setframe_gc(o, obj2gco(L));
setframe_gc(o, obj2gco(L), LJ_TTHREAD);
L->top = L->base = o+1;
err_msgv(L, LJ_ERR_BADCALL, tname);
}

View File

@ -24,7 +24,7 @@ enum {
#define frame_gc(f) (gcref((f)->fr.func))
#define frame_ftsz(f) ((ptrdiff_t)(f)->fr.tp.ftsz)
#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
#define setframe_gc(f, p) (setgcref((f)->fr.func, (p)))
#define setframe_gc(f, p, tp) (setgcref((f)->fr.func, (p)), UNUSED(tp))
#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (int32_t)(sz))
#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))

View File

@ -392,7 +392,7 @@ void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)
UNUSED(L);
lua_assert(ir->o != IR_KSLOT); /* Common mistake. */
switch (ir->o) {
case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break;
case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break;
case IR_KINT: setintV(tv, ir->i); break;
case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break;
case IR_KPTR: case IR_KKPTR: case IR_KNULL:

View File

@ -83,7 +83,7 @@ int lj_meta_tailcall(lua_State *L, cTValue *tv)
copyTV(L, base-1, tv); /* Replace frame with new object. */
top->u32.lo = LJ_CONT_TAILCALL;
setframe_pc(top, pc);
setframe_gc(top+1, obj2gco(L)); /* Dummy frame object. */
setframe_gc(top+1, obj2gco(L), LJ_TTHREAD); /* Dummy frame object. */
setframe_ftsz(top+1, ((char *)(top+2) - (char *)base) + FRAME_CONT);
L->base = L->top = top+2;
/*
@ -355,7 +355,7 @@ TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins)
o2 = &mref(curr_proto(L)->k, cTValue)[bc_d(ins)];
} else {
lua_assert(op == BC_ISEQP);
setitype(&tv, ~bc_d(ins));
setpriV(&tv, ~bc_d(ins));
o2 = &tv;
}
mo = lj_meta_lookup(L, o1mm, MM_eq);

View File

@ -43,12 +43,10 @@ typedef struct GCRef {
#define gcref(r) ((GCobj *)(uintptr_t)(r).gcptr32)
#define gcrefp(r, t) ((t *)(void *)(uintptr_t)(r).gcptr32)
#define gcrefu(r) ((r).gcptr32)
#define gcrefi(r) ((int32_t)(r).gcptr32)
#define gcrefeq(r1, r2) ((r1).gcptr32 == (r2).gcptr32)
#define gcnext(gc) (gcref((gc)->gch.nextgc))
#define setgcref(r, gc) ((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch)
#define setgcrefi(r, i) ((r).gcptr32 = (uint32_t)(i))
#define setgcrefp(r, p) ((r).gcptr32 = (uint32_t)(uintptr_t)(p))
#define setgcrefnull(r) ((r).gcptr32 = 0)
#define setgcrefr(r, v) ((r).gcptr32 = (v).gcptr32)
@ -720,6 +718,7 @@ typedef union GCobj {
#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))
#define setpriV(o, i) (setitype((o), (i)))
static LJ_AINLINE void setlightudV(TValue *o, void *p)
{
@ -744,9 +743,14 @@ static LJ_AINLINE void setlightudV(TValue *o, void *p)
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)
static LJ_AINLINE void setgcVraw(TValue *o, GCobj *v, uint32_t itype)
{
setgcref(o->gcr, v); setitype(o, itype); tvchecklive(L, o);
setgcref(o->gcr, v); setitype(o, itype);
}
static LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t it)
{
setgcVraw(o, v, it); tvchecklive(L, o);
}
#define define_setV(name, type, tag) \

View File

@ -1684,10 +1684,9 @@ static void expr_bracket(LexState *ls, ExpDesc *v)
static void expr_kvalue(TValue *v, ExpDesc *e)
{
if (e->k <= VKTRUE) {
setitype(v, ~(uint32_t)e->k);
setpriV(v, ~(uint32_t)e->k);
} else if (e->k == VKSTR) {
setgcref(v->gcr, obj2gco(e->u.sval));
setitype(v, LJ_TSTR);
setgcVraw(v, obj2gco(e->u.sval), LJ_TSTR);
} else {
lua_assert(tvisnumber(expr_numtv(e)));
*v = *expr_numtv(e);

View File

@ -1891,7 +1891,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, ~rc); ix.key = rc = TREF_PRI(IRT_NIL+rc); break;
case BCMpri: setpriV(rcv, ~rc); ix.key = rc = TREF_PRI(IRT_NIL+rc); break;
case BCMnum: { cTValue *tv = proto_knumtv(J->pt, rc);
copyTV(J->L, rcv, tv); ix.key = rc = tvisint(tv) ? lj_ir_kint(J, intV(tv)) :
lj_ir_knumint(J, numV(tv)); } break;

View File

@ -613,8 +613,7 @@ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,
o->u64 = *(uint64_t *)sps;
} else {
lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */
setgcrefi(o->gcr, *sps);
setitype(o, irt_toitype(t));
setgcV(J->L, o, (GCobj *)(uintptr_t)*(GCSize *)sps, irt_toitype(t));
}
} else { /* Restore from register. */
Reg r = regsp_reg(rs);
@ -632,10 +631,10 @@ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,
} else if (LJ_64 && irt_islightud(t)) {
/* 64 bit lightuserdata which may escape already has the tag bits. */
o->u64 = ex->gpr[r-RID_MIN_GPR];
} else if (irt_ispri(t)) {
setpriV(o, irt_toitype(t));
} else {
if (!irt_ispri(t))
setgcrefi(o->gcr, ex->gpr[r-RID_MIN_GPR]);
setitype(o, irt_toitype(t));
setgcV(J->L, o, (GCobj *)ex->gpr[r-RID_MIN_GPR], irt_toitype(t));
}
}
}