diff options
Diffstat (limited to 'ldebug.c')
| -rw-r--r-- | ldebug.c | 67 |
1 files changed, 50 insertions, 17 deletions
| @@ -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 | ||
| 26 | static const char *getfuncname (lua_State *L, StkId f, const char **name); | ||
| 27 | |||
| 26 | 28 | ||
| 27 | static void setnormalized (TObject *d, const TObject *s) { | 29 | static 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 | ||
| 230 | int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | 232 | int 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 | ||
| 393 | static 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 | |||
| 432 | void 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 | |||
