diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-27 08:52:30 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-27 08:52:30 -0300 |
commit | 92f6e0c1bfb27cad95d99e99912e2e0c509dcc30 (patch) | |
tree | 1ab713c16652a5a4e667457041ce7364256a6b2c /ldo.c | |
parent | 5cd99b82b7fc11c527929e5e95f03767f6432d8e (diff) | |
download | lua-92f6e0c1bfb27cad95d99e99912e2e0c509dcc30.tar.gz lua-92f6e0c1bfb27cad95d99e99912e2e0c509dcc30.tar.bz2 lua-92f6e0c1bfb27cad95d99e99912e2e0c509dcc30.zip |
no-nonsense debug information about tail calls
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.212 2003/01/23 11:31:38 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.213 2003/02/13 16:08:47 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -31,6 +31,7 @@ | |||
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | |||
34 | /* | 35 | /* |
35 | ** {====================================================== | 36 | ** {====================================================== |
36 | ** Error-recovery functions (based on long jumps) | 37 | ** Error-recovery functions (based on long jumps) |
@@ -161,7 +162,10 @@ void luaD_callhook (lua_State *L, int event, int line) { | |||
161 | lua_Debug ar; | 162 | lua_Debug ar; |
162 | ar.event = event; | 163 | ar.event = event; |
163 | ar.currentline = line; | 164 | ar.currentline = line; |
164 | ar.i_ci = L->ci - L->base_ci; | 165 | if (event == LUA_HOOKTAILRET) |
166 | ar.i_ci = 0; /* tail call; no debug information about it */ | ||
167 | else | ||
168 | ar.i_ci = L->ci - L->base_ci; | ||
165 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 169 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
166 | L->ci->top = L->top + LUA_MINSTACK; | 170 | L->ci->top = L->top + LUA_MINSTACK; |
167 | L->allowhook = 0; /* cannot call hooks inside a hook */ | 171 | L->allowhook = 0; /* cannot call hooks inside a hook */ |
@@ -232,6 +236,7 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
232 | L->base = L->ci->base = restorestack(L, funcr) + 1; | 236 | L->base = L->ci->base = restorestack(L, funcr) + 1; |
233 | ci->top = L->base + p->maxstacksize; | 237 | ci->top = L->base + p->maxstacksize; |
234 | ci->u.l.savedpc = p->code; /* starting point */ | 238 | ci->u.l.savedpc = p->code; /* starting point */ |
239 | ci->u.l.tailcalls = 0; | ||
235 | ci->state = CI_SAVEDPC; | 240 | ci->state = CI_SAVEDPC; |
236 | while (L->top < ci->top) | 241 | while (L->top < ci->top) |
237 | setnilvalue(L->top++); | 242 | setnilvalue(L->top++); |
@@ -261,13 +266,21 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
261 | } | 266 | } |
262 | 267 | ||
263 | 268 | ||
269 | static StkId callrethooks (lua_State *L, StkId firstResult) { | ||
270 | ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ | ||
271 | luaD_callhook(L, LUA_HOOKRET, -1); | ||
272 | if (!(L->ci->state & CI_C)) { /* Lua function? */ | ||
273 | while (L->ci->u.l.tailcalls--) /* call hook for eventual tail calls */ | ||
274 | luaD_callhook(L, LUA_HOOKTAILRET, -1); | ||
275 | } | ||
276 | return restorestack(L, fr); | ||
277 | } | ||
278 | |||
279 | |||
264 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { | 280 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { |
265 | StkId res; | 281 | StkId res; |
266 | if (L->hookmask & LUA_MASKRET) { | 282 | if (L->hookmask & LUA_MASKRET) |
267 | ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ | 283 | firstResult = callrethooks(L, firstResult); |
268 | luaD_callhook(L, LUA_HOOKRET, -1); | ||
269 | firstResult = restorestack(L, fr); | ||
270 | } | ||
271 | res = L->base - 1; /* res == final position of 1st result */ | 284 | res = L->base - 1; /* res == final position of 1st result */ |
272 | L->ci--; | 285 | L->ci--; |
273 | L->base = L->ci->base; /* restore base */ | 286 | L->base = L->ci->base; /* restore base */ |