Lines Matching refs:L

51 void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {  in luaD_seterrorobj()  argument
54 setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); in luaD_seterrorobj()
58 setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); in luaD_seterrorobj()
63 setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ in luaD_seterrorobj()
67 L->top = oldtop + 1; in luaD_seterrorobj()
71 static void restore_stack_limit (lua_State *L) { in restore_stack_limit() argument
72 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); in restore_stack_limit()
73 if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ in restore_stack_limit()
74 int inuse = cast_int(L->ci - L->base_ci); in restore_stack_limit()
76 luaD_reallocCI(L, LUAI_MAXCALLS); in restore_stack_limit()
81 static void resetstack (lua_State *L, int status) { in resetstack() argument
82 L->ci = L->base_ci; in resetstack()
83 L->base = L->ci->base; in resetstack()
84 luaF_close(L, L->base); /* close eventual pending closures */ in resetstack()
85 luaD_seterrorobj(L, status, L->base); in resetstack()
86 L->nCcalls = L->baseCcalls; in resetstack()
87 L->allowhook = 1; in resetstack()
88 restore_stack_limit(L); in resetstack()
89 L->errfunc = 0; in resetstack()
90 L->errorJmp = NULL; in resetstack()
94 void luaD_throw (lua_State *L, int errcode) { in luaD_throw() argument
95 if (L->errorJmp) { in luaD_throw()
96 L->errorJmp->status = errcode; in luaD_throw()
97 LUAI_THROW(L, L->errorJmp); in luaD_throw()
100 L->status = cast_byte(errcode); in luaD_throw()
101 if (G(L)->panic) { in luaD_throw()
102 resetstack(L, errcode); in luaD_throw()
103 lua_unlock(L); in luaD_throw()
104 G(L)->panic(L); in luaD_throw()
111 int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { in luaD_rawrunprotected() argument
114 lj.previous = L->errorJmp; /* chain new error handler */ in luaD_rawrunprotected()
115 L->errorJmp = &lj; in luaD_rawrunprotected()
116 LUAI_TRY(L, &lj, in luaD_rawrunprotected()
117 (*f)(L, ud); in luaD_rawrunprotected()
119 L->errorJmp = lj.previous; /* restore old error handler */ in luaD_rawrunprotected()
126 static void correctstack (lua_State *L, TValue *oldstack) { in correctstack() argument
129 L->top = (L->top - oldstack) + L->stack; in correctstack()
130 for (up = L->openupval; up != NULL; up = up->gch.next) in correctstack()
131 gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; in correctstack()
132 for (ci = L->base_ci; ci <= L->ci; ci++) { in correctstack()
133 ci->top = (ci->top - oldstack) + L->stack; in correctstack()
134 ci->base = (ci->base - oldstack) + L->stack; in correctstack()
135 ci->func = (ci->func - oldstack) + L->stack; in correctstack()
137 L->base = (L->base - oldstack) + L->stack; in correctstack()
141 void luaD_reallocstack (lua_State *L, int newsize) { in luaD_reallocstack() argument
142 TValue *oldstack = L->stack; in luaD_reallocstack()
144 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); in luaD_reallocstack()
145 luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); in luaD_reallocstack()
146 L->stacksize = realsize; in luaD_reallocstack()
147 L->stack_last = L->stack+newsize; in luaD_reallocstack()
148 correctstack(L, oldstack); in luaD_reallocstack()
152 void luaD_reallocCI (lua_State *L, int newsize) { in luaD_reallocCI() argument
153 CallInfo *oldci = L->base_ci; in luaD_reallocCI()
154 luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); in luaD_reallocCI()
155 L->size_ci = newsize; in luaD_reallocCI()
156 L->ci = (L->ci - oldci) + L->base_ci; in luaD_reallocCI()
157 L->end_ci = L->base_ci + L->size_ci - 1; in luaD_reallocCI()
161 void luaD_growstack (lua_State *L, int n) { in luaD_growstack() argument
162 if (n <= L->stacksize) /* double size is enough? */ in luaD_growstack()
163 luaD_reallocstack(L, 2*L->stacksize); in luaD_growstack()
165 luaD_reallocstack(L, L->stacksize + n); in luaD_growstack()
169 static CallInfo *growCI (lua_State *L) { in growCI() argument
170 if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ in growCI()
171 luaD_throw(L, LUA_ERRERR); in growCI()
173 luaD_reallocCI(L, 2*L->size_ci); in growCI()
174 if (L->size_ci > LUAI_MAXCALLS) in growCI()
175 luaG_runerror(L, "stack overflow"); in growCI()
177 return ++L->ci; in growCI()
181 void luaD_callhook (lua_State *L, int event, int line) { in luaD_callhook() argument
182 lua_Hook hook = L->hook; in luaD_callhook()
183 if (hook && L->allowhook) { in luaD_callhook()
184 ptrdiff_t top = savestack(L, L->top); in luaD_callhook()
185 ptrdiff_t ci_top = savestack(L, L->ci->top); in luaD_callhook()
192 ar.i_ci = cast_int(L->ci - L->base_ci); in luaD_callhook()
193 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ in luaD_callhook()
194 L->ci->top = L->top + LUA_MINSTACK; in luaD_callhook()
195 lua_assert(L->ci->top <= L->stack_last); in luaD_callhook()
196 L->allowhook = 0; /* cannot call hooks inside a hook */ in luaD_callhook()
197 lua_unlock(L); in luaD_callhook()
198 (*hook)(L, &ar); in luaD_callhook()
199 lua_lock(L); in luaD_callhook()
200 lua_assert(!L->allowhook); in luaD_callhook()
201 L->allowhook = 1; in luaD_callhook()
202 L->ci->top = restorestack(L, ci_top); in luaD_callhook()
203 L->top = restorestack(L, top); in luaD_callhook()
208 static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { in adjust_varargs() argument
214 setnilvalue(L->top++); in adjust_varargs()
219 luaC_checkGC(L); in adjust_varargs()
220 luaD_checkstack(L, p->maxstacksize); in adjust_varargs()
221 htab = luaH_new(L, nvar, 1); /* create `arg' table */ in adjust_varargs()
223 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); in adjust_varargs()
225 setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); in adjust_varargs()
229 fixed = L->top - actual; /* first fixed argument */ in adjust_varargs()
230 base = L->top; /* final position of first argument */ in adjust_varargs()
232 setobjs2s(L, L->top++, fixed+i); in adjust_varargs()
237 sethvalue(L, L->top++, htab); in adjust_varargs()
244 static StkId tryfuncTM (lua_State *L, StkId func) { in tryfuncTM() argument
245 const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); in tryfuncTM()
247 ptrdiff_t funcr = savestack(L, func); in tryfuncTM()
249 luaG_typeerror(L, func, "call"); in tryfuncTM()
251 for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); in tryfuncTM()
252 incr_top(L); in tryfuncTM()
253 func = restorestack(L, funcr); /* previous call may change stack */ in tryfuncTM()
254 setobj2s(L, func, tm); /* tag method is the new function to be called */ in tryfuncTM()
260 #define inc_ci(L) \ argument
261 ((L->ci == L->end_ci) ? growCI(L) : \
262 (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))
265 int luaD_precall (lua_State *L, StkId func, int nresults) { in luaD_precall() argument
269 func = tryfuncTM(L, func); /* check the `function' tag method */ in luaD_precall()
270 funcr = savestack(L, func); in luaD_precall()
272 L->ci->savedpc = L->savedpc; in luaD_precall()
277 luaD_checkstack(L, p->maxstacksize); in luaD_precall()
278 func = restorestack(L, funcr); in luaD_precall()
281 if (L->top > base + p->numparams) in luaD_precall()
282 L->top = base + p->numparams; in luaD_precall()
285 int nargs = cast_int(L->top - func) - 1; in luaD_precall()
286 base = adjust_varargs(L, p, nargs); in luaD_precall()
287 func = restorestack(L, funcr); /* previous call may change the stack */ in luaD_precall()
289 ci = inc_ci(L); /* now `enter' new function */ in luaD_precall()
291 L->base = ci->base = base; in luaD_precall()
292 ci->top = L->base + p->maxstacksize; in luaD_precall()
293 lua_assert(ci->top <= L->stack_last); in luaD_precall()
294 L->savedpc = p->code; /* starting point */ in luaD_precall()
297 for (st = L->top; st < ci->top; st++) in luaD_precall()
299 L->top = ci->top; in luaD_precall()
300 if (L->hookmask & LUA_MASKCALL) { in luaD_precall()
301 L->savedpc++; /* hooks assume 'pc' is already incremented */ in luaD_precall()
302 luaD_callhook(L, LUA_HOOKCALL, -1); in luaD_precall()
303 L->savedpc--; /* correct 'pc' */ in luaD_precall()
310 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ in luaD_precall()
311 ci = inc_ci(L); /* now `enter' new function */ in luaD_precall()
312 ci->func = restorestack(L, funcr); in luaD_precall()
313 L->base = ci->base = ci->func + 1; in luaD_precall()
314 ci->top = L->top + LUA_MINSTACK; in luaD_precall()
315 lua_assert(ci->top <= L->stack_last); in luaD_precall()
317 if (L->hookmask & LUA_MASKCALL) in luaD_precall()
318 luaD_callhook(L, LUA_HOOKCALL, -1); in luaD_precall()
319 lua_unlock(L); in luaD_precall()
320 n = (*curr_func(L)->c.f)(L); /* do the actual call */ in luaD_precall()
321 lua_lock(L); in luaD_precall()
325 luaD_poscall(L, L->top - n); in luaD_precall()
332 static StkId callrethooks (lua_State *L, StkId firstResult) { in callrethooks() argument
333 ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ in callrethooks()
334 luaD_callhook(L, LUA_HOOKRET, -1); in callrethooks()
335 if (f_isLua(L->ci)) { /* Lua function? */ in callrethooks()
336 while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ in callrethooks()
337 luaD_callhook(L, LUA_HOOKTAILRET, -1); in callrethooks()
339 return restorestack(L, fr); in callrethooks()
343 int luaD_poscall (lua_State *L, StkId firstResult) { in luaD_poscall() argument
347 if (L->hookmask & LUA_MASKRET) in luaD_poscall()
348 firstResult = callrethooks(L, firstResult); in luaD_poscall()
349 ci = L->ci--; in luaD_poscall()
352 L->base = (ci - 1)->base; /* restore base */ in luaD_poscall()
353 L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ in luaD_poscall()
355 for (i = wanted; i != 0 && firstResult < L->top; i--) in luaD_poscall()
356 setobjs2s(L, res++, firstResult++); in luaD_poscall()
359 L->top = res; in luaD_poscall()
370 void luaD_call (lua_State *L, StkId func, int nResults) { in luaD_call() argument
371 if (++L->nCcalls >= LUAI_MAXCCALLS) { in luaD_call()
372 if (L->nCcalls == LUAI_MAXCCALLS) in luaD_call()
373 luaG_runerror(L, "C stack overflow"); in luaD_call()
374 else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) in luaD_call()
375 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ in luaD_call()
377 if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ in luaD_call()
378 luaV_execute(L, 1); /* call it */ in luaD_call()
379 L->nCcalls--; in luaD_call()
380 luaC_checkGC(L); in luaD_call()
384 static void resume (lua_State *L, void *ud) { in resume() argument
386 CallInfo *ci = L->ci; in resume()
387 if (L->status == 0) { /* start coroutine? */ in resume()
388 lua_assert(ci == L->base_ci && firstArg > L->base); in resume()
389 if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) in resume()
393 lua_assert(L->status == LUA_YIELD); in resume()
394 L->status = 0; in resume()
399 if (luaD_poscall(L, firstArg)) /* complete it... */ in resume()
400 L->top = L->ci->top; /* and correct top if not multiple results */ in resume()
403 L->base = L->ci->base; in resume()
405 luaV_execute(L, cast_int(L->ci - L->base_ci)); in resume()
409 static int resume_error (lua_State *L, const char *msg) { in resume_error() argument
410 L->top = L->ci->base; in resume_error()
411 setsvalue2s(L, L->top, luaS_new(L, msg)); in resume_error()
412 incr_top(L); in resume_error()
413 lua_unlock(L); in resume_error()
418 LUA_API int lua_resume (lua_State *L, int nargs) { in lua_resume() argument
420 lua_lock(L); in lua_resume()
421 if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) in lua_resume()
422 return resume_error(L, "cannot resume non-suspended coroutine"); in lua_resume()
423 if (L->nCcalls >= LUAI_MAXCCALLS) in lua_resume()
424 return resume_error(L, "C stack overflow"); in lua_resume()
425 luai_userstateresume(L, nargs); in lua_resume()
426 lua_assert(L->errfunc == 0); in lua_resume()
427 L->baseCcalls = ++L->nCcalls; in lua_resume()
428 status = luaD_rawrunprotected(L, resume, L->top - nargs); in lua_resume()
430 L->status = cast_byte(status); /* mark thread as `dead' */ in lua_resume()
431 luaD_seterrorobj(L, status, L->top); in lua_resume()
432 L->ci->top = L->top; in lua_resume()
435 lua_assert(L->nCcalls == L->baseCcalls); in lua_resume()
436 status = L->status; in lua_resume()
438 --L->nCcalls; in lua_resume()
439 lua_unlock(L); in lua_resume()
444 LUA_API int lua_yield (lua_State *L, int nresults) { in lua_yield() argument
445 luai_userstateyield(L, nresults); in lua_yield()
446 lua_lock(L); in lua_yield()
447 if (L->nCcalls > L->baseCcalls) in lua_yield()
448 luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); in lua_yield()
449 L->base = L->top - nresults; /* protect stack slots below */ in lua_yield()
450 L->status = LUA_YIELD; in lua_yield()
451 lua_unlock(L); in lua_yield()
456 int luaD_pcall (lua_State *L, Pfunc func, void *u, in luaD_pcall() argument
459 unsigned short oldnCcalls = L->nCcalls; in luaD_pcall()
460 ptrdiff_t old_ci = saveci(L, L->ci); in luaD_pcall()
461 lu_byte old_allowhooks = L->allowhook; in luaD_pcall()
462 ptrdiff_t old_errfunc = L->errfunc; in luaD_pcall()
463 L->errfunc = ef; in luaD_pcall()
464 status = luaD_rawrunprotected(L, func, u); in luaD_pcall()
466 StkId oldtop = restorestack(L, old_top); in luaD_pcall()
467 luaF_close(L, oldtop); /* close eventual pending closures */ in luaD_pcall()
468 luaD_seterrorobj(L, status, oldtop); in luaD_pcall()
469 L->nCcalls = oldnCcalls; in luaD_pcall()
470 L->ci = restoreci(L, old_ci); in luaD_pcall()
471 L->base = L->ci->base; in luaD_pcall()
472 L->savedpc = L->ci->savedpc; in luaD_pcall()
473 L->allowhook = old_allowhooks; in luaD_pcall()
474 restore_stack_limit(L); in luaD_pcall()
476 L->errfunc = old_errfunc; in luaD_pcall()
491 static void f_parser (lua_State *L, void *ud) { in f_parser() argument
497 luaC_checkGC(L); in f_parser()
498 tf = (luaY_parser)(L, p->z, in f_parser()
500 cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); in f_parser()
503 cl->l.upvals[i] = luaF_newupval(L); in f_parser()
504 setclvalue(L, L->top, cl); in f_parser()
505 incr_top(L); in f_parser()
509 int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { in luaD_protectedparser() argument
513 luaZ_initbuffer(L, &p.buff); in luaD_protectedparser()
514 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); in luaD_protectedparser()
515 luaZ_freebuffer(L, &p.buff); in luaD_protectedparser()