aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-10 16:50:47 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-10 16:50:47 -0300
commitdaf09c476fe375d8a9a47bc1294a1cd430290226 (patch)
tree1d4ecc2d4001f2195168eaeafb257c9af8b94793 /ldebug.c
parente238efc5367a8d88757dd84df0683e1d8d9f9211 (diff)
downloadlua-daf09c476fe375d8a9a47bc1294a1cd430290226.tar.gz
lua-daf09c476fe375d8a9a47bc1294a1cd430290226.tar.bz2
lua-daf09c476fe375d8a9a47bc1294a1cd430290226.zip
still better error messages
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c84
1 files changed, 40 insertions, 44 deletions
diff --git a/ldebug.c b/ldebug.c
index 57d01b49..e81661e2 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.30 2000/08/08 20:42:07 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.31 2000/08/09 19:16:57 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -57,7 +57,7 @@ lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) {
57 57
58static StkId aux_stackedfunction (lua_State *L, int level, StkId top) { 58static StkId aux_stackedfunction (lua_State *L, int level, StkId top) {
59 int i; 59 int i;
60 for (i = (top-1)-L->stack; i>=0; i--) { 60 for (i = (top-1) - L->stack; i>=0; i--) {
61 if (is_T_MARK(L->stack[i].ttype)) { 61 if (is_T_MARK(L->stack[i].ttype)) {
62 if (level == 0) 62 if (level == 0)
63 return L->stack+i; 63 return L->stack+i;
@@ -214,7 +214,7 @@ static const char *travglobals (lua_State *L, const TObject *o) {
214} 214}
215 215
216 216
217static void lua_getobjname (lua_State *L, StkId f, lua_Debug *ar) { 217static void lua_getname (lua_State *L, StkId f, lua_Debug *ar) {
218 TObject o; 218 TObject o;
219 setnormalized(&o, f); 219 setnormalized(&o, f);
220 /* try to find a name for given function */ 220 /* try to find a name for given function */
@@ -247,7 +247,7 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
247 ar->nups = lua_nups(func); 247 ar->nups = lua_nups(func);
248 break; 248 break;
249 case 'n': 249 case 'n':
250 lua_getobjname(L, func, ar); 250 lua_getname(L, func, ar);
251 break; 251 break;
252 case 'f': 252 case 'f':
253 setnormalized(L->top, func); 253 setnormalized(L->top, func);
@@ -267,8 +267,16 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
267** ======================================================= 267** =======================================================
268*/ 268*/
269 269
270
271static int pushpc (int *stack, int pc, int top, int n) {
272 while (n--)
273 stack[top++] = pc-1;
274 return top;
275}
276
277
270static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { 278static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
271 int stack[MAXSTACK]; /* stores last instruction that changes each value */ 279 int stack[MAXSTACK]; /* stores last instruction that changed a stack entry */
272 const Instruction *code = pt->code; 280 const Instruction *code = pt->code;
273 int top = pt->numparams; 281 int top = pt->numparams;
274 int pc = 0; 282 int pc = 0;
@@ -276,7 +284,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
276 top++; /* `arg' */ 284 top++; /* `arg' */
277 while (pc < lastpc) { 285 while (pc < lastpc) {
278 const Instruction i = code[pc++]; 286 const Instruction i = code[pc++];
279 LUA_ASSERT(top <= pt->maxstacksize, "wrong stack"); 287 LUA_ASSERT(0 <= top && top <= pt->maxstacksize, "wrong stack");
280 switch (GET_OPCODE(i)) { 288 switch (GET_OPCODE(i)) {
281 case OP_RETURN: { 289 case OP_RETURN: {
282 LUA_ASSERT(top >= GETARG_U(i), "wrong stack"); 290 LUA_ASSERT(top >= GETARG_U(i), "wrong stack");
@@ -287,9 +295,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
287 int nresults = GETARG_B(i); 295 int nresults = GETARG_B(i);
288 if (nresults == MULT_RET) nresults = 1; 296 if (nresults == MULT_RET) nresults = 1;
289 LUA_ASSERT(top >= GETARG_A(i), "wrong stack"); 297 LUA_ASSERT(top >= GETARG_A(i), "wrong stack");
290 top = GETARG_A(i); 298 top = pushpc(stack, pc, GETARG_A(i), nresults);
291 while (nresults--)
292 stack[top++] = pc-1;
293 break; 299 break;
294 } 300 }
295 case OP_TAILCALL: { 301 case OP_TAILCALL: {
@@ -298,9 +304,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
298 break; 304 break;
299 } 305 }
300 case OP_PUSHNIL: { 306 case OP_PUSHNIL: {
301 int n; 307 top = pushpc(stack, pc, top, GETARG_U(i));
302 for (n=0; n<GETARG_U(i); n++)
303 stack[top++] = pc-1;
304 break; 308 break;
305 } 309 }
306 case OP_POP: { 310 case OP_POP: {
@@ -321,33 +325,27 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
321 stack[top++] = pc-1; 325 stack[top++] = pc-1;
322 break; 326 break;
323 } 327 }
324 case OP_JMPONT:
325 case OP_JMPONF: {
326 int newpc = pc + GETARG_S(i);
327 if (lastpc < newpc)
328 top--; /* original code did not jump; condition was false */
329 else {
330 stack[top-1] = pc-1; /* value generated by or-and */
331 pc = newpc; /* do the jump */
332 }
333 break;
334 }
335 case OP_PUSHNILJMP: {
336 break; /* do not `push', to compensate next instruction */
337 }
338 case OP_CLOSURE: { 328 case OP_CLOSURE: {
339 top -= GETARG_B(i); 329 top -= GETARG_B(i);
340 stack[top++] = pc-1; 330 stack[top++] = pc-1;
341 break; 331 break;
342 } 332 }
343 default: { 333 default: {
344 int n; 334 OpCode op = GET_OPCODE(i);
345 LUA_ASSERT(luaK_opproperties[GET_OPCODE(i)].push != VD, 335 LUA_ASSERT(luaK_opproperties[op].push != VD,
346 "invalid opcode for default"); 336 "invalid opcode for default");
347 top -= luaK_opproperties[GET_OPCODE(i)].pop; 337 top -= luaK_opproperties[op].pop;
348 LUA_ASSERT(top >= 0, "wrong stack"); 338 LUA_ASSERT(top >= 0, "wrong stack");
349 for (n=0; n<luaK_opproperties[GET_OPCODE(i)].push; n++) 339 top = pushpc(stack, pc, top, luaK_opproperties[op].push);
350 stack[top++] = pc-1; 340 if (ISJUMP(op)) {
341 int newpc = pc + GETARG_S(i);
342 /* jump is forward and do not skip `lastpc'? */
343 if (pc < newpc && newpc <= lastpc) {
344 if (op == OP_JMPONT || op == OP_JMPONF)
345 stack[top++] = pc-1; /* do not pop when jumping */
346 pc = newpc; /* do the jump */
347 }
348 }
351 } 349 }
352 } 350 }
353 } 351 }
@@ -355,7 +353,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
355} 353}
356 354
357 355
358static const char *getname (lua_State *L, StkId obj, const char **name) { 356static const char *getobjname (lua_State *L, StkId obj, const char **name) {
359 StkId func = aux_stackedfunction(L, 0, obj); 357 StkId func = aux_stackedfunction(L, 0, obj);
360 if (func == NULL || ttype(func) != TAG_LMARK) 358 if (func == NULL || ttype(func) != TAG_LMARK)
361 return NULL; /* not a Lua function */ 359 return NULL; /* not a Lua function */
@@ -389,23 +387,21 @@ static const char *getname (lua_State *L, StkId obj, const char **name) {
389/* }====================================================== */ 387/* }====================================================== */
390 388
391 389
392static void call_index_error (lua_State *L, StkId o, const char *op, 390void luaG_typeerror (lua_State *L, StkId o, const char *op) {
393 const char *tp) {
394 const char *name; 391 const char *name;
395 const char *kind = getname(L, o, &name); 392 const char *kind = getobjname(L, o, &name);
393 const char *t = lua_type(L, o);
396 if (kind) 394 if (kind)
397 luaL_verror(L, "%s `%s' is not a %s", kind, name, tp); 395 luaL_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)",
396 op, kind, name, t);
398 else 397 else
399 luaL_verror(L, "attempt to %.10s a %.10s value", op, lua_type(L, o)); 398 luaL_verror(L, "attempt to %.30s a %.10s value", op, t);
400}
401
402
403void luaG_callerror (lua_State *L, StkId func) {
404 call_index_error(L, func, "call", "function");
405} 399}
406 400
407 401
408void luaG_indexerror (lua_State *L, StkId t) { 402void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op) {
409 call_index_error(L, t, "index", "table"); 403 if (ttype(p1) == t) p1++;
404 LUA_ASSERT(ttype(p1) != t, "must be an error");
405 luaG_typeerror(L, p1, op);
410} 406}
411 407