commit facfec0687ff20351d3c7520344a722b9149c9ea
parent 34df9976a9fe9a94a4ee96d7ff0ebceac025172d
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 3 Jan 2002 15:42:35 -0200
small optimizations
Diffstat:
3 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/ldo.c b/ldo.c
@@ -49,7 +49,6 @@ void luaD_init (lua_State *L, int stacksize) {
L->ci = L->base_ci;
L->ci->base = L->top;
L->ci->savedpc = NULL;
- L->ci->pc = NULL;
L->size_ci = 20;
L->end_ci = L->base_ci + L->size_ci;
}
@@ -107,6 +106,7 @@ void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event) {
lua_Debug ar;
ar.event = event;
ar._ci = L->ci - L->base_ci;
+ L->ci->pc = NULL; /* function is not active */
dohook(L, &ar, callhook);
}
}
@@ -135,11 +135,9 @@ StkId luaD_precall (lua_State *L, StkId func) {
luaD_openstack(L, func);
setobj(func, tm); /* tag method is the new function to be called */
}
- lua_assert(ttype(func) == LUA_TFUNCTION);
ci = newci(L);
ci->base = func+1;
ci->savedpc = NULL;
- ci->pc = NULL;
if (L->callhook)
luaD_callHook(L, L->callhook, "call");
if (!clvalue(func)->c.isC) return NULL;
diff --git a/lstate.h b/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $
+** $Id: lstate.h,v 1.68 2001/12/18 20:52:30 roberto Exp $
** Global State
** See Copyright Notice in lua.h
*/
@@ -76,6 +76,7 @@ typedef struct CallInfo {
StkId base; /* base for called function */
const Instruction *savedpc;
lua_Hook linehook;
+ StkId top; /* top for this function (when it's a Lua function) */
/* extra information for debugging */
const Instruction **pc;
int lastpc; /* last pc traced */
diff --git a/lvm.c b/lvm.c
@@ -105,7 +105,6 @@ static void callTM (lua_State *L, const TObject *f,
}
-
/*
** Function to index a table.
** Receives the table at `t' and the key at `key'.
@@ -141,7 +140,6 @@ void luaV_gettable (lua_State *L, StkId t, TObject *key, StkId res) {
}
-
/*
** Receives table at `t', key at `key' and value at `val'.
*/
@@ -285,7 +283,7 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
TObject tempb, tempc;
if ((b = luaV_tonumber(b, &tempb)) != NULL &&
(c = luaV_tonumber(c, &tempc)) != NULL) {
- TObject o, f;
+ TObject f, o;
setsvalue(&o, luaS_newliteral(L, "pow"));
luaV_gettable(L, gt(L), &o, &f);
if (ttype(&f) != LUA_TFUNCTION)
@@ -323,10 +321,10 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
}
-#define luaV_poscall(L,c,f) \
+#define luaV_poscall(L,c,f,ci) \
if (c != NO_REG) { \
luaD_poscall(L, c, f); \
- L->top = base + cl->p->maxstacksize; \
+ L->top = ci->top; \
} \
else { \
luaD_poscall(L, LUA_MULTRET, f); \
@@ -344,14 +342,15 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
lua_Hook linehook;
reinit:
lua_assert(L->ci->savedpc == NULL);
+ L->ci->pc = &pc;
+ L->ci->top = base + cl->p->maxstacksize;
if (cl->p->is_vararg) /* varargs? */
adjust_varargs(L, base, cl->p->numparams);
if (base > L->stack_last - cl->p->maxstacksize)
luaD_stackerror(L);
- while (L->top < base + cl->p->maxstacksize)
+ while (L->top < L->ci->top)
setnilvalue(L->top++);
- L->top = base + cl->p->maxstacksize;
- L->ci->pc = &pc;
+ L->top = L->ci->top;
linehook = L->ci->linehook = L->linehook;
pc = cl->p->code;
/* main loop of interpreter */
@@ -360,6 +359,8 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
const StkId ra = RA(i);
if (linehook)
traceexec(L, linehook);
+ lua_assert(L->top == L->ci->top || GET_OPCODE(i) == OP_CALL ||
+ GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO);
switch (GET_OPCODE(i)) {
case OP_MOVE: {
setobj(ra, RB(i));
@@ -539,7 +540,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
firstResult = luaD_precall(L, ra);
if (firstResult) {
/* it was a C function (`precall' called it); adjust results */
- luaV_poscall(L, GETARG_C(i), firstResult);
+ luaV_poscall(L, GETARG_C(i), firstResult, L->ci);
}
else { /* it is a Lua function: `call' it */
CallInfo *ci = L->ci;
@@ -553,7 +554,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
case OP_RETURN: {
CallInfo *ci;
int b;
- luaF_close(L, base);
+ if (L->openupval) luaF_close(L, base);
b = GETARG_B(i);
if (b != NO_REG) L->top = ra+b;
ci = L->ci - 1;
@@ -567,7 +568,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
pc = ci->savedpc;
ci->savedpc = NULL;
lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL);
- luaV_poscall(L, GETARG_C(*(pc-1)), ra);
+ luaV_poscall(L, GETARG_C(*(pc-1)), ra, ci);
}
break;
}
@@ -630,8 +631,10 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
bc = GETARG_Bc(i);
if (GET_OPCODE(i) == OP_SETLIST)
n = (bc&(LFIELDS_PER_FLUSH-1)) + 1;
- else
+ else {
n = L->top - ra - 1;
+ L->top = L->ci->top;
+ }
bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
for (; n > 0; n--)
luaH_setnum(L, h, bc+n, ra+n);