removed dirt optimizations that gave small gains

This commit is contained in:
Roberto Ierusalimschy 2005-04-04 15:12:51 -03:00
parent 409ee99900
commit 0316308c0d
4 changed files with 54 additions and 89 deletions

10
lapi.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 2.35 2005/03/21 18:12:21 roberto Exp roberto $ ** $Id: lapi.c,v 2.36 2005/03/22 16:04:29 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -526,7 +526,7 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
lua_lock(L); lua_lock(L);
t = index2adr(L, idx); t = index2adr(L, idx);
api_checkvalidindex(L, t); api_checkvalidindex(L, t);
luaV_gettable(L, t, L->top - 1, L->top - 1, NULL); luaV_gettable(L, t, L->top - 1, L->top - 1);
lua_unlock(L); lua_unlock(L);
} }
@ -538,7 +538,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
t = index2adr(L, idx); t = index2adr(L, idx);
api_checkvalidindex(L, t); api_checkvalidindex(L, t);
setsvalue(L, &key, luaS_new(L, k)); setsvalue(L, &key, luaS_new(L, k));
luaV_gettable(L, t, &key, L->top, NULL); luaV_gettable(L, t, &key, L->top);
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
} }
@ -632,7 +632,7 @@ LUA_API void lua_settable (lua_State *L, int idx) {
api_checknelems(L, 2); api_checknelems(L, 2);
t = index2adr(L, idx); t = index2adr(L, idx);
api_checkvalidindex(L, t); api_checkvalidindex(L, t);
luaV_settable(L, t, L->top - 2, L->top - 1, NULL); luaV_settable(L, t, L->top - 2, L->top - 1);
L->top -= 2; /* pop index and value */ L->top -= 2; /* pop index and value */
lua_unlock(L); lua_unlock(L);
} }
@ -646,7 +646,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
t = index2adr(L, idx); t = index2adr(L, idx);
api_checkvalidindex(L, t); api_checkvalidindex(L, t);
setsvalue(L, &key, luaS_new(L, k)); setsvalue(L, &key, luaS_new(L, k));
luaV_settable(L, t, &key, L->top - 1, NULL); luaV_settable(L, t, &key, L->top - 1);
L->top--; /* pop value */ L->top--; /* pop value */
lua_unlock(L); lua_unlock(L);
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.c,v 2.11 2004/12/03 20:35:33 roberto Exp roberto $ ** $Id: ldebug.c,v 2.12 2004/12/20 15:50:00 roberto Exp roberto $
** Debug Interface ** Debug Interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -30,17 +30,18 @@
static const char *getfuncname (CallInfo *ci, const char **name); static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
static int currentpc (CallInfo *ci) { static int currentpc (lua_State *L, CallInfo *ci) {
UNUSED(L);
if (!isLua(ci)) return -1; /* function is not a Lua function? */ if (!isLua(ci)) return -1; /* function is not a Lua function? */
return pcRel(ci->savedpc, ci_func(ci)->l.p); return pcRel(ci->savedpc, ci_func(ci)->l.p);
} }
static int currentline (CallInfo *ci) { static int currentline (lua_State *L, CallInfo *ci) {
int pc = currentpc(ci); int pc = currentpc(L, ci);
if (pc < 0) if (pc < 0)
return -1; /* only active lua functions have current-line information */ return -1; /* only active lua functions have current-line information */
else else
@ -116,7 +117,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
ci = L->base_ci + ar->i_ci; ci = L->base_ci + ar->i_ci;
fp = getluaproto(ci); fp = getluaproto(ci);
if (fp) { /* is a Lua function? */ if (fp) { /* is a Lua function? */
name = luaF_getlocalname(fp, n, currentpc(ci)); name = luaF_getlocalname(fp, n, currentpc(L, ci));
if (name) if (name)
luaA_pushobject(L, ci->base+(n-1)); /* push value */ luaA_pushobject(L, ci->base+(n-1)); /* push value */
} }
@ -135,7 +136,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
fp = getluaproto(ci); fp = getluaproto(ci);
L->top--; /* pop new value */ L->top--; /* pop new value */
if (fp) { /* is a Lua function? */ if (fp) { /* is a Lua function? */
name = luaF_getlocalname(fp, n, currentpc(ci)); name = luaF_getlocalname(fp, n, currentpc(L, ci));
if (!name || name[0] == '(') /* `(' starts private locals */ if (!name || name[0] == '(') /* `(' starts private locals */
name = NULL; name = NULL;
else else
@ -183,7 +184,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
break; break;
} }
case 'l': { case 'l': {
ar->currentline = (ci) ? currentline(ci) : -1; ar->currentline = (ci) ? currentline(L, ci) : -1;
break; break;
} }
case 'u': { case 'u': {
@ -191,7 +192,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
break; break;
} }
case 'n': { case 'n': {
ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL; ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
if (ar->namewhat == NULL) { if (ar->namewhat == NULL) {
ar->namewhat = ""; /* not found */ ar->namewhat = ""; /* not found */
ar->name = NULL; ar->name = NULL;
@ -446,10 +447,11 @@ static const char *kname (Proto *p, int c) {
} }
static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,
const char **name) {
if (isLua(ci)) { /* a Lua function? */ if (isLua(ci)) { /* a Lua function? */
Proto *p = ci_func(ci)->l.p; Proto *p = ci_func(ci)->l.p;
int pc = currentpc(ci); int pc = currentpc(L, ci);
Instruction i; Instruction i;
*name = luaF_getlocalname(p, stackpos+1, pc); *name = luaF_getlocalname(p, stackpos+1, pc);
if (*name) /* is a local? */ if (*name) /* is a local? */
@ -467,7 +469,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) {
int a = GETARG_A(i); int a = GETARG_A(i);
int b = GETARG_B(i); /* move from `b' to `a' */ int b = GETARG_B(i); /* move from `b' to `a' */
if (b < a) if (b < a)
return getobjname(ci, b, name); /* get name for `b' */ return getobjname(L, ci, b, name); /* get name for `b' */
break; break;
} }
case OP_GETTABLE: { case OP_GETTABLE: {
@ -492,15 +494,15 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) {
} }
static const char *getfuncname (CallInfo *ci, const char **name) { static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
Instruction i; Instruction i;
if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
return NULL; /* calling function is not Lua (or is unknown) */ return NULL; /* calling function is not Lua (or is unknown) */
ci--; /* calling function */ ci--; /* calling function */
i = ci_func(ci)->l.p->code[currentpc(ci)]; i = ci_func(ci)->l.p->code[currentpc(L, ci)];
if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
GET_OPCODE(i) == OP_TFORLOOP) GET_OPCODE(i) == OP_TFORLOOP)
return getobjname(ci, GETARG_A(i), name); return getobjname(L, ci, GETARG_A(i), name);
else else
return NULL; /* no useful name can be found */ return NULL; /* no useful name can be found */
} }
@ -519,7 +521,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
const char *name = NULL; const char *name = NULL;
const char *t = luaT_typenames[ttype(o)]; const char *t = luaT_typenames[ttype(o)];
const char *kind = (isinstack(L->ci, o)) ? const char *kind = (isinstack(L->ci, o)) ?
getobjname(L->ci, o - L->base, &name) : NULL; getobjname(L, L->ci, o - L->base, &name) : NULL;
if (kind) if (kind)
luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", luaG_runerror(L, "attempt to %s %s `%s' (a %s value)",
op, kind, name, t); op, kind, name, t);
@ -558,7 +560,7 @@ static void addinfo (lua_State *L, const char *msg) {
CallInfo *ci = L->ci; CallInfo *ci = L->ci;
if (isLua(ci)) { /* is Lua code? */ if (isLua(ci)) { /* is Lua code? */
char buff[LUA_IDSIZE]; /* add file:line information */ char buff[LUA_IDSIZE]; /* add file:line information */
int line = currentline(ci); int line = currentline(L, ci);
luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
} }

89
lvm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 2.34 2005/03/18 18:01:37 roberto Exp roberto $ ** $Id: lvm.c,v 2.35 2005/03/28 17:17:53 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -108,8 +108,7 @@ static void callTM (lua_State *L) {
} }
StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
const Instruction *pc) {
int loop; int loop;
for (loop = 0; loop < MAXTAGLOOP; loop++) { for (loop = 0; loop < MAXTAGLOOP; loop++) {
const TValue *tm; const TValue *tm;
@ -119,30 +118,24 @@ StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val,
if (!ttisnil(res) || /* result is no nil? */ if (!ttisnil(res) || /* result is no nil? */
(tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
setobj2s(L, val, res); setobj2s(L, val, res);
return L->base; return;
} }
/* else will try the tag method */ /* else will try the tag method */
} }
else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) { else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
L->ci->savedpc = pc;
luaG_typeerror(L, t, "index"); luaG_typeerror(L, t, "index");
}
if (ttisfunction(tm)) { if (ttisfunction(tm)) {
L->ci->savedpc = pc;
prepTMcall(L, tm, t, key); prepTMcall(L, tm, t, key);
callTMres(L, val); callTMres(L, val);
return L->base; return;
} }
t = tm; /* else repeat with `tm' */ t = tm; /* else repeat with `tm' */
} }
L->ci->savedpc = pc;
luaG_runerror(L, "loop in gettable"); luaG_runerror(L, "loop in gettable");
return NULL; /* to avoid warnings */
} }
StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
const Instruction *pc) {
int loop; int loop;
for (loop = 0; loop < MAXTAGLOOP; loop++) { for (loop = 0; loop < MAXTAGLOOP; loop++) {
const TValue *tm; const TValue *tm;
@ -153,26 +146,21 @@ StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val,
(tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
setobj2t(L, oldval, val); setobj2t(L, oldval, val);
luaC_barriert(L, h, val); luaC_barriert(L, h, val);
return L->base; return;
} }
/* else will try the tag method */ /* else will try the tag method */
} }
else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) { else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
L->ci->savedpc = pc;
luaG_typeerror(L, t, "index"); luaG_typeerror(L, t, "index");
}
if (ttisfunction(tm)) { if (ttisfunction(tm)) {
L->ci->savedpc = pc;
prepTMcall(L, tm, t, key); prepTMcall(L, tm, t, key);
setobj2s(L, L->top+3, val); /* 3th argument */ setobj2s(L, L->top+3, val); /* 3th argument */
callTM(L); callTM(L);
return L->base; return;
} }
t = tm; /* else repeat with `tm' */ t = tm; /* else repeat with `tm' */
} }
L->ci->savedpc = pc;
luaG_runerror(L, "loop in settable"); luaG_runerror(L, "loop in settable");
return NULL; /* to avoid warnings */
} }
@ -330,10 +318,9 @@ void luaV_concat (lua_State *L, int total, int last) {
static StkId Arith (lua_State *L, StkId ra, const TValue *rb, static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op, const Instruction *pc) { const TValue *rc, TMS op) {
TValue tempb, tempc; TValue tempb, tempc;
const TValue *b, *c; const TValue *b, *c;
L->ci->savedpc = pc;
if ((b = luaV_tonumber(rb, &tempb)) != NULL && if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) { (c = luaV_tonumber(rc, &tempc)) != NULL) {
lua_Number nb = nvalue(b), nc = nvalue(c); lua_Number nb = nvalue(b), nc = nvalue(c);
@ -377,7 +364,6 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
StkId luaV_execute (lua_State *L, int nexeccalls) { StkId luaV_execute (lua_State *L, int nexeccalls) {
LClosure *cl; LClosure *cl;
TValue *k; TValue *k;
StkId base;
const Instruction *pc; const Instruction *pc;
callentry: /* entry point when calling new functions */ callentry: /* entry point when calling new functions */
if (L->hookmask & LUA_MASKCALL) if (L->hookmask & LUA_MASKCALL)
@ -385,10 +371,10 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
retentry: /* entry point when returning to old functions */ retentry: /* entry point when returning to old functions */
pc = L->ci->savedpc; pc = L->ci->savedpc;
cl = &clvalue(L->ci->func)->l; cl = &clvalue(L->ci->func)->l;
base = L->base;
k = cl->p->k; k = cl->p->k;
/* main loop of interpreter */ /* main loop of interpreter */
for (;;) { for (;;) {
StkId base;
const Instruction i = *pc++; const Instruction i = *pc++;
StkId ra; StkId ra;
if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
@ -398,11 +384,12 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
L->ci->savedpc = pc - 1; L->ci->savedpc = pc - 1;
return NULL; return NULL;
} }
base = L->base;
} }
/* warning!! several calls may realloc the stack and invalidate `ra' */ /* warning!! several calls may realloc the stack and invalidate `ra' */
base = L->base;
ra = RA(i); ra = RA(i);
lua_assert(base == L->ci->base && base == L->base); L->ci->savedpc = pc;
lua_assert(base == L->ci->base);
lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
switch (GET_OPCODE(i)) { switch (GET_OPCODE(i)) {
@ -436,18 +423,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
TValue *rb = KBx(i); TValue *rb = KBx(i);
sethvalue(L, &g, cl->env); sethvalue(L, &g, cl->env);
lua_assert(ttisstring(rb)); lua_assert(ttisstring(rb));
base = luaV_gettable(L, &g, rb, ra, pc); /***/ luaV_gettable(L, &g, rb, ra); /***/
continue; continue;
} }
case OP_GETTABLE: { case OP_GETTABLE: {
base = luaV_gettable(L, RB(i), RKC(i), ra, pc); /***/ luaV_gettable(L, RB(i), RKC(i), ra); /***/
continue; continue;
} }
case OP_SETGLOBAL: { case OP_SETGLOBAL: {
TValue g; TValue g;
sethvalue(L, &g, cl->env); sethvalue(L, &g, cl->env);
lua_assert(ttisstring(KBx(i))); lua_assert(ttisstring(KBx(i)));
base = luaV_settable(L, &g, KBx(i), ra, pc); /***/ luaV_settable(L, &g, KBx(i), ra); /***/
continue; continue;
} }
case OP_SETUPVAL: { case OP_SETUPVAL: {
@ -457,22 +444,20 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
continue; continue;
} }
case OP_SETTABLE: { case OP_SETTABLE: {
base = luaV_settable(L, ra, RKB(i), RKC(i), pc); /***/ luaV_settable(L, ra, RKB(i), RKC(i)); /***/
continue; continue;
} }
case OP_NEWTABLE: { case OP_NEWTABLE: {
int b = GETARG_B(i); int b = GETARG_B(i);
int c = GETARG_C(i); int c = GETARG_C(i);
sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
L->ci->savedpc = pc;
luaC_checkGC(L); /***/ luaC_checkGC(L); /***/
base = L->base;
continue; continue;
} }
case OP_SELF: { case OP_SELF: {
StkId rb = RB(i); StkId rb = RB(i);
setobjs2s(L, ra+1, rb); setobjs2s(L, ra+1, rb);
base = luaV_gettable(L, rb, RKC(i), ra, pc); /***/ luaV_gettable(L, rb, RKC(i), ra); /***/
continue; continue;
} }
case OP_ADD: { case OP_ADD: {
@ -483,7 +468,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setnvalue(ra, luai_numadd(nb, nc)); setnvalue(ra, luai_numadd(nb, nc));
} }
else else
base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/ Arith(L, ra, rb, rc, TM_ADD); /***/
continue; continue;
} }
case OP_SUB: { case OP_SUB: {
@ -494,7 +479,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setnvalue(ra, luai_numsub(nb, nc)); setnvalue(ra, luai_numsub(nb, nc));
} }
else else
base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/ Arith(L, ra, rb, rc, TM_SUB); /***/
continue; continue;
} }
case OP_MUL: { case OP_MUL: {
@ -505,7 +490,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setnvalue(ra, luai_nummul(nb, nc)); setnvalue(ra, luai_nummul(nb, nc));
} }
else else
base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/ Arith(L, ra, rb, rc, TM_MUL); /***/
continue; continue;
} }
case OP_DIV: { case OP_DIV: {
@ -516,7 +501,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setnvalue(ra, luai_numdiv(nb, nc)); setnvalue(ra, luai_numdiv(nb, nc));
} }
else else
base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/ Arith(L, ra, rb, rc, TM_DIV); /***/
continue; continue;
} }
case OP_MOD: { case OP_MOD: {
@ -527,7 +512,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setnvalue(ra, luai_nummod(nb, nc)); setnvalue(ra, luai_nummod(nb, nc));
} }
else else
base = Arith(L, ra, rb, rc, TM_MOD, pc); /***/ Arith(L, ra, rb, rc, TM_MOD); /***/
continue; continue;
} }
case OP_POW: { case OP_POW: {
@ -538,7 +523,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setnvalue(ra, luai_numpow(nb, nc)); setnvalue(ra, luai_numpow(nb, nc));
} }
else else
base = Arith(L, ra, rb, rc, TM_POW, pc); /***/ Arith(L, ra, rb, rc, TM_POW); /***/
continue; continue;
} }
case OP_UNM: { case OP_UNM: {
@ -550,10 +535,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
} }
else { else {
setnilvalue(&temp); setnilvalue(&temp);
L->ci->savedpc = pc;
if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/ if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/
luaG_aritherror(L, RB(i), &temp); luaG_aritherror(L, RB(i), &temp);
base = L->base;
} }
continue; continue;
} }
@ -572,7 +555,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); setnvalue(ra, cast(lua_Number, tsvalue(rb)->len));
break; break;
default: /* no metamethod?? */ default: /* no metamethod?? */
L->ci->savedpc = pc;
luaG_typeerror(L, rb, "get the size of"); luaG_typeerror(L, rb, "get the size of");
} }
continue; continue;
@ -580,7 +562,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
case OP_CONCAT: { case OP_CONCAT: {
int b = GETARG_B(i); int b = GETARG_B(i);
int c = GETARG_C(i); int c = GETARG_C(i);
L->ci->savedpc = pc;
luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/ luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/
luaC_checkGC(L); /***/ luaC_checkGC(L); /***/
base = L->base; base = L->base;
@ -592,24 +573,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
continue; continue;
} }
case OP_EQ: { case OP_EQ: {
L->ci->savedpc = pc;
if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
else dojump(L, pc, GETARG_sBx(*pc) + 1); else dojump(L, pc, GETARG_sBx(*pc) + 1);
base = L->base;
continue; continue;
} }
case OP_LT: { case OP_LT: {
L->ci->savedpc = pc;
if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
else dojump(L, pc, GETARG_sBx(*pc) + 1); else dojump(L, pc, GETARG_sBx(*pc) + 1);
base = L->base;
continue; continue;
} }
case OP_LE: { case OP_LE: {
L->ci->savedpc = pc;
if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
else dojump(L, pc, GETARG_sBx(*pc) + 1); else dojump(L, pc, GETARG_sBx(*pc) + 1);
base = L->base;
continue; continue;
} }
case OP_TEST: { case OP_TEST: {
@ -626,7 +601,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
int b = GETARG_B(i); int b = GETARG_B(i);
int nresults = GETARG_C(i) - 1; int nresults = GETARG_C(i) - 1;
if (b != 0) L->top = ra+b; /* else previous instruction set top */ if (b != 0) L->top = ra+b; /* else previous instruction set top */
L->ci->savedpc = pc;
pcr = luaD_precall(L, ra, nresults); pcr = luaD_precall(L, ra, nresults);
if (pcr == PCRLUA) { if (pcr == PCRLUA) {
nexeccalls++; nexeccalls++;
@ -635,7 +609,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
else if (pcr == PCRC) { else if (pcr == PCRC) {
/* it was a C function (`precall' called it); adjust results */ /* it was a C function (`precall' called it); adjust results */
if (nresults >= 0) L->top = L->ci->top; if (nresults >= 0) L->top = L->ci->top;
base = L->base;
continue; continue;
} }
else { else {
@ -647,7 +620,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
int pcr; int pcr;
int b = GETARG_B(i); int b = GETARG_B(i);
if (b != 0) L->top = ra+b; /* else previous instruction set top */ if (b != 0) L->top = ra+b; /* else previous instruction set top */
L->ci->savedpc = pc;
lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
pcr = luaD_precall(L, ra, LUA_MULTRET); pcr = luaD_precall(L, ra, LUA_MULTRET);
if (pcr == PCRLUA) { if (pcr == PCRLUA) {
@ -657,20 +629,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
StkId func = ci->func; StkId func = ci->func;
StkId pfunc = (ci+1)->func; /* previous function index */ StkId pfunc = (ci+1)->func; /* previous function index */
if (L->openupval) luaF_close(L, ci->base); if (L->openupval) luaF_close(L, ci->base);
base = ci->base = ci->func + ((ci+1)->base - pfunc); L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
L->base = base;
for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
setobjs2s(L, func+aux, pfunc+aux); setobjs2s(L, func+aux, pfunc+aux);
ci->top = L->top = func+aux; /* correct top */ ci->top = L->top = func+aux; /* correct top */
lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
ci->savedpc = L->ci->savedpc; ci->savedpc = (ci+1)->savedpc;
ci->tailcalls++; /* one more call lost */ ci->tailcalls++; /* one more call lost */
L->ci--; /* remove new frame */ L->ci--; /* remove new frame */
goto callentry; goto callentry;
} }
else if (pcr == PCRC) { else if (pcr == PCRC) {
/* it was a C function (`precall' called it) */ /* it was a C function (`precall' called it) */
base = L->base;
continue; continue;
} }
else { else {
@ -683,7 +653,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
int b = GETARG_B(i); int b = GETARG_B(i);
if (b != 0) L->top = ra+b-1; if (b != 0) L->top = ra+b-1;
if (L->openupval) luaF_close(L, base); if (L->openupval) luaF_close(L, base);
L->ci->savedpc = pc;
if (--nexeccalls == 0) /* was previous function running `here'? */ if (--nexeccalls == 0) /* was previous function running `here'? */
return ra; /* no: return */ return ra; /* no: return */
else { /* yes: continue its execution */ else { /* yes: continue its execution */
@ -710,7 +679,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
const TValue *init = ra; const TValue *init = ra;
const TValue *plimit = ra+1; const TValue *plimit = ra+1;
const TValue *pstep = ra+2; const TValue *pstep = ra+2;
L->ci->savedpc = pc;
if (!tonumber(init, ra)) if (!tonumber(init, ra))
luaG_runerror(L, "`for' initial value must be a number"); luaG_runerror(L, "`for' initial value must be a number");
else if (!tonumber(plimit, ra+1)) else if (!tonumber(plimit, ra+1))
@ -727,7 +695,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
setobjs2s(L, cb+1, ra+1); setobjs2s(L, cb+1, ra+1);
setobjs2s(L, cb, ra); setobjs2s(L, cb, ra);
L->top = cb+3; /* func. + 2 args (state and index) */ L->top = cb+3; /* func. + 2 args (state and index) */
L->ci->savedpc = pc;
luaD_call(L, cb, GETARG_C(i)); /***/ luaD_call(L, cb, GETARG_C(i)); /***/
L->top = L->ci->top; L->top = L->ci->top;
base = L->base; base = L->base;
@ -791,9 +758,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
} }
} }
setclvalue(L, ra, ncl); setclvalue(L, ra, ncl);
L->ci->savedpc = pc;
luaC_checkGC(L); /***/ luaC_checkGC(L); /***/
base = L->base;
continue; continue;
} }
case OP_VARARG: { case OP_VARARG: {

8
lvm.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.h,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ ** $Id: lvm.h,v 2.2 2004/05/14 19:25:09 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -26,10 +26,8 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
const TValue *luaV_tonumber (const TValue *obj, TValue *n); const TValue *luaV_tonumber (const TValue *obj, TValue *n);
int luaV_tostring (lua_State *L, StkId obj); int luaV_tostring (lua_State *L, StkId obj);
StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val);
const Instruction *pc); void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val);
StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val,
const Instruction *pc);
StkId luaV_execute (lua_State *L, int nexeccalls); StkId luaV_execute (lua_State *L, int nexeccalls);
void luaV_concat (lua_State *L, int total, int last); void luaV_concat (lua_State *L, int total, int last);