aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/lua/ldo.c
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-12-02 10:40:09 +0800
committerLi Jin <dragon-fly@qq.com>2022-12-02 10:40:09 +0800
commit298b18dbe852300199cc529c942a181bead5f135 (patch)
treef4b5ae89b6920fa0a12c693118f85334f19754f8 /src/3rdParty/lua/ldo.c
parenta6a65ba26a9d320611abcbfba49fa724edfb4dad (diff)
downloadyuescript-298b18dbe852300199cc529c942a181bead5f135.tar.gz
yuescript-298b18dbe852300199cc529c942a181bead5f135.tar.bz2
yuescript-298b18dbe852300199cc529c942a181bead5f135.zip
update Lua.
Diffstat (limited to 'src/3rdParty/lua/ldo.c')
-rw-r--r--src/3rdParty/lua/ldo.c175
1 files changed, 99 insertions, 76 deletions
diff --git a/src/3rdParty/lua/ldo.c b/src/3rdParty/lua/ldo.c
index 419b3db..c30cde7 100644
--- a/src/3rdParty/lua/ldo.c
+++ b/src/3rdParty/lua/ldo.c
@@ -104,11 +104,11 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
104 } 104 }
105 default: { 105 default: {
106 lua_assert(errorstatus(errcode)); /* real error */ 106 lua_assert(errorstatus(errcode)); /* real error */
107 setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ 107 setobjs2s(L, oldtop, L->top.p - 1); /* error message on current top */
108 break; 108 break;
109 } 109 }
110 } 110 }
111 L->top = oldtop + 1; 111 L->top.p = oldtop + 1;
112} 112}
113 113
114 114
@@ -121,7 +121,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
121 global_State *g = G(L); 121 global_State *g = G(L);
122 errcode = luaE_resetthread(L, errcode); /* close all upvalues */ 122 errcode = luaE_resetthread(L, errcode); /* close all upvalues */
123 if (g->mainthread->errorJmp) { /* main thread has a handler? */ 123 if (g->mainthread->errorJmp) { /* main thread has a handler? */
124 setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ 124 setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */
125 luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ 125 luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
126 } 126 }
127 else { /* no handler at all; abort */ 127 else { /* no handler at all; abort */
@@ -157,16 +157,38 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
157** Stack reallocation 157** Stack reallocation
158** =================================================================== 158** ===================================================================
159*/ 159*/
160static void correctstack (lua_State *L, StkId oldstack, StkId newstack) { 160
161
162/*
163** Change all pointers to the stack into offsets.
164*/
165static void relstack (lua_State *L) {
161 CallInfo *ci; 166 CallInfo *ci;
162 UpVal *up; 167 UpVal *up;
163 L->top = (L->top - oldstack) + newstack; 168 L->top.offset = savestack(L, L->top.p);
164 L->tbclist = (L->tbclist - oldstack) + newstack; 169 L->tbclist.offset = savestack(L, L->tbclist.p);
165 for (up = L->openupval; up != NULL; up = up->u.open.next) 170 for (up = L->openupval; up != NULL; up = up->u.open.next)
166 up->v = s2v((uplevel(up) - oldstack) + newstack); 171 up->v.offset = savestack(L, uplevel(up));
167 for (ci = L->ci; ci != NULL; ci = ci->previous) { 172 for (ci = L->ci; ci != NULL; ci = ci->previous) {
168 ci->top = (ci->top - oldstack) + newstack; 173 ci->top.offset = savestack(L, ci->top.p);
169 ci->func = (ci->func - oldstack) + newstack; 174 ci->func.offset = savestack(L, ci->func.p);
175 }
176}
177
178
179/*
180** Change back all offsets into pointers.
181*/
182static void correctstack (lua_State *L) {
183 CallInfo *ci;
184 UpVal *up;
185 L->top.p = restorestack(L, L->top.offset);
186 L->tbclist.p = restorestack(L, L->tbclist.offset);
187 for (up = L->openupval; up != NULL; up = up->u.open.next)
188 up->v.p = s2v(restorestack(L, up->v.offset));
189 for (ci = L->ci; ci != NULL; ci = ci->previous) {
190 ci->top.p = restorestack(L, ci->top.offset);
191 ci->func.p = restorestack(L, ci->func.offset);
170 if (isLua(ci)) 192 if (isLua(ci))
171 ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */ 193 ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */
172 } 194 }
@@ -176,38 +198,39 @@ static void correctstack (lua_State *L, StkId oldstack, StkId newstack) {
176/* some space for error handling */ 198/* some space for error handling */
177#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200) 199#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
178 200
179
180/* 201/*
181** Reallocate the stack to a new size, correcting all pointers into 202** Reallocate the stack to a new size, correcting all pointers into it.
182** it. (There are pointers to a stack from its upvalues, from its list 203** In ISO C, any pointer use after the pointer has been deallocated is
183** of call infos, plus a few individual pointers.) The reallocation is 204** undefined behavior. So, before the reallocation, all pointers are
184** done in two steps (allocation + free) because the correction must be 205** changed to offsets, and after the reallocation they are changed back
185** done while both addresses (the old stack and the new one) are valid. 206** to pointers. As during the reallocation the pointers are invalid, the
186** (In ISO C, any pointer use after the pointer has been deallocated is 207** reallocation cannot run emergency collections.
187** undefined behavior.) 208**
188** In case of allocation error, raise an error or return false according 209** In case of allocation error, raise an error or return false according
189** to 'raiseerror'. 210** to 'raiseerror'.
190*/ 211*/
191int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { 212int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
192 int oldsize = stacksize(L); 213 int oldsize = stacksize(L);
193 int i; 214 int i;
194 StkId newstack = luaM_reallocvector(L, NULL, 0, 215 StkId newstack;
195 newsize + EXTRA_STACK, StackValue); 216 int oldgcstop = G(L)->gcstopem;
196 lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); 217 lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
218 relstack(L); /* change pointers to offsets */
219 G(L)->gcstopem = 1; /* stop emergency collection */
220 newstack = luaM_reallocvector(L, L->stack.p, oldsize + EXTRA_STACK,
221 newsize + EXTRA_STACK, StackValue);
222 G(L)->gcstopem = oldgcstop; /* restore emergency collection */
197 if (l_unlikely(newstack == NULL)) { /* reallocation failed? */ 223 if (l_unlikely(newstack == NULL)) { /* reallocation failed? */
224 correctstack(L); /* change offsets back to pointers */
198 if (raiseerror) 225 if (raiseerror)
199 luaM_error(L); 226 luaM_error(L);
200 else return 0; /* do not raise an error */ 227 else return 0; /* do not raise an error */
201 } 228 }
202 /* number of elements to be copied to the new stack */ 229 L->stack.p = newstack;
203 i = ((oldsize <= newsize) ? oldsize : newsize) + EXTRA_STACK; 230 correctstack(L); /* change offsets back to pointers */
204 memcpy(newstack, L->stack, i * sizeof(StackValue)); 231 L->stack_last.p = L->stack.p + newsize;
205 for (; i < newsize + EXTRA_STACK; i++) 232 for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++)
206 setnilvalue(s2v(newstack + i)); /* erase new segment */ 233 setnilvalue(s2v(newstack + i)); /* erase new segment */
207 correctstack(L, L->stack, newstack);
208 luaM_freearray(L, L->stack, oldsize + EXTRA_STACK);
209 L->stack = newstack;
210 L->stack_last = L->stack + newsize;
211 return 1; 234 return 1;
212} 235}
213 236
@@ -229,7 +252,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
229 } 252 }
230 else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */ 253 else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */
231 int newsize = 2 * size; /* tentative new size */ 254 int newsize = 2 * size; /* tentative new size */
232 int needed = cast_int(L->top - L->stack) + n; 255 int needed = cast_int(L->top.p - L->stack.p) + n;
233 if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ 256 if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */
234 newsize = LUAI_MAXSTACK; 257 newsize = LUAI_MAXSTACK;
235 if (newsize < needed) /* but must respect what was asked for */ 258 if (newsize < needed) /* but must respect what was asked for */
@@ -253,12 +276,12 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
253static int stackinuse (lua_State *L) { 276static int stackinuse (lua_State *L) {
254 CallInfo *ci; 277 CallInfo *ci;
255 int res; 278 int res;
256 StkId lim = L->top; 279 StkId lim = L->top.p;
257 for (ci = L->ci; ci != NULL; ci = ci->previous) { 280 for (ci = L->ci; ci != NULL; ci = ci->previous) {
258 if (lim < ci->top) lim = ci->top; 281 if (lim < ci->top.p) lim = ci->top.p;
259 } 282 }
260 lua_assert(lim <= L->stack_last + EXTRA_STACK); 283 lua_assert(lim <= L->stack_last.p + EXTRA_STACK);
261 res = cast_int(lim - L->stack) + 1; /* part of stack in use */ 284 res = cast_int(lim - L->stack.p) + 1; /* part of stack in use */
262 if (res < LUA_MINSTACK) 285 if (res < LUA_MINSTACK)
263 res = LUA_MINSTACK; /* ensure a minimum size */ 286 res = LUA_MINSTACK; /* ensure a minimum size */
264 return res; 287 return res;
@@ -295,7 +318,7 @@ void luaD_shrinkstack (lua_State *L) {
295 318
296void luaD_inctop (lua_State *L) { 319void luaD_inctop (lua_State *L) {
297 luaD_checkstack(L, 1); 320 luaD_checkstack(L, 1);
298 L->top++; 321 L->top.p++;
299} 322}
300 323
301/* }================================================================== */ 324/* }================================================================== */
@@ -312,8 +335,8 @@ void luaD_hook (lua_State *L, int event, int line,
312 if (hook && L->allowhook) { /* make sure there is a hook */ 335 if (hook && L->allowhook) { /* make sure there is a hook */
313 int mask = CIST_HOOKED; 336 int mask = CIST_HOOKED;
314 CallInfo *ci = L->ci; 337 CallInfo *ci = L->ci;
315 ptrdiff_t top = savestack(L, L->top); /* preserve original 'top' */ 338 ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */
316 ptrdiff_t ci_top = savestack(L, ci->top); /* idem for 'ci->top' */ 339 ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */
317 lua_Debug ar; 340 lua_Debug ar;
318 ar.event = event; 341 ar.event = event;
319 ar.currentline = line; 342 ar.currentline = line;
@@ -323,11 +346,11 @@ void luaD_hook (lua_State *L, int event, int line,
323 ci->u2.transferinfo.ftransfer = ftransfer; 346 ci->u2.transferinfo.ftransfer = ftransfer;
324 ci->u2.transferinfo.ntransfer = ntransfer; 347 ci->u2.transferinfo.ntransfer = ntransfer;
325 } 348 }
326 if (isLua(ci) && L->top < ci->top) 349 if (isLua(ci) && L->top.p < ci->top.p)
327 L->top = ci->top; /* protect entire activation register */ 350 L->top.p = ci->top.p; /* protect entire activation register */
328 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ 351 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
329 if (ci->top < L->top + LUA_MINSTACK) 352 if (ci->top.p < L->top.p + LUA_MINSTACK)
330 ci->top = L->top + LUA_MINSTACK; 353 ci->top.p = L->top.p + LUA_MINSTACK;
331 L->allowhook = 0; /* cannot call hooks inside a hook */ 354 L->allowhook = 0; /* cannot call hooks inside a hook */
332 ci->callstatus |= mask; 355 ci->callstatus |= mask;
333 lua_unlock(L); 356 lua_unlock(L);
@@ -335,8 +358,8 @@ void luaD_hook (lua_State *L, int event, int line,
335 lua_lock(L); 358 lua_lock(L);
336 lua_assert(!L->allowhook); 359 lua_assert(!L->allowhook);
337 L->allowhook = 1; 360 L->allowhook = 1;
338 ci->top = restorestack(L, ci_top); 361 ci->top.p = restorestack(L, ci_top);
339 L->top = restorestack(L, top); 362 L->top.p = restorestack(L, top);
340 ci->callstatus &= ~mask; 363 ci->callstatus &= ~mask;
341 } 364 }
342} 365}
@@ -367,7 +390,7 @@ void luaD_hookcall (lua_State *L, CallInfo *ci) {
367*/ 390*/
368static void rethook (lua_State *L, CallInfo *ci, int nres) { 391static void rethook (lua_State *L, CallInfo *ci, int nres) {
369 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ 392 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */
370 StkId firstres = L->top - nres; /* index of first result */ 393 StkId firstres = L->top.p - nres; /* index of first result */
371 int delta = 0; /* correction for vararg functions */ 394 int delta = 0; /* correction for vararg functions */
372 int ftransfer; 395 int ftransfer;
373 if (isLua(ci)) { 396 if (isLua(ci)) {
@@ -375,10 +398,10 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {
375 if (p->is_vararg) 398 if (p->is_vararg)
376 delta = ci->u.l.nextraargs + p->numparams + 1; 399 delta = ci->u.l.nextraargs + p->numparams + 1;
377 } 400 }
378 ci->func += delta; /* if vararg, back to virtual 'func' */ 401 ci->func.p += delta; /* if vararg, back to virtual 'func' */
379 ftransfer = cast(unsigned short, firstres - ci->func); 402 ftransfer = cast(unsigned short, firstres - ci->func.p);
380 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ 403 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */
381 ci->func -= delta; 404 ci->func.p -= delta;
382 } 405 }
383 if (isLua(ci = ci->previous)) 406 if (isLua(ci = ci->previous))
384 L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* set 'oldpc' */ 407 L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* set 'oldpc' */
@@ -397,9 +420,9 @@ StkId luaD_tryfuncTM (lua_State *L, StkId func) {
397 tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */ 420 tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */
398 if (l_unlikely(ttisnil(tm))) 421 if (l_unlikely(ttisnil(tm)))
399 luaG_callerror(L, s2v(func)); /* nothing to call */ 422 luaG_callerror(L, s2v(func)); /* nothing to call */
400 for (p = L->top; p > func; p--) /* open space for metamethod */ 423 for (p = L->top.p; p > func; p--) /* open space for metamethod */
401 setobjs2s(L, p, p-1); 424 setobjs2s(L, p, p-1);
402 L->top++; /* stack space pre-allocated by the caller */ 425 L->top.p++; /* stack space pre-allocated by the caller */
403 setobj2s(L, func, tm); /* metamethod is the new function to be called */ 426 setobj2s(L, func, tm); /* metamethod is the new function to be called */
404 return func; 427 return func;
405} 428}
@@ -416,14 +439,14 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) {
416 int i; 439 int i;
417 switch (wanted) { /* handle typical cases separately */ 440 switch (wanted) { /* handle typical cases separately */
418 case 0: /* no values needed */ 441 case 0: /* no values needed */
419 L->top = res; 442 L->top.p = res;
420 return; 443 return;
421 case 1: /* one value needed */ 444 case 1: /* one value needed */
422 if (nres == 0) /* no results? */ 445 if (nres == 0) /* no results? */
423 setnilvalue(s2v(res)); /* adjust with nil */ 446 setnilvalue(s2v(res)); /* adjust with nil */
424 else /* at least one result */ 447 else /* at least one result */
425 setobjs2s(L, res, L->top - nres); /* move it to proper place */ 448 setobjs2s(L, res, L->top.p - nres); /* move it to proper place */
426 L->top = res + 1; 449 L->top.p = res + 1;
427 return; 450 return;
428 case LUA_MULTRET: 451 case LUA_MULTRET:
429 wanted = nres; /* we want all results */ 452 wanted = nres; /* we want all results */
@@ -446,14 +469,14 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) {
446 break; 469 break;
447 } 470 }
448 /* generic case */ 471 /* generic case */
449 firstresult = L->top - nres; /* index of first result */ 472 firstresult = L->top.p - nres; /* index of first result */
450 if (nres > wanted) /* extra results? */ 473 if (nres > wanted) /* extra results? */
451 nres = wanted; /* don't need them */ 474 nres = wanted; /* don't need them */
452 for (i = 0; i < nres; i++) /* move all results to correct place */ 475 for (i = 0; i < nres; i++) /* move all results to correct place */
453 setobjs2s(L, res + i, firstresult + i); 476 setobjs2s(L, res + i, firstresult + i);
454 for (; i < wanted; i++) /* complete wanted number of results */ 477 for (; i < wanted; i++) /* complete wanted number of results */
455 setnilvalue(s2v(res + i)); 478 setnilvalue(s2v(res + i));
456 L->top = res + wanted; /* top points after the last result */ 479 L->top.p = res + wanted; /* top points after the last result */
457} 480}
458 481
459 482
@@ -468,7 +491,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
468 if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted))) 491 if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted)))
469 rethook(L, ci, nres); 492 rethook(L, ci, nres);
470 /* move results to proper place */ 493 /* move results to proper place */
471 moveresults(L, ci->func, nres, wanted); 494 moveresults(L, ci->func.p, nres, wanted);
472 /* function cannot be in any of these cases when returning */ 495 /* function cannot be in any of these cases when returning */
473 lua_assert(!(ci->callstatus & 496 lua_assert(!(ci->callstatus &
474 (CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_TRAN | CIST_CLSRET))); 497 (CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_TRAN | CIST_CLSRET)));
@@ -483,10 +506,10 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
483l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, 506l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
484 int mask, StkId top) { 507 int mask, StkId top) {
485 CallInfo *ci = L->ci = next_ci(L); /* new frame */ 508 CallInfo *ci = L->ci = next_ci(L); /* new frame */
486 ci->func = func; 509 ci->func.p = func;
487 ci->nresults = nret; 510 ci->nresults = nret;
488 ci->callstatus = mask; 511 ci->callstatus = mask;
489 ci->top = top; 512 ci->top.p = top;
490 return ci; 513 return ci;
491} 514}
492 515
@@ -500,10 +523,10 @@ l_sinline int precallC (lua_State *L, StkId func, int nresults,
500 CallInfo *ci; 523 CallInfo *ci;
501 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ 524 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
502 L->ci = ci = prepCallInfo(L, func, nresults, CIST_C, 525 L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
503 L->top + LUA_MINSTACK); 526 L->top.p + LUA_MINSTACK);
504 lua_assert(ci->top <= L->stack_last); 527 lua_assert(ci->top.p <= L->stack_last.p);
505 if (l_unlikely(L->hookmask & LUA_MASKCALL)) { 528 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
506 int narg = cast_int(L->top - func) - 1; 529 int narg = cast_int(L->top.p - func) - 1;
507 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg); 530 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
508 } 531 }
509 lua_unlock(L); 532 lua_unlock(L);
@@ -535,17 +558,17 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
535 int nfixparams = p->numparams; 558 int nfixparams = p->numparams;
536 int i; 559 int i;
537 checkstackGCp(L, fsize - delta, func); 560 checkstackGCp(L, fsize - delta, func);
538 ci->func -= delta; /* restore 'func' (if vararg) */ 561 ci->func.p -= delta; /* restore 'func' (if vararg) */
539 for (i = 0; i < narg1; i++) /* move down function and arguments */ 562 for (i = 0; i < narg1; i++) /* move down function and arguments */
540 setobjs2s(L, ci->func + i, func + i); 563 setobjs2s(L, ci->func.p + i, func + i);
541 func = ci->func; /* moved-down function */ 564 func = ci->func.p; /* moved-down function */
542 for (; narg1 <= nfixparams; narg1++) 565 for (; narg1 <= nfixparams; narg1++)
543 setnilvalue(s2v(func + narg1)); /* complete missing arguments */ 566 setnilvalue(s2v(func + narg1)); /* complete missing arguments */
544 ci->top = func + 1 + fsize; /* top for new function */ 567 ci->top.p = func + 1 + fsize; /* top for new function */
545 lua_assert(ci->top <= L->stack_last); 568 lua_assert(ci->top.p <= L->stack_last.p);
546 ci->u.l.savedpc = p->code; /* starting point */ 569 ci->u.l.savedpc = p->code; /* starting point */
547 ci->callstatus |= CIST_TAIL; 570 ci->callstatus |= CIST_TAIL;
548 L->top = func + narg1; /* set top */ 571 L->top.p = func + narg1; /* set top */
549 return -1; 572 return -1;
550 } 573 }
551 default: { /* not a function */ 574 default: { /* not a function */
@@ -578,15 +601,15 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
578 case LUA_VLCL: { /* Lua function */ 601 case LUA_VLCL: { /* Lua function */
579 CallInfo *ci; 602 CallInfo *ci;
580 Proto *p = clLvalue(s2v(func))->p; 603 Proto *p = clLvalue(s2v(func))->p;
581 int narg = cast_int(L->top - func) - 1; /* number of real arguments */ 604 int narg = cast_int(L->top.p - func) - 1; /* number of real arguments */
582 int nfixparams = p->numparams; 605 int nfixparams = p->numparams;
583 int fsize = p->maxstacksize; /* frame size */ 606 int fsize = p->maxstacksize; /* frame size */
584 checkstackGCp(L, fsize, func); 607 checkstackGCp(L, fsize, func);
585 L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize); 608 L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize);
586 ci->u.l.savedpc = p->code; /* starting point */ 609 ci->u.l.savedpc = p->code; /* starting point */
587 for (; narg < nfixparams; narg++) 610 for (; narg < nfixparams; narg++)
588 setnilvalue(s2v(L->top++)); /* complete missing arguments */ 611 setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
589 lua_assert(ci->top <= L->stack_last); 612 lua_assert(ci->top.p <= L->stack_last.p);
590 return ci; 613 return ci;
591 } 614 }
592 default: { /* not a function */ 615 default: { /* not a function */
@@ -748,8 +771,8 @@ static CallInfo *findpcall (lua_State *L) {
748** coroutine error handler and should not kill the coroutine.) 771** coroutine error handler and should not kill the coroutine.)
749*/ 772*/
750static int resume_error (lua_State *L, const char *msg, int narg) { 773static int resume_error (lua_State *L, const char *msg, int narg) {
751 L->top -= narg; /* remove args from the stack */ 774 L->top.p -= narg; /* remove args from the stack */
752 setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */ 775 setsvalue2s(L, L->top.p, luaS_new(L, msg)); /* push error message */
753 api_incr_top(L); 776 api_incr_top(L);
754 lua_unlock(L); 777 lua_unlock(L);
755 return LUA_ERRRUN; 778 return LUA_ERRRUN;
@@ -765,7 +788,7 @@ static int resume_error (lua_State *L, const char *msg, int narg) {
765*/ 788*/
766static void resume (lua_State *L, void *ud) { 789static void resume (lua_State *L, void *ud) {
767 int n = *(cast(int*, ud)); /* number of arguments */ 790 int n = *(cast(int*, ud)); /* number of arguments */
768 StkId firstArg = L->top - n; /* first argument */ 791 StkId firstArg = L->top.p - n; /* first argument */
769 CallInfo *ci = L->ci; 792 CallInfo *ci = L->ci;
770 if (L->status == LUA_OK) /* starting a coroutine? */ 793 if (L->status == LUA_OK) /* starting a coroutine? */
771 ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */ 794 ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */
@@ -773,7 +796,7 @@ static void resume (lua_State *L, void *ud) {
773 lua_assert(L->status == LUA_YIELD); 796 lua_assert(L->status == LUA_YIELD);
774 L->status = LUA_OK; /* mark that it is running (again) */ 797 L->status = LUA_OK; /* mark that it is running (again) */
775 if (isLua(ci)) { /* yielded inside a hook? */ 798 if (isLua(ci)) { /* yielded inside a hook? */
776 L->top = firstArg; /* discard arguments */ 799 L->top.p = firstArg; /* discard arguments */
777 luaV_execute(L, ci); /* just continue running Lua code */ 800 luaV_execute(L, ci); /* just continue running Lua code */
778 } 801 }
779 else { /* 'common' yield */ 802 else { /* 'common' yield */
@@ -816,7 +839,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
816 if (L->status == LUA_OK) { /* may be starting a coroutine */ 839 if (L->status == LUA_OK) { /* may be starting a coroutine */
817 if (L->ci != &L->base_ci) /* not in base level? */ 840 if (L->ci != &L->base_ci) /* not in base level? */
818 return resume_error(L, "cannot resume non-suspended coroutine", nargs); 841 return resume_error(L, "cannot resume non-suspended coroutine", nargs);
819 else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ 842 else if (L->top.p - (L->ci->func.p + 1) == nargs) /* no function? */
820 return resume_error(L, "cannot resume dead coroutine", nargs); 843 return resume_error(L, "cannot resume dead coroutine", nargs);
821 } 844 }
822 else if (L->status != LUA_YIELD) /* ended with errors? */ 845 else if (L->status != LUA_YIELD) /* ended with errors? */
@@ -834,11 +857,11 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
834 lua_assert(status == L->status); /* normal end or yield */ 857 lua_assert(status == L->status); /* normal end or yield */
835 else { /* unrecoverable error */ 858 else { /* unrecoverable error */
836 L->status = cast_byte(status); /* mark thread as 'dead' */ 859 L->status = cast_byte(status); /* mark thread as 'dead' */
837 luaD_seterrorobj(L, status, L->top); /* push error message */ 860 luaD_seterrorobj(L, status, L->top.p); /* push error message */
838 L->ci->top = L->top; 861 L->ci->top.p = L->top.p;
839 } 862 }
840 *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield 863 *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield
841 : cast_int(L->top - (L->ci->func + 1)); 864 : cast_int(L->top.p - (L->ci->func.p + 1));
842 lua_unlock(L); 865 lua_unlock(L);
843 return status; 866 return status;
844} 867}
@@ -993,7 +1016,7 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
993 p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; 1016 p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;
994 p.dyd.label.arr = NULL; p.dyd.label.size = 0; 1017 p.dyd.label.arr = NULL; p.dyd.label.size = 0;
995 luaZ_initbuffer(L, &p.buff); 1018 luaZ_initbuffer(L, &p.buff);
996 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); 1019 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc);
997 luaZ_freebuffer(L, &p.buff); 1020 luaZ_freebuffer(L, &p.buff);
998 luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size); 1021 luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);
999 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); 1022 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);