Lines Matching +full:- +full:g +full:-
46 global_State g; member
51 #define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))
89 void luaE_setdebt (global_State *g, l_mem debt) { in luaE_setdebt() argument
90 l_mem tb = gettotalbytes(g); in luaE_setdebt()
92 if (debt < tb - MAX_LMEM) in luaE_setdebt()
93 debt = tb - MAX_LMEM; /* will make 'totalbytes == MAX_LMEM' */ in luaE_setdebt()
94 g->totalbytes = tb - debt; in luaE_setdebt()
95 g->GCdebt = debt; in luaE_setdebt()
107 lua_assert(L->ci->next == NULL); in luaE_extendCI()
109 lua_assert(L->ci->next == NULL); in luaE_extendCI()
110 L->ci->next = ci; in luaE_extendCI()
111 ci->previous = L->ci; in luaE_extendCI()
112 ci->next = NULL; in luaE_extendCI()
113 ci->u.l.trap = 0; in luaE_extendCI()
114 L->nci++; in luaE_extendCI()
123 CallInfo *ci = L->ci; in luaE_freeCI()
124 CallInfo *next = ci->next; in luaE_freeCI()
125 ci->next = NULL; in luaE_freeCI()
127 next = ci->next; in luaE_freeCI()
129 L->nci--; in luaE_freeCI()
139 CallInfo *ci = L->ci->next; /* first free CallInfo */ in luaE_shrinkCI()
143 while ((next = ci->next) != NULL) { /* two extra elements? */ in luaE_shrinkCI()
144 CallInfo *next2 = next->next; /* next's next */ in luaE_shrinkCI()
145 ci->next = next2; /* remove next from the list */ in luaE_shrinkCI()
146 L->nci--; in luaE_shrinkCI()
151 next2->previous = ci; in luaE_shrinkCI()
174 L->nCcalls++; in luaE_incCstack()
183 L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue); in stack_init()
184 L1->tbclist.p = L1->stack.p; in stack_init()
186 setnilvalue(s2v(L1->stack.p + i)); /* erase new stack */ in stack_init()
187 L1->top.p = L1->stack.p; in stack_init()
188 L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE; in stack_init()
190 ci = &L1->base_ci; in stack_init()
191 ci->next = ci->previous = NULL; in stack_init()
192 ci->callstatus = CIST_C; in stack_init()
193 ci->func.p = L1->top.p; in stack_init()
194 ci->u.c.k = NULL; in stack_init()
195 ci->nresults = 0; in stack_init()
196 setnilvalue(s2v(L1->top.p)); /* 'function' entry for this 'ci' */ in stack_init()
197 L1->top.p++; in stack_init()
198 ci->top.p = L1->top.p + LUA_MINSTACK; in stack_init()
199 L1->ci = ci; in stack_init()
204 if (L->stack.p == NULL) in freestack()
206 L->ci = &L->base_ci; /* free the entire 'ci' list */ in freestack()
208 lua_assert(L->nci == 0); in freestack()
209 luaM_freearray(L, L->stack.p, stacksize(L) + EXTRA_STACK); /* free stack */ in freestack()
216 static void init_registry (lua_State *L, global_State *g) { in init_registry() argument
219 sethvalue(L, &g->l_registry, registry); in init_registry()
222 setthvalue(L, ®istry->array[LUA_RIDX_MAINTHREAD - 1], L); in init_registry()
224 sethvalue(L, ®istry->array[LUA_RIDX_GLOBALS - 1], luaH_new(L)); in init_registry()
229 ** open parts of the state that may cause memory-allocation errors.
232 global_State *g = G(L); in f_luaopen() local
235 init_registry(L, g); in f_luaopen()
239 g->gcstp = 0; /* allow gc */ in f_luaopen()
240 setnilvalue(&g->nilvalue); /* now state is complete */ in f_luaopen()
249 static void preinit_thread (lua_State *L, global_State *g) { in preinit_thread() argument
250 G(L) = g; in preinit_thread()
251 L->stack.p = NULL; in preinit_thread()
252 L->ci = NULL; in preinit_thread()
253 L->nci = 0; in preinit_thread()
254 L->twups = L; /* thread has no upvalues */ in preinit_thread()
255 L->nCcalls = 0; in preinit_thread()
256 L->errorJmp = NULL; in preinit_thread()
257 L->hook = NULL; in preinit_thread()
258 L->hookmask = 0; in preinit_thread()
259 L->basehookcount = 0; in preinit_thread()
260 L->allowhook = 1; in preinit_thread()
262 L->openupval = NULL; in preinit_thread()
263 L->status = LUA_OK; in preinit_thread()
264 L->errfunc = 0; in preinit_thread()
265 L->oldpc = 0; in preinit_thread()
270 global_State *g = G(L); in close_state() local
271 if (!completestate(g)) /* closing a partially built state? */ in close_state()
274 L->ci = &L->base_ci; /* unwind CallInfo list */ in close_state()
279 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); in close_state()
281 lua_assert(gettotalbytes(g) == sizeof(LG)); in close_state()
282 (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ in close_state()
287 global_State *g = G(L); in lua_newthread() local
296 setthvalue2s(L, L->top.p, L1); in lua_newthread()
298 preinit_thread(L1, g); in lua_newthread()
299 L1->hookmask = L->hookmask; in lua_newthread()
300 L1->basehookcount = L->basehookcount; in lua_newthread()
301 L1->hook = L->hook; in lua_newthread()
304 memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread), in lua_newthread()
315 luaF_closeupval(L1, L1->stack.p); /* close all upvalues */ in luaE_freethread()
316 lua_assert(L1->openupval == NULL); in luaE_freethread()
324 CallInfo *ci = L->ci = &L->base_ci; /* unwind CallInfo list */ in luaE_resetthread()
325 setnilvalue(s2v(L->stack.p)); /* 'function' entry for basic 'ci' */ in luaE_resetthread()
326 ci->func.p = L->stack.p; in luaE_resetthread()
327 ci->callstatus = CIST_C; in luaE_resetthread()
330 L->status = LUA_OK; /* so it can run __close metamethods */ in luaE_resetthread()
333 luaD_seterrorobj(L, status, L->stack.p + 1); in luaE_resetthread()
335 L->top.p = L->stack.p + 1; in luaE_resetthread()
336 ci->top.p = L->top.p + LUA_MINSTACK; in luaE_resetthread()
337 luaD_reallocstack(L, cast_int(ci->top.p - L->stack.p), 0); in luaE_resetthread()
345 L->nCcalls = (from) ? getCcalls(from) : 0; in lua_closethread()
346 status = luaE_resetthread(L, L->status); in lua_closethread()
363 global_State *g; in lua_newstate() local
366 L = &l->l.l; in lua_newstate()
367 g = &l->g; in lua_newstate()
368 L->tt = LUA_VTHREAD; in lua_newstate()
369 g->currentwhite = bitmask(WHITE0BIT); in lua_newstate()
370 L->marked = luaC_white(g); in lua_newstate()
371 preinit_thread(L, g); in lua_newstate()
372 g->allgc = obj2gco(L); /* by now, only object is the main thread */ in lua_newstate()
373 L->next = NULL; in lua_newstate()
375 g->frealloc = f; in lua_newstate()
376 g->ud = ud; in lua_newstate()
377 g->warnf = NULL; in lua_newstate()
378 g->ud_warn = NULL; in lua_newstate()
379 g->mainthread = L; in lua_newstate()
380 g->seed = luai_makeseed(L); in lua_newstate()
381 g->gcstp = GCSTPGC; /* no GC while building state */ in lua_newstate()
382 g->strt.size = g->strt.nuse = 0; in lua_newstate()
383 g->strt.hash = NULL; in lua_newstate()
384 setnilvalue(&g->l_registry); in lua_newstate()
385 g->panic = NULL; in lua_newstate()
386 g->gcstate = GCSpause; in lua_newstate()
387 g->gckind = KGC_INC; in lua_newstate()
388 g->gcstopem = 0; in lua_newstate()
389 g->gcemergency = 0; in lua_newstate()
390 g->finobj = g->tobefnz = g->fixedgc = NULL; in lua_newstate()
391 g->firstold1 = g->survival = g->old1 = g->reallyold = NULL; in lua_newstate()
392 g->finobjsur = g->finobjold1 = g->finobjrold = NULL; in lua_newstate()
393 g->sweepgc = NULL; in lua_newstate()
394 g->gray = g->grayagain = NULL; in lua_newstate()
395 g->weak = g->ephemeron = g->allweak = NULL; in lua_newstate()
396 g->twups = NULL; in lua_newstate()
397 g->totalbytes = sizeof(LG); in lua_newstate()
398 g->GCdebt = 0; in lua_newstate()
399 g->lastatomic = 0; in lua_newstate()
400 setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ in lua_newstate()
401 setgcparam(g->gcpause, LUAI_GCPAUSE); in lua_newstate()
402 setgcparam(g->gcstepmul, LUAI_GCMUL); in lua_newstate()
403 g->gcstepsize = LUAI_GCSTEPSIZE; in lua_newstate()
404 setgcparam(g->genmajormul, LUAI_GENMAJORMUL); in lua_newstate()
405 g->genminormul = LUAI_GENMINORMUL; in lua_newstate()
406 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; in lua_newstate()
418 L = G(L)->mainthread; /* only the main thread can be closed */ in lua_close()
424 lua_WarnFunction wf = G(L)->warnf; in luaE_warning()
426 wf(G(L)->ud_warn, msg, tocont); in luaE_warning()
434 TValue *errobj = s2v(L->top.p - 1); /* error object */ in luaE_warnerror()