minimizing the code ran by 'vmfetch' + no more 'vra'

(the code is simpler without 'vra' and conversion is a no-op)
This commit is contained in:
Roberto Ierusalimschy 2018-05-02 15:17:59 -03:00
parent deb807837c
commit e64e20ac81
3 changed files with 128 additions and 125 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.155 2018/02/17 19:29:29 roberto Exp roberto $
** $Id: ldebug.c,v 2.156 2018/03/16 15:33:34 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -783,17 +783,24 @@ static int changedline (Proto *p, int oldpc, int newpc) {
}
void luaG_traceexec (lua_State *L) {
int luaG_traceexec (lua_State *L, const Instruction *pc) {
CallInfo *ci = L->ci;
lu_byte mask = L->hookmask;
int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
int counthook;
if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) { /* no hooks? */
ci->u.l.trap = 0; /* don't need to stop again */
return 0; /* turn off 'trap' */
}
pc++; /* reference is always next instruction */
ci->u.l.savedpc = pc; /* save 'pc' */
counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
if (counthook)
resethookcount(L); /* reset count */
else if (!(mask & LUA_MASKLINE))
return; /* no line hook and count != 0; nothing to be done */
return 1; /* no line hook and count != 0; nothing to be done now */
if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
return; /* do not call hook again (VM yielded, so it did not move) */
return 1; /* do not call hook again (VM yielded, so it did not move) */
}
if (!isIT(*(ci->u.l.savedpc - 1)))
L->top = ci->top; /* prepare top */
@ -801,15 +808,14 @@ void luaG_traceexec (lua_State *L) {
luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */
if (mask & LUA_MASKLINE) {
Proto *p = ci_func(ci)->p;
const Instruction *npc = ci->u.l.savedpc;
int npci = pcRel(npc, p);
int npci = pcRel(pc, p);
if (npci == 0 || /* call linehook when enter a new function, */
npc <= L->oldpc || /* when jump back (loop), or when */
pc <= L->oldpc || /* when jump back (loop), or when */
changedline(p, pcRel(L->oldpc, p), npci)) { /* enter new line */
int newline = luaG_getfuncline(p, npci); /* new line */
int newline = luaG_getfuncline(p, npci);
luaD_hook(L, LUA_HOOKLINE, newline, 0, 0); /* call line hook */
}
L->oldpc = npc;
L->oldpc = pc; /* 'pc' of last call to line hook */
}
if (L->status == LUA_YIELD) { /* did hook yield? */
if (counthook)
@ -818,5 +824,6 @@ void luaG_traceexec (lua_State *L) {
ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
luaD_throw(L, LUA_YIELD);
}
return 1; /* keep 'trap' on */
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.h,v 2.15 2017/06/27 11:35:31 roberto Exp roberto $
** $Id: ldebug.h,v 2.16 2018/01/28 15:13:26 roberto Exp roberto $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
*/
@ -37,7 +37,7 @@ LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,
TString *src, int line);
LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
LUAI_FUNC void luaG_traceexec (lua_State *L);
LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc);
#endif

222
lvm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.352 2018/04/02 17:52:07 roberto Exp roberto $
** $Id: lvm.c,v 2.353 2018/04/04 14:23:41 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -489,7 +489,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
case LUA_TNIL: return 1;
case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));
case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1! */
case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
case LUA_TLCF: return fvalue(t1) == fvalue(t2);
case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
@ -867,15 +867,12 @@ void luaV_finishOp (lua_State *L) {
/* fetch an instruction and prepare its execution */
#define vmfetch() { \
i = *(pc++); \
if (trap) { \
if (!(L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT))) \
trap = ci->u.l.trap = 0; /* no need to stop again */ \
else { savepc(L); luaG_traceexec(L); } \
updatebase(ci); /* the trap may be just for that */ \
if (trap) { /* stack reallocation or hooks? */ \
trap = luaG_traceexec(L, pc); /* handle hooks */ \
updatebase(ci); /* correct stack */ \
} \
i = *(pc++); \
ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \
vra = s2v(ra); \
}
#define vmdispatch(o) switch(o)
@ -899,7 +896,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
pc = ci->u.l.savedpc;
if (trap) {
if (cl->p->is_vararg)
trap = 0; /* hooks will start with PREPVARARG instruction */
trap = 0; /* hooks will start after PREPVARARG instruction */
else if (pc == cl->p->code) /* first instruction (not resuming)? */
luaD_hookcall(L, ci);
ci->u.l.trap = 1; /* there may be other hooks */
@ -910,7 +907,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int cond; /* flag for conditional jumps */
Instruction i; /* instruction being executed */
StkId ra; /* instruction's A register */
TValue *vra; /* corresponding value */
vmfetch();
lua_assert(base == ci->func + 1);
lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
@ -927,12 +923,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
}
vmcase(OP_LOADI) {
lua_Integer b = GETARG_sBx(i);
setivalue(vra, b);
setivalue(s2v(ra), b);
vmbreak;
}
vmcase(OP_LOADF) {
int b = GETARG_sBx(i);
setfltvalue(vra, cast_num(b));
setfltvalue(s2v(ra), cast_num(b));
vmbreak;
}
vmcase(OP_LOADKX) {
@ -942,7 +938,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmbreak;
}
vmcase(OP_LOADBOOL) {
setbvalue(vra, GETARG_B(i));
setbvalue(s2v(ra), GETARG_B(i));
if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
vmbreak;
}
@ -960,8 +956,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
}
vmcase(OP_SETUPVAL) {
UpVal *uv = cl->upvals[GETARG_B(i)];
setobj(L, uv->v, vra);
luaC_barrier(L, uv, vra);
setobj(L, uv->v, s2v(ra));
luaC_barrier(L, uv, s2v(ra));
vmbreak;
}
vmcase(OP_GETTABUP) {
@ -1035,25 +1031,25 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = RKC(i); /* value */
lua_Unsigned n;
if (ttisinteger(rb) /* fast track for integers? */
? (n = ivalue(rb), luaV_fastgeti(L, vra, n, slot))
: luaV_fastget(L, vra, rb, slot, luaH_get)) {
luaV_finishfastset(L, vra, slot, rc);
? (n = ivalue(rb), luaV_fastgeti(L, s2v(ra), n, slot))
: luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) {
luaV_finishfastset(L, s2v(ra), slot, rc);
}
else
Protect(luaV_finishset(L, vra, rb, rc, slot));
Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
vmbreak;
}
vmcase(OP_SETI) {
const TValue *slot;
int c = GETARG_B(i);
TValue *rc = RKC(i);
if (luaV_fastgeti(L, vra, c, slot)) {
luaV_finishfastset(L, vra, slot, rc);
if (luaV_fastgeti(L, s2v(ra), c, slot)) {
luaV_finishfastset(L, s2v(ra), slot, rc);
}
else {
TValue key;
setivalue(&key, c);
Protect(luaV_finishset(L, vra, &key, rc, slot));
Protect(luaV_finishset(L, s2v(ra), &key, rc, slot));
}
vmbreak;
}
@ -1062,11 +1058,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rb = KB(i);
TValue *rc = RKC(i);
TString *key = tsvalue(rb); /* key must be a string */
if (luaV_fastget(L, vra, key, slot, luaH_getshortstr)) {
luaV_finishfastset(L, vra, slot, rc);
if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {
luaV_finishfastset(L, s2v(ra), slot, rc);
}
else
Protect(luaV_finishset(L, vra, rb, rc, slot));
Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
vmbreak;
}
vmcase(OP_NEWTABLE) {
@ -1099,10 +1095,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Number nb;
if (ttisinteger(rb)) {
setivalue(vra, intop(+, ivalue(rb), ic));
setivalue(s2v(ra), intop(+, ivalue(rb), ic));
}
else if (tonumberns(rb, nb)) {
setfltvalue(vra, luai_numadd(L, nb, cast_num(ic)));
setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic)));
}
else
Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_ADD));
@ -1113,10 +1109,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Number nb;
if (ttisinteger(rb)) {
setivalue(vra, intop(-, ivalue(rb), ic));
setivalue(s2v(ra), intop(-, ivalue(rb), ic));
}
else if (tonumberns(rb, nb)) {
setfltvalue(vra, luai_numsub(L, nb, cast_num(ic)));
setfltvalue(s2v(ra), luai_numsub(L, nb, cast_num(ic)));
}
else
Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_SUB));
@ -1127,10 +1123,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Number nb;
if (ttisinteger(rb)) {
setivalue(vra, intop(*, ivalue(rb), ic));
setivalue(s2v(ra), intop(*, ivalue(rb), ic));
}
else if (tonumberns(rb, nb)) {
setfltvalue(vra, luai_nummul(L, nb, cast_num(ic)));
setfltvalue(s2v(ra), luai_nummul(L, nb, cast_num(ic)));
}
else
Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_MUL));
@ -1141,13 +1137,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Number nb;
if (ttisinteger(rb)) {
setivalue(vra, luaV_mod(L, ivalue(rb), ic));
setivalue(s2v(ra), luaV_mod(L, ivalue(rb), ic));
}
else if (tonumberns(rb, nb)) {
lua_Number m;
lua_Number nc = cast_num(ic);
luai_nummod(L, nb, nc, m);
setfltvalue(vra, m);
setfltvalue(s2v(ra), m);
}
else
Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_MOD));
@ -1159,7 +1155,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb;
if (tonumberns(rb, nb)) {
lua_Number nc = cast_num(ic);
setfltvalue(vra, luai_numpow(L, nb, nc));
setfltvalue(s2v(ra), luai_numpow(L, nb, nc));
}
else
Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_POW));
@ -1171,7 +1167,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb;
if (tonumberns(rb, nb)) {
lua_Number nc = cast_num(ic);
setfltvalue(vra, luai_numdiv(L, nb, nc));
setfltvalue(s2v(ra), luai_numdiv(L, nb, nc));
}
else
Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_DIV));
@ -1182,11 +1178,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Number nb;
if (ttisinteger(rb)) {
setivalue(vra, luaV_div(L, ivalue(rb), ic));
setivalue(s2v(ra), luaV_div(L, ivalue(rb), ic));
}
else if (tonumberns(rb, nb)) {
lua_Number nc = cast_num(ic);
setfltvalue(vra, luai_numdiv(L, nb, nc));
setfltvalue(s2v(ra), luai_numdiv(L, nb, nc));
}
else
Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_IDIV));
@ -1198,10 +1194,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb; lua_Number nc;
if (ttisinteger(rb) && ttisinteger(rc)) {
lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
setivalue(vra, intop(+, ib, ic));
setivalue(s2v(ra), intop(+, ib, ic));
}
else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
setfltvalue(vra, luai_numadd(L, nb, nc));
setfltvalue(s2v(ra), luai_numadd(L, nb, nc));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD));
@ -1213,10 +1209,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb; lua_Number nc;
if (ttisinteger(rb) && ttisinteger(rc)) {
lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
setivalue(vra, intop(-, ib, ic));
setivalue(s2v(ra), intop(-, ib, ic));
}
else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
setfltvalue(vra, luai_numsub(L, nb, nc));
setfltvalue(s2v(ra), luai_numsub(L, nb, nc));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB));
@ -1228,10 +1224,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb; lua_Number nc;
if (ttisinteger(rb) && ttisinteger(rc)) {
lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
setivalue(vra, intop(*, ib, ic));
setivalue(s2v(ra), intop(*, ib, ic));
}
else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
setfltvalue(vra, luai_nummul(L, nb, nc));
setfltvalue(s2v(ra), luai_nummul(L, nb, nc));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL));
@ -1242,7 +1238,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = vRC(i);
lua_Number nb; lua_Number nc;
if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
setfltvalue(vra, luai_numdiv(L, nb, nc));
setfltvalue(s2v(ra), luai_numdiv(L, nb, nc));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV));
@ -1253,7 +1249,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *p2 = KC(i);
lua_Integer i1;
if (tointegerns(p1, &i1)) {
setivalue(vra, intop(&, i1, ivalue(p2)));
setivalue(s2v(ra), intop(&, i1, ivalue(p2)));
}
else
Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BAND));
@ -1264,7 +1260,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *p2 = KC(i);
lua_Integer i1;
if (tointegerns(p1, &i1)) {
setivalue(vra, intop(|, i1, ivalue(p2)));
setivalue(s2v(ra), intop(|, i1, ivalue(p2)));
}
else
Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BOR));
@ -1275,7 +1271,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *p2 = KC(i);
lua_Integer i1;
if (tointegerns(p1, &i1)) {
setivalue(vra, intop(^, i1, ivalue(p2)));
setivalue(s2v(ra), intop(^, i1, ivalue(p2)));
}
else
Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BXOR));
@ -1286,7 +1282,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = vRC(i);
lua_Integer ib; lua_Integer ic;
if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
setivalue(vra, intop(&, ib, ic));
setivalue(s2v(ra), intop(&, ib, ic));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND));
@ -1297,7 +1293,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = vRC(i);
lua_Integer ib; lua_Integer ic;
if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
setivalue(vra, intop(|, ib, ic));
setivalue(s2v(ra), intop(|, ib, ic));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR));
@ -1308,7 +1304,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = vRC(i);
lua_Integer ib; lua_Integer ic;
if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
setivalue(vra, intop(^, ib, ic));
setivalue(s2v(ra), intop(^, ib, ic));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR));
@ -1319,7 +1315,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Integer ib;
if (tointegerns(rb, &ib)) {
setivalue(vra, luaV_shiftl(ib, -ic));
setivalue(s2v(ra), luaV_shiftl(ib, -ic));
}
else {
TMS ev = TM_SHR;
@ -1335,7 +1331,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Integer ib;
if (tointegerns(rb, &ib)) {
setivalue(vra, luaV_shiftl(ic, ib));
setivalue(s2v(ra), luaV_shiftl(ic, ib));
}
else
Protect(luaT_trybiniTM(L, rb, ic, 1, ra, TM_SHL));
@ -1346,7 +1342,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = vRC(i);
lua_Integer ib; lua_Integer ic;
if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
setivalue(vra, luaV_shiftl(ib, ic));
setivalue(s2v(ra), luaV_shiftl(ib, ic));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL));
@ -1357,7 +1353,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = vRC(i);
lua_Integer ib; lua_Integer ic;
if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
setivalue(vra, luaV_shiftl(ib, -ic));
setivalue(s2v(ra), luaV_shiftl(ib, -ic));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR));
@ -1369,12 +1365,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb; lua_Number nc;
if (ttisinteger(rb) && ttisinteger(rc)) {
lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
setivalue(vra, luaV_mod(L, ib, ic));
setivalue(s2v(ra), luaV_mod(L, ib, ic));
}
else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
lua_Number m;
luai_nummod(L, nb, nc, m);
setfltvalue(vra, m);
setfltvalue(s2v(ra), m);
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD));
@ -1386,10 +1382,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb; lua_Number nc;
if (ttisinteger(rb) && ttisinteger(rc)) {
lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
setivalue(vra, luaV_div(L, ib, ic));
setivalue(s2v(ra), luaV_div(L, ib, ic));
}
else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
setfltvalue(vra, luai_numidiv(L, nb, nc));
setfltvalue(s2v(ra), luai_numidiv(L, nb, nc));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV));
@ -1400,7 +1396,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = vRC(i);
lua_Number nb; lua_Number nc;
if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
setfltvalue(vra, luai_numpow(L, nb, nc));
setfltvalue(s2v(ra), luai_numpow(L, nb, nc));
}
else
Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW));
@ -1411,10 +1407,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Number nb;
if (ttisinteger(rb)) {
lua_Integer ib = ivalue(rb);
setivalue(vra, intop(-, 0, ib));
setivalue(s2v(ra), intop(-, 0, ib));
}
else if (tonumberns(rb, nb)) {
setfltvalue(vra, luai_numunm(L, nb));
setfltvalue(s2v(ra), luai_numunm(L, nb));
}
else
Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
@ -1424,7 +1420,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rb = vRB(i);
lua_Integer ib;
if (tointegerns(rb, &ib)) {
setivalue(vra, intop(^, ~l_castS2U(0), ib));
setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
}
else
Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
@ -1433,7 +1429,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmcase(OP_NOT) {
TValue *rb = vRB(i);
int nrb = l_isfalse(rb); /* next assignment may change this value */
setbvalue(vra, nrb);
setbvalue(s2v(ra), nrb);
vmbreak;
}
vmcase(OP_LEN) {
@ -1457,45 +1453,45 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
}
vmcase(OP_EQ) {
TValue *rb = vRB(i);
Protect(cond = luaV_equalobj(L, vra, rb));
Protect(cond = luaV_equalobj(L, s2v(ra), rb));
docondjump();
vmbreak;
}
vmcase(OP_LT) {
TValue *rb = vRB(i);
if (ttisinteger(vra) && ttisinteger(rb))
cond = (ivalue(vra) < ivalue(rb));
else if (ttisnumber(vra) && ttisnumber(rb))
cond = LTnum(vra, rb);
if (ttisinteger(s2v(ra)) && ttisinteger(rb))
cond = (ivalue(s2v(ra)) < ivalue(rb));
else if (ttisnumber(s2v(ra)) && ttisnumber(rb))
cond = LTnum(s2v(ra), rb);
else
Protect(cond = lessthanothers(L, vra, rb));
Protect(cond = lessthanothers(L, s2v(ra), rb));
docondjump();
vmbreak;
}
vmcase(OP_LE) {
TValue *rb = vRB(i);
if (ttisinteger(vra) && ttisinteger(rb))
cond = (ivalue(vra) <= ivalue(rb));
else if (ttisnumber(vra) && ttisnumber(rb))
cond = LEnum(vra, rb);
if (ttisinteger(s2v(ra)) && ttisinteger(rb))
cond = (ivalue(s2v(ra)) <= ivalue(rb));
else if (ttisnumber(s2v(ra)) && ttisnumber(rb))
cond = LEnum(s2v(ra), rb);
else
Protect(cond = lessequalothers(L, vra, rb));
Protect(cond = lessequalothers(L, s2v(ra), rb));
docondjump();
vmbreak;
}
vmcase(OP_EQK) {
TValue *rb = KB(i);
/* basic types do not use '__eq'; we can use raw equality */
cond = luaV_equalobj(NULL, vra, rb);
cond = luaV_equalobj(NULL, s2v(ra), rb);
docondjump();
vmbreak;
}
vmcase(OP_EQI) {
int im = GETARG_sB(i);
if (ttisinteger(vra))
cond = (ivalue(vra) == im);
else if (ttisfloat(vra))
cond = luai_numeq(fltvalue(vra), cast_num(im));
if (ttisinteger(s2v(ra)))
cond = (ivalue(s2v(ra)) == im);
else if (ttisfloat(s2v(ra)))
cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im));
else
cond = 0; /* other types cannot be equal to a number */
docondjump();
@ -1503,50 +1499,50 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
}
vmcase(OP_LTI) {
int im = GETARG_sB(i);
if (ttisinteger(vra))
cond = (ivalue(vra) < im);
else if (ttisfloat(vra))
cond = luai_numlt(fltvalue(vra), cast_num(im));
if (ttisinteger(s2v(ra)))
cond = (ivalue(s2v(ra)) < im);
else if (ttisfloat(s2v(ra)))
cond = luai_numlt(fltvalue(s2v(ra)), cast_num(im));
else
Protect(cond = luaT_callorderiTM(L, vra, im, 0, TM_LT));
Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 0, TM_LT));
docondjump();
vmbreak;
}
vmcase(OP_LEI) {
int im = GETARG_sB(i);
if (ttisinteger(vra))
cond = (ivalue(vra) <= im);
else if (ttisfloat(vra))
cond = luai_numle(fltvalue(vra), cast_num(im));
if (ttisinteger(s2v(ra)))
cond = (ivalue(s2v(ra)) <= im);
else if (ttisfloat(s2v(ra)))
cond = luai_numle(fltvalue(s2v(ra)), cast_num(im));
else
Protect(cond = luaT_callorderiTM(L, vra, im, 0, TM_LE));
Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 0, TM_LE));
docondjump();
vmbreak;
}
vmcase(OP_GTI) {
int im = GETARG_sB(i);
if (ttisinteger(vra))
cond = (im < ivalue(vra));
else if (ttisfloat(vra))
cond = luai_numlt(cast_num(im), fltvalue(vra));
if (ttisinteger(s2v(ra)))
cond = (im < ivalue(s2v(ra)));
else if (ttisfloat(s2v(ra)))
cond = luai_numlt(cast_num(im), fltvalue(s2v(ra)));
else
Protect(cond = luaT_callorderiTM(L, vra, im, 1, TM_LT));
Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 1, TM_LT));
docondjump();
vmbreak;
}
vmcase(OP_GEI) {
int im = GETARG_sB(i);
if (ttisinteger(vra))
cond = (im <= ivalue(vra));
else if (ttisfloat(vra))
cond = luai_numle(cast_num(im), fltvalue(vra));
if (ttisinteger(s2v(ra)))
cond = (im <= ivalue(s2v(ra)));
else if (ttisfloat(s2v(ra)))
cond = luai_numle(cast_num(im), fltvalue(s2v(ra)));
else
Protect(cond = luaT_callorderiTM(L, vra, im, 1, TM_LE));
Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 1, TM_LE));
docondjump();
vmbreak;
}
vmcase(OP_TEST) {
cond = !l_isfalse(vra);
cond = !l_isfalse(s2v(ra));
docondjump();
vmbreak;
}
@ -1583,11 +1579,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
delta = ci->u.l.nextraargs + nparams1;
luaF_close(L, base); /* close upvalues from current call */
}
if (!ttisfunction(vra)) { /* not a function? */
if (!ttisfunction(s2v(ra))) { /* not a function? */
luaD_tryfuncTM(L, ra); /* try '__call' metamethod */
b++; /* there is now one extra argument */
}
if (!ttisLclosure(vra)) { /* C function? */
if (!ttisLclosure(s2v(ra))) { /* C function? */
luaD_call(L, ra, LUA_MULTRET); /* call it */
updatetrap(ci);
if (trap) { /* stack may have been relocated */
@ -1647,18 +1643,18 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
return;
}
vmcase(OP_FORLOOP1) {
lua_Integer idx = intop(+, ivalue(vra), 1); /* increment index */
lua_Integer idx = intop(+, ivalue(s2v(ra)), 1); /* increment index */
lua_Integer limit = ivalue(s2v(ra + 1));
if (idx <= limit) {
pc -= GETARG_Bx(i); /* jump back */
chgivalue(vra, idx); /* update internal index... */
chgivalue(s2v(ra), idx); /* update internal index... */
setivalue(s2v(ra + 3), idx); /* ...and external index */
}
updatetrap(ci);
vmbreak;
}
vmcase(OP_FORPREP1) {
TValue *init = vra;
TValue *init = s2v(ra);
TValue *plimit = s2v(ra + 1);
lua_Integer ilimit, initv;
int stopnow;
@ -1673,25 +1669,25 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmbreak;
}
vmcase(OP_FORLOOP) {
if (ttisinteger(vra)) { /* integer loop? */
if (ttisinteger(s2v(ra))) { /* integer loop? */
lua_Integer step = ivalue(s2v(ra + 2));
lua_Integer idx = intop(+, ivalue(vra), step); /* increment index */
lua_Integer idx = intop(+, ivalue(s2v(ra)), step); /* new index */
lua_Integer limit = ivalue(s2v(ra + 1));
if ((0 < step) ? (idx <= limit) : (limit <= idx)) {
pc -= GETARG_Bx(i); /* jump back */
chgivalue(vra, idx); /* update internal index... */
chgivalue(s2v(ra), idx); /* update internal index... */
setivalue(s2v(ra + 3), idx); /* ...and external index */
}
}
else { /* floating loop */
lua_Number step = fltvalue(s2v(ra + 2));
lua_Number limit = fltvalue(s2v(ra + 1));
lua_Number idx = fltvalue(vra);
lua_Number idx = fltvalue(s2v(ra));
idx = luai_numadd(L, idx, step); /* inc. index */
if (luai_numlt(0, step) ? luai_numle(idx, limit)
: luai_numle(limit, idx)) {
pc -= GETARG_Bx(i); /* jump back */
chgfltvalue(vra, idx); /* update internal index... */
chgfltvalue(s2v(ra), idx); /* update internal index... */
setfltvalue(s2v(ra + 3), idx); /* ...and external index */
}
}
@ -1699,7 +1695,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmbreak;
}
vmcase(OP_FORPREP) {
TValue *init = vra;
TValue *init = s2v(ra);
TValue *plimit = s2v(ra + 1);
TValue *pstep = s2v(ra + 2);
lua_Integer ilimit;
@ -1761,7 +1757,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
if (c == 0) {
c = GETARG_Ax(*pc); pc++;
}
h = hvalue(vra);
h = hvalue(s2v(ra));
last = ((c-1)*LFIELDS_PER_FLUSH) + n;
if (last > h->sizearray) /* needs more space? */
luaH_resizearray(L, h, last); /* preallocate it at once */