Lines Matching refs:L

58 #define LUAI_THROW(L,c)		throw(c)  argument
59 #define LUAI_TRY(L,c,a) \ argument
66 #define LUAI_THROW(L,c) _longjmp((c)->b, 1) argument
67 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } argument
73 #define LUAI_THROW(L,c) longjmp((c)->b, 1) argument
74 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } argument
91 void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { in luaD_seterrorobj() argument
94 setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ in luaD_seterrorobj()
98 setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); 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()
114 l_noret luaD_throw (lua_State *L, int errcode) { in luaD_throw() argument
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()
120 global_State *g = G(L); 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()
124 setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ 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()
132 lua_unlock(L); in luaD_throw()
133 g->panic(L); /* call panic function (last chance to jump out) */ in luaD_throw()
141 int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { in luaD_rawrunprotected() argument
142 l_uint32 oldnCcalls = L->nCcalls; in luaD_rawrunprotected()
145 lj.previous = L->errorJmp; /* chain new error handler */ in luaD_rawrunprotected()
146 L->errorJmp = &lj; in luaD_rawrunprotected()
147 LUAI_TRY(L, &lj, in luaD_rawrunprotected()
148 (*f)(L, ud); in luaD_rawrunprotected()
150 L->errorJmp = lj.previous; /* restore old error handler */ in luaD_rawrunprotected()
151 L->nCcalls = oldnCcalls; in luaD_rawrunprotected()
163 static void correctstack (lua_State *L, StkId oldstack, StkId newstack) { in correctstack() argument
168 L->top = (L->top - oldstack) + newstack; in correctstack()
169 for (up = L->openupval; up != NULL; up = up->u.open.next) in correctstack()
171 for (ci = L->ci; ci != NULL; ci = ci->previous) { in correctstack()
184 int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { in luaD_reallocstack() argument
185 int lim = stacksize(L); in luaD_reallocstack()
186 StkId newstack = luaM_reallocvector(L, L->stack, in luaD_reallocstack()
191 luaM_error(L); in luaD_reallocstack()
196 correctstack(L, L->stack, newstack); in luaD_reallocstack()
197 L->stack = newstack; in luaD_reallocstack()
198 L->stack_last = L->stack + newsize; in luaD_reallocstack()
207 int luaD_growstack (lua_State *L, int n, int raiseerror) { in luaD_growstack() argument
208 int size = stacksize(L); in luaD_growstack()
213 lua_assert(stacksize(L) == ERRORSTACKSIZE); in luaD_growstack()
215 luaD_throw(L, LUA_ERRERR); /* error inside message handler */ in luaD_growstack()
220 int needed = cast_int(L->top - L->stack) + n; in luaD_growstack()
226 return luaD_reallocstack(L, newsize, raiseerror); in luaD_growstack()
229 luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); in luaD_growstack()
231 luaG_runerror(L, "stack overflow"); in luaD_growstack()
238 static int stackinuse (lua_State *L) { in stackinuse() argument
241 StkId lim = L->top; in stackinuse()
242 for (ci = L->ci; ci != NULL; ci = ci->previous) { in stackinuse()
245 lua_assert(lim <= L->stack_last); in stackinuse()
246 res = cast_int(lim - L->stack) + 1; /* part of stack in use */ in stackinuse()
262 void luaD_shrinkstack (lua_State *L) { in luaD_shrinkstack() argument
263 int inuse = stackinuse(L); in luaD_shrinkstack()
273 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) in luaD_shrinkstack()
274 luaD_reallocstack(L, nsize, 0); /* ok if that fails */ in luaD_shrinkstack()
276 condmovestack(L,{},{}); /* (change only for debugging) */ in luaD_shrinkstack()
277 luaE_shrinkCI(L); /* shrink CI list */ in luaD_shrinkstack()
281 void luaD_inctop (lua_State *L) { in luaD_inctop() argument
282 luaD_checkstack(L, 1); in luaD_inctop()
283 L->top++; in luaD_inctop()
294 void luaD_hook (lua_State *L, int event, int line, in luaD_hook() argument
296 lua_Hook hook = L->hook; in luaD_hook()
297 if (hook && L->allowhook) { /* make sure there is a hook */ in luaD_hook()
299 CallInfo *ci = L->ci; in luaD_hook()
300 ptrdiff_t top = savestack(L, L->top); in luaD_hook()
301 ptrdiff_t ci_top = savestack(L, ci->top); in luaD_hook()
311 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ in luaD_hook()
312 if (L->top + LUA_MINSTACK > ci->top) in luaD_hook()
313 ci->top = L->top + LUA_MINSTACK; in luaD_hook()
314 L->allowhook = 0; /* cannot call hooks inside a hook */ in luaD_hook()
316 lua_unlock(L); in luaD_hook()
317 (*hook)(L, &ar); in luaD_hook()
318 lua_lock(L); in luaD_hook()
319 lua_assert(!L->allowhook); in luaD_hook()
320 L->allowhook = 1; in luaD_hook()
321 ci->top = restorestack(L, ci_top); in luaD_hook()
322 L->top = restorestack(L, top); in luaD_hook()
333 void luaD_hookcall (lua_State *L, CallInfo *ci) { in luaD_hookcall() argument
336 if (!(L->hookmask & LUA_MASKCALL)) /* some other hook? */ in luaD_hookcall()
339 L->top = ci->top; /* prepare top */ in luaD_hookcall()
341 luaD_hook(L, hook, -1, 1, p->numparams); in luaD_hookcall()
346 static StkId rethook (lua_State *L, CallInfo *ci, StkId firstres, int nres) { in rethook() argument
347 ptrdiff_t oldtop = savestack(L, L->top); /* hook may change top */ in rethook()
353 if (L->top < ci->top) in rethook()
354 L->top = ci->top; /* correct top to run hook */ in rethook()
356 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ in rethook()
360 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ in rethook()
364 L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* update 'oldpc' */ in rethook()
365 return restorestack(L, oldtop); in rethook()
374 void luaD_tryfuncTM (lua_State *L, StkId func) { in luaD_tryfuncTM() argument
375 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); in luaD_tryfuncTM()
378 luaG_typeerror(L, s2v(func), "call"); /* nothing to call */ in luaD_tryfuncTM()
379 for (p = L->top; p > func; p--) /* open space for metamethod */ in luaD_tryfuncTM()
380 setobjs2s(L, p, p-1); in luaD_tryfuncTM()
381 L->top++; /* stack space pre-allocated by the caller */ in luaD_tryfuncTM()
382 setobj2s(L, func, tm); /* metamethod is the new function to be called */ in luaD_tryfuncTM()
392 static void moveresults (lua_State *L, StkId res, int nres, int wanted) { in moveresults() argument
397 L->top = res; in moveresults()
403 setobjs2s(L, res, L->top - nres); /* move it to proper place */ in moveresults()
404 L->top = res + 1; in moveresults()
411 ptrdiff_t savedres = savestack(L, res); in moveresults()
412 luaF_close(L, res, LUA_OK); /* may change the stack */ in moveresults()
413 res = restorestack(L, savedres); in moveresults()
420 firstresult = L->top - nres; /* index of first result */ in moveresults()
423 setobjs2s(L, res + i, firstresult + i); in moveresults()
426 L->top = res + wanted; /* top points after the last result */ in moveresults()
434 void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { in luaD_poscall() argument
435 if (L->hookmask) in luaD_poscall()
436 L->top = rethook(L, ci, L->top - nres, nres); in luaD_poscall()
437 L->ci = ci->previous; /* back to caller */ in luaD_poscall()
439 moveresults(L, ci->func, nres, ci->nresults); in luaD_poscall()
444 #define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L)) argument
452 void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { in luaD_pretailcall() argument
458 setobjs2s(L, ci->func + i, func + i); in luaD_pretailcall()
459 checkstackGC(L, fsize); in luaD_pretailcall()
464 lua_assert(ci->top <= L->stack_last); in luaD_pretailcall()
467 L->top = func + narg1; /* set top */ in luaD_pretailcall()
479 CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { in luaD_precall() argument
491 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ in luaD_precall()
492 L->ci = ci = next_ci(L); in luaD_precall()
495 ci->top = L->top + LUA_MINSTACK; in luaD_precall()
497 lua_assert(ci->top <= L->stack_last); in luaD_precall()
498 if (L->hookmask & LUA_MASKCALL) { in luaD_precall()
499 int narg = cast_int(L->top - func) - 1; in luaD_precall()
500 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg); in luaD_precall()
502 lua_unlock(L); in luaD_precall()
503 n = (*f)(L); /* do the actual call */ in luaD_precall()
504 lua_lock(L); in luaD_precall()
505 api_checknelems(L, n); in luaD_precall()
506 luaD_poscall(L, ci, n); in luaD_precall()
512 int narg = cast_int(L->top - func) - 1; /* number of real arguments */ in luaD_precall()
515 checkstackGCp(L, fsize, func); in luaD_precall()
516 L->ci = ci = next_ci(L); in luaD_precall()
521 L->ci = ci; in luaD_precall()
523 setnilvalue(s2v(L->top++)); /* complete missing arguments */ in luaD_precall()
524 lua_assert(ci->top <= L->stack_last); in luaD_precall()
528 checkstackGCp(L, 1, func); /* space for metamethod */ in luaD_precall()
529 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ in luaD_precall()
541 static void ccall (lua_State *L, StkId func, int nResults, int inc) { in ccall() argument
543 L->nCcalls += inc; in ccall()
544 if (unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) in ccall()
545 luaE_checkcstack(L); in ccall()
546 if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */ in ccall()
548 luaV_execute(L, ci); /* call it */ in ccall()
550 L->nCcalls -= inc; in ccall()
557 void luaD_call (lua_State *L, StkId func, int nResults) { in luaD_call() argument
558 ccall(L, func, nResults, 1); in luaD_call()
565 void luaD_callnoyield (lua_State *L, StkId func, int nResults) { in luaD_callnoyield() argument
566 ccall(L, func, nResults, nyci); in luaD_callnoyield()
574 static void finishCcall (lua_State *L, int status) { in finishCcall() argument
575 CallInfo *ci = L->ci; in finishCcall()
578 lua_assert(ci->u.c.k != NULL && yieldable(L)); in finishCcall()
583 L->errfunc = ci->u.c.old_errfunc; /* with the same error function */ in finishCcall()
587 adjustresults(L, ci->nresults); in finishCcall()
588 lua_unlock(L); in finishCcall()
589 n = (*ci->u.c.k)(L, status, ci->u.c.ctx); /* call continuation function */ in finishCcall()
590 lua_lock(L); in finishCcall()
591 api_checknelems(L, n); in finishCcall()
592 luaD_poscall(L, ci, n); /* finish 'luaD_call' */ in finishCcall()
604 static void unroll (lua_State *L, void *ud) { in unroll() argument
607 finishCcall(L, *(int *)ud); /* finish 'lua_pcallk' callee */ in unroll()
608 while ((ci = L->ci) != &L->base_ci) { /* something in the stack */ in unroll()
610 finishCcall(L, LUA_YIELD); /* complete its execution */ in unroll()
612 luaV_finishOp(L); /* finish interrupted instruction */ in unroll()
613 luaV_execute(L, ci); /* execute down to higher C 'boundary' */ in unroll()
623 static CallInfo *findpcall (lua_State *L) { in findpcall() argument
625 for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */ in findpcall()
638 static int recover (lua_State *L, int status) { in recover() argument
640 CallInfo *ci = findpcall(L); in recover()
643 oldtop = restorestack(L, ci->u2.funcidx); in recover()
644 L->ci = ci; in recover()
645 L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ in recover()
646 status = luaF_close(L, oldtop, status); /* may change the stack */ in recover()
647 oldtop = restorestack(L, ci->u2.funcidx); in recover()
648 luaD_seterrorobj(L, status, oldtop); in recover()
649 luaD_shrinkstack(L); /* restore stack size in case of overflow */ in recover()
650 L->errfunc = ci->u.c.old_errfunc; in recover()
660 static int resume_error (lua_State *L, const char *msg, int narg) { in resume_error() argument
661 L->top -= narg; /* remove args from the stack */ in resume_error()
662 setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */ in resume_error()
663 api_incr_top(L); in resume_error()
664 lua_unlock(L); in resume_error()
676 static void resume (lua_State *L, void *ud) { in resume() argument
678 StkId firstArg = L->top - n; /* first argument */ in resume()
679 CallInfo *ci = L->ci; in resume()
680 if (L->status == LUA_OK) /* starting a coroutine? */ in resume()
681 ccall(L, firstArg - 1, LUA_MULTRET, 1); /* just call its body */ in resume()
683 lua_assert(L->status == LUA_YIELD); in resume()
684 L->status = LUA_OK; /* mark that it is running (again) */ in resume()
685 luaE_incCstack(L); /* control the C stack */ in resume()
687 luaV_execute(L, ci); /* just continue running Lua code */ in resume()
690 lua_unlock(L); in resume()
691 n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */ in resume()
692 lua_lock(L); in resume()
693 api_checknelems(L, n); in resume()
695 luaD_poscall(L, ci, n); /* finish 'luaD_call' */ in resume()
697 unroll(L, NULL); /* run continuation */ in resume()
701 LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, in lua_resume() argument
704 lua_lock(L); in lua_resume()
705 if (L->status == LUA_OK) { /* may be starting a coroutine */ in lua_resume()
706 if (L->ci != &L->base_ci) /* not in base level? */ in lua_resume()
707 return resume_error(L, "cannot resume non-suspended coroutine", nargs); in lua_resume()
708 else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ in lua_resume()
709 return resume_error(L, "cannot resume dead coroutine", nargs); in lua_resume()
711 else if (L->status != LUA_YIELD) /* ended with errors? */ in lua_resume()
712 return resume_error(L, "cannot resume dead coroutine", nargs); in lua_resume()
713 L->nCcalls = (from) ? getCcalls(from) : 0; in lua_resume()
714 luai_userstateresume(L, nargs); in lua_resume()
715 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); in lua_resume()
716 status = luaD_rawrunprotected(L, resume, &nargs); in lua_resume()
718 while (errorstatus(status) && recover(L, status)) { in lua_resume()
720 status = luaD_rawrunprotected(L, unroll, &status); in lua_resume()
723 lua_assert(status == L->status); /* normal end or yield */ in lua_resume()
725 L->status = cast_byte(status); /* mark thread as 'dead' */ in lua_resume()
726 luaD_seterrorobj(L, status, L->top); /* push error message */ in lua_resume()
727 L->ci->top = L->top; in lua_resume()
729 *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield in lua_resume()
730 : cast_int(L->top - (L->ci->func + 1)); in lua_resume()
731 lua_unlock(L); in lua_resume()
736 LUA_API int lua_isyieldable (lua_State *L) { in lua_isyieldable() argument
737 return yieldable(L); in lua_isyieldable()
741 LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, in lua_yieldk() argument
744 luai_userstateyield(L, nresults); in lua_yieldk()
745 lua_lock(L); in lua_yieldk()
746 ci = L->ci; in lua_yieldk()
747 api_checknelems(L, nresults); in lua_yieldk()
748 if (unlikely(!yieldable(L))) { in lua_yieldk()
749 if (L != G(L)->mainthread) in lua_yieldk()
750 luaG_runerror(L, "attempt to yield across a C-call boundary"); in lua_yieldk()
752 luaG_runerror(L, "attempt to yield from outside a coroutine"); in lua_yieldk()
754 L->status = LUA_YIELD; in lua_yieldk()
757 api_check(L, k == NULL, "hooks cannot continue after yielding"); in lua_yieldk()
764 luaD_throw(L, LUA_YIELD); in lua_yieldk()
767 lua_unlock(L); in lua_yieldk()
777 int luaD_pcall (lua_State *L, Pfunc func, void *u, in luaD_pcall() argument
780 CallInfo *old_ci = L->ci; in luaD_pcall()
781 lu_byte old_allowhooks = L->allowhook; in luaD_pcall()
782 ptrdiff_t old_errfunc = L->errfunc; in luaD_pcall()
783 L->errfunc = ef; in luaD_pcall()
784 status = luaD_rawrunprotected(L, func, u); in luaD_pcall()
786 StkId oldtop = restorestack(L, old_top); in luaD_pcall()
787 L->ci = old_ci; in luaD_pcall()
788 L->allowhook = old_allowhooks; in luaD_pcall()
789 status = luaF_close(L, oldtop, status); in luaD_pcall()
790 oldtop = restorestack(L, old_top); /* previous call may change stack */ in luaD_pcall()
791 luaD_seterrorobj(L, status, oldtop); in luaD_pcall()
792 luaD_shrinkstack(L); /* restore stack size in case of overflow */ in luaD_pcall()
794 L->errfunc = old_errfunc; in luaD_pcall()
812 static void checkmode (lua_State *L, const char *mode, const char *x) { in checkmode() argument
814 luaO_pushfstring(L, in checkmode()
816 luaD_throw(L, LUA_ERRSYNTAX); in checkmode()
821 static void f_parser (lua_State *L, void *ud) { in f_parser() argument
826 checkmode(L, p->mode, "binary"); in f_parser()
827 cl = luaU_undump(L, p->z, p->name); in f_parser()
830 checkmode(L, p->mode, "text"); in f_parser()
831 cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); in f_parser()
834 luaF_initupvals(L, cl); in f_parser()
838 int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, in luaD_protectedparser() argument
842 incnny(L); /* cannot yield during parsing */ in luaD_protectedparser()
847 luaZ_initbuffer(L, &p.buff); in luaD_protectedparser()
848 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); in luaD_protectedparser()
849 luaZ_freebuffer(L, &p.buff); in luaD_protectedparser()
850 luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size); in luaD_protectedparser()
851 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); in luaD_protectedparser()
852 luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size); in luaD_protectedparser()
853 decnny(L); in luaD_protectedparser()