diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-20 12:58:05 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-20 12:58:05 -0200 |
commit | 1d5b885437286a307a77b5d12756d73d374efd54 (patch) | |
tree | b2daefb8d44be37af3b61816eb1f966c94d44393 /ldebug.c | |
parent | 4dc0be950ad67e4385400aacd25e10325a2a6e59 (diff) | |
download | lua-1d5b885437286a307a77b5d12756d73d374efd54.tar.gz lua-1d5b885437286a307a77b5d12756d73d374efd54.tar.bz2 lua-1d5b885437286a307a77b5d12756d73d374efd54.zip |
when running Lua code, there is no need to keep 'L->top' "correct";
set it only when needed.
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.148 2017/12/13 18:32:09 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.149 2017/12/15 13:07:10 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 | */ |
@@ -189,14 +189,10 @@ static const char *upvalname (Proto *p, int uv) { | |||
189 | 189 | ||
190 | static const char *findlocal (lua_State *L, CallInfo *ci, int n, | 190 | static const char *findlocal (lua_State *L, CallInfo *ci, int n, |
191 | StkId *pos) { | 191 | StkId *pos) { |
192 | const char *name = NULL; | 192 | StkId base = ci->func + 1; |
193 | StkId base; | 193 | const char *name = (isLua(ci)) |
194 | if (isLua(ci)) { | 194 | ? luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)) |
195 | base = ci->func + 1; | 195 | : NULL; |
196 | name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)); | ||
197 | } | ||
198 | else | ||
199 | base = ci->func + 1; | ||
200 | if (name == NULL) { /* no 'standard' name? */ | 196 | if (name == NULL) { /* no 'standard' name? */ |
201 | StkId limit = (ci == L->ci) ? L->top : ci->next->func; | 197 | StkId limit = (ci == L->ci) ? L->top : ci->next->func; |
202 | if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */ | 198 | if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */ |
@@ -741,6 +737,8 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { | |||
741 | const char *msg; | 737 | const char *msg; |
742 | va_list argp; | 738 | va_list argp; |
743 | luaC_checkGC(L); /* error message uses memory */ | 739 | luaC_checkGC(L); /* error message uses memory */ |
740 | if (isLuacode(ci)) | ||
741 | L->top = ci->top; /* prepare top */ | ||
744 | va_start(argp, fmt); | 742 | va_start(argp, fmt); |
745 | msg = luaO_pushvfstring(L, fmt, argp); /* format message */ | 743 | msg = luaO_pushvfstring(L, fmt, argp); /* format message */ |
746 | va_end(argp); | 744 | va_end(argp); |
@@ -764,6 +762,7 @@ static int changedline (Proto *p, int oldpc, int newpc) { | |||
764 | 762 | ||
765 | 763 | ||
766 | void luaG_traceexec (lua_State *L) { | 764 | void luaG_traceexec (lua_State *L) { |
765 | ptrdiff_t oldtop = savestack(L, L->top); | ||
767 | CallInfo *ci = L->ci; | 766 | CallInfo *ci = L->ci; |
768 | lu_byte mask = L->hookmask; | 767 | lu_byte mask = L->hookmask; |
769 | int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT)); | 768 | int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT)); |
@@ -775,6 +774,7 @@ void luaG_traceexec (lua_State *L) { | |||
775 | ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */ | 774 | ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */ |
776 | return; /* do not call hook again (VM yielded, so it did not move) */ | 775 | return; /* do not call hook again (VM yielded, so it did not move) */ |
777 | } | 776 | } |
777 | L->top = ci->top; /* prepare top */ | ||
778 | if (counthook) | 778 | if (counthook) |
779 | luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */ | 779 | luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */ |
780 | if (mask & LUA_MASKLINE) { | 780 | if (mask & LUA_MASKLINE) { |
@@ -789,6 +789,7 @@ void luaG_traceexec (lua_State *L) { | |||
789 | } | 789 | } |
790 | L->oldpc = npc; | 790 | L->oldpc = npc; |
791 | } | 791 | } |
792 | L->top = restorestack(L, oldtop); | ||
792 | if (L->status == LUA_YIELD) { /* did hook yield? */ | 793 | if (L->status == LUA_YIELD) { /* did hook yield? */ |
793 | if (counthook) | 794 | if (counthook) |
794 | L->hookcount = 1; /* undo decrement to zero */ | 795 | L->hookcount = 1; /* undo decrement to zero */ |