aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-10-29 12:06:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-10-29 12:06:37 -0300
commit413a393e6222482f46599e138bebac162610a572 (patch)
tree181517f8ec8d56f9101de33f4891729044f244de /lstate.c
parentba089bcb08a0efc6c26fb5c1e3c9d61c00cc012c (diff)
downloadlua-413a393e6222482f46599e138bebac162610a572.tar.gz
lua-413a393e6222482f46599e138bebac162610a572.tar.bz2
lua-413a393e6222482f46599e138bebac162610a572.zip
Stack indices changed to union's
That will allow to change pointers to offsets while reallocating the stack.
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/lstate.c b/lstate.c
index 4b5c1000..c63fe867 100644
--- a/lstate.c
+++ b/lstate.c
@@ -180,33 +180,33 @@ LUAI_FUNC void luaE_incCstack (lua_State *L) {
180static void stack_init (lua_State *L1, lua_State *L) { 180static void stack_init (lua_State *L1, lua_State *L) {
181 int i; CallInfo *ci; 181 int i; CallInfo *ci;
182 /* initialize stack array */ 182 /* initialize stack array */
183 L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue); 183 L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
184 L1->tbclist = L1->stack; 184 L1->tbclist.p = L1->stack.p;
185 for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++) 185 for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++)
186 setnilvalue(s2v(L1->stack + i)); /* erase new stack */ 186 setnilvalue(s2v(L1->stack.p + i)); /* erase new stack */
187 L1->top = L1->stack; 187 L1->top.p = L1->stack.p;
188 L1->stack_last = L1->stack + BASIC_STACK_SIZE; 188 L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE;
189 /* initialize first ci */ 189 /* initialize first ci */
190 ci = &L1->base_ci; 190 ci = &L1->base_ci;
191 ci->next = ci->previous = NULL; 191 ci->next = ci->previous = NULL;
192 ci->callstatus = CIST_C; 192 ci->callstatus = CIST_C;
193 ci->func = L1->top; 193 ci->func.p = L1->top.p;
194 ci->u.c.k = NULL; 194 ci->u.c.k = NULL;
195 ci->nresults = 0; 195 ci->nresults = 0;
196 setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */ 196 setnilvalue(s2v(L1->top.p)); /* 'function' entry for this 'ci' */
197 L1->top++; 197 L1->top.p++;
198 ci->top = L1->top + LUA_MINSTACK; 198 ci->top.p = L1->top.p + LUA_MINSTACK;
199 L1->ci = ci; 199 L1->ci = ci;
200} 200}
201 201
202 202
203static void freestack (lua_State *L) { 203static void freestack (lua_State *L) {
204 if (L->stack == NULL) 204 if (L->stack.p == NULL)
205 return; /* stack not completely built yet */ 205 return; /* stack not completely built yet */
206 L->ci = &L->base_ci; /* free the entire 'ci' list */ 206 L->ci = &L->base_ci; /* free the entire 'ci' list */
207 luaE_freeCI(L); 207 luaE_freeCI(L);
208 lua_assert(L->nci == 0); 208 lua_assert(L->nci == 0);
209 luaM_freearray(L, L->stack, stacksize(L) + EXTRA_STACK); /* free stack */ 209 luaM_freearray(L, L->stack.p, stacksize(L) + EXTRA_STACK); /* free stack */
210} 210}
211 211
212 212
@@ -248,7 +248,7 @@ static void f_luaopen (lua_State *L, void *ud) {
248*/ 248*/
249static void preinit_thread (lua_State *L, global_State *g) { 249static void preinit_thread (lua_State *L, global_State *g) {
250 G(L) = g; 250 G(L) = g;
251 L->stack = NULL; 251 L->stack.p = NULL;
252 L->ci = NULL; 252 L->ci = NULL;
253 L->nci = 0; 253 L->nci = 0;
254 L->twups = L; /* thread has no upvalues */ 254 L->twups = L; /* thread has no upvalues */
@@ -297,7 +297,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
297 L1->next = g->allgc; 297 L1->next = g->allgc;
298 g->allgc = obj2gco(L1); 298 g->allgc = obj2gco(L1);
299 /* anchor it on L stack */ 299 /* anchor it on L stack */
300 setthvalue2s(L, L->top, L1); 300 setthvalue2s(L, L->top.p, L1);
301 api_incr_top(L); 301 api_incr_top(L);
302 preinit_thread(L1, g); 302 preinit_thread(L1, g);
303 L1->hookmask = L->hookmask; 303 L1->hookmask = L->hookmask;
@@ -316,7 +316,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
316 316
317void luaE_freethread (lua_State *L, lua_State *L1) { 317void luaE_freethread (lua_State *L, lua_State *L1) {
318 LX *l = fromstate(L1); 318 LX *l = fromstate(L1);
319 luaF_closeupval(L1, L1->stack); /* close all upvalues */ 319 luaF_closeupval(L1, L1->stack.p); /* close all upvalues */
320 lua_assert(L1->openupval == NULL); 320 lua_assert(L1->openupval == NULL);
321 luai_userstatefree(L, L1); 321 luai_userstatefree(L, L1);
322 freestack(L1); 322 freestack(L1);
@@ -326,19 +326,19 @@ void luaE_freethread (lua_State *L, lua_State *L1) {
326 326
327int luaE_resetthread (lua_State *L, int status) { 327int luaE_resetthread (lua_State *L, int status) {
328 CallInfo *ci = L->ci = &L->base_ci; /* unwind CallInfo list */ 328 CallInfo *ci = L->ci = &L->base_ci; /* unwind CallInfo list */
329 setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */ 329 setnilvalue(s2v(L->stack.p)); /* 'function' entry for basic 'ci' */
330 ci->func = L->stack; 330 ci->func.p = L->stack.p;
331 ci->callstatus = CIST_C; 331 ci->callstatus = CIST_C;
332 if (status == LUA_YIELD) 332 if (status == LUA_YIELD)
333 status = LUA_OK; 333 status = LUA_OK;
334 L->status = LUA_OK; /* so it can run __close metamethods */ 334 L->status = LUA_OK; /* so it can run __close metamethods */
335 status = luaD_closeprotected(L, 1, status); 335 status = luaD_closeprotected(L, 1, status);
336 if (status != LUA_OK) /* errors? */ 336 if (status != LUA_OK) /* errors? */
337 luaD_seterrorobj(L, status, L->stack + 1); 337 luaD_seterrorobj(L, status, L->stack.p + 1);
338 else 338 else
339 L->top = L->stack + 1; 339 L->top.p = L->stack.p + 1;
340 ci->top = L->top + LUA_MINSTACK; 340 ci->top.p = L->top.p + LUA_MINSTACK;
341 luaD_reallocstack(L, cast_int(ci->top - L->stack), 0); 341 luaD_reallocstack(L, cast_int(ci->top.p - L->stack.p), 0);
342 return status; 342 return status;
343} 343}
344 344
@@ -427,7 +427,7 @@ void luaE_warning (lua_State *L, const char *msg, int tocont) {
427** Generate a warning from an error message 427** Generate a warning from an error message
428*/ 428*/
429void luaE_warnerror (lua_State *L, const char *where) { 429void luaE_warnerror (lua_State *L, const char *where) {
430 TValue *errobj = s2v(L->top - 1); /* error object */ 430 TValue *errobj = s2v(L->top.p - 1); /* error object */
431 const char *msg = (ttisstring(errobj)) 431 const char *msg = (ttisstring(errobj))
432 ? svalue(errobj) 432 ? svalue(errobj)
433 : "error object is not a string"; 433 : "error object is not a string";