diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-26 17:40:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-26 17:40:29 -0300 |
commit | 0fe2576a39633ab7873f9d4fd989f1e5203a5725 (patch) | |
tree | c759f10fb3565f924dad29874d85d9d1b139c3bf /ldebug.c | |
parent | d08d237a49ff3cb961012b1de374914af6da3000 (diff) | |
download | lua-0fe2576a39633ab7873f9d4fd989f1e5203a5725.tar.gz lua-0fe2576a39633ab7873f9d4fd989f1e5203a5725.tar.bz2 lua-0fe2576a39633ab7873f9d4fd989f1e5203a5725.zip |
new instructions to optimize indexing on upvalues
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 35 |
1 files changed, 26 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.62 2010/01/11 17:37:59 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.63 2010/01/13 16:18:25 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 | */ |
@@ -270,12 +270,10 @@ static const char *kname (Proto *p, int c) { | |||
270 | 270 | ||
271 | static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | 271 | static const char *getobjname (lua_State *L, CallInfo *ci, int reg, |
272 | const char **name) { | 272 | const char **name) { |
273 | Proto *p; | 273 | Proto *p = ci_func(ci)->l.p; |
274 | int lastpc, pc; | ||
275 | const char *what = NULL; | 274 | const char *what = NULL; |
276 | lua_assert(isLua(ci)); | 275 | int lastpc = currentpc(ci); |
277 | p = ci_func(ci)->l.p; | 276 | int pc; |
278 | lastpc = currentpc(ci); | ||
279 | *name = luaF_getlocalname(p, reg + 1, lastpc); | 277 | *name = luaF_getlocalname(p, reg + 1, lastpc); |
280 | if (*name) /* is a local? */ | 278 | if (*name) /* is a local? */ |
281 | return "local"; | 279 | return "local"; |
@@ -305,6 +303,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
305 | } | 303 | } |
306 | break; | 304 | break; |
307 | } | 305 | } |
306 | case OP_GETTABUP: | ||
308 | case OP_GETTABLE: { | 307 | case OP_GETTABLE: { |
309 | if (reg == a) { | 308 | if (reg == a) { |
310 | int k = GETARG_C(i); /* key index */ | 309 | int k = GETARG_C(i); /* key index */ |
@@ -378,6 +377,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |||
378 | return getobjname(L, ci, GETARG_A(i), name); | 377 | return getobjname(L, ci, GETARG_A(i), name); |
379 | case OP_GETGLOBAL: | 378 | case OP_GETGLOBAL: |
380 | case OP_SELF: | 379 | case OP_SELF: |
380 | case OP_GETTABUP: | ||
381 | case OP_GETTABLE: tm = TM_INDEX; break; | 381 | case OP_GETTABLE: tm = TM_INDEX; break; |
382 | case OP_SETGLOBAL: | 382 | case OP_SETGLOBAL: |
383 | case OP_SETTABLE: tm = TM_NEWINDEX; break; | 383 | case OP_SETTABLE: tm = TM_NEWINDEX; break; |
@@ -413,13 +413,30 @@ static int isinstack (CallInfo *ci, const TValue *o) { | |||
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | static const char *getupvalname (CallInfo *ci, const TValue *o, | ||
417 | const char **name) { | ||
418 | LClosure *c = &ci_func(ci)->l; | ||
419 | int i; | ||
420 | for (i = 0; i < c->nupvalues; i++) { | ||
421 | if (c->upvals[i]->v == o) { | ||
422 | *name = getstr(c->p->upvalues[i].name); | ||
423 | return "upvalue"; | ||
424 | } | ||
425 | } | ||
426 | return NULL; | ||
427 | } | ||
428 | |||
429 | |||
416 | void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { | 430 | void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { |
417 | CallInfo *ci = L->ci; | 431 | CallInfo *ci = L->ci; |
418 | const char *name = NULL; | 432 | const char *name = NULL; |
419 | const char *t = typename(ttype(o)); | 433 | const char *t = typename(ttype(o)); |
420 | const char *kind = (isLua(ci) && isinstack(ci, o)) ? | 434 | const char *kind = NULL; |
421 | getobjname(L, ci, cast_int(o - ci->u.l.base), &name) : | 435 | if (isLua(ci)) { |
422 | NULL; | 436 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ |
437 | if (!kind && isinstack(ci, o)) /* no? try a register */ | ||
438 | kind = getobjname(L, ci, cast_int(o - ci->u.l.base), &name); | ||
439 | } | ||
423 | if (kind) | 440 | if (kind) |
424 | luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", | 441 | luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", |
425 | op, kind, name, t); | 442 | op, kind, name, t); |