Lines Matching refs:L
97 #define LUAI_THROW(L,c) longjmp(&(c)->b) argument
98 #define LUAI_TRY(L,c,a) if (setjmp(&(c)->b) == 0) { a } argument
112 #define LUAI_THROW(L,c) longjmp((c)->b, 1) argument
113 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } argument
121 #define LUAI_THROW(L,c) throw(c) argument
122 #define LUAI_TRY(L,c,a) \ argument
128 #define LUAI_THROW(L,c) _longjmp((c)->b, 1) argument
129 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } argument
134 #define LUAI_THROW(L,c) longjmp((c)->b, 1) argument
135 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } argument
153 static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { in seterrorobj() argument
156 setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ in seterrorobj()
160 setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); in seterrorobj()
164 setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ in seterrorobj()
168 L->top = oldtop + 1; in seterrorobj()
172 l_noret luaD_throw (lua_State *L, int errcode) { in luaD_throw() argument
173 if (L->errorJmp) { /* thread has an error handler? */ in luaD_throw()
174 L->errorJmp->status = errcode; /* set status */ in luaD_throw()
175 LUAI_THROW(L, L->errorJmp); /* jump to it */ in luaD_throw()
178 L->status = cast_byte(errcode); /* mark it as dead */ in luaD_throw()
179 if (G(L)->mainthread->errorJmp) { /* main thread has a handler? */ in luaD_throw()
180 setobjs2s(L, G(L)->mainthread->top++, L->top - 1); /* copy error obj. */ in luaD_throw()
181 luaD_throw(G(L)->mainthread, errcode); /* re-throw in main thread */ in luaD_throw()
184 if (G(L)->panic) { /* panic function? */ in luaD_throw()
185 lua_unlock(L); in luaD_throw()
186 G(L)->panic(L); /* call it (last chance to jump out) */ in luaD_throw()
194 int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { in luaD_rawrunprotected() argument
195 unsigned short oldnCcalls = L->nCcalls; in luaD_rawrunprotected()
198 lj.previous = L->errorJmp; /* chain new error handler */ in luaD_rawrunprotected()
199 L->errorJmp = &lj; in luaD_rawrunprotected()
200 LUAI_TRY(L, &lj, in luaD_rawrunprotected()
201 (*f)(L, ud); in luaD_rawrunprotected()
203 L->errorJmp = lj.previous; /* restore old error handler */ in luaD_rawrunprotected()
204 L->nCcalls = oldnCcalls; in luaD_rawrunprotected()
211 static void correctstack (lua_State *L, TValue *oldstack) { in correctstack() argument
214 L->top = (L->top - oldstack) + L->stack; in correctstack()
215 for (up = L->openupval; up != NULL; up = up->gch.next) in correctstack()
216 gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; in correctstack()
217 for (ci = L->ci; ci != NULL; ci = ci->previous) { in correctstack()
218 ci->top = (ci->top - oldstack) + L->stack; in correctstack()
219 ci->func = (ci->func - oldstack) + L->stack; in correctstack()
221 ci->u.l.base = (ci->u.l.base - oldstack) + L->stack; in correctstack()
230 void luaD_reallocstack (lua_State *L, int newsize) { in luaD_reallocstack() argument
231 TValue *oldstack = L->stack; in luaD_reallocstack()
232 int lim = L->stacksize; in luaD_reallocstack()
234 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK); in luaD_reallocstack()
235 luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue); in luaD_reallocstack()
237 setnilvalue(L->stack + lim); /* erase new segment */ in luaD_reallocstack()
238 L->stacksize = newsize; in luaD_reallocstack()
239 L->stack_last = L->stack + newsize - EXTRA_STACK; in luaD_reallocstack()
240 correctstack(L, oldstack); in luaD_reallocstack()
244 void luaD_growstack (lua_State *L, int n) { in luaD_growstack() argument
245 int size = L->stacksize; in luaD_growstack()
247 luaD_throw(L, LUA_ERRERR); in luaD_growstack()
249 int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK; in luaD_growstack()
254 luaD_reallocstack(L, ERRORSTACKSIZE); in luaD_growstack()
255 luaG_runerror(L, "stack overflow"); in luaD_growstack()
258 luaD_reallocstack(L, newsize); in luaD_growstack()
263 static int stackinuse (lua_State *L) { in stackinuse() argument
265 StkId lim = L->top; in stackinuse()
266 for (ci = L->ci; ci != NULL; ci = ci->previous) { in stackinuse()
267 lua_assert(ci->top <= L->stack_last); in stackinuse()
270 return cast_int(lim - L->stack) + 1; /* part of stack in use */ in stackinuse()
274 void luaD_shrinkstack (lua_State *L) { in luaD_shrinkstack() argument
275 int inuse = stackinuse(L); in luaD_shrinkstack()
279 goodsize >= L->stacksize) /* would grow instead of shrink? */ in luaD_shrinkstack()
280 condmovestack(L); /* don't change stack (change only for debugging) */ in luaD_shrinkstack()
282 luaD_reallocstack(L, goodsize); /* shrink it */ in luaD_shrinkstack()
286 void luaD_hook (lua_State *L, int event, int line) { in luaD_hook() argument
287 lua_Hook hook = L->hook; in luaD_hook()
288 if (hook && L->allowhook) { in luaD_hook()
289 CallInfo *ci = L->ci; in luaD_hook()
290 ptrdiff_t top = savestack(L, L->top); in luaD_hook()
291 ptrdiff_t ci_top = savestack(L, ci->top); in luaD_hook()
296 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ in luaD_hook()
297 ci->top = L->top + LUA_MINSTACK; in luaD_hook()
298 lua_assert(ci->top <= L->stack_last); in luaD_hook()
299 L->allowhook = 0; /* cannot call hooks inside a hook */ in luaD_hook()
301 lua_unlock(L); in luaD_hook()
302 (*hook)(L, &ar); in luaD_hook()
303 lua_lock(L); in luaD_hook()
304 lua_assert(!L->allowhook); in luaD_hook()
305 L->allowhook = 1; in luaD_hook()
306 ci->top = restorestack(L, ci_top); in luaD_hook()
307 L->top = restorestack(L, top); in luaD_hook()
313 static void callhook (lua_State *L, CallInfo *ci) { in callhook() argument
321 luaD_hook(L, hook, -1); in callhook()
326 static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { in adjust_varargs() argument
332 luaD_checkstack(L, p->maxstacksize); /* check again for new 'base' */ in adjust_varargs()
333 fixed = L->top - actual; /* first fixed argument */ in adjust_varargs()
334 base = L->top; /* final position of first argument */ in adjust_varargs()
336 setobjs2s(L, L->top++, fixed + i); in adjust_varargs()
343 static StkId tryfuncTM (lua_State *L, StkId func) { in tryfuncTM() argument
344 const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); in tryfuncTM()
346 ptrdiff_t funcr = savestack(L, func); in tryfuncTM()
348 luaG_typeerror(L, func, "call"); in tryfuncTM()
350 for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); in tryfuncTM()
351 incr_top(L); in tryfuncTM()
352 func = restorestack(L, funcr); /* previous call may change stack */ in tryfuncTM()
353 setobj2s(L, func, tm); /* tag method is the new function to be called */ in tryfuncTM()
359 #define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L))) argument
365 int luaD_precall (lua_State *L, StkId func, int nresults) { in luaD_precall() argument
369 ptrdiff_t funcr = savestack(L, func); in luaD_precall()
377 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ in luaD_precall()
378 ci = next_ci(L); /* now 'enter' new function */ in luaD_precall()
380 ci->func = restorestack(L, funcr); in luaD_precall()
381 ci->top = L->top + LUA_MINSTACK; in luaD_precall()
382 lua_assert(ci->top <= L->stack_last); in luaD_precall()
384 luaC_checkGC(L); /* stack grow uses memory */ in luaD_precall()
385 if (L->hookmask & LUA_MASKCALL) in luaD_precall()
386 luaD_hook(L, LUA_HOOKCALL, -1); in luaD_precall()
387 lua_unlock(L); in luaD_precall()
388 n = (*f)(L); /* do the actual call */ in luaD_precall()
389 lua_lock(L); in luaD_precall()
390 api_checknelems(L, n); in luaD_precall()
391 luaD_poscall(L, L->top - n); in luaD_precall()
397 n = cast_int(L->top - func) - 1; /* number of real arguments */ in luaD_precall()
398 luaD_checkstack(L, p->maxstacksize); in luaD_precall()
400 setnilvalue(L->top++); /* complete missing arguments */ in luaD_precall()
402 func = restorestack(L, funcr); in luaD_precall()
406 base = adjust_varargs(L, p, n); in luaD_precall()
407 func = restorestack(L, funcr); /* previous call can change stack */ in luaD_precall()
409 ci = next_ci(L); /* now 'enter' new function */ in luaD_precall()
414 lua_assert(ci->top <= L->stack_last); in luaD_precall()
417 L->top = ci->top; in luaD_precall()
418 luaC_checkGC(L); /* stack grow uses memory */ in luaD_precall()
419 if (L->hookmask & LUA_MASKCALL) in luaD_precall()
420 callhook(L, ci); in luaD_precall()
424 func = tryfuncTM(L, func); /* retry with 'function' tag method */ in luaD_precall()
425 return luaD_precall(L, func, nresults); /* now it must be a function */ in luaD_precall()
431 int luaD_poscall (lua_State *L, StkId firstResult) { in luaD_poscall() argument
434 CallInfo *ci = L->ci; in luaD_poscall()
435 if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) { in luaD_poscall()
436 if (L->hookmask & LUA_MASKRET) { in luaD_poscall()
437 ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */ in luaD_poscall()
438 luaD_hook(L, LUA_HOOKRET, -1); in luaD_poscall()
439 firstResult = restorestack(L, fr); in luaD_poscall()
441 L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */ in luaD_poscall()
445 L->ci = ci = ci->previous; /* back to caller */ in luaD_poscall()
447 for (i = wanted; i != 0 && firstResult < L->top; i--) in luaD_poscall()
448 setobjs2s(L, res++, firstResult++); in luaD_poscall()
451 L->top = res; in luaD_poscall()
462 void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) { in luaD_call() argument
463 if (++L->nCcalls >= LUAI_MAXCCALLS) { in luaD_call()
464 if (L->nCcalls == LUAI_MAXCCALLS) in luaD_call()
465 luaG_runerror(L, "C stack overflow"); in luaD_call()
466 else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) in luaD_call()
467 luaD_throw(L, LUA_ERRERR); /* error while handling stack error */ in luaD_call()
470 if (L->runerror == 0 && remaining < LUAI_MINCSTACK) in luaD_call()
471 luaG_runerror(L, "C stack overflow"); in luaD_call()
472 if (L->runerror != 0 && remaining < LUAI_MINCSTACK / 2) in luaD_call()
473 luaD_throw(L, LUA_ERRERR); /* error while handling stack error */ in luaD_call()
474 if (!allowyield) L->nny++; in luaD_call()
475 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ in luaD_call()
476 luaV_execute(L); /* call it */ in luaD_call()
477 if (!allowyield) L->nny--; in luaD_call()
478 L->nCcalls--; in luaD_call()
482 static void finishCcall (lua_State *L) { in finishCcall() argument
483 CallInfo *ci = L->ci; in finishCcall()
486 lua_assert(L->nny == 0); in finishCcall()
489 L->errfunc = ci->u.c.old_errfunc; in finishCcall()
492 adjustresults(L, ci->nresults); in finishCcall()
498 lua_unlock(L); in finishCcall()
499 n = (*ci->u.c.k)(L); in finishCcall()
500 lua_lock(L); in finishCcall()
501 api_checknelems(L, n); in finishCcall()
503 luaD_poscall(L, L->top - n); in finishCcall()
507 static void unroll (lua_State *L, void *ud) { in unroll() argument
510 if (L->ci == &L->base_ci) /* stack is empty? */ in unroll()
512 if (!isLua(L->ci)) /* C function? */ in unroll()
513 finishCcall(L); in unroll()
515 luaV_finishOp(L); /* finish interrupted instruction */ in unroll()
516 luaV_execute(L); /* execute down to higher C 'boundary' */ in unroll()
525 static CallInfo *findpcall (lua_State *L) { in findpcall() argument
527 for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */ in findpcall()
535 static int recover (lua_State *L, int status) { in recover() argument
537 CallInfo *ci = findpcall(L); in recover()
540 oldtop = restorestack(L, ci->extra); in recover()
541 luaF_close(L, oldtop); in recover()
542 seterrorobj(L, status, oldtop); in recover()
543 L->ci = ci; in recover()
544 L->allowhook = ci->u.c.old_allowhook; in recover()
545 L->nny = 0; /* should be zero to be yieldable */ in recover()
546 luaD_shrinkstack(L); in recover()
547 L->errfunc = ci->u.c.old_errfunc; in recover()
559 static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) { in resume_error() argument
560 L->top = firstArg; /* remove args from the stack */ in resume_error()
561 setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */ in resume_error()
562 api_incr_top(L); in resume_error()
563 luaD_throw(L, -1); /* jump back to 'lua_resume' */ in resume_error()
570 static void resume_cb (lua_State *L, void *ud) { in resume_cb() argument
571 int nCcalls = L->nCcalls; in resume_cb()
573 CallInfo *ci = L->ci; in resume_cb()
575 resume_error(L, "C stack overflow", firstArg); in resume_cb()
576 if (L->status == LUA_OK) { /* may be starting a coroutine */ in resume_cb()
577 if (ci != &L->base_ci) /* not in base level? */ in resume_cb()
578 resume_error(L, "cannot resume non-suspended coroutine", firstArg); in resume_cb()
580 if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */ in resume_cb()
581 luaV_execute(L); /* call it */ in resume_cb()
583 else if (L->status != LUA_YIELD) in resume_cb()
584 resume_error(L, "cannot resume dead coroutine", firstArg); in resume_cb()
586 L->status = LUA_OK; in resume_cb()
587 ci->func = restorestack(L, ci->extra); in resume_cb()
589 luaV_execute(L); /* just continue running Lua code */ in resume_cb()
595 lua_unlock(L); in resume_cb()
596 n = (*ci->u.c.k)(L); /* call continuation */ in resume_cb()
597 lua_lock(L); in resume_cb()
598 api_checknelems(L, n); in resume_cb()
599 firstArg = L->top - n; /* yield results come from continuation */ in resume_cb()
601 luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ in resume_cb()
603 unroll(L, NULL); in resume_cb()
605 lua_assert(nCcalls == L->nCcalls); in resume_cb()
609 LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) { in lua_resume() argument
611 int oldnny = L->nny; /* save 'nny' */ in lua_resume()
612 lua_lock(L); in lua_resume()
613 luai_userstateresume(L, nargs); in lua_resume()
614 L->nCcalls = (from) ? from->nCcalls + 1 : 1; in lua_resume()
615 L->nny = 0; /* allow yields */ in lua_resume()
616 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); in lua_resume()
617 status = luaD_rawrunprotected(L, resume_cb, L->top - nargs); in lua_resume()
622 if (recover(L, status)) /* recover point? */ in lua_resume()
623 status = luaD_rawrunprotected(L, unroll, NULL); /* run continuation */ in lua_resume()
625 L->status = cast_byte(status); /* mark thread as `dead' */ in lua_resume()
626 seterrorobj(L, status, L->top); in lua_resume()
627 L->ci->top = L->top; in lua_resume()
631 lua_assert(status == L->status); in lua_resume()
633 L->nny = oldnny; /* restore 'nny' */ in lua_resume()
634 L->nCcalls--; in lua_resume()
635 lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0)); in lua_resume()
636 lua_unlock(L); in lua_resume()
641 LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) { in lua_yieldk() argument
642 CallInfo *ci = L->ci; in lua_yieldk()
643 luai_userstateyield(L, nresults); in lua_yieldk()
644 lua_lock(L); in lua_yieldk()
645 api_checknelems(L, nresults); in lua_yieldk()
646 if (L->nny > 0) { in lua_yieldk()
647 if (L != G(L)->mainthread) in lua_yieldk()
648 luaG_runerror(L, "attempt to yield across a C-call boundary"); in lua_yieldk()
650 luaG_runerror(L, "attempt to yield from outside a coroutine"); in lua_yieldk()
652 L->status = LUA_YIELD; in lua_yieldk()
653 ci->extra = savestack(L, ci->func); /* save current 'func' */ in lua_yieldk()
655 api_check(L, k == NULL, "hooks cannot continue after yielding"); in lua_yieldk()
660 ci->func = L->top - nresults - 1; /* protect stack below results */ in lua_yieldk()
661 luaD_throw(L, LUA_YIELD); in lua_yieldk()
664 lua_unlock(L); in lua_yieldk()
669 int luaD_pcall (lua_State *L, Pfunc func, void *u, in luaD_pcall() argument
672 CallInfo *old_ci = L->ci; in luaD_pcall()
673 lu_byte old_allowhooks = L->allowhook; in luaD_pcall()
674 unsigned short old_nny = L->nny; in luaD_pcall()
675 ptrdiff_t old_errfunc = L->errfunc; in luaD_pcall()
676 L->errfunc = ef; in luaD_pcall()
677 status = luaD_rawrunprotected(L, func, u); in luaD_pcall()
679 StkId oldtop = restorestack(L, old_top); in luaD_pcall()
680 luaF_close(L, oldtop); /* close possible pending closures */ in luaD_pcall()
681 seterrorobj(L, status, oldtop); in luaD_pcall()
682 L->ci = old_ci; in luaD_pcall()
683 L->allowhook = old_allowhooks; in luaD_pcall()
684 L->nny = old_nny; in luaD_pcall()
685 luaD_shrinkstack(L); in luaD_pcall()
687 L->errfunc = old_errfunc; in luaD_pcall()
705 static void checkmode (lua_State *L, const char *mode, const char *x) { in checkmode() argument
707 luaO_pushfstring(L, in checkmode()
709 luaD_throw(L, LUA_ERRSYNTAX); in checkmode()
714 static void f_parser (lua_State *L, void *ud) { in f_parser() argument
720 checkmode(L, p->mode, "text"); in f_parser()
721 cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); in f_parser()
724 UpVal *up = luaF_newupval(L); in f_parser()
726 luaC_objbarrier(L, cl, up); in f_parser()
731 int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, in luaD_protectedparser() argument
735 L->nny++; /* cannot yield during parsing */ in luaD_protectedparser()
740 luaZ_initbuffer(L, &p.buff); in luaD_protectedparser()
741 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); in luaD_protectedparser()
742 luaZ_freebuffer(L, &p.buff); in luaD_protectedparser()
743 luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size); in luaD_protectedparser()
744 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); in luaD_protectedparser()
745 luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size); in luaD_protectedparser()
746 L->nny--; in luaD_protectedparser()