diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-30 10:16:19 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-30 10:16:19 -0300 |
commit | 4c6afbcb01d1cae72d829af5301df5f592fa2079 (patch) | |
tree | 91047c8b1c19e9211438e9581239add4a6ccffbb | |
parent | f2206b2abe848f65956fa48da338c2bfac599e4a (diff) | |
download | lua-4c6afbcb01d1cae72d829af5301df5f592fa2079.tar.gz lua-4c6afbcb01d1cae72d829af5301df5f592fa2079.tar.bz2 lua-4c6afbcb01d1cae72d829af5301df5f592fa2079.zip |
Struct 'transferinfo' moved to "lua_State"
That reduces the size of "CallInfo". Moreover, bit CIST_HOOKED from
call status is not needed. When in a hook, 'transferinfo' is always
valid, being zero when the hook is not call/return.
-rw-r--r-- | ldebug.c | 6 | ||||
-rw-r--r-- | ldo.c | 14 | ||||
-rw-r--r-- | lstate.h | 20 |
3 files changed, 16 insertions, 24 deletions
@@ -364,11 +364,11 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, | |||
364 | break; | 364 | break; |
365 | } | 365 | } |
366 | case 'r': { | 366 | case 'r': { |
367 | if (ci == NULL || !(ci->callstatus & CIST_TRAN)) | 367 | if (ci == NULL || !(ci->callstatus & CIST_HOOKED)) |
368 | ar->ftransfer = ar->ntransfer = 0; | 368 | ar->ftransfer = ar->ntransfer = 0; |
369 | else { | 369 | else { |
370 | ar->ftransfer = ci->u2.transferinfo.ftransfer; | 370 | ar->ftransfer = L->transferinfo.ftransfer; |
371 | ar->ntransfer = ci->u2.transferinfo.ntransfer; | 371 | ar->ntransfer = L->transferinfo.ntransfer; |
372 | } | 372 | } |
373 | break; | 373 | break; |
374 | } | 374 | } |
@@ -357,7 +357,6 @@ void luaD_hook (lua_State *L, int event, int line, | |||
357 | int ftransfer, int ntransfer) { | 357 | int ftransfer, int ntransfer) { |
358 | lua_Hook hook = L->hook; | 358 | lua_Hook hook = L->hook; |
359 | if (hook && L->allowhook) { /* make sure there is a hook */ | 359 | if (hook && L->allowhook) { /* make sure there is a hook */ |
360 | unsigned mask = CIST_HOOKED; | ||
361 | CallInfo *ci = L->ci; | 360 | CallInfo *ci = L->ci; |
362 | ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */ | 361 | ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */ |
363 | ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */ | 362 | ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */ |
@@ -365,18 +364,15 @@ void luaD_hook (lua_State *L, int event, int line, | |||
365 | ar.event = event; | 364 | ar.event = event; |
366 | ar.currentline = line; | 365 | ar.currentline = line; |
367 | ar.i_ci = ci; | 366 | ar.i_ci = ci; |
368 | if (ntransfer != 0) { | 367 | L->transferinfo.ftransfer = ftransfer; |
369 | mask |= CIST_TRAN; /* 'ci' has transfer information */ | 368 | L->transferinfo.ntransfer = ntransfer; |
370 | ci->u2.transferinfo.ftransfer = ftransfer; | ||
371 | ci->u2.transferinfo.ntransfer = ntransfer; | ||
372 | } | ||
373 | if (isLua(ci) && L->top.p < ci->top.p) | 369 | if (isLua(ci) && L->top.p < ci->top.p) |
374 | L->top.p = ci->top.p; /* protect entire activation register */ | 370 | L->top.p = ci->top.p; /* protect entire activation register */ |
375 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 371 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
376 | if (ci->top.p < L->top.p + LUA_MINSTACK) | 372 | if (ci->top.p < L->top.p + LUA_MINSTACK) |
377 | ci->top.p = L->top.p + LUA_MINSTACK; | 373 | ci->top.p = L->top.p + LUA_MINSTACK; |
378 | L->allowhook = 0; /* cannot call hooks inside a hook */ | 374 | L->allowhook = 0; /* cannot call hooks inside a hook */ |
379 | ci->callstatus |= mask; | 375 | ci->callstatus |= CIST_HOOKED; |
380 | lua_unlock(L); | 376 | lua_unlock(L); |
381 | (*hook)(L, &ar); | 377 | (*hook)(L, &ar); |
382 | lua_lock(L); | 378 | lua_lock(L); |
@@ -384,7 +380,7 @@ void luaD_hook (lua_State *L, int event, int line, | |||
384 | L->allowhook = 1; | 380 | L->allowhook = 1; |
385 | ci->top.p = restorestack(L, ci_top); | 381 | ci->top.p = restorestack(L, ci_top); |
386 | L->top.p = restorestack(L, top); | 382 | L->top.p = restorestack(L, top); |
387 | ci->callstatus &= ~mask; | 383 | ci->callstatus &= ~CIST_HOOKED; |
388 | } | 384 | } |
389 | } | 385 | } |
390 | 386 | ||
@@ -525,7 +521,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { | |||
525 | moveresults(L, ci->func.p, nres, fwanted); | 521 | moveresults(L, ci->func.p, nres, fwanted); |
526 | /* function cannot be in any of these cases when returning */ | 522 | /* function cannot be in any of these cases when returning */ |
527 | lua_assert(!(ci->callstatus & | 523 | lua_assert(!(ci->callstatus & |
528 | (CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_TRAN | CIST_CLSRET))); | 524 | (CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_CLSRET))); |
529 | L->ci = ci->previous; /* back to caller (after closing variables) */ | 525 | L->ci = ci->previous; /* back to caller (after closing variables) */ |
530 | } | 526 | } |
531 | 527 | ||
@@ -183,8 +183,6 @@ typedef struct stringtable { | |||
183 | ** yield (from the yield until the next resume); | 183 | ** yield (from the yield until the next resume); |
184 | ** - field 'nres' is used only while closing tbc variables when | 184 | ** - field 'nres' is used only while closing tbc variables when |
185 | ** returning from a function; | 185 | ** returning from a function; |
186 | ** - field 'transferinfo' is used only during call/returnhooks, | ||
187 | ** before the function starts or after it ends. | ||
188 | */ | 186 | */ |
189 | struct CallInfo { | 187 | struct CallInfo { |
190 | StkIdRel func; /* function index in the stack */ | 188 | StkIdRel func; /* function index in the stack */ |
@@ -206,10 +204,6 @@ struct CallInfo { | |||
206 | int funcidx; /* called-function index */ | 204 | int funcidx; /* called-function index */ |
207 | int nyield; /* number of values yielded */ | 205 | int nyield; /* number of values yielded */ |
208 | int nres; /* number of values returned */ | 206 | int nres; /* number of values returned */ |
209 | struct { /* info about transferred values (for call/return hooks) */ | ||
210 | int ftransfer; /* offset of first value transferred */ | ||
211 | int ntransfer; /* number of values transferred */ | ||
212 | } transferinfo; | ||
213 | } u2; | 207 | } u2; |
214 | l_uint32 callstatus; | 208 | l_uint32 callstatus; |
215 | }; | 209 | }; |
@@ -236,15 +230,13 @@ struct CallInfo { | |||
236 | #define CIST_HOOKYIELD (cast(l_uint32, 1) << 14) | 230 | #define CIST_HOOKYIELD (cast(l_uint32, 1) << 14) |
237 | /* function "called" a finalizer */ | 231 | /* function "called" a finalizer */ |
238 | #define CIST_FIN (cast(l_uint32, 1) << 15) | 232 | #define CIST_FIN (cast(l_uint32, 1) << 15) |
239 | /* 'ci' has transfer information */ | ||
240 | #define CIST_TRAN (cast(l_uint32, 1) << 16) | ||
241 | /* function is closing tbc variables */ | 233 | /* function is closing tbc variables */ |
242 | #define CIST_CLSRET (cast(l_uint32, 1) << 17) | 234 | #define CIST_CLSRET (cast(l_uint32, 1) << 16) |
243 | /* Bits 18-20 are used for CIST_RECST (see below) */ | 235 | /* Bits 17-19 are used for CIST_RECST (see below) */ |
244 | #define CIST_RECST 18 /* the offset, not the mask */ | 236 | #define CIST_RECST 17 /* the offset, not the mask */ |
245 | #if defined(LUA_COMPAT_LT_LE) | 237 | #if defined(LUA_COMPAT_LT_LE) |
246 | /* using __lt for __le */ | 238 | /* using __lt for __le */ |
247 | #define CIST_LEQ (cast(l_uint32, 1) << 21) | 239 | #define CIST_LEQ (cast(l_uint32, 1) << 20) |
248 | #endif | 240 | #endif |
249 | 241 | ||
250 | 242 | ||
@@ -354,6 +346,10 @@ struct lua_State { | |||
354 | int basehookcount; | 346 | int basehookcount; |
355 | int hookcount; | 347 | int hookcount; |
356 | volatile l_signalT hookmask; | 348 | volatile l_signalT hookmask; |
349 | struct { /* info about transferred values (for call/return hooks) */ | ||
350 | int ftransfer; /* offset of first value transferred */ | ||
351 | int ntransfer; /* number of values transferred */ | ||
352 | } transferinfo; | ||
357 | }; | 353 | }; |
358 | 354 | ||
359 | 355 | ||