|
@@ -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<GETARG_U(i); n++)
|
|
|
- stack[top++] = pc-1;
|
|
|
+ top = pushpc(stack, pc, top, GETARG_U(i));
|
|
|
break;
|
|
|
}
|
|
|
case OP_POP: {
|
|
@@ -321,33 +325,27 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
|
|
|
stack[top++] = pc-1;
|
|
|
break;
|
|
|
}
|
|
|
- case OP_JMPONT:
|
|
|
- case OP_JMPONF: {
|
|
|
- int newpc = pc + GETARG_S(i);
|
|
|
- if (lastpc < newpc)
|
|
|
- top--; /* original code did not jump; condition was false */
|
|
|
- else {
|
|
|
- stack[top-1] = pc-1; /* value generated by or-and */
|
|
|
- pc = newpc; /* do the jump */
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case OP_PUSHNILJMP: {
|
|
|
- break; /* do not `push', to compensate next instruction */
|
|
|
- }
|
|
|
case OP_CLOSURE: {
|
|
|
top -= GETARG_B(i);
|
|
|
stack[top++] = pc-1;
|
|
|
break;
|
|
|
}
|
|
|
default: {
|
|
|
- int n;
|
|
|
- LUA_ASSERT(luaK_opproperties[GET_OPCODE(i)].push != VD,
|
|
|
+ OpCode op = GET_OPCODE(i);
|
|
|
+ LUA_ASSERT(luaK_opproperties[op].push != VD,
|
|
|
"invalid opcode for default");
|
|
|
- top -= luaK_opproperties[GET_OPCODE(i)].pop;
|
|
|
+ top -= luaK_opproperties[op].pop;
|
|
|
LUA_ASSERT(top >= 0, "wrong stack");
|
|
|
- for (n=0; n<luaK_opproperties[GET_OPCODE(i)].push; n++)
|
|
|
- stack[top++] = pc-1;
|
|
|
+ top = pushpc(stack, pc, top, luaK_opproperties[op].push);
|
|
|
+ if (ISJUMP(op)) {
|
|
|
+ int newpc = pc + GETARG_S(i);
|
|
|
+ /* jump is forward and do not skip `lastpc'? */
|
|
|
+ if (pc < newpc && newpc <= lastpc) {
|
|
|
+ if (op == OP_JMPONT || op == OP_JMPONF)
|
|
|
+ stack[top++] = pc-1; /* do not pop when jumping */
|
|
|
+ pc = newpc; /* do the jump */
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -355,7 +353,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-static const char *getname (lua_State *L, StkId obj, const char **name) {
|
|
|
+static const char *getobjname (lua_State *L, StkId obj, const char **name) {
|
|
|
StkId func = aux_stackedfunction(L, 0, obj);
|
|
|
if (func == NULL || ttype(func) != TAG_LMARK)
|
|
|
return NULL; /* not a Lua function */
|
|
@@ -389,23 +387,21 @@ static const char *getname (lua_State *L, StkId obj, const char **name) {
|
|
|
/* }====================================================== */
|
|
|
|
|
|
|
|
|
-static void call_index_error (lua_State *L, StkId o, const char *op,
|
|
|
- const char *tp) {
|
|
|
+void luaG_typeerror (lua_State *L, StkId o, const char *op) {
|
|
|
const char *name;
|
|
|
- const char *kind = getname(L, o, &name);
|
|
|
+ const char *kind = getobjname(L, o, &name);
|
|
|
+ const char *t = lua_type(L, o);
|
|
|
if (kind)
|
|
|
- luaL_verror(L, "%s `%s' is not a %s", kind, name, tp);
|
|
|
+ luaL_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)",
|
|
|
+ op, kind, name, t);
|
|
|
else
|
|
|
- luaL_verror(L, "attempt to %.10s a %.10s value", op, lua_type(L, o));
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void luaG_callerror (lua_State *L, StkId func) {
|
|
|
- call_index_error(L, func, "call", "function");
|
|
|
+ luaL_verror(L, "attempt to %.30s a %.10s value", op, t);
|
|
|
}
|
|
|
|
|
|
|
|
|
-void luaG_indexerror (lua_State *L, StkId t) {
|
|
|
- call_index_error(L, t, "index", "table");
|
|
|
+void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op) {
|
|
|
+ if (ttype(p1) == t) p1++;
|
|
|
+ LUA_ASSERT(ttype(p1) != t, "must be an error");
|
|
|
+ luaG_typeerror(L, p1, op);
|
|
|
}
|
|
|
|