Lines Matching +full:- +full:- +full:ci

43 ** Error-recovery functions
60 try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
66 #define LUAI_THROW(L,c) _longjmp((c)->b, 1)
67 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
73 #define LUAI_THROW(L,c) longjmp((c)->b, 1)
74 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
94 setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ in luaD_seterrorobj()
106 setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ in luaD_seterrorobj()
110 L->top = oldtop + 1; in luaD_seterrorobj()
115 if (L->errorJmp) { /* thread has an error handler? */ in luaD_throw()
116 L->errorJmp->status = errcode; /* set status */ in luaD_throw()
117 LUAI_THROW(L, L->errorJmp); /* jump to it */ in luaD_throw()
121 errcode = luaF_close(L, L->stack, errcode); /* close all upvalues */ in luaD_throw()
122 L->status = cast_byte(errcode); /* mark it as dead */ in luaD_throw()
123 if (g->mainthread->errorJmp) { /* main thread has a handler? */ in luaD_throw()
124 setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ in luaD_throw()
125 luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ in luaD_throw()
128 if (g->panic) { /* panic function? */ in luaD_throw()
129 luaD_seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */ in luaD_throw()
130 if (L->ci->top < L->top) in luaD_throw()
131 L->ci->top = L->top; /* pushing msg. can break this invariant */ in luaD_throw()
133 g->panic(L); /* call panic function (last chance to jump out) */ in luaD_throw()
143 l_uint32 oldnCcalls = g->Cstacklimit - (L->nCcalls + L->nci); in luaD_rawrunprotected()
146 lj.previous = L->errorJmp; /* chain new error handler */ in luaD_rawrunprotected()
147 L->errorJmp = &lj; in luaD_rawrunprotected()
151 L->errorJmp = lj.previous; /* restore old error handler */ in luaD_rawrunprotected()
152 L->nCcalls = g->Cstacklimit - oldnCcalls - L->nci; in luaD_rawrunprotected()
165 CallInfo *ci; in correctstack() local
169 L->top = (L->top - oldstack) + newstack; in correctstack()
170 for (up = L->openupval; up != NULL; up = up->u.open.next) in correctstack()
171 up->v = s2v((uplevel(up) - oldstack) + newstack); in correctstack()
172 for (ci = L->ci; ci != NULL; ci = ci->previous) { in correctstack()
173 ci->top = (ci->top - oldstack) + newstack; in correctstack()
174 ci->func = (ci->func - oldstack) + newstack; in correctstack()
175 if (isLua(ci)) in correctstack()
176 ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */ in correctstack()
186 int lim = L->stacksize; in luaD_reallocstack()
187 StkId newstack = luaM_reallocvector(L, L->stack, lim, newsize, StackValue); in luaD_reallocstack()
189 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK); in luaD_reallocstack()
197 correctstack(L, L->stack, newstack); in luaD_reallocstack()
198 L->stack = newstack; in luaD_reallocstack()
199 L->stacksize = newsize; in luaD_reallocstack()
200 L->stack_last = L->stack + newsize - EXTRA_STACK; in luaD_reallocstack()
210 int size = L->stacksize; in luaD_growstack()
218 int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK; in luaD_growstack()
236 CallInfo *ci; in stackinuse() local
237 StkId lim = L->top; in stackinuse()
238 for (ci = L->ci; ci != NULL; ci = ci->previous) { in stackinuse()
239 if (lim < ci->top) lim = ci->top; in stackinuse()
241 lua_assert(lim <= L->stack_last); in stackinuse()
242 return cast_int(lim - L->stack) + 1; /* part of stack in use */ in stackinuse()
253 if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && goodsize < L->stacksize) in luaD_shrinkstack()
257 luaE_shrinkCI(L); /* shrink CI list */ in luaD_shrinkstack()
263 L->top++; in luaD_inctop()
271 ** called. (Both 'L->hook' and 'L->hookmask', which trigger this
276 lua_Hook hook = L->hook; in luaD_hook()
277 if (hook && L->allowhook) { /* make sure there is a hook */ in luaD_hook()
279 CallInfo *ci = L->ci; in luaD_hook() local
280 ptrdiff_t top = savestack(L, L->top); in luaD_hook()
281 ptrdiff_t ci_top = savestack(L, ci->top); in luaD_hook()
285 ar.i_ci = ci; in luaD_hook()
287 mask |= CIST_TRAN; /* 'ci' has transfer information */ in luaD_hook()
288 ci->u2.transferinfo.ftransfer = ftransfer; in luaD_hook()
289 ci->u2.transferinfo.ntransfer = ntransfer; in luaD_hook()
292 if (L->top + LUA_MINSTACK > ci->top) in luaD_hook()
293 ci->top = L->top + LUA_MINSTACK; in luaD_hook()
294 L->allowhook = 0; /* cannot call hooks inside a hook */ in luaD_hook()
295 ci->callstatus |= mask; in luaD_hook()
299 lua_assert(!L->allowhook); in luaD_hook()
300 L->allowhook = 1; in luaD_hook()
301 ci->top = restorestack(L, ci_top); in luaD_hook()
302 L->top = restorestack(L, top); in luaD_hook()
303 ci->callstatus &= ~mask; in luaD_hook()
313 void luaD_hookcall (lua_State *L, CallInfo *ci) { in luaD_hookcall() argument
314 int hook = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL : LUA_HOOKCALL; in luaD_hookcall()
316 if (!(L->hookmask & LUA_MASKCALL)) /* some other hook? */ in luaD_hookcall()
318 p = clLvalue(s2v(ci->func))->p; in luaD_hookcall()
319 L->top = ci->top; /* prepare top */ in luaD_hookcall()
320 ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ in luaD_hookcall()
321 luaD_hook(L, hook, -1, 1, p->numparams); in luaD_hookcall()
322 ci->u.l.savedpc--; /* correct 'pc' */ in luaD_hookcall()
326 static StkId rethook (lua_State *L, CallInfo *ci, StkId firstres, int nres) { in rethook() argument
327 ptrdiff_t oldtop = savestack(L, L->top); /* hook may change top */ in rethook()
329 if (isLuacode(ci)) { in rethook()
330 Proto *p = ci_func(ci)->p; in rethook()
331 if (p->is_vararg) in rethook()
332 delta = ci->u.l.nextraargs + p->numparams + 1; in rethook()
333 if (L->top < ci->top) in rethook()
334 L->top = ci->top; /* correct top to run hook */ in rethook()
336 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ in rethook()
338 ci->func += delta; /* if vararg, back to virtual 'func' */ in rethook()
339 ftransfer = cast(unsigned short, firstres - ci->func); in rethook()
340 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ in rethook()
341 ci->func -= delta; in rethook()
343 if (isLua(ci = ci->previous)) in rethook()
344 L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* update 'oldpc' */ in rethook()
359 for (p = L->top; p > func; p--) /* open space for metamethod */ in luaD_tryfuncTM()
360 setobjs2s(L, p, p-1); in luaD_tryfuncTM()
361 L->top++; /* stack space pre-allocated by the caller */ in luaD_tryfuncTM()
377 L->top = res; in moveresults()
383 setobjs2s(L, res, L->top - nres); /* move it to proper place */ in moveresults()
384 L->top = res + 1; in moveresults()
389 default: /* multiple results (or to-be-closed variables) */ in moveresults()
390 if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ in moveresults()
400 firstresult = L->top - nres; /* index of first result */ in moveresults()
406 L->top = res + wanted; /* top points after the last result */ in moveresults()
414 void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { in luaD_poscall() argument
415 if (L->hookmask) in luaD_poscall()
416 L->top = rethook(L, ci, L->top - nres, nres); in luaD_poscall()
417 L->ci = ci->previous; /* back to caller */ in luaD_poscall()
419 moveresults(L, ci->func, nres, ci->nresults); in luaD_poscall()
424 #define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L))
432 void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { in luaD_pretailcall() argument
433 Proto *p = clLvalue(s2v(func))->p; in luaD_pretailcall()
434 int fsize = p->maxstacksize; /* frame size */ in luaD_pretailcall()
435 int nfixparams = p->numparams; in luaD_pretailcall()
438 setobjs2s(L, ci->func + i, func + i); in luaD_pretailcall()
440 func = ci->func; /* moved-down function */ in luaD_pretailcall()
443 ci->top = func + 1 + fsize; /* top for new function */ in luaD_pretailcall()
444 lua_assert(ci->top <= L->stack_last); in luaD_pretailcall()
445 ci->u.l.savedpc = p->code; /* starting point */ in luaD_pretailcall()
446 ci->callstatus |= CIST_TAIL; in luaD_pretailcall()
447 L->top = func + narg1; /* set top */ in luaD_pretailcall()
462 f = clCvalue(s2v(func))->f; in luaD_call()
468 CallInfo *ci; in luaD_call() local
470 L->ci = ci = next_ci(L); in luaD_call()
471 ci->nresults = nresults; in luaD_call()
472 ci->callstatus = CIST_C; in luaD_call()
473 ci->top = L->top + LUA_MINSTACK; in luaD_call()
474 ci->func = func; in luaD_call()
475 lua_assert(ci->top <= L->stack_last); in luaD_call()
476 if (L->hookmask & LUA_MASKCALL) { in luaD_call()
477 int narg = cast_int(L->top - func) - 1; in luaD_call()
478 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg); in luaD_call()
484 luaD_poscall(L, ci, n); in luaD_call()
488 CallInfo *ci; in luaD_call() local
489 Proto *p = clLvalue(s2v(func))->p; in luaD_call()
490 int narg = cast_int(L->top - func) - 1; /* number of real arguments */ in luaD_call()
491 int nfixparams = p->numparams; in luaD_call()
492 int fsize = p->maxstacksize; /* frame size */ in luaD_call()
494 L->ci = ci = next_ci(L); in luaD_call()
495 ci->nresults = nresults; in luaD_call()
496 ci->u.l.savedpc = p->code; /* starting point */ in luaD_call()
497 ci->callstatus = 0; in luaD_call()
498 ci->top = func + 1 + fsize; in luaD_call()
499 ci->func = func; in luaD_call()
500 L->ci = ci; in luaD_call()
502 setnilvalue(s2v(L->top++)); /* complete missing arguments */ in luaD_call()
503 lua_assert(ci->top <= L->stack_last); in luaD_call()
504 luaV_execute(L, ci); /* run the function */ in luaD_call()
535 CallInfo *ci = L->ci; in finishCcall() local
538 lua_assert(ci->u.c.k != NULL && yieldable(L)); in finishCcall()
540 lua_assert((ci->callstatus & CIST_YPCALL) || status == LUA_YIELD); in finishCcall()
541 if (ci->callstatus & CIST_YPCALL) { /* was inside a pcall? */ in finishCcall()
542 ci->callstatus &= ~CIST_YPCALL; /* continuation is also inside it */ in finishCcall()
543 L->errfunc = ci->u.c.old_errfunc; /* with the same error function */ in finishCcall()
547 adjustresults(L, ci->nresults); in finishCcall()
549 n = (*ci->u.c.k)(L, status, ci->u.c.ctx); /* call continuation function */ in finishCcall()
552 luaD_poscall(L, ci, n); /* finish 'luaD_call' */ in finishCcall()
559 ** interruption long-jumps out of the loop). If the coroutine is
565 CallInfo *ci; in unroll() local
568 while ((ci = L->ci) != &L->base_ci) { /* something in the stack */ in unroll()
569 if (!isLua(ci)) /* C function? */ in unroll()
573 luaV_execute(L, ci); /* execute down to higher C 'boundary' */ in unroll()
584 CallInfo *ci; in findpcall() local
585 for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */ in findpcall()
586 if (ci->callstatus & CIST_YPCALL) in findpcall()
587 return ci; in findpcall()
600 CallInfo *ci = findpcall(L); in recover() local
601 if (ci == NULL) return 0; /* no recovery point */ in recover()
603 oldtop = restorestack(L, ci->u2.funcidx); in recover()
605 oldtop = restorestack(L, ci->u2.funcidx); in recover()
607 L->ci = ci; in recover()
608 L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ in recover()
610 L->errfunc = ci->u.c.old_errfunc; in recover()
621 L->top -= narg; /* remove args from the stack */ in resume_error()
622 setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */ in resume_error()
633 ** function), plus erroneous cases: non-suspended coroutine or dead
638 StkId firstArg = L->top - n; /* first argument */ in resume()
639 CallInfo *ci = L->ci; in resume() local
640 if (L->status == LUA_OK) { /* starting a coroutine? */ in resume()
641 luaD_call(L, firstArg - 1, LUA_MULTRET); in resume()
644 lua_assert(L->status == LUA_YIELD); in resume()
645 L->status = LUA_OK; /* mark that it is running (again) */ in resume()
646 if (isLua(ci)) /* yielded inside a hook? */ in resume()
647 luaV_execute(L, ci); /* just continue running Lua code */ in resume()
649 if (ci->u.c.k != NULL) { /* does it have a continuation function? */ in resume()
651 n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */ in resume()
655 luaD_poscall(L, ci, n); /* finish 'luaD_call' */ in resume()
665 if (L->status == LUA_OK) { /* may be starting a coroutine */ in lua_resume()
666 if (L->ci != &L->base_ci) /* not in base level? */ in lua_resume()
667 return resume_error(L, "cannot resume non-suspended coroutine", nargs); in lua_resume()
668 else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ in lua_resume()
671 else if (L->status != LUA_YIELD) /* ended with errors? */ in lua_resume()
674 L->nCcalls = CSTACKTHREAD; in lua_resume()
676 L->nCcalls = getCcalls(from) - L->nci - CSTACKCF; in lua_resume()
677 if (L->nCcalls <= CSTACKERR) in lua_resume()
680 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); in lua_resume()
688 lua_assert(status == L->status); /* normal end or yield */ in lua_resume()
690 L->status = cast_byte(status); /* mark thread as 'dead' */ in lua_resume()
691 luaD_seterrorobj(L, status, L->top); /* push error message */ in lua_resume()
692 L->ci->top = L->top; in lua_resume()
694 *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield in lua_resume()
695 : cast_int(L->top - (L->ci->func + 1)); in lua_resume()
708 CallInfo *ci; in lua_yieldk() local
711 ci = L->ci; in lua_yieldk()
714 if (L != G(L)->mainthread) in lua_yieldk()
715 luaG_runerror(L, "attempt to yield across a C-call boundary"); in lua_yieldk()
719 L->status = LUA_YIELD; in lua_yieldk()
720 if (isLua(ci)) { /* inside a hook? */ in lua_yieldk()
721 lua_assert(!isLuacode(ci)); in lua_yieldk()
723 ci->u2.nyield = 0; /* no results */ in lua_yieldk()
726 if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ in lua_yieldk()
727 ci->u.c.ctx = ctx; /* save context */ in lua_yieldk()
728 ci->u2.nyield = nresults; /* save number of results */ in lua_yieldk()
731 lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ in lua_yieldk()
745 CallInfo *old_ci = L->ci; in luaD_pcall()
746 lu_byte old_allowhooks = L->allowhook; in luaD_pcall()
747 ptrdiff_t old_errfunc = L->errfunc; in luaD_pcall()
748 L->errfunc = ef; in luaD_pcall()
752 L->ci = old_ci; in luaD_pcall()
753 L->allowhook = old_allowhooks; in luaD_pcall()
759 L->errfunc = old_errfunc; in luaD_pcall()
789 int c = zgetc(p->z); /* read first character */ in f_parser()
791 checkmode(L, p->mode, "binary"); in f_parser()
792 cl = luaU_undump(L, p->z, p->name); in f_parser()
795 checkmode(L, p->mode, "text"); in f_parser()
796 cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); in f_parser()
798 lua_assert(cl->nupvalues == cl->p->sizeupvalues); in f_parser()
813 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); in luaD_protectedparser()