diff options
-rw-r--r-- | ldebug.c | 4 | ||||
-rw-r--r-- | ldo.c | 30 | ||||
-rw-r--r-- | ldo.h | 3 | ||||
-rw-r--r-- | lvm.c | 7 |
4 files changed, 23 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.151 2017/12/28 15:42:57 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.152 2018/01/10 12:02:35 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 | */ |
@@ -143,7 +143,7 @@ LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { | |||
143 | L->basehookcount = count; | 143 | L->basehookcount = count; |
144 | resethookcount(L); | 144 | resethookcount(L); |
145 | L->hookmask = cast_byte(mask); | 145 | L->hookmask = cast_byte(mask); |
146 | if (mask & (LUA_MASKLINE | LUA_MASKCOUNT)) | 146 | if (mask) |
147 | settraps(L->ci); /* to trace inside 'luaV_execute' */ | 147 | settraps(L->ci); /* to trace inside 'luaV_execute' */ |
148 | } | 148 | } |
149 | 149 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.188 2018/01/28 13:39:52 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.189 2018/01/29 16:21:35 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 | */ |
@@ -294,19 +294,21 @@ void luaD_hook (lua_State *L, int event, int line) { | |||
294 | } | 294 | } |
295 | 295 | ||
296 | 296 | ||
297 | static void hookcall (lua_State *L, CallInfo *ci, int istail) { | 297 | /* |
298 | int hook; | 298 | ** Executes a call hook for Lua functions. This function is called |
299 | ci->u.l.trap = 1; | 299 | ** whenever 'hookmask' is not zero, so it checks whether call hooks are |
300 | if (!(L->hookmask & LUA_MASKCALL)) | 300 | ** active. Also, this function can be called when resuming a function, |
301 | return; /* some other hook */ | 301 | ** so it checks whether the function is in its first instruction. |
302 | */ | ||
303 | void luaD_hookcall (lua_State *L, CallInfo *ci) { | ||
304 | Proto *p = clLvalue(s2v(ci->func))->p; | ||
305 | int hook = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL : LUA_HOOKCALL; | ||
306 | ci->u.l.trap = 1; /* there may be other hooks */ | ||
307 | if (!(L->hookmask & LUA_MASKCALL) || /* some other hook? */ | ||
308 | ci->u.l.savedpc != p->code) /* not 1st instruction? */ | ||
309 | return; /* don't call hook */ | ||
302 | L->top = ci->top; /* prepare top */ | 310 | L->top = ci->top; /* prepare top */ |
303 | ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ | 311 | ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ |
304 | if (istail) { | ||
305 | ci->callstatus |= CIST_TAIL; | ||
306 | hook = LUA_HOOKTAILCALL; | ||
307 | } | ||
308 | else | ||
309 | hook = LUA_HOOKCALL; | ||
310 | luaD_hook(L, hook, -1); | 312 | luaD_hook(L, hook, -1); |
311 | ci->u.l.savedpc--; /* correct 'pc' */ | 313 | ci->u.l.savedpc--; /* correct 'pc' */ |
312 | } | 314 | } |
@@ -427,8 +429,6 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { | |||
427 | L->top = func + narg1; /* set top */ | 429 | L->top = func + narg1; /* set top */ |
428 | luaT_adjustvarargs(L, nfixparams, narg1 - 1); | 430 | luaT_adjustvarargs(L, nfixparams, narg1 - 1); |
429 | } | 431 | } |
430 | if (L->hookmask) | ||
431 | hookcall(L, ci, 1); | ||
432 | } | 432 | } |
433 | 433 | ||
434 | 434 | ||
@@ -483,8 +483,6 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
483 | ci->callstatus = 0; | 483 | ci->callstatus = 0; |
484 | if (p->is_vararg) | 484 | if (p->is_vararg) |
485 | luaT_adjustvarargs(L, nfixparams, narg); /* may invoke GC */ | 485 | luaT_adjustvarargs(L, nfixparams, narg); /* may invoke GC */ |
486 | if (L->hookmask) | ||
487 | hookcall(L, ci, 0); | ||
488 | luaV_execute(L, ci); /* run the function */ | 486 | luaV_execute(L, ci); /* run the function */ |
489 | break; | 487 | break; |
490 | } | 488 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.h,v 2.38 2017/12/11 12:43:40 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 2.39 2018/01/10 19:19:27 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 | */ |
@@ -48,6 +48,7 @@ typedef void (*Pfunc) (lua_State *L, void *ud); | |||
48 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, | 48 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, |
49 | const char *mode); | 49 | const char *mode); |
50 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); | 50 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); |
51 | LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); | ||
51 | LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n); | 52 | LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n); |
52 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); | 53 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); |
53 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); | 54 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.335 2018/01/27 16:56:33 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.336 2018/01/29 16:21:35 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 | */ |
@@ -832,8 +832,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
832 | TValue *k; | 832 | TValue *k; |
833 | StkId base; | 833 | StkId base; |
834 | const Instruction *pc; | 834 | const Instruction *pc; |
835 | int trap = ci->u.l.trap; | 835 | int trap; |
836 | tailcall: | 836 | tailcall: |
837 | trap = L->hookmask; | ||
838 | if (trap) | ||
839 | luaD_hookcall(L, ci); | ||
837 | cl = clLvalue(s2v(ci->func)); | 840 | cl = clLvalue(s2v(ci->func)); |
838 | k = cl->p->k; | 841 | k = cl->p->k; |
839 | base = ci->func + 1; | 842 | base = ci->func + 1; |