diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-07 13:55:18 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-07 13:55:18 -0200 |
| commit | 4e0de3a43cc30a83334c272cb7575bf8412bfeae (patch) | |
| tree | cfa3ca4d88a658d2d7d4ac2bc788ffb64fa7eeea | |
| parent | 318a9a5859826d7af0294664e206236fc8814319 (diff) | |
| download | lua-4e0de3a43cc30a83334c272cb7575bf8412bfeae.tar.gz lua-4e0de3a43cc30a83334c272cb7575bf8412bfeae.tar.bz2 lua-4e0de3a43cc30a83334c272cb7575bf8412bfeae.zip | |
details
| -rw-r--r-- | ldo.c | 29 |
1 files changed, 16 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.190 2018/02/06 19:16:56 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.191 2018/02/07 15:18:04 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 | */ |
| @@ -398,7 +398,11 @@ void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { | |||
| 398 | 398 | ||
| 399 | 399 | ||
| 400 | 400 | ||
| 401 | #define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L))) | 401 | #define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L)) |
| 402 | |||
| 403 | |||
| 404 | #define checkstackGC(L,fsize) \ | ||
| 405 | luaD_checkstackaux(L, (fsize), (void)0, luaC_checkGC(L)) | ||
| 402 | 406 | ||
| 403 | 407 | ||
| 404 | /* | 408 | /* |
| @@ -413,7 +417,7 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { | |||
| 413 | int i; | 417 | int i; |
| 414 | for (i = 0; i < narg1; i++) /* move down function and arguments */ | 418 | for (i = 0; i < narg1; i++) /* move down function and arguments */ |
| 415 | setobjs2s(L, ci->func + i, func + i); | 419 | setobjs2s(L, ci->func + i, func + i); |
| 416 | luaD_checkstackaux(L, fsize, (void)0, luaC_checkGC(L)); | 420 | checkstackGC(L, fsize); |
| 417 | func = ci->func; /* moved-down function */ | 421 | func = ci->func; /* moved-down function */ |
| 418 | for (; narg1 <= nfixparams; narg1++) | 422 | for (; narg1 <= nfixparams; narg1++) |
| 419 | setnilvalue(s2v(func + narg1)); /* complete missing arguments */ | 423 | setnilvalue(s2v(func + narg1)); /* complete missing arguments */ |
| @@ -434,7 +438,8 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { | |||
| 434 | void luaD_call (lua_State *L, StkId func, int nresults) { | 438 | void luaD_call (lua_State *L, StkId func, int nresults) { |
| 435 | lua_CFunction f; | 439 | lua_CFunction f; |
| 436 | TValue *funcv = s2v(func); | 440 | TValue *funcv = s2v(func); |
| 437 | CallInfo *ci; | 441 | CallInfo *ci = next_ci(L); |
| 442 | ci->nresults = nresults; | ||
| 438 | switch (ttype(funcv)) { | 443 | switch (ttype(funcv)) { |
| 439 | case LUA_TCCL: /* C closure */ | 444 | case LUA_TCCL: /* C closure */ |
| 440 | f = clCvalue(funcv)->f; | 445 | f = clCvalue(funcv)->f; |
| @@ -444,12 +449,11 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
| 444 | Cfunc: { | 449 | Cfunc: { |
| 445 | int n; /* number of returns */ | 450 | int n; /* number of returns */ |
| 446 | checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ | 451 | checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ |
| 447 | ci = next_ci(L); /* now 'enter' new function */ | 452 | ci->callstatus = CIST_C; |
| 448 | ci->nresults = nresults; | ||
| 449 | ci->func = func; | ||
| 450 | ci->top = L->top + LUA_MINSTACK; | 453 | ci->top = L->top + LUA_MINSTACK; |
| 454 | ci->func = func; | ||
| 451 | lua_assert(ci->top <= L->stack_last); | 455 | lua_assert(ci->top <= L->stack_last); |
| 452 | ci->callstatus = CIST_C; | 456 | L->ci = ci; /* now 'enter' new function */ |
| 453 | if (L->hookmask & LUA_MASKCALL) | 457 | if (L->hookmask & LUA_MASKCALL) |
| 454 | luaD_hook(L, LUA_HOOKCALL, -1); | 458 | luaD_hook(L, LUA_HOOKCALL, -1); |
| 455 | lua_unlock(L); | 459 | lua_unlock(L); |
| @@ -464,16 +468,15 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
| 464 | int narg = cast_int(L->top - func) - 1; /* number of real arguments */ | 468 | int narg = cast_int(L->top - func) - 1; /* number of real arguments */ |
| 465 | int nfixparams = p->numparams; | 469 | int nfixparams = p->numparams; |
| 466 | int fsize = p->maxstacksize; /* frame size */ | 470 | int fsize = p->maxstacksize; /* frame size */ |
| 471 | ci->u.l.savedpc = p->code; /* starting point */ | ||
| 467 | checkstackp(L, fsize, func); | 472 | checkstackp(L, fsize, func); |
| 468 | for (; narg < nfixparams; narg++) | 473 | for (; narg < nfixparams; narg++) |
| 469 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ | 474 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ |
| 470 | ci = next_ci(L); /* now 'enter' new function */ | 475 | ci->callstatus = 0; |
| 471 | ci->nresults = nresults; | ||
| 472 | ci->func = func; | ||
| 473 | ci->top = func + 1 + fsize; | 476 | ci->top = func + 1 + fsize; |
| 477 | ci->func = func; | ||
| 478 | L->ci = ci; /* now 'enter' new function */ | ||
| 474 | lua_assert(ci->top <= L->stack_last); | 479 | lua_assert(ci->top <= L->stack_last); |
| 475 | ci->u.l.savedpc = p->code; /* starting point */ | ||
| 476 | ci->callstatus = 0; | ||
| 477 | luaV_execute(L, ci); /* run the function */ | 480 | luaV_execute(L, ci); /* run the function */ |
| 478 | break; | 481 | break; |
| 479 | } | 482 | } |
