Undo change in the handling of 'L->top' (commit b80077b8f3)
With MMBIN instructions, there are fewer opcodes that need to update
'L->top', so that change does not seem to pay for the increased
complexity.
diff --git a/lapi.c b/lapi.c
index a9ffad8..0ea3dc0 100644
--- a/lapi.c
+++ b/lapi.c
@@ -329,14 +329,12 @@
o1 = index2value(L, index1);
o2 = index2value(L, index2);
if (isvalid(L, o1) && isvalid(L, o2)) {
- ptrdiff_t top = savestack(L, L->top);
switch (op) {
case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;
case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
default: api_check(L, 0, "invalid option");
}
- L->top = restorestack(L, top);
}
lua_unlock(L);
return i;
diff --git a/lobject.c b/lobject.c
index b376ab1..b4efae4 100644
--- a/lobject.c
+++ b/lobject.c
@@ -127,9 +127,7 @@
StkId res) {
if (!luaO_rawarith(L, op, p1, p2, s2v(res))) {
/* could not perform raw operation; try metamethod */
- ptrdiff_t top = savestack(L, L->top);
luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));
- L->top = restorestack(L, top);
}
}
diff --git a/ltm.c b/ltm.c
index 991e62c..1e32d86 100644
--- a/ltm.c
+++ b/ltm.c
@@ -147,7 +147,6 @@
void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
StkId res, TMS event) {
- L->top = L->ci->top;
if (!callbinTM(L, p1, p2, res, event)) {
switch (event) {
case TM_BAND: case TM_BOR: case TM_BXOR:
@@ -191,7 +190,6 @@
int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
TMS event) {
- L->top = L->ci->top;
if (callbinTM(L, p1, p2, L->top, event)) /* try original event */
return !l_isfalse(s2v(L->top));
#if defined(LUA_COMPAT_LT_LE)
diff --git a/lvm.c b/lvm.c
index 71f6ae0..46150ef 100644
--- a/lvm.c
+++ b/lvm.c
@@ -516,7 +516,6 @@
if (tm == NULL) /* no TM? */
return 0; /* objects are different */
else {
- L->top = L->ci->top;
luaT_callTMres(L, tm, t1, t2, L->top); /* call TM */
return !l_isfalse(s2v(L->top));
}
@@ -925,7 +924,7 @@
else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \
cond = opf(s2v(ra), rb); \
else \
- ProtectNT(cond = other(L, s2v(ra), rb)); \
+ Protect(cond = other(L, s2v(ra), rb)); \
docondjump(); }
@@ -944,7 +943,7 @@
} \
else { \
int isf = GETARG_C(i); \
- ProtectNT(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \
+ Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \
} \
docondjump(); }
@@ -989,7 +988,7 @@
/* for test instructions, execute the jump instruction that follows it */
-#define donextjump(ci) { i = *pc; dojump(ci, i, 1); }
+#define donextjump(ci) { Instruction ni = *pc; dojump(ci, ni, 1); }
/*
** do a conditional jump: skip next instruction if 'cond' is not what
@@ -1408,7 +1407,7 @@
TMS tm = (TMS)GETARG_C(i);
StkId result = RA(pi);
lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR);
- ProtectNT(luaT_trybinTM(L, s2v(ra), rb, result, tm));
+ Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm));
vmbreak;
}
vmcase(OP_MMBINI) {
@@ -1417,7 +1416,7 @@
TMS tm = (TMS)GETARG_C(i);
int flip = GETARG_k(i);
StkId result = RA(pi);
- ProtectNT(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));
+ Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));
vmbreak;
}
vmcase(OP_MMBINK) {
@@ -1426,7 +1425,7 @@
TMS tm = (TMS)GETARG_C(i);
int flip = GETARG_k(i);
StkId result = RA(pi);
- ProtectNT(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));
+ Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));
vmbreak;
}
vmcase(OP_UNM) {
@@ -1440,7 +1439,7 @@
setfltvalue(s2v(ra), luai_numunm(L, nb));
}
else
- ProtectNT(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
+ Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
vmbreak;
}
vmcase(OP_BNOT) {
@@ -1450,7 +1449,7 @@
setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
}
else
- ProtectNT(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
+ Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
vmbreak;
}
vmcase(OP_NOT) {
@@ -1486,7 +1485,7 @@
vmcase(OP_EQ) {
int cond;
TValue *rb = vRB(i);
- ProtectNT(cond = luaV_equalobj(L, s2v(ra), rb));
+ Protect(cond = luaV_equalobj(L, s2v(ra), rb));
docondjump();
vmbreak;
}