diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-15 13:34:29 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-15 13:34:29 -0200 |
| commit | 0682fe816929da2e5abe8e191ad9c8509e6bfc12 (patch) | |
| tree | bac8b079fde63e7f2e436e51ed6fd571dfd6f195 /ldo.c | |
| parent | b1379936cf35787d3ef3aab82d1607a3e1562eef (diff) | |
| download | lua-0682fe816929da2e5abe8e191ad9c8509e6bfc12.tar.gz lua-0682fe816929da2e5abe8e191ad9c8509e6bfc12.tar.bz2 lua-0682fe816929da2e5abe8e191ad9c8509e6bfc12.zip | |
some simplifications/optimizations in returns from Lua functions
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 24 |
1 files changed, 16 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.192 2018/02/07 15:55:18 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.193 2018/02/09 15:16:06 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 | */ |
| @@ -310,11 +310,19 @@ void luaD_hookcall (lua_State *L, CallInfo *ci) { | |||
| 310 | } | 310 | } |
| 311 | 311 | ||
| 312 | 312 | ||
| 313 | void luaD_rethook (lua_State *L, CallInfo *ci) { | 313 | static void rethook (lua_State *L, CallInfo *ci) { |
| 314 | if (isLuacode(ci)) | 314 | int delta = 0; |
| 315 | if (isLuacode(ci)) { | ||
| 316 | Proto *p = clLvalue(s2v(ci->func))->p; | ||
| 317 | if (p->is_vararg) | ||
| 318 | delta = ci->u.l.nextraargs + p->numparams + 1; | ||
| 315 | L->top = ci->top; /* prepare top */ | 319 | L->top = ci->top; /* prepare top */ |
| 316 | if (L->hookmask & LUA_MASKRET) /* is return hook on? */ | 320 | } |
| 321 | if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ | ||
| 322 | ci->func += delta; /* if vararg, back to virtual 'func' */ | ||
| 317 | luaD_hook(L, LUA_HOOKRET, -1); /* call it */ | 323 | luaD_hook(L, LUA_HOOKRET, -1); /* call it */ |
| 324 | ci->func -= delta; | ||
| 325 | } | ||
| 318 | if (isLua(ci->previous)) | 326 | if (isLua(ci->previous)) |
| 319 | L->oldpc = ci->previous->u.l.savedpc; /* update 'oldpc' */ | 327 | L->oldpc = ci->previous->u.l.savedpc; /* update 'oldpc' */ |
| 320 | } | 328 | } |
| @@ -343,8 +351,8 @@ void luaD_tryfuncTM (lua_State *L, StkId func) { | |||
| 343 | ** expressions, multiple results for tail calls/single parameters) | 351 | ** expressions, multiple results for tail calls/single parameters) |
| 344 | ** separated. | 352 | ** separated. |
| 345 | */ | 353 | */ |
| 346 | void luaD_moveresults (lua_State *L, StkId firstResult, StkId res, | 354 | static void moveresults (lua_State *L, StkId firstResult, StkId res, |
| 347 | int nres, int wanted) { | 355 | int nres, int wanted) { |
| 348 | switch (wanted) { /* handle typical cases separately */ | 356 | switch (wanted) { /* handle typical cases separately */ |
| 349 | case 0: break; /* nothing to move */ | 357 | case 0: break; /* nothing to move */ |
| 350 | case 1: { /* one result needed */ | 358 | case 1: { /* one result needed */ |
| @@ -387,12 +395,12 @@ void luaD_moveresults (lua_State *L, StkId firstResult, StkId res, | |||
| 387 | void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { | 395 | void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { |
| 388 | if (L->hookmask) { | 396 | if (L->hookmask) { |
| 389 | ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */ | 397 | ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */ |
| 390 | luaD_rethook(L, ci); | 398 | rethook(L, ci); |
| 391 | firstResult = restorestack(L, fr); | 399 | firstResult = restorestack(L, fr); |
| 392 | } | 400 | } |
| 393 | L->ci = ci->previous; /* back to caller */ | 401 | L->ci = ci->previous; /* back to caller */ |
| 394 | /* move results to proper place */ | 402 | /* move results to proper place */ |
| 395 | luaD_moveresults(L, firstResult, ci->func, nres, ci->nresults); | 403 | moveresults(L, firstResult, ci->func, nres, ci->nresults); |
| 396 | } | 404 | } |
| 397 | 405 | ||
| 398 | 406 | ||
