diff options
Diffstat (limited to '')
| -rw-r--r-- | ldo.c | 108 |
1 files changed, 54 insertions, 54 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.93 2011/02/23 13:13:10 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.94 2011/05/30 16:36:38 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 | */ |
| @@ -293,59 +293,59 @@ static StkId tryfuncTM (lua_State *L, StkId func) { | |||
| 293 | ** returns true if function has been executed (C function) | 293 | ** returns true if function has been executed (C function) |
| 294 | */ | 294 | */ |
| 295 | int luaD_precall (lua_State *L, StkId func, int nresults) { | 295 | int luaD_precall (lua_State *L, StkId func, int nresults) { |
| 296 | Closure *cl; | ||
| 297 | lua_CFunction f; | 296 | lua_CFunction f; |
| 298 | ptrdiff_t funcr; | 297 | CallInfo *ci; |
| 299 | if (!ttisfunction(func)) /* `func' is not a function? */ | 298 | int n; /* number of arguments (Lua) or returns (C) */ |
| 300 | func = tryfuncTM(L, func); /* check the `function' tag method */ | 299 | ptrdiff_t funcr = savestack(L, func); |
| 301 | funcr = savestack(L, func); | 300 | switch (ttype(func)) { |
| 302 | if (ttislcf(func) || (cl = clvalue(func), cl->c.isC)) { /* C function? */ | 301 | case LUA_TLCF: /* light C function */ |
| 303 | CallInfo *ci; | 302 | f = fvalue(func); |
| 304 | int n; | 303 | goto Cfunc; |
| 305 | f = (ttislcf(func) ? fvalue(func) : cl->c.f); | 304 | case LUA_TCCL: { /* C closure */ |
| 306 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 305 | f = clCvalue(func)->f; |
| 307 | ci = next_ci(L); /* now 'enter' new function */ | 306 | Cfunc: |
| 308 | ci->nresults = nresults; | 307 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
| 309 | ci->func = restorestack(L, funcr); | 308 | ci = next_ci(L); /* now 'enter' new function */ |
| 310 | ci->top = L->top + LUA_MINSTACK; | 309 | ci->nresults = nresults; |
| 311 | lua_assert(ci->top <= L->stack_last); | 310 | ci->func = restorestack(L, funcr); |
| 312 | ci->callstatus = 0; | 311 | ci->top = L->top + LUA_MINSTACK; |
| 313 | if (L->hookmask & LUA_MASKCALL) | 312 | lua_assert(ci->top <= L->stack_last); |
| 314 | luaD_hook(L, LUA_HOOKCALL, -1); | 313 | ci->callstatus = 0; |
| 315 | lua_unlock(L); | 314 | if (L->hookmask & LUA_MASKCALL) |
| 316 | n = (*f)(L); /* do the actual call */ | 315 | luaD_hook(L, LUA_HOOKCALL, -1); |
| 317 | lua_lock(L); | 316 | lua_unlock(L); |
| 318 | api_checknelems(L, n); | 317 | n = (*f)(L); /* do the actual call */ |
| 319 | luaD_poscall(L, L->top - n); | 318 | lua_lock(L); |
| 320 | return 1; | 319 | api_checknelems(L, n); |
| 321 | } | 320 | luaD_poscall(L, L->top - n); |
| 322 | else { /* Lua function: prepare its call */ | 321 | return 1; |
| 323 | CallInfo *ci; | 322 | } |
| 324 | int nparams, nargs; | 323 | case LUA_TLCL: { /* Lua function: prepare its call */ |
| 325 | StkId base; | 324 | StkId base; |
| 326 | Proto *p = cl->l.p; | 325 | Proto *p = clLvalue(func)->p; |
| 327 | luaD_checkstack(L, p->maxstacksize); | 326 | luaD_checkstack(L, p->maxstacksize); |
| 328 | func = restorestack(L, funcr); | 327 | func = restorestack(L, funcr); |
| 329 | nargs = cast_int(L->top - func) - 1; /* number of real arguments */ | 328 | n = cast_int(L->top - func) - 1; /* number of real arguments */ |
| 330 | nparams = p->numparams; /* number of expected parameters */ | 329 | for (; n < p->numparams; n++) |
| 331 | for (; nargs < nparams; nargs++) | 330 | setnilvalue(L->top++); /* complete missing arguments */ |
| 332 | setnilvalue(L->top++); /* complete missing arguments */ | 331 | base = (!p->is_vararg) ? func + 1 : adjust_varargs(L, p, n); |
| 333 | if (!p->is_vararg) /* no varargs? */ | 332 | ci = next_ci(L); /* now 'enter' new function */ |
| 334 | base = func + 1; | 333 | ci->nresults = nresults; |
| 335 | else /* vararg function */ | 334 | ci->func = func; |
| 336 | base = adjust_varargs(L, p, nargs); | 335 | ci->u.l.base = base; |
| 337 | ci = next_ci(L); /* now 'enter' new function */ | 336 | ci->top = base + p->maxstacksize; |
| 338 | ci->nresults = nresults; | 337 | lua_assert(ci->top <= L->stack_last); |
| 339 | ci->func = func; | 338 | ci->u.l.savedpc = p->code; /* starting point */ |
| 340 | ci->u.l.base = base; | 339 | ci->callstatus = CIST_LUA; |
| 341 | ci->top = base + p->maxstacksize; | 340 | L->top = ci->top; |
| 342 | lua_assert(ci->top <= L->stack_last); | 341 | if (L->hookmask & LUA_MASKCALL) |
| 343 | ci->u.l.savedpc = p->code; /* starting point */ | 342 | callhook(L, ci); |
| 344 | ci->callstatus = CIST_LUA; | 343 | return 0; |
| 345 | L->top = ci->top; | 344 | } |
| 346 | if (L->hookmask & LUA_MASKCALL) | 345 | default: { /* not a function */ |
| 347 | callhook(L, ci); | 346 | func = tryfuncTM(L, func); /* retry with 'function' tag method */ |
| 348 | return 0; | 347 | return luaD_precall(L, func, nresults); |
| 348 | } | ||
| 349 | } | 349 | } |
| 350 | } | 350 | } |
| 351 | 351 | ||
| @@ -626,7 +626,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
| 626 | setptvalue2s(L, L->top, tf); | 626 | setptvalue2s(L, L->top, tf); |
| 627 | incr_top(L); | 627 | incr_top(L); |
| 628 | cl = luaF_newLclosure(L, tf); | 628 | cl = luaF_newLclosure(L, tf); |
| 629 | setclvalue(L, L->top - 1, cl); | 629 | setclLvalue(L, L->top - 1, cl); |
| 630 | for (i = 0; i < tf->sizeupvalues; i++) /* initialize upvalues */ | 630 | for (i = 0; i < tf->sizeupvalues; i++) /* initialize upvalues */ |
| 631 | cl->l.upvals[i] = luaF_newupval(L); | 631 | cl->l.upvals[i] = luaF_newupval(L); |
| 632 | } | 632 | } |
