diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-29 12:06:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-29 12:06:37 -0300 |
commit | 413a393e6222482f46599e138bebac162610a572 (patch) | |
tree | 181517f8ec8d56f9101de33f4891729044f244de /ldo.c | |
parent | ba089bcb08a0efc6c26fb5c1e3c9d61c00cc012c (diff) | |
download | lua-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 'ldo.c')
-rw-r--r-- | ldo.c | 125 |
1 files changed, 62 insertions, 63 deletions
@@ -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 */ |
@@ -160,13 +160,13 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { | |||
160 | static void correctstack (lua_State *L, StkId oldstack, StkId newstack) { | 160 | static void correctstack (lua_State *L, StkId oldstack, StkId newstack) { |
161 | CallInfo *ci; | 161 | CallInfo *ci; |
162 | UpVal *up; | 162 | UpVal *up; |
163 | L->top = (L->top - oldstack) + newstack; | 163 | L->top.p = (L->top.p - oldstack) + newstack; |
164 | L->tbclist = (L->tbclist - oldstack) + newstack; | 164 | L->tbclist.p = (L->tbclist.p - oldstack) + newstack; |
165 | for (up = L->openupval; up != NULL; up = up->u.open.next) | 165 | for (up = L->openupval; up != NULL; up = up->u.open.next) |
166 | up->v = s2v((uplevel(up) - oldstack) + newstack); | 166 | up->v.p = s2v((uplevel(up) - oldstack) + newstack); |
167 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 167 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
168 | ci->top = (ci->top - oldstack) + newstack; | 168 | ci->top.p = (ci->top.p - oldstack) + newstack; |
169 | ci->func = (ci->func - oldstack) + newstack; | 169 | ci->func.p = (ci->func.p - oldstack) + newstack; |
170 | if (isLua(ci)) | 170 | if (isLua(ci)) |
171 | ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */ | 171 | ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */ |
172 | } | 172 | } |
@@ -176,7 +176,6 @@ static void correctstack (lua_State *L, StkId oldstack, StkId newstack) { | |||
176 | /* some space for error handling */ | 176 | /* some space for error handling */ |
177 | #define ERRORSTACKSIZE (LUAI_MAXSTACK + 200) | 177 | #define ERRORSTACKSIZE (LUAI_MAXSTACK + 200) |
178 | 178 | ||
179 | |||
180 | /* | 179 | /* |
181 | ** Reallocate the stack to a new size, correcting all pointers into | 180 | ** Reallocate the stack to a new size, correcting all pointers into |
182 | ** it. (There are pointers to a stack from its upvalues, from its list | 181 | ** it. (There are pointers to a stack from its upvalues, from its list |
@@ -201,13 +200,13 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | |||
201 | } | 200 | } |
202 | /* number of elements to be copied to the new stack */ | 201 | /* number of elements to be copied to the new stack */ |
203 | i = ((oldsize <= newsize) ? oldsize : newsize) + EXTRA_STACK; | 202 | i = ((oldsize <= newsize) ? oldsize : newsize) + EXTRA_STACK; |
204 | memcpy(newstack, L->stack, i * sizeof(StackValue)); | 203 | memcpy(newstack, L->stack.p, i * sizeof(StackValue)); |
205 | for (; i < newsize + EXTRA_STACK; i++) | 204 | for (; i < newsize + EXTRA_STACK; i++) |
206 | setnilvalue(s2v(newstack + i)); /* erase new segment */ | 205 | setnilvalue(s2v(newstack + i)); /* erase new segment */ |
207 | correctstack(L, L->stack, newstack); | 206 | correctstack(L, L->stack.p, newstack); |
208 | luaM_freearray(L, L->stack, oldsize + EXTRA_STACK); | 207 | luaM_freearray(L, L->stack.p, oldsize + EXTRA_STACK); |
209 | L->stack = newstack; | 208 | L->stack.p = newstack; |
210 | L->stack_last = L->stack + newsize; | 209 | L->stack_last.p = L->stack.p + newsize; |
211 | return 1; | 210 | return 1; |
212 | } | 211 | } |
213 | 212 | ||
@@ -229,7 +228,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) { | |||
229 | } | 228 | } |
230 | else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */ | 229 | else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */ |
231 | int newsize = 2 * size; /* tentative new size */ | 230 | int newsize = 2 * size; /* tentative new size */ |
232 | int needed = cast_int(L->top - L->stack) + n; | 231 | int needed = cast_int(L->top.p - L->stack.p) + n; |
233 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ | 232 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ |
234 | newsize = LUAI_MAXSTACK; | 233 | newsize = LUAI_MAXSTACK; |
235 | if (newsize < needed) /* but must respect what was asked for */ | 234 | if (newsize < needed) /* but must respect what was asked for */ |
@@ -253,12 +252,12 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) { | |||
253 | static int stackinuse (lua_State *L) { | 252 | static int stackinuse (lua_State *L) { |
254 | CallInfo *ci; | 253 | CallInfo *ci; |
255 | int res; | 254 | int res; |
256 | StkId lim = L->top; | 255 | StkId lim = L->top.p; |
257 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 256 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
258 | if (lim < ci->top) lim = ci->top; | 257 | if (lim < ci->top.p) lim = ci->top.p; |
259 | } | 258 | } |
260 | lua_assert(lim <= L->stack_last + EXTRA_STACK); | 259 | lua_assert(lim <= L->stack_last.p + EXTRA_STACK); |
261 | res = cast_int(lim - L->stack) + 1; /* part of stack in use */ | 260 | res = cast_int(lim - L->stack.p) + 1; /* part of stack in use */ |
262 | if (res < LUA_MINSTACK) | 261 | if (res < LUA_MINSTACK) |
263 | res = LUA_MINSTACK; /* ensure a minimum size */ | 262 | res = LUA_MINSTACK; /* ensure a minimum size */ |
264 | return res; | 263 | return res; |
@@ -295,7 +294,7 @@ void luaD_shrinkstack (lua_State *L) { | |||
295 | 294 | ||
296 | void luaD_inctop (lua_State *L) { | 295 | void luaD_inctop (lua_State *L) { |
297 | luaD_checkstack(L, 1); | 296 | luaD_checkstack(L, 1); |
298 | L->top++; | 297 | L->top.p++; |
299 | } | 298 | } |
300 | 299 | ||
301 | /* }================================================================== */ | 300 | /* }================================================================== */ |
@@ -312,8 +311,8 @@ void luaD_hook (lua_State *L, int event, int line, | |||
312 | if (hook && L->allowhook) { /* make sure there is a hook */ | 311 | if (hook && L->allowhook) { /* make sure there is a hook */ |
313 | int mask = CIST_HOOKED; | 312 | int mask = CIST_HOOKED; |
314 | CallInfo *ci = L->ci; | 313 | CallInfo *ci = L->ci; |
315 | ptrdiff_t top = savestack(L, L->top); /* preserve original 'top' */ | 314 | ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */ |
316 | ptrdiff_t ci_top = savestack(L, ci->top); /* idem for 'ci->top' */ | 315 | ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */ |
317 | lua_Debug ar; | 316 | lua_Debug ar; |
318 | ar.event = event; | 317 | ar.event = event; |
319 | ar.currentline = line; | 318 | ar.currentline = line; |
@@ -323,11 +322,11 @@ void luaD_hook (lua_State *L, int event, int line, | |||
323 | ci->u2.transferinfo.ftransfer = ftransfer; | 322 | ci->u2.transferinfo.ftransfer = ftransfer; |
324 | ci->u2.transferinfo.ntransfer = ntransfer; | 323 | ci->u2.transferinfo.ntransfer = ntransfer; |
325 | } | 324 | } |
326 | if (isLua(ci) && L->top < ci->top) | 325 | if (isLua(ci) && L->top.p < ci->top.p) |
327 | L->top = ci->top; /* protect entire activation register */ | 326 | L->top.p = ci->top.p; /* protect entire activation register */ |
328 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 327 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
329 | if (ci->top < L->top + LUA_MINSTACK) | 328 | if (ci->top.p < L->top.p + LUA_MINSTACK) |
330 | ci->top = L->top + LUA_MINSTACK; | 329 | ci->top.p = L->top.p + LUA_MINSTACK; |
331 | L->allowhook = 0; /* cannot call hooks inside a hook */ | 330 | L->allowhook = 0; /* cannot call hooks inside a hook */ |
332 | ci->callstatus |= mask; | 331 | ci->callstatus |= mask; |
333 | lua_unlock(L); | 332 | lua_unlock(L); |
@@ -335,8 +334,8 @@ void luaD_hook (lua_State *L, int event, int line, | |||
335 | lua_lock(L); | 334 | lua_lock(L); |
336 | lua_assert(!L->allowhook); | 335 | lua_assert(!L->allowhook); |
337 | L->allowhook = 1; | 336 | L->allowhook = 1; |
338 | ci->top = restorestack(L, ci_top); | 337 | ci->top.p = restorestack(L, ci_top); |
339 | L->top = restorestack(L, top); | 338 | L->top.p = restorestack(L, top); |
340 | ci->callstatus &= ~mask; | 339 | ci->callstatus &= ~mask; |
341 | } | 340 | } |
342 | } | 341 | } |
@@ -367,7 +366,7 @@ void luaD_hookcall (lua_State *L, CallInfo *ci) { | |||
367 | */ | 366 | */ |
368 | static void rethook (lua_State *L, CallInfo *ci, int nres) { | 367 | static void rethook (lua_State *L, CallInfo *ci, int nres) { |
369 | if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ | 368 | if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ |
370 | StkId firstres = L->top - nres; /* index of first result */ | 369 | StkId firstres = L->top.p - nres; /* index of first result */ |
371 | int delta = 0; /* correction for vararg functions */ | 370 | int delta = 0; /* correction for vararg functions */ |
372 | int ftransfer; | 371 | int ftransfer; |
373 | if (isLua(ci)) { | 372 | if (isLua(ci)) { |
@@ -375,10 +374,10 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) { | |||
375 | if (p->is_vararg) | 374 | if (p->is_vararg) |
376 | delta = ci->u.l.nextraargs + p->numparams + 1; | 375 | delta = ci->u.l.nextraargs + p->numparams + 1; |
377 | } | 376 | } |
378 | ci->func += delta; /* if vararg, back to virtual 'func' */ | 377 | ci->func.p += delta; /* if vararg, back to virtual 'func' */ |
379 | ftransfer = cast(unsigned short, firstres - ci->func); | 378 | ftransfer = cast(unsigned short, firstres - ci->func.p); |
380 | luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ | 379 | luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ |
381 | ci->func -= delta; | 380 | ci->func.p -= delta; |
382 | } | 381 | } |
383 | if (isLua(ci = ci->previous)) | 382 | if (isLua(ci = ci->previous)) |
384 | L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* set 'oldpc' */ | 383 | L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* set 'oldpc' */ |
@@ -397,9 +396,9 @@ StkId luaD_tryfuncTM (lua_State *L, StkId func) { | |||
397 | tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */ | 396 | tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */ |
398 | if (l_unlikely(ttisnil(tm))) | 397 | if (l_unlikely(ttisnil(tm))) |
399 | luaG_callerror(L, s2v(func)); /* nothing to call */ | 398 | luaG_callerror(L, s2v(func)); /* nothing to call */ |
400 | for (p = L->top; p > func; p--) /* open space for metamethod */ | 399 | for (p = L->top.p; p > func; p--) /* open space for metamethod */ |
401 | setobjs2s(L, p, p-1); | 400 | setobjs2s(L, p, p-1); |
402 | L->top++; /* stack space pre-allocated by the caller */ | 401 | L->top.p++; /* stack space pre-allocated by the caller */ |
403 | setobj2s(L, func, tm); /* metamethod is the new function to be called */ | 402 | setobj2s(L, func, tm); /* metamethod is the new function to be called */ |
404 | return func; | 403 | return func; |
405 | } | 404 | } |
@@ -416,14 +415,14 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
416 | int i; | 415 | int i; |
417 | switch (wanted) { /* handle typical cases separately */ | 416 | switch (wanted) { /* handle typical cases separately */ |
418 | case 0: /* no values needed */ | 417 | case 0: /* no values needed */ |
419 | L->top = res; | 418 | L->top.p = res; |
420 | return; | 419 | return; |
421 | case 1: /* one value needed */ | 420 | case 1: /* one value needed */ |
422 | if (nres == 0) /* no results? */ | 421 | if (nres == 0) /* no results? */ |
423 | setnilvalue(s2v(res)); /* adjust with nil */ | 422 | setnilvalue(s2v(res)); /* adjust with nil */ |
424 | else /* at least one result */ | 423 | else /* at least one result */ |
425 | setobjs2s(L, res, L->top - nres); /* move it to proper place */ | 424 | setobjs2s(L, res, L->top.p - nres); /* move it to proper place */ |
426 | L->top = res + 1; | 425 | L->top.p = res + 1; |
427 | return; | 426 | return; |
428 | case LUA_MULTRET: | 427 | case LUA_MULTRET: |
429 | wanted = nres; /* we want all results */ | 428 | wanted = nres; /* we want all results */ |
@@ -446,14 +445,14 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
446 | break; | 445 | break; |
447 | } | 446 | } |
448 | /* generic case */ | 447 | /* generic case */ |
449 | firstresult = L->top - nres; /* index of first result */ | 448 | firstresult = L->top.p - nres; /* index of first result */ |
450 | if (nres > wanted) /* extra results? */ | 449 | if (nres > wanted) /* extra results? */ |
451 | nres = wanted; /* don't need them */ | 450 | nres = wanted; /* don't need them */ |
452 | for (i = 0; i < nres; i++) /* move all results to correct place */ | 451 | for (i = 0; i < nres; i++) /* move all results to correct place */ |
453 | setobjs2s(L, res + i, firstresult + i); | 452 | setobjs2s(L, res + i, firstresult + i); |
454 | for (; i < wanted; i++) /* complete wanted number of results */ | 453 | for (; i < wanted; i++) /* complete wanted number of results */ |
455 | setnilvalue(s2v(res + i)); | 454 | setnilvalue(s2v(res + i)); |
456 | L->top = res + wanted; /* top points after the last result */ | 455 | L->top.p = res + wanted; /* top points after the last result */ |
457 | } | 456 | } |
458 | 457 | ||
459 | 458 | ||
@@ -468,7 +467,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { | |||
468 | if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted))) | 467 | if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted))) |
469 | rethook(L, ci, nres); | 468 | rethook(L, ci, nres); |
470 | /* move results to proper place */ | 469 | /* move results to proper place */ |
471 | moveresults(L, ci->func, nres, wanted); | 470 | moveresults(L, ci->func.p, nres, wanted); |
472 | /* function cannot be in any of these cases when returning */ | 471 | /* function cannot be in any of these cases when returning */ |
473 | lua_assert(!(ci->callstatus & | 472 | lua_assert(!(ci->callstatus & |
474 | (CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_TRAN | CIST_CLSRET))); | 473 | (CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_TRAN | CIST_CLSRET))); |
@@ -483,10 +482,10 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { | |||
483 | l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, | 482 | l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, |
484 | int mask, StkId top) { | 483 | int mask, StkId top) { |
485 | CallInfo *ci = L->ci = next_ci(L); /* new frame */ | 484 | CallInfo *ci = L->ci = next_ci(L); /* new frame */ |
486 | ci->func = func; | 485 | ci->func.p = func; |
487 | ci->nresults = nret; | 486 | ci->nresults = nret; |
488 | ci->callstatus = mask; | 487 | ci->callstatus = mask; |
489 | ci->top = top; | 488 | ci->top.p = top; |
490 | return ci; | 489 | return ci; |
491 | } | 490 | } |
492 | 491 | ||
@@ -500,10 +499,10 @@ l_sinline int precallC (lua_State *L, StkId func, int nresults, | |||
500 | CallInfo *ci; | 499 | CallInfo *ci; |
501 | checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ | 500 | checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ |
502 | L->ci = ci = prepCallInfo(L, func, nresults, CIST_C, | 501 | L->ci = ci = prepCallInfo(L, func, nresults, CIST_C, |
503 | L->top + LUA_MINSTACK); | 502 | L->top.p + LUA_MINSTACK); |
504 | lua_assert(ci->top <= L->stack_last); | 503 | lua_assert(ci->top.p <= L->stack_last.p); |
505 | if (l_unlikely(L->hookmask & LUA_MASKCALL)) { | 504 | if (l_unlikely(L->hookmask & LUA_MASKCALL)) { |
506 | int narg = cast_int(L->top - func) - 1; | 505 | int narg = cast_int(L->top.p - func) - 1; |
507 | luaD_hook(L, LUA_HOOKCALL, -1, 1, narg); | 506 | luaD_hook(L, LUA_HOOKCALL, -1, 1, narg); |
508 | } | 507 | } |
509 | lua_unlock(L); | 508 | lua_unlock(L); |
@@ -535,17 +534,17 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, | |||
535 | int nfixparams = p->numparams; | 534 | int nfixparams = p->numparams; |
536 | int i; | 535 | int i; |
537 | checkstackGCp(L, fsize - delta, func); | 536 | checkstackGCp(L, fsize - delta, func); |
538 | ci->func -= delta; /* restore 'func' (if vararg) */ | 537 | ci->func.p -= delta; /* restore 'func' (if vararg) */ |
539 | for (i = 0; i < narg1; i++) /* move down function and arguments */ | 538 | for (i = 0; i < narg1; i++) /* move down function and arguments */ |
540 | setobjs2s(L, ci->func + i, func + i); | 539 | setobjs2s(L, ci->func.p + i, func + i); |
541 | func = ci->func; /* moved-down function */ | 540 | func = ci->func.p; /* moved-down function */ |
542 | for (; narg1 <= nfixparams; narg1++) | 541 | for (; narg1 <= nfixparams; narg1++) |
543 | setnilvalue(s2v(func + narg1)); /* complete missing arguments */ | 542 | setnilvalue(s2v(func + narg1)); /* complete missing arguments */ |
544 | ci->top = func + 1 + fsize; /* top for new function */ | 543 | ci->top.p = func + 1 + fsize; /* top for new function */ |
545 | lua_assert(ci->top <= L->stack_last); | 544 | lua_assert(ci->top.p <= L->stack_last.p); |
546 | ci->u.l.savedpc = p->code; /* starting point */ | 545 | ci->u.l.savedpc = p->code; /* starting point */ |
547 | ci->callstatus |= CIST_TAIL; | 546 | ci->callstatus |= CIST_TAIL; |
548 | L->top = func + narg1; /* set top */ | 547 | L->top.p = func + narg1; /* set top */ |
549 | return -1; | 548 | return -1; |
550 | } | 549 | } |
551 | default: { /* not a function */ | 550 | default: { /* not a function */ |
@@ -578,15 +577,15 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { | |||
578 | case LUA_VLCL: { /* Lua function */ | 577 | case LUA_VLCL: { /* Lua function */ |
579 | CallInfo *ci; | 578 | CallInfo *ci; |
580 | Proto *p = clLvalue(s2v(func))->p; | 579 | Proto *p = clLvalue(s2v(func))->p; |
581 | int narg = cast_int(L->top - func) - 1; /* number of real arguments */ | 580 | int narg = cast_int(L->top.p - func) - 1; /* number of real arguments */ |
582 | int nfixparams = p->numparams; | 581 | int nfixparams = p->numparams; |
583 | int fsize = p->maxstacksize; /* frame size */ | 582 | int fsize = p->maxstacksize; /* frame size */ |
584 | checkstackGCp(L, fsize, func); | 583 | checkstackGCp(L, fsize, func); |
585 | L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize); | 584 | L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize); |
586 | ci->u.l.savedpc = p->code; /* starting point */ | 585 | ci->u.l.savedpc = p->code; /* starting point */ |
587 | for (; narg < nfixparams; narg++) | 586 | for (; narg < nfixparams; narg++) |
588 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ | 587 | setnilvalue(s2v(L->top.p++)); /* complete missing arguments */ |
589 | lua_assert(ci->top <= L->stack_last); | 588 | lua_assert(ci->top.p <= L->stack_last.p); |
590 | return ci; | 589 | return ci; |
591 | } | 590 | } |
592 | default: { /* not a function */ | 591 | default: { /* not a function */ |
@@ -748,8 +747,8 @@ static CallInfo *findpcall (lua_State *L) { | |||
748 | ** coroutine error handler and should not kill the coroutine.) | 747 | ** coroutine error handler and should not kill the coroutine.) |
749 | */ | 748 | */ |
750 | static int resume_error (lua_State *L, const char *msg, int narg) { | 749 | static int resume_error (lua_State *L, const char *msg, int narg) { |
751 | L->top -= narg; /* remove args from the stack */ | 750 | L->top.p -= narg; /* remove args from the stack */ |
752 | setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */ | 751 | setsvalue2s(L, L->top.p, luaS_new(L, msg)); /* push error message */ |
753 | api_incr_top(L); | 752 | api_incr_top(L); |
754 | lua_unlock(L); | 753 | lua_unlock(L); |
755 | return LUA_ERRRUN; | 754 | return LUA_ERRRUN; |
@@ -765,7 +764,7 @@ static int resume_error (lua_State *L, const char *msg, int narg) { | |||
765 | */ | 764 | */ |
766 | static void resume (lua_State *L, void *ud) { | 765 | static void resume (lua_State *L, void *ud) { |
767 | int n = *(cast(int*, ud)); /* number of arguments */ | 766 | int n = *(cast(int*, ud)); /* number of arguments */ |
768 | StkId firstArg = L->top - n; /* first argument */ | 767 | StkId firstArg = L->top.p - n; /* first argument */ |
769 | CallInfo *ci = L->ci; | 768 | CallInfo *ci = L->ci; |
770 | if (L->status == LUA_OK) /* starting a coroutine? */ | 769 | if (L->status == LUA_OK) /* starting a coroutine? */ |
771 | ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */ | 770 | ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */ |
@@ -773,7 +772,7 @@ static void resume (lua_State *L, void *ud) { | |||
773 | lua_assert(L->status == LUA_YIELD); | 772 | lua_assert(L->status == LUA_YIELD); |
774 | L->status = LUA_OK; /* mark that it is running (again) */ | 773 | L->status = LUA_OK; /* mark that it is running (again) */ |
775 | if (isLua(ci)) { /* yielded inside a hook? */ | 774 | if (isLua(ci)) { /* yielded inside a hook? */ |
776 | L->top = firstArg; /* discard arguments */ | 775 | L->top.p = firstArg; /* discard arguments */ |
777 | luaV_execute(L, ci); /* just continue running Lua code */ | 776 | luaV_execute(L, ci); /* just continue running Lua code */ |
778 | } | 777 | } |
779 | else { /* 'common' yield */ | 778 | else { /* 'common' yield */ |
@@ -816,7 +815,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 */ | 815 | if (L->status == LUA_OK) { /* may be starting a coroutine */ |
817 | if (L->ci != &L->base_ci) /* not in base level? */ | 816 | if (L->ci != &L->base_ci) /* not in base level? */ |
818 | return resume_error(L, "cannot resume non-suspended coroutine", nargs); | 817 | return resume_error(L, "cannot resume non-suspended coroutine", nargs); |
819 | else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ | 818 | else if (L->top.p - (L->ci->func.p + 1) == nargs) /* no function? */ |
820 | return resume_error(L, "cannot resume dead coroutine", nargs); | 819 | return resume_error(L, "cannot resume dead coroutine", nargs); |
821 | } | 820 | } |
822 | else if (L->status != LUA_YIELD) /* ended with errors? */ | 821 | else if (L->status != LUA_YIELD) /* ended with errors? */ |
@@ -834,11 +833,11 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, | |||
834 | lua_assert(status == L->status); /* normal end or yield */ | 833 | lua_assert(status == L->status); /* normal end or yield */ |
835 | else { /* unrecoverable error */ | 834 | else { /* unrecoverable error */ |
836 | L->status = cast_byte(status); /* mark thread as 'dead' */ | 835 | L->status = cast_byte(status); /* mark thread as 'dead' */ |
837 | luaD_seterrorobj(L, status, L->top); /* push error message */ | 836 | luaD_seterrorobj(L, status, L->top.p); /* push error message */ |
838 | L->ci->top = L->top; | 837 | L->ci->top.p = L->top.p; |
839 | } | 838 | } |
840 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield | 839 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield |
841 | : cast_int(L->top - (L->ci->func + 1)); | 840 | : cast_int(L->top.p - (L->ci->func.p + 1)); |
842 | lua_unlock(L); | 841 | lua_unlock(L); |
843 | return status; | 842 | return status; |
844 | } | 843 | } |
@@ -993,7 +992,7 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, | |||
993 | p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; | 992 | p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; |
994 | p.dyd.label.arr = NULL; p.dyd.label.size = 0; | 993 | p.dyd.label.arr = NULL; p.dyd.label.size = 0; |
995 | luaZ_initbuffer(L, &p.buff); | 994 | luaZ_initbuffer(L, &p.buff); |
996 | status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); | 995 | status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc); |
997 | luaZ_freebuffer(L, &p.buff); | 996 | luaZ_freebuffer(L, &p.buff); |
998 | luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size); | 997 | luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size); |
999 | luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); | 998 | luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); |