From daf09c476fe375d8a9a47bc1294a1cd430290226 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 10 Aug 2000 16:50:47 -0300 Subject: still better error messages --- ldebug.c | 84 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 44 deletions(-) (limited to 'ldebug.c') diff --git a/ldebug.c b/ldebug.c index 57d01b49..e81661e2 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.30 2000/08/08 20:42:07 roberto Exp roberto $ +** $Id: ldebug.c,v 1.31 2000/08/09 19:16:57 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -57,7 +57,7 @@ lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { static StkId aux_stackedfunction (lua_State *L, int level, StkId top) { int i; - for (i = (top-1)-L->stack; i>=0; i--) { + for (i = (top-1) - L->stack; i>=0; i--) { if (is_T_MARK(L->stack[i].ttype)) { if (level == 0) return L->stack+i; @@ -214,7 +214,7 @@ static const char *travglobals (lua_State *L, const TObject *o) { } -static void lua_getobjname (lua_State *L, StkId f, lua_Debug *ar) { +static void lua_getname (lua_State *L, StkId f, lua_Debug *ar) { TObject o; setnormalized(&o, f); /* try to find a name for given function */ @@ -247,7 +247,7 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { ar->nups = lua_nups(func); break; case 'n': - lua_getobjname(L, func, ar); + lua_getname(L, func, ar); break; case 'f': setnormalized(L->top, func); @@ -267,8 +267,16 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { ** ======================================================= */ + +static int pushpc (int *stack, int pc, int top, int n) { + while (n--) + stack[top++] = pc-1; + return top; +} + + static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { - int stack[MAXSTACK]; /* stores last instruction that changes each value */ + int stack[MAXSTACK]; /* stores last instruction that changed a stack entry */ const Instruction *code = pt->code; int top = pt->numparams; int pc = 0; @@ -276,7 +284,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { top++; /* `arg' */ while (pc < lastpc) { const Instruction i = code[pc++]; - LUA_ASSERT(top <= pt->maxstacksize, "wrong stack"); + LUA_ASSERT(0 <= top && top <= pt->maxstacksize, "wrong stack"); switch (GET_OPCODE(i)) { case OP_RETURN: { LUA_ASSERT(top >= GETARG_U(i), "wrong stack"); @@ -287,9 +295,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { int nresults = GETARG_B(i); if (nresults == MULT_RET) nresults = 1; LUA_ASSERT(top >= GETARG_A(i), "wrong stack"); - top = GETARG_A(i); - while (nresults--) - stack[top++] = pc-1; + top = pushpc(stack, pc, GETARG_A(i), nresults); break; } case OP_TAILCALL: { @@ -298,9 +304,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { break; } case OP_PUSHNIL: { - int n; - for (n=0; n= 0, "wrong stack"); - for (n=0; n