aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-23 16:29:41 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-23 16:29:41 -0200
commit194a4f9710130cdb90df9f4094d81813bdb8ad6b (patch)
tree16a532914ecdaf7d94a52695085c5449b76a330d /ldo.c
parent196c87c9cecfacf978f37de4ec69eba0a5971256 (diff)
downloadlua-194a4f9710130cdb90df9f4094d81813bdb8ad6b.tar.gz
lua-194a4f9710130cdb90df9f4094d81813bdb8ad6b.tar.bz2
lua-194a4f9710130cdb90df9f4094d81813bdb8ad6b.zip
small simplifications in 'luaD_poscall'
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/ldo.c b/ldo.c
index 6b8162d2..37688a87 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.173 2017/11/21 14:17:35 roberto Exp roberto $ 2** $Id: ldo.c,v 2.174 2017/11/23 16:35:54 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*/
@@ -297,6 +297,14 @@ static void callhook (lua_State *L, CallInfo *ci, int istail) {
297} 297}
298 298
299 299
300static void rethook (lua_State *L, CallInfo *ci) {
301 if (L->hookmask & LUA_MASKRET) /* is return hook on? */
302 luaD_hook(L, LUA_HOOKRET, -1); /* call it */
303 if (isLua(ci->previous))
304 L->oldpc = ci->previous->u.l.savedpc; /* update 'oldpc' */
305}
306
307
300/* 308/*
301** Check whether __call metafield of 'func' is a function. If so, put 309** Check whether __call metafield of 'func' is a function. If so, put
302** it in stack below original 'func' so that 'luaD_call' can call 310** it in stack below original 'func' so that 'luaD_call' can call
@@ -323,8 +331,8 @@ StkId luaD_tryfuncTM (lua_State *L, StkId func) {
323** expressions, multiple results for tail calls/single parameters) 331** expressions, multiple results for tail calls/single parameters)
324** separated. 332** separated.
325*/ 333*/
326static int moveresults (lua_State *L, StkId firstResult, StkId res, 334static void moveresults (lua_State *L, StkId firstResult, StkId res,
327 int nres, int wanted) { 335 int nres, int wanted) {
328 switch (wanted) { /* handle typical cases separately */ 336 switch (wanted) { /* handle typical cases separately */
329 case 0: break; /* nothing to move */ 337 case 0: break; /* nothing to move */
330 case 1: { /* one result needed */ 338 case 1: { /* one result needed */
@@ -339,7 +347,7 @@ static int moveresults (lua_State *L, StkId firstResult, StkId res,
339 for (i = 0; i < nres; i++) /* move all results to correct place */ 347 for (i = 0; i < nres; i++) /* move all results to correct place */
340 setobjs2s(L, res + i, firstResult + i); 348 setobjs2s(L, res + i, firstResult + i);
341 L->top = res + nres; 349 L->top = res + nres;
342 return 0; /* wanted == LUA_MULTRET */ 350 return;
343 } 351 }
344 default: { 352 default: {
345 int i; 353 int i;
@@ -357,7 +365,6 @@ static int moveresults (lua_State *L, StkId firstResult, StkId res,
357 } 365 }
358 } 366 }
359 L->top = res + wanted; /* top points after the last result */ 367 L->top = res + wanted; /* top points after the last result */
360 return 1;
361} 368}
362 369
363 370
@@ -366,22 +373,15 @@ static int moveresults (lua_State *L, StkId firstResult, StkId res,
366** moves current number of results to proper place; returns 0 iff call 373** moves current number of results to proper place; returns 0 iff call
367** wanted multiple (variable number of) results. 374** wanted multiple (variable number of) results.
368*/ 375*/
369int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { 376void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
370 StkId res; 377 if (L->hookmask) {
371 int wanted = ci->nresults; 378 ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */
372 if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) { 379 rethook(L, ci);
373 if (L->hookmask & LUA_MASKRET) { 380 firstResult = restorestack(L, fr);
374 ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */
375 luaD_hook(L, LUA_HOOKRET, -1);
376 firstResult = restorestack(L, fr);
377 }
378 if (isLua(ci->previous))
379 L->oldpc = ci->previous->u.l.savedpc;
380 } 381 }
381 res = ci->func; /* res == final position of 1st result */
382 L->ci = ci->previous; /* back to caller */ 382 L->ci = ci->previous; /* back to caller */
383 /* move results to proper place */ 383 /* move results to proper place */
384 return moveresults(L, firstResult, res, nres, wanted); 384 moveresults(L, firstResult, ci->func, nres, ci->nresults);
385} 385}
386 386
387 387