aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldebug.c67
-rw-r--r--ldebug.h3
-rw-r--r--lobject.c6
-rw-r--r--luadebug.h4
-rw-r--r--lvm.c4
5 files changed, 61 insertions, 23 deletions
diff --git a/ldebug.c b/ldebug.c
index e81661e2..e0b3925a 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.31 2000/08/09 19:16:57 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.32 2000/08/10 19:50:47 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*/
@@ -23,6 +23,8 @@
23#include "luadebug.h" 23#include "luadebug.h"
24 24
25 25
26static const char *getfuncname (lua_State *L, StkId f, const char **name);
27
26 28
27static void setnormalized (TObject *d, const TObject *s) { 29static void setnormalized (TObject *d, const TObject *s) {
28 switch (s->ttype) { 30 switch (s->ttype) {
@@ -229,7 +231,8 @@ static void lua_getname (lua_State *L, StkId f, lua_Debug *ar) {
229 231
230int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { 232int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
231 StkId func; 233 StkId func;
232 if (*what != '>') 234 int isactive = (*what != '>');
235 if (isactive)
233 func = ar->_func; 236 func = ar->_func;
234 else { 237 else {
235 what++; /* skip the '>' */ 238 what++; /* skip the '>' */
@@ -237,23 +240,30 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
237 } 240 }
238 for (; *what; what++) { 241 for (; *what; what++) {
239 switch (*what) { 242 switch (*what) {
240 case 'S': 243 case 'S': {
241 lua_funcinfo(ar, func); 244 lua_funcinfo(ar, func);
242 break; 245 break;
243 case 'l': 246 }
247 case 'l': {
244 ar->currentline = lua_currentline(func); 248 ar->currentline = lua_currentline(func);
245 break; 249 break;
246 case 'u': 250 }
251 case 'u': {
247 ar->nups = lua_nups(func); 252 ar->nups = lua_nups(func);
248 break; 253 break;
249 case 'n': 254 }
250 lua_getname(L, func, ar); 255 case 'n': {
256 ar->namewhat = getfuncname(L, func, &ar->name);
257 if (ar->namewhat == NULL)
258 lua_getname(L, func, ar);
251 break; 259 break;
252 case 'f': 260 }
261 case 'f': {
253 setnormalized(L->top, func); 262 setnormalized(L->top, func);
254 incr_top; 263 incr_top;
255 ar->func = lua_pop(L); 264 ar->func = lua_pop(L);
256 break; 265 break;
266 }
257 default: return 0; /* invalid option */ 267 default: return 0; /* invalid option */
258 } 268 }
259 } 269 }
@@ -286,10 +296,11 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
286 const Instruction i = code[pc++]; 296 const Instruction i = code[pc++];
287 LUA_ASSERT(0 <= top && top <= pt->maxstacksize, "wrong stack"); 297 LUA_ASSERT(0 <= top && top <= pt->maxstacksize, "wrong stack");
288 switch (GET_OPCODE(i)) { 298 switch (GET_OPCODE(i)) {
289 case OP_RETURN: { 299 case OP_RETURN:
290 LUA_ASSERT(top >= GETARG_U(i), "wrong stack"); 300 case OP_TAILCALL:
291 top = GETARG_U(i); 301 case OP_END: {
292 break; 302 LUA_INTERNALERROR("invalid symbolic run");
303 return CREATE_0(OP_END); /* stop execution */
293 } 304 }
294 case OP_CALL: { 305 case OP_CALL: {
295 int nresults = GETARG_B(i); 306 int nresults = GETARG_B(i);
@@ -298,11 +309,6 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
298 top = pushpc(stack, pc, GETARG_A(i), nresults); 309 top = pushpc(stack, pc, GETARG_A(i), nresults);
299 break; 310 break;
300 } 311 }
301 case OP_TAILCALL: {
302 LUA_ASSERT(top >= GETARG_A(i), "wrong stack");
303 top = GETARG_B(i);
304 break;
305 }
306 case OP_PUSHNIL: { 312 case OP_PUSHNIL: {
307 top = pushpc(stack, pc, top, GETARG_U(i)); 313 top = pushpc(stack, pc, top, GETARG_U(i));
308 break; 314 break;
@@ -384,6 +390,23 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) {
384} 390}
385 391
386 392
393static const char *getfuncname (lua_State *L, StkId f, const char **name) {
394 StkId func = aux_stackedfunction(L, 0, f); /* calling function */
395 if (func == NULL || ttype(func) != TAG_LMARK)
396 return NULL; /* not a Lua function */
397 else {
398 Proto *p = infovalue(func)->func->f.l;
399 Instruction i = p->code[lua_currentpc(func)];
400 switch (GET_OPCODE(i)) {
401 case OP_CALL: case OP_TAILCALL:
402 return getobjname(L, (func+1)+GETARG_A(i), name);
403 default:
404 return NULL; /* no usefull name found */
405 }
406 }
407}
408
409
387/* }====================================================== */ 410/* }====================================================== */
388 411
389 412
@@ -405,3 +428,13 @@ void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op) {
405 luaG_typeerror(L, p1, op); 428 luaG_typeerror(L, p1, op);
406} 429}
407 430
431
432void luaG_ordererror (lua_State *L, StkId top) {
433 const char *t1 = lua_type(L, top-2);
434 const char *t2 = lua_type(L, top-1);
435 if (t1[2] == t2[2])
436 luaL_verror(L, "attempt to compare two %.10s values", t1);
437 else
438 luaL_verror(L, "attempt to compare %.10s with %.10s", t1, t2);
439}
440
diff --git a/ldebug.h b/ldebug.h
index 3db8976f..eabad3d7 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.h,v 1.3 2000/08/08 18:26:05 roberto Exp roberto $ 2** $Id: ldebug.h,v 1.4 2000/08/10 19:50:47 roberto Exp roberto $
3** Auxiliary functions from Debug Interface module 3** Auxiliary functions from Debug Interface module
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,6 +15,7 @@
15void luaG_typeerror (lua_State *L, StkId o, const char *op); 15void luaG_typeerror (lua_State *L, StkId o, const char *op);
16void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op); 16void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op);
17int luaG_getline (int *lineinfo, int pc, int refline, int *refi); 17int luaG_getline (int *lineinfo, int pc, int refline, int *refi);
18void luaG_ordererror (lua_State *L, StkId top);
18 19
19 20
20#endif 21#endif
diff --git a/lobject.c b/lobject.c
index d6d3f9c4..c833e921 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.43 2000/06/30 14:35:17 roberto Exp roberto $ 2** $Id: lobject.c,v 1.44 2000/08/09 19:16:57 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,6 +12,10 @@
12#include "lobject.h" 12#include "lobject.h"
13 13
14 14
15/*
16** you can use the fact that the 3rd letter or each name is always different
17** (e-m-r-b-n-l) to compare and switch these strings
18*/
15const char *const luaO_typenames[] = { /* ORDER LUA_T */ 19const char *const luaO_typenames[] = { /* ORDER LUA_T */
16 "userdata", "number", "string", "table", "function", "function", "nil", 20 "userdata", "number", "string", "table", "function", "function", "nil",
17 "function", "function" 21 "function", "function"
diff --git a/luadebug.h b/luadebug.h
index ce69c50e..6944cc17 100644
--- a/luadebug.h
+++ b/luadebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luadebug.h,v 1.10 2000/03/30 17:19:48 roberto Exp roberto $ 2** $Id: luadebug.h,v 1.11 2000/08/08 20:42:07 roberto Exp roberto $
3** Debugging API 3** Debugging API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -34,7 +34,7 @@ struct lua_Debug {
34 const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ 34 const char *what; /* (S) `Lua' function, `C' function, Lua `main' */
35 int currentline; /* (l) */ 35 int currentline; /* (l) */
36 const char *name; /* (n) */ 36 const char *name; /* (n) */
37 const char *namewhat; /* (n) global, tag method, local, field */ 37 const char *namewhat; /* (n) `global', `tag method', `local', `field' */
38 int nups; /* (u) number of upvalues */ 38 int nups; /* (u) number of upvalues */
39 lua_Object func; /* (f) function being executed */ 39 lua_Object func; /* (f) function being executed */
40 /* private part */ 40 /* private part */
diff --git a/lvm.c b/lvm.c
index 3152a74c..e4fee4ed 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.124 2000/08/09 19:16:57 roberto Exp roberto $ 2** $Id: lvm.c,v 1.125 2000/08/10 19:50:47 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -279,7 +279,7 @@ int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top)
279 *top++ = *l; 279 *top++ = *l;
280 *top++ = *r; 280 *top++ = *r;
281 if (!call_binTM(L, top, IM_LT)) 281 if (!call_binTM(L, top, IM_LT))
282 lua_error(L, "unexpected type in comparison"); 282 luaG_ordererror(L, top-2);
283 L->top--; 283 L->top--;
284 return (ttype(L->top) != TAG_NIL); 284 return (ttype(L->top) != TAG_NIL);
285 } 285 }