aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--lapi.c235
-rw-r--r--lapi.h17
-rw-r--r--ldebug.c52
-rw-r--r--ldebug.h2
-rw-r--r--ldo.c125
-rw-r--r--ldo.h7
-rw-r--r--lfunc.c42
-rw-r--r--lfunc.h4
-rw-r--r--lgc.c20
-rw-r--r--llex.c4
-rw-r--r--lobject.c6
-rw-r--r--lobject.h10
-rw-r--r--lparser.c6
-rw-r--r--lstate.c42
-rw-r--r--lstate.h14
-rw-r--r--ltests.c24
-rw-r--r--ltm.c38
-rw-r--r--lundump.c6
-rw-r--r--lvm.c100
19 files changed, 384 insertions, 370 deletions
diff --git a/lapi.c b/lapi.c
index 5833c7b0..34e64af1 100644
--- a/lapi.c
+++ b/lapi.c
@@ -60,27 +60,28 @@ const char lua_ident[] =
60static TValue *index2value (lua_State *L, int idx) { 60static TValue *index2value (lua_State *L, int idx) {
61 CallInfo *ci = L->ci; 61 CallInfo *ci = L->ci;
62 if (idx > 0) { 62 if (idx > 0) {
63 StkId o = ci->func + idx; 63 StkId o = ci->func.p + idx;
64 api_check(L, idx <= L->ci->top - (ci->func + 1), "unacceptable index"); 64 api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index");
65 if (o >= L->top) return &G(L)->nilvalue; 65 if (o >= L->top.p) return &G(L)->nilvalue;
66 else return s2v(o); 66 else return s2v(o);
67 } 67 }
68 else if (!ispseudo(idx)) { /* negative index */ 68 else if (!ispseudo(idx)) { /* negative index */
69 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); 69 api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
70 return s2v(L->top + idx); 70 "invalid index");
71 return s2v(L->top.p + idx);
71 } 72 }
72 else if (idx == LUA_REGISTRYINDEX) 73 else if (idx == LUA_REGISTRYINDEX)
73 return &G(L)->l_registry; 74 return &G(L)->l_registry;
74 else { /* upvalues */ 75 else { /* upvalues */
75 idx = LUA_REGISTRYINDEX - idx; 76 idx = LUA_REGISTRYINDEX - idx;
76 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); 77 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
77 if (ttisCclosure(s2v(ci->func))) { /* C closure? */ 78 if (ttisCclosure(s2v(ci->func.p))) { /* C closure? */
78 CClosure *func = clCvalue(s2v(ci->func)); 79 CClosure *func = clCvalue(s2v(ci->func.p));
79 return (idx <= func->nupvalues) ? &func->upvalue[idx-1] 80 return (idx <= func->nupvalues) ? &func->upvalue[idx-1]
80 : &G(L)->nilvalue; 81 : &G(L)->nilvalue;
81 } 82 }
82 else { /* light C function or Lua function (through a hook)?) */ 83 else { /* light C function or Lua function (through a hook)?) */
83 api_check(L, ttislcf(s2v(ci->func)), "caller not a C function"); 84 api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function");
84 return &G(L)->nilvalue; /* no upvalues */ 85 return &G(L)->nilvalue; /* no upvalues */
85 } 86 }
86 } 87 }
@@ -94,14 +95,15 @@ static TValue *index2value (lua_State *L, int idx) {
94l_sinline StkId index2stack (lua_State *L, int idx) { 95l_sinline StkId index2stack (lua_State *L, int idx) {
95 CallInfo *ci = L->ci; 96 CallInfo *ci = L->ci;
96 if (idx > 0) { 97 if (idx > 0) {
97 StkId o = ci->func + idx; 98 StkId o = ci->func.p + idx;
98 api_check(L, o < L->top, "invalid index"); 99 api_check(L, o < L->top.p, "invalid index");
99 return o; 100 return o;
100 } 101 }
101 else { /* non-positive index */ 102 else { /* non-positive index */
102 api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); 103 api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
104 "invalid index");
103 api_check(L, !ispseudo(idx), "invalid index"); 105 api_check(L, !ispseudo(idx), "invalid index");
104 return L->top + idx; 106 return L->top.p + idx;
105 } 107 }
106} 108}
107 109
@@ -112,12 +114,12 @@ LUA_API int lua_checkstack (lua_State *L, int n) {
112 lua_lock(L); 114 lua_lock(L);
113 ci = L->ci; 115 ci = L->ci;
114 api_check(L, n >= 0, "negative 'n'"); 116 api_check(L, n >= 0, "negative 'n'");
115 if (L->stack_last - L->top > n) /* stack large enough? */ 117 if (L->stack_last.p - L->top.p > n) /* stack large enough? */
116 res = 1; /* yes; check is OK */ 118 res = 1; /* yes; check is OK */
117 else /* need to grow stack */ 119 else /* need to grow stack */
118 res = luaD_growstack(L, n, 0); 120 res = luaD_growstack(L, n, 0);
119 if (res && ci->top < L->top + n) 121 if (res && ci->top.p < L->top.p + n)
120 ci->top = L->top + n; /* adjust frame top */ 122 ci->top.p = L->top.p + n; /* adjust frame top */
121 lua_unlock(L); 123 lua_unlock(L);
122 return res; 124 return res;
123} 125}
@@ -129,11 +131,11 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
129 lua_lock(to); 131 lua_lock(to);
130 api_checknelems(from, n); 132 api_checknelems(from, n);
131 api_check(from, G(from) == G(to), "moving among independent states"); 133 api_check(from, G(from) == G(to), "moving among independent states");
132 api_check(from, to->ci->top - to->top >= n, "stack overflow"); 134 api_check(from, to->ci->top.p - to->top.p >= n, "stack overflow");
133 from->top -= n; 135 from->top.p -= n;
134 for (i = 0; i < n; i++) { 136 for (i = 0; i < n; i++) {
135 setobjs2s(to, to->top, from->top + i); 137 setobjs2s(to, to->top.p, from->top.p + i);
136 to->top++; /* stack already checked by previous 'api_check' */ 138 to->top.p++; /* stack already checked by previous 'api_check' */
137 } 139 }
138 lua_unlock(to); 140 lua_unlock(to);
139} 141}
@@ -167,12 +169,12 @@ LUA_API lua_Number lua_version (lua_State *L) {
167LUA_API int lua_absindex (lua_State *L, int idx) { 169LUA_API int lua_absindex (lua_State *L, int idx) {
168 return (idx > 0 || ispseudo(idx)) 170 return (idx > 0 || ispseudo(idx))
169 ? idx 171 ? idx
170 : cast_int(L->top - L->ci->func) + idx; 172 : cast_int(L->top.p - L->ci->func.p) + idx;
171} 173}
172 174
173 175
174LUA_API int lua_gettop (lua_State *L) { 176LUA_API int lua_gettop (lua_State *L) {
175 return cast_int(L->top - (L->ci->func + 1)); 177 return cast_int(L->top.p - (L->ci->func.p + 1));
176} 178}
177 179
178 180
@@ -182,24 +184,24 @@ LUA_API void lua_settop (lua_State *L, int idx) {
182 ptrdiff_t diff; /* difference for new top */ 184 ptrdiff_t diff; /* difference for new top */
183 lua_lock(L); 185 lua_lock(L);
184 ci = L->ci; 186 ci = L->ci;
185 func = ci->func; 187 func = ci->func.p;
186 if (idx >= 0) { 188 if (idx >= 0) {
187 api_check(L, idx <= ci->top - (func + 1), "new top too large"); 189 api_check(L, idx <= ci->top.p - (func + 1), "new top too large");
188 diff = ((func + 1) + idx) - L->top; 190 diff = ((func + 1) + idx) - L->top.p;
189 for (; diff > 0; diff--) 191 for (; diff > 0; diff--)
190 setnilvalue(s2v(L->top++)); /* clear new slots */ 192 setnilvalue(s2v(L->top.p++)); /* clear new slots */
191 } 193 }
192 else { 194 else {
193 api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); 195 api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top");
194 diff = idx + 1; /* will "subtract" index (as it is negative) */ 196 diff = idx + 1; /* will "subtract" index (as it is negative) */
195 } 197 }
196 api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot"); 198 api_check(L, L->tbclist.p < L->top.p, "previous pop of an unclosed slot");
197 newtop = L->top + diff; 199 newtop = L->top.p + diff;
198 if (diff < 0 && L->tbclist >= newtop) { 200 if (diff < 0 && L->tbclist.p >= newtop) {
199 lua_assert(hastocloseCfunc(ci->nresults)); 201 lua_assert(hastocloseCfunc(ci->nresults));
200 newtop = luaF_close(L, newtop, CLOSEKTOP, 0); 202 newtop = luaF_close(L, newtop, CLOSEKTOP, 0);
201 } 203 }
202 L->top = newtop; /* correct top only after closing any upvalue */ 204 L->top.p = newtop; /* correct top only after closing any upvalue */
203 lua_unlock(L); 205 lua_unlock(L);
204} 206}
205 207
@@ -208,7 +210,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) {
208 StkId level; 210 StkId level;
209 lua_lock(L); 211 lua_lock(L);
210 level = index2stack(L, idx); 212 level = index2stack(L, idx);
211 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level, 213 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist.p == level,
212 "no variable to close at given level"); 214 "no variable to close at given level");
213 level = luaF_close(L, level, CLOSEKTOP, 0); 215 level = luaF_close(L, level, CLOSEKTOP, 0);
214 setnilvalue(s2v(level)); 216 setnilvalue(s2v(level));
@@ -239,7 +241,7 @@ l_sinline void reverse (lua_State *L, StkId from, StkId to) {
239LUA_API void lua_rotate (lua_State *L, int idx, int n) { 241LUA_API void lua_rotate (lua_State *L, int idx, int n) {
240 StkId p, t, m; 242 StkId p, t, m;
241 lua_lock(L); 243 lua_lock(L);
242 t = L->top - 1; /* end of stack segment being rotated */ 244 t = L->top.p - 1; /* end of stack segment being rotated */
243 p = index2stack(L, idx); /* start of segment */ 245 p = index2stack(L, idx); /* start of segment */
244 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); 246 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
245 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ 247 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */
@@ -258,7 +260,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {
258 api_check(L, isvalid(L, to), "invalid index"); 260 api_check(L, isvalid(L, to), "invalid index");
259 setobj(L, to, fr); 261 setobj(L, to, fr);
260 if (isupvalue(toidx)) /* function upvalue? */ 262 if (isupvalue(toidx)) /* function upvalue? */
261 luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr); 263 luaC_barrier(L, clCvalue(s2v(L->ci->func.p)), fr);
262 /* LUA_REGISTRYINDEX does not need gc barrier 264 /* LUA_REGISTRYINDEX does not need gc barrier
263 (collector revisits it before finishing collection) */ 265 (collector revisits it before finishing collection) */
264 lua_unlock(L); 266 lua_unlock(L);
@@ -267,7 +269,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {
267 269
268LUA_API void lua_pushvalue (lua_State *L, int idx) { 270LUA_API void lua_pushvalue (lua_State *L, int idx) {
269 lua_lock(L); 271 lua_lock(L);
270 setobj2s(L, L->top, index2value(L, idx)); 272 setobj2s(L, L->top.p, index2value(L, idx));
271 api_incr_top(L); 273 api_incr_top(L);
272 lua_unlock(L); 274 lua_unlock(L);
273} 275}
@@ -336,12 +338,12 @@ LUA_API void lua_arith (lua_State *L, int op) {
336 api_checknelems(L, 2); /* all other operations expect two operands */ 338 api_checknelems(L, 2); /* all other operations expect two operands */
337 else { /* for unary operations, add fake 2nd operand */ 339 else { /* for unary operations, add fake 2nd operand */
338 api_checknelems(L, 1); 340 api_checknelems(L, 1);
339 setobjs2s(L, L->top, L->top - 1); 341 setobjs2s(L, L->top.p, L->top.p - 1);
340 api_incr_top(L); 342 api_incr_top(L);
341 } 343 }
342 /* first operand at top - 2, second at top - 1; result go to top - 2 */ 344 /* first operand at top - 2, second at top - 1; result go to top - 2 */
343 luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2); 345 luaO_arith(L, op, s2v(L->top.p - 2), s2v(L->top.p - 1), L->top.p - 2);
344 L->top--; /* remove second operand */ 346 L->top.p--; /* remove second operand */
345 lua_unlock(L); 347 lua_unlock(L);
346} 348}
347 349
@@ -367,7 +369,7 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
367 369
368 370
369LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { 371LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {
370 size_t sz = luaO_str2num(s, s2v(L->top)); 372 size_t sz = luaO_str2num(s, s2v(L->top.p));
371 if (sz != 0) 373 if (sz != 0)
372 api_incr_top(L); 374 api_incr_top(L);
373 return sz; 375 return sz;
@@ -494,7 +496,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) {
494 496
495LUA_API void lua_pushnil (lua_State *L) { 497LUA_API void lua_pushnil (lua_State *L) {
496 lua_lock(L); 498 lua_lock(L);
497 setnilvalue(s2v(L->top)); 499 setnilvalue(s2v(L->top.p));
498 api_incr_top(L); 500 api_incr_top(L);
499 lua_unlock(L); 501 lua_unlock(L);
500} 502}
@@ -502,7 +504,7 @@ LUA_API void lua_pushnil (lua_State *L) {
502 504
503LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { 505LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
504 lua_lock(L); 506 lua_lock(L);
505 setfltvalue(s2v(L->top), n); 507 setfltvalue(s2v(L->top.p), n);
506 api_incr_top(L); 508 api_incr_top(L);
507 lua_unlock(L); 509 lua_unlock(L);
508} 510}
@@ -510,7 +512,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
510 512
511LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { 513LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
512 lua_lock(L); 514 lua_lock(L);
513 setivalue(s2v(L->top), n); 515 setivalue(s2v(L->top.p), n);
514 api_incr_top(L); 516 api_incr_top(L);
515 lua_unlock(L); 517 lua_unlock(L);
516} 518}
@@ -525,7 +527,7 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
525 TString *ts; 527 TString *ts;
526 lua_lock(L); 528 lua_lock(L);
527 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); 529 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
528 setsvalue2s(L, L->top, ts); 530 setsvalue2s(L, L->top.p, ts);
529 api_incr_top(L); 531 api_incr_top(L);
530 luaC_checkGC(L); 532 luaC_checkGC(L);
531 lua_unlock(L); 533 lua_unlock(L);
@@ -536,11 +538,11 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
536LUA_API const char *lua_pushstring (lua_State *L, const char *s) { 538LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
537 lua_lock(L); 539 lua_lock(L);
538 if (s == NULL) 540 if (s == NULL)
539 setnilvalue(s2v(L->top)); 541 setnilvalue(s2v(L->top.p));
540 else { 542 else {
541 TString *ts; 543 TString *ts;
542 ts = luaS_new(L, s); 544 ts = luaS_new(L, s);
543 setsvalue2s(L, L->top, ts); 545 setsvalue2s(L, L->top.p, ts);
544 s = getstr(ts); /* internal copy's address */ 546 s = getstr(ts); /* internal copy's address */
545 } 547 }
546 api_incr_top(L); 548 api_incr_top(L);
@@ -577,7 +579,7 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
577LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { 579LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
578 lua_lock(L); 580 lua_lock(L);
579 if (n == 0) { 581 if (n == 0) {
580 setfvalue(s2v(L->top), fn); 582 setfvalue(s2v(L->top.p), fn);
581 api_incr_top(L); 583 api_incr_top(L);
582 } 584 }
583 else { 585 else {
@@ -586,13 +588,13 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
586 api_check(L, n <= MAXUPVAL, "upvalue index too large"); 588 api_check(L, n <= MAXUPVAL, "upvalue index too large");
587 cl = luaF_newCclosure(L, n); 589 cl = luaF_newCclosure(L, n);
588 cl->f = fn; 590 cl->f = fn;
589 L->top -= n; 591 L->top.p -= n;
590 while (n--) { 592 while (n--) {
591 setobj2n(L, &cl->upvalue[n], s2v(L->top + n)); 593 setobj2n(L, &cl->upvalue[n], s2v(L->top.p + n));
592 /* does not need barrier because closure is white */ 594 /* does not need barrier because closure is white */
593 lua_assert(iswhite(cl)); 595 lua_assert(iswhite(cl));
594 } 596 }
595 setclCvalue(L, s2v(L->top), cl); 597 setclCvalue(L, s2v(L->top.p), cl);
596 api_incr_top(L); 598 api_incr_top(L);
597 luaC_checkGC(L); 599 luaC_checkGC(L);
598 } 600 }
@@ -603,9 +605,9 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
603LUA_API void lua_pushboolean (lua_State *L, int b) { 605LUA_API void lua_pushboolean (lua_State *L, int b) {
604 lua_lock(L); 606 lua_lock(L);
605 if (b) 607 if (b)
606 setbtvalue(s2v(L->top)); 608 setbtvalue(s2v(L->top.p));
607 else 609 else
608 setbfvalue(s2v(L->top)); 610 setbfvalue(s2v(L->top.p));
609 api_incr_top(L); 611 api_incr_top(L);
610 lua_unlock(L); 612 lua_unlock(L);
611} 613}
@@ -613,7 +615,7 @@ LUA_API void lua_pushboolean (lua_State *L, int b) {
613 615
614LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { 616LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
615 lua_lock(L); 617 lua_lock(L);
616 setpvalue(s2v(L->top), p); 618 setpvalue(s2v(L->top.p), p);
617 api_incr_top(L); 619 api_incr_top(L);
618 lua_unlock(L); 620 lua_unlock(L);
619} 621}
@@ -621,7 +623,7 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
621 623
622LUA_API int lua_pushthread (lua_State *L) { 624LUA_API int lua_pushthread (lua_State *L) {
623 lua_lock(L); 625 lua_lock(L);
624 setthvalue(L, s2v(L->top), L); 626 setthvalue(L, s2v(L->top.p), L);
625 api_incr_top(L); 627 api_incr_top(L);
626 lua_unlock(L); 628 lua_unlock(L);
627 return (G(L)->mainthread == L); 629 return (G(L)->mainthread == L);
@@ -638,16 +640,16 @@ l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) {
638 const TValue *slot; 640 const TValue *slot;
639 TString *str = luaS_new(L, k); 641 TString *str = luaS_new(L, k);
640 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { 642 if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
641 setobj2s(L, L->top, slot); 643 setobj2s(L, L->top.p, slot);
642 api_incr_top(L); 644 api_incr_top(L);
643 } 645 }
644 else { 646 else {
645 setsvalue2s(L, L->top, str); 647 setsvalue2s(L, L->top.p, str);
646 api_incr_top(L); 648 api_incr_top(L);
647 luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); 649 luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);
648 } 650 }
649 lua_unlock(L); 651 lua_unlock(L);
650 return ttype(s2v(L->top - 1)); 652 return ttype(s2v(L->top.p - 1));
651} 653}
652 654
653 655
@@ -674,13 +676,13 @@ LUA_API int lua_gettable (lua_State *L, int idx) {
674 TValue *t; 676 TValue *t;
675 lua_lock(L); 677 lua_lock(L);
676 t = index2value(L, idx); 678 t = index2value(L, idx);
677 if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) { 679 if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) {
678 setobj2s(L, L->top - 1, slot); 680 setobj2s(L, L->top.p - 1, slot);
679 } 681 }
680 else 682 else
681 luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); 683 luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);
682 lua_unlock(L); 684 lua_unlock(L);
683 return ttype(s2v(L->top - 1)); 685 return ttype(s2v(L->top.p - 1));
684} 686}
685 687
686 688
@@ -696,27 +698,27 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
696 lua_lock(L); 698 lua_lock(L);
697 t = index2value(L, idx); 699 t = index2value(L, idx);
698 if (luaV_fastgeti(L, t, n, slot)) { 700 if (luaV_fastgeti(L, t, n, slot)) {
699 setobj2s(L, L->top, slot); 701 setobj2s(L, L->top.p, slot);
700 } 702 }
701 else { 703 else {
702 TValue aux; 704 TValue aux;
703 setivalue(&aux, n); 705 setivalue(&aux, n);
704 luaV_finishget(L, t, &aux, L->top, slot); 706 luaV_finishget(L, t, &aux, L->top.p, slot);
705 } 707 }
706 api_incr_top(L); 708 api_incr_top(L);
707 lua_unlock(L); 709 lua_unlock(L);
708 return ttype(s2v(L->top - 1)); 710 return ttype(s2v(L->top.p - 1));
709} 711}
710 712
711 713
712l_sinline int finishrawget (lua_State *L, const TValue *val) { 714l_sinline int finishrawget (lua_State *L, const TValue *val) {
713 if (isempty(val)) /* avoid copying empty items to the stack */ 715 if (isempty(val)) /* avoid copying empty items to the stack */
714 setnilvalue(s2v(L->top)); 716 setnilvalue(s2v(L->top.p));
715 else 717 else
716 setobj2s(L, L->top, val); 718 setobj2s(L, L->top.p, val);
717 api_incr_top(L); 719 api_incr_top(L);
718 lua_unlock(L); 720 lua_unlock(L);
719 return ttype(s2v(L->top - 1)); 721 return ttype(s2v(L->top.p - 1));
720} 722}
721 723
722 724
@@ -733,8 +735,8 @@ LUA_API int lua_rawget (lua_State *L, int idx) {
733 lua_lock(L); 735 lua_lock(L);
734 api_checknelems(L, 1); 736 api_checknelems(L, 1);
735 t = gettable(L, idx); 737 t = gettable(L, idx);
736 val = luaH_get(t, s2v(L->top - 1)); 738 val = luaH_get(t, s2v(L->top.p - 1));
737 L->top--; /* remove key */ 739 L->top.p--; /* remove key */
738 return finishrawget(L, val); 740 return finishrawget(L, val);
739} 741}
740 742
@@ -761,7 +763,7 @@ LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
761 Table *t; 763 Table *t;
762 lua_lock(L); 764 lua_lock(L);
763 t = luaH_new(L); 765 t = luaH_new(L);
764 sethvalue2s(L, L->top, t); 766 sethvalue2s(L, L->top.p, t);
765 api_incr_top(L); 767 api_incr_top(L);
766 if (narray > 0 || nrec > 0) 768 if (narray > 0 || nrec > 0)
767 luaH_resize(L, t, narray, nrec); 769 luaH_resize(L, t, narray, nrec);
@@ -788,7 +790,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
788 break; 790 break;
789 } 791 }
790 if (mt != NULL) { 792 if (mt != NULL) {
791 sethvalue2s(L, L->top, mt); 793 sethvalue2s(L, L->top.p, mt);
792 api_incr_top(L); 794 api_incr_top(L);
793 res = 1; 795 res = 1;
794 } 796 }
@@ -804,12 +806,12 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) {
804 o = index2value(L, idx); 806 o = index2value(L, idx);
805 api_check(L, ttisfulluserdata(o), "full userdata expected"); 807 api_check(L, ttisfulluserdata(o), "full userdata expected");
806 if (n <= 0 || n > uvalue(o)->nuvalue) { 808 if (n <= 0 || n > uvalue(o)->nuvalue) {
807 setnilvalue(s2v(L->top)); 809 setnilvalue(s2v(L->top.p));
808 t = LUA_TNONE; 810 t = LUA_TNONE;
809 } 811 }
810 else { 812 else {
811 setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv); 813 setobj2s(L, L->top.p, &uvalue(o)->uv[n - 1].uv);
812 t = ttype(s2v(L->top)); 814 t = ttype(s2v(L->top.p));
813 } 815 }
814 api_incr_top(L); 816 api_incr_top(L);
815 lua_unlock(L); 817 lua_unlock(L);
@@ -829,14 +831,14 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) {
829 TString *str = luaS_new(L, k); 831 TString *str = luaS_new(L, k);
830 api_checknelems(L, 1); 832 api_checknelems(L, 1);
831 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { 833 if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
832 luaV_finishfastset(L, t, slot, s2v(L->top - 1)); 834 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
833 L->top--; /* pop value */ 835 L->top.p--; /* pop value */
834 } 836 }
835 else { 837 else {
836 setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ 838 setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */
837 api_incr_top(L); 839 api_incr_top(L);
838 luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot); 840 luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot);
839 L->top -= 2; /* pop value and key */ 841 L->top.p -= 2; /* pop value and key */
840 } 842 }
841 lua_unlock(L); /* lock done by caller */ 843 lua_unlock(L); /* lock done by caller */
842} 844}
@@ -856,12 +858,12 @@ LUA_API void lua_settable (lua_State *L, int idx) {
856 lua_lock(L); 858 lua_lock(L);
857 api_checknelems(L, 2); 859 api_checknelems(L, 2);
858 t = index2value(L, idx); 860 t = index2value(L, idx);
859 if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) { 861 if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) {
860 luaV_finishfastset(L, t, slot, s2v(L->top - 1)); 862 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
861 } 863 }
862 else 864 else
863 luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot); 865 luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot);
864 L->top -= 2; /* pop index and value */ 866 L->top.p -= 2; /* pop index and value */
865 lua_unlock(L); 867 lua_unlock(L);
866} 868}
867 869
@@ -879,14 +881,14 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
879 api_checknelems(L, 1); 881 api_checknelems(L, 1);
880 t = index2value(L, idx); 882 t = index2value(L, idx);
881 if (luaV_fastgeti(L, t, n, slot)) { 883 if (luaV_fastgeti(L, t, n, slot)) {
882 luaV_finishfastset(L, t, slot, s2v(L->top - 1)); 884 luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
883 } 885 }
884 else { 886 else {
885 TValue aux; 887 TValue aux;
886 setivalue(&aux, n); 888 setivalue(&aux, n);
887 luaV_finishset(L, t, &aux, s2v(L->top - 1), slot); 889 luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot);
888 } 890 }
889 L->top--; /* pop value */ 891 L->top.p--; /* pop value */
890 lua_unlock(L); 892 lua_unlock(L);
891} 893}
892 894
@@ -896,16 +898,16 @@ static void aux_rawset (lua_State *L, int idx, TValue *key, int n) {
896 lua_lock(L); 898 lua_lock(L);
897 api_checknelems(L, n); 899 api_checknelems(L, n);
898 t = gettable(L, idx); 900 t = gettable(L, idx);
899 luaH_set(L, t, key, s2v(L->top - 1)); 901 luaH_set(L, t, key, s2v(L->top.p - 1));
900 invalidateTMcache(t); 902 invalidateTMcache(t);
901 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); 903 luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1));
902 L->top -= n; 904 L->top.p -= n;
903 lua_unlock(L); 905 lua_unlock(L);
904} 906}
905 907
906 908
907LUA_API void lua_rawset (lua_State *L, int idx) { 909LUA_API void lua_rawset (lua_State *L, int idx) {
908 aux_rawset(L, idx, s2v(L->top - 2), 2); 910 aux_rawset(L, idx, s2v(L->top.p - 2), 2);
909} 911}
910 912
911 913
@@ -921,9 +923,9 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
921 lua_lock(L); 923 lua_lock(L);
922 api_checknelems(L, 1); 924 api_checknelems(L, 1);
923 t = gettable(L, idx); 925 t = gettable(L, idx);
924 luaH_setint(L, t, n, s2v(L->top - 1)); 926 luaH_setint(L, t, n, s2v(L->top.p - 1));
925 luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); 927 luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1));
926 L->top--; 928 L->top.p--;
927 lua_unlock(L); 929 lua_unlock(L);
928} 930}
929 931
@@ -934,11 +936,11 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
934 lua_lock(L); 936 lua_lock(L);
935 api_checknelems(L, 1); 937 api_checknelems(L, 1);
936 obj = index2value(L, objindex); 938 obj = index2value(L, objindex);
937 if (ttisnil(s2v(L->top - 1))) 939 if (ttisnil(s2v(L->top.p - 1)))
938 mt = NULL; 940 mt = NULL;
939 else { 941 else {
940 api_check(L, ttistable(s2v(L->top - 1)), "table expected"); 942 api_check(L, ttistable(s2v(L->top.p - 1)), "table expected");
941 mt = hvalue(s2v(L->top - 1)); 943 mt = hvalue(s2v(L->top.p - 1));
942 } 944 }
943 switch (ttype(obj)) { 945 switch (ttype(obj)) {
944 case LUA_TTABLE: { 946 case LUA_TTABLE: {
@@ -962,7 +964,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
962 break; 964 break;
963 } 965 }
964 } 966 }
965 L->top--; 967 L->top.p--;
966 lua_unlock(L); 968 lua_unlock(L);
967 return 1; 969 return 1;
968} 970}
@@ -978,11 +980,11 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {
978 if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue))) 980 if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue)))
979 res = 0; /* 'n' not in [1, uvalue(o)->nuvalue] */ 981 res = 0; /* 'n' not in [1, uvalue(o)->nuvalue] */
980 else { 982 else {
981 setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top - 1)); 983 setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top.p - 1));
982 luaC_barrierback(L, gcvalue(o), s2v(L->top - 1)); 984 luaC_barrierback(L, gcvalue(o), s2v(L->top.p - 1));
983 res = 1; 985 res = 1;
984 } 986 }
985 L->top--; 987 L->top.p--;
986 lua_unlock(L); 988 lua_unlock(L);
987 return res; 989 return res;
988} 990}
@@ -994,7 +996,8 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {
994 996
995 997
996#define checkresults(L,na,nr) \ 998#define checkresults(L,na,nr) \
997 api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \ 999 api_check(L, (nr) == LUA_MULTRET \
1000 || (L->ci->top.p - L->top.p >= (nr) - (na)), \
998 "results from function overflow current stack size") 1001 "results from function overflow current stack size")
999 1002
1000 1003
@@ -1007,7 +1010,7 @@ LUA_API void lua_callk (lua_State *L, int nargs, int nresults,
1007 api_checknelems(L, nargs+1); 1010 api_checknelems(L, nargs+1);
1008 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); 1011 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
1009 checkresults(L, nargs, nresults); 1012 checkresults(L, nargs, nresults);
1010 func = L->top - (nargs+1); 1013 func = L->top.p - (nargs+1);
1011 if (k != NULL && yieldable(L)) { /* need to prepare continuation? */ 1014 if (k != NULL && yieldable(L)) { /* need to prepare continuation? */
1012 L->ci->u.c.k = k; /* save continuation */ 1015 L->ci->u.c.k = k; /* save continuation */
1013 L->ci->u.c.ctx = ctx; /* save context */ 1016 L->ci->u.c.ctx = ctx; /* save context */
@@ -1055,7 +1058,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
1055 api_check(L, ttisfunction(s2v(o)), "error handler must be a function"); 1058 api_check(L, ttisfunction(s2v(o)), "error handler must be a function");
1056 func = savestack(L, o); 1059 func = savestack(L, o);
1057 } 1060 }
1058 c.func = L->top - (nargs+1); /* function to be called */ 1061 c.func = L->top.p - (nargs+1); /* function to be called */
1059 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */ 1062 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */
1060 c.nresults = nresults; /* do a 'conventional' protected call */ 1063 c.nresults = nresults; /* do a 'conventional' protected call */
1061 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); 1064 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
@@ -1090,12 +1093,12 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
1090 luaZ_init(L, &z, reader, data); 1093 luaZ_init(L, &z, reader, data);
1091 status = luaD_protectedparser(L, &z, chunkname, mode); 1094 status = luaD_protectedparser(L, &z, chunkname, mode);
1092 if (status == LUA_OK) { /* no errors? */ 1095 if (status == LUA_OK) { /* no errors? */
1093 LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ 1096 LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */
1094 if (f->nupvalues >= 1) { /* does it have an upvalue? */ 1097 if (f->nupvalues >= 1) { /* does it have an upvalue? */
1095 /* get global table from registry */ 1098 /* get global table from registry */
1096 const TValue *gt = getGtable(L); 1099 const TValue *gt = getGtable(L);
1097 /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ 1100 /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
1098 setobj(L, f->upvals[0]->v, gt); 1101 setobj(L, f->upvals[0]->v.p, gt);
1099 luaC_barrier(L, f->upvals[0], gt); 1102 luaC_barrier(L, f->upvals[0], gt);
1100 } 1103 }
1101 } 1104 }
@@ -1109,7 +1112,7 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {
1109 TValue *o; 1112 TValue *o;
1110 lua_lock(L); 1113 lua_lock(L);
1111 api_checknelems(L, 1); 1114 api_checknelems(L, 1);
1112 o = s2v(L->top - 1); 1115 o = s2v(L->top.p - 1);
1113 if (isLfunction(o)) 1116 if (isLfunction(o))
1114 status = luaU_dump(L, getproto(o), writer, data, strip); 1117 status = luaU_dump(L, getproto(o), writer, data, strip);
1115 else 1118 else
@@ -1235,7 +1238,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1235LUA_API int lua_error (lua_State *L) { 1238LUA_API int lua_error (lua_State *L) {
1236 TValue *errobj; 1239 TValue *errobj;
1237 lua_lock(L); 1240 lua_lock(L);
1238 errobj = s2v(L->top - 1); 1241 errobj = s2v(L->top.p - 1);
1239 api_checknelems(L, 1); 1242 api_checknelems(L, 1);
1240 /* error object is the memory error message? */ 1243 /* error object is the memory error message? */
1241 if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg)) 1244 if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg))
@@ -1253,12 +1256,12 @@ LUA_API int lua_next (lua_State *L, int idx) {
1253 lua_lock(L); 1256 lua_lock(L);
1254 api_checknelems(L, 1); 1257 api_checknelems(L, 1);
1255 t = gettable(L, idx); 1258 t = gettable(L, idx);
1256 more = luaH_next(L, t, L->top - 1); 1259 more = luaH_next(L, t, L->top.p - 1);
1257 if (more) { 1260 if (more) {
1258 api_incr_top(L); 1261 api_incr_top(L);
1259 } 1262 }
1260 else /* no more elements */ 1263 else /* no more elements */
1261 L->top -= 1; /* remove key */ 1264 L->top.p -= 1; /* remove key */
1262 lua_unlock(L); 1265 lua_unlock(L);
1263 return more; 1266 return more;
1264} 1267}
@@ -1270,7 +1273,7 @@ LUA_API void lua_toclose (lua_State *L, int idx) {
1270 lua_lock(L); 1273 lua_lock(L);
1271 o = index2stack(L, idx); 1274 o = index2stack(L, idx);
1272 nresults = L->ci->nresults; 1275 nresults = L->ci->nresults;
1273 api_check(L, L->tbclist < o, "given index below or equal a marked one"); 1276 api_check(L, L->tbclist.p < o, "given index below or equal a marked one");
1274 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ 1277 luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */
1275 if (!hastocloseCfunc(nresults)) /* function not marked yet? */ 1278 if (!hastocloseCfunc(nresults)) /* function not marked yet? */
1276 L->ci->nresults = codeNresults(nresults); /* mark it */ 1279 L->ci->nresults = codeNresults(nresults); /* mark it */
@@ -1285,7 +1288,7 @@ LUA_API void lua_concat (lua_State *L, int n) {
1285 if (n > 0) 1288 if (n > 0)
1286 luaV_concat(L, n); 1289 luaV_concat(L, n);
1287 else { /* nothing to concatenate */ 1290 else { /* nothing to concatenate */
1288 setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); /* push empty string */ 1291 setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */
1289 api_incr_top(L); 1292 api_incr_top(L);
1290 } 1293 }
1291 luaC_checkGC(L); 1294 luaC_checkGC(L);
@@ -1297,7 +1300,7 @@ LUA_API void lua_len (lua_State *L, int idx) {
1297 TValue *t; 1300 TValue *t;
1298 lua_lock(L); 1301 lua_lock(L);
1299 t = index2value(L, idx); 1302 t = index2value(L, idx);
1300 luaV_objlen(L, L->top, t); 1303 luaV_objlen(L, L->top.p, t);
1301 api_incr_top(L); 1304 api_incr_top(L);
1302 lua_unlock(L); 1305 lua_unlock(L);
1303} 1306}
@@ -1342,7 +1345,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
1342 lua_lock(L); 1345 lua_lock(L);
1343 api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); 1346 api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value");
1344 u = luaS_newudata(L, size, nuvalue); 1347 u = luaS_newudata(L, size, nuvalue);
1345 setuvalue(L, s2v(L->top), u); 1348 setuvalue(L, s2v(L->top.p), u);
1346 api_incr_top(L); 1349 api_incr_top(L);
1347 luaC_checkGC(L); 1350 luaC_checkGC(L);
1348 lua_unlock(L); 1351 lua_unlock(L);
@@ -1368,7 +1371,7 @@ static const char *aux_upvalue (TValue *fi, int n, TValue **val,
1368 Proto *p = f->p; 1371 Proto *p = f->p;
1369 if (!(cast_uint(n) - 1u < cast_uint(p->sizeupvalues))) 1372 if (!(cast_uint(n) - 1u < cast_uint(p->sizeupvalues)))
1370 return NULL; /* 'n' not in [1, p->sizeupvalues] */ 1373 return NULL; /* 'n' not in [1, p->sizeupvalues] */
1371 *val = f->upvals[n-1]->v; 1374 *val = f->upvals[n-1]->v.p;
1372 if (owner) *owner = obj2gco(f->upvals[n - 1]); 1375 if (owner) *owner = obj2gco(f->upvals[n - 1]);
1373 name = p->upvalues[n-1].name; 1376 name = p->upvalues[n-1].name;
1374 return (name == NULL) ? "(no name)" : getstr(name); 1377 return (name == NULL) ? "(no name)" : getstr(name);
@@ -1384,7 +1387,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
1384 lua_lock(L); 1387 lua_lock(L);
1385 name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); 1388 name = aux_upvalue(index2value(L, funcindex), n, &val, NULL);
1386 if (name) { 1389 if (name) {
1387 setobj2s(L, L->top, val); 1390 setobj2s(L, L->top.p, val);
1388 api_incr_top(L); 1391 api_incr_top(L);
1389 } 1392 }
1390 lua_unlock(L); 1393 lua_unlock(L);
@@ -1402,8 +1405,8 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
1402 api_checknelems(L, 1); 1405 api_checknelems(L, 1);
1403 name = aux_upvalue(fi, n, &val, &owner); 1406 name = aux_upvalue(fi, n, &val, &owner);
1404 if (name) { 1407 if (name) {
1405 L->top--; 1408 L->top.p--;
1406 setobj(L, val, s2v(L->top)); 1409 setobj(L, val, s2v(L->top.p));
1407 luaC_barrier(L, owner, val); 1410 luaC_barrier(L, owner, val);
1408 } 1411 }
1409 lua_unlock(L); 1412 lua_unlock(L);
diff --git a/lapi.h b/lapi.h
index 9e99cc44..a742427c 100644
--- a/lapi.h
+++ b/lapi.h
@@ -12,23 +12,26 @@
12#include "lstate.h" 12#include "lstate.h"
13 13
14 14
15/* Increments 'L->top', checking for stack overflows */ 15/* Increments 'L->top.p', checking for stack overflows */
16#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 16#define api_incr_top(L) {L->top.p++; \
17 "stack overflow");} 17 api_check(L, L->top.p <= L->ci->top.p, \
18 "stack overflow");}
18 19
19 20
20/* 21/*
21** If a call returns too many multiple returns, the callee may not have 22** If a call returns too many multiple returns, the callee may not have
22** stack space to accommodate all results. In this case, this macro 23** stack space to accommodate all results. In this case, this macro
23** increases its stack space ('L->ci->top'). 24** increases its stack space ('L->ci->top.p').
24*/ 25*/
25#define adjustresults(L,nres) \ 26#define adjustresults(L,nres) \
26 { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 27 { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
28 L->ci->top.p = L->top.p; }
27 29
28 30
29/* Ensure the stack has at least 'n' elements */ 31/* Ensure the stack has at least 'n' elements */
30#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 32#define api_checknelems(L,n) \
31 "not enough elements in the stack") 33 api_check(L, (n) < (L->top.p - L->ci->func.p), \
34 "not enough elements in the stack")
32 35
33 36
34/* 37/*
diff --git a/ldebug.c b/ldebug.c
index fa15eaf6..3fae5cf2 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -182,10 +182,10 @@ static const char *upvalname (const Proto *p, int uv) {
182 182
183 183
184static const char *findvararg (CallInfo *ci, int n, StkId *pos) { 184static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
185 if (clLvalue(s2v(ci->func))->p->is_vararg) { 185 if (clLvalue(s2v(ci->func.p))->p->is_vararg) {
186 int nextra = ci->u.l.nextraargs; 186 int nextra = ci->u.l.nextraargs;
187 if (n >= -nextra) { /* 'n' is negative */ 187 if (n >= -nextra) { /* 'n' is negative */
188 *pos = ci->func - nextra - (n + 1); 188 *pos = ci->func.p - nextra - (n + 1);
189 return "(vararg)"; /* generic name for any vararg */ 189 return "(vararg)"; /* generic name for any vararg */
190 } 190 }
191 } 191 }
@@ -194,7 +194,7 @@ static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
194 194
195 195
196const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) { 196const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {
197 StkId base = ci->func + 1; 197 StkId base = ci->func.p + 1;
198 const char *name = NULL; 198 const char *name = NULL;
199 if (isLua(ci)) { 199 if (isLua(ci)) {
200 if (n < 0) /* access to vararg values? */ 200 if (n < 0) /* access to vararg values? */
@@ -203,7 +203,7 @@ const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {
203 name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)); 203 name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
204 } 204 }
205 if (name == NULL) { /* no 'standard' name? */ 205 if (name == NULL) { /* no 'standard' name? */
206 StkId limit = (ci == L->ci) ? L->top : ci->next->func; 206 StkId limit = (ci == L->ci) ? L->top.p : ci->next->func.p;
207 if (limit - base >= n && n > 0) { /* is 'n' inside 'ci' stack? */ 207 if (limit - base >= n && n > 0) { /* is 'n' inside 'ci' stack? */
208 /* generic name for any valid slot */ 208 /* generic name for any valid slot */
209 name = isLua(ci) ? "(temporary)" : "(C temporary)"; 209 name = isLua(ci) ? "(temporary)" : "(C temporary)";
@@ -221,16 +221,16 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
221 const char *name; 221 const char *name;
222 lua_lock(L); 222 lua_lock(L);
223 if (ar == NULL) { /* information about non-active function? */ 223 if (ar == NULL) { /* information about non-active function? */
224 if (!isLfunction(s2v(L->top - 1))) /* not a Lua function? */ 224 if (!isLfunction(s2v(L->top.p - 1))) /* not a Lua function? */
225 name = NULL; 225 name = NULL;
226 else /* consider live variables at function start (parameters) */ 226 else /* consider live variables at function start (parameters) */
227 name = luaF_getlocalname(clLvalue(s2v(L->top - 1))->p, n, 0); 227 name = luaF_getlocalname(clLvalue(s2v(L->top.p - 1))->p, n, 0);
228 } 228 }
229 else { /* active function; get information through 'ar' */ 229 else { /* active function; get information through 'ar' */
230 StkId pos = NULL; /* to avoid warnings */ 230 StkId pos = NULL; /* to avoid warnings */
231 name = luaG_findlocal(L, ar->i_ci, n, &pos); 231 name = luaG_findlocal(L, ar->i_ci, n, &pos);
232 if (name) { 232 if (name) {
233 setobjs2s(L, L->top, pos); 233 setobjs2s(L, L->top.p, pos);
234 api_incr_top(L); 234 api_incr_top(L);
235 } 235 }
236 } 236 }
@@ -245,8 +245,8 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
245 lua_lock(L); 245 lua_lock(L);
246 name = luaG_findlocal(L, ar->i_ci, n, &pos); 246 name = luaG_findlocal(L, ar->i_ci, n, &pos);
247 if (name) { 247 if (name) {
248 setobjs2s(L, pos, L->top - 1); 248 setobjs2s(L, pos, L->top.p - 1);
249 L->top--; /* pop value */ 249 L->top.p--; /* pop value */
250 } 250 }
251 lua_unlock(L); 251 lua_unlock(L);
252 return name; 252 return name;
@@ -289,7 +289,7 @@ static int nextline (const Proto *p, int currentline, int pc) {
289 289
290static void collectvalidlines (lua_State *L, Closure *f) { 290static void collectvalidlines (lua_State *L, Closure *f) {
291 if (noLuaClosure(f)) { 291 if (noLuaClosure(f)) {
292 setnilvalue(s2v(L->top)); 292 setnilvalue(s2v(L->top.p));
293 api_incr_top(L); 293 api_incr_top(L);
294 } 294 }
295 else { 295 else {
@@ -298,7 +298,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {
298 const Proto *p = f->l.p; 298 const Proto *p = f->l.p;
299 int currentline = p->linedefined; 299 int currentline = p->linedefined;
300 Table *t = luaH_new(L); /* new table to store active lines */ 300 Table *t = luaH_new(L); /* new table to store active lines */
301 sethvalue2s(L, L->top, t); /* push it on stack */ 301 sethvalue2s(L, L->top.p, t); /* push it on stack */
302 api_incr_top(L); 302 api_incr_top(L);
303 setbtvalue(&v); /* boolean 'true' to be the value of all indices */ 303 setbtvalue(&v); /* boolean 'true' to be the value of all indices */
304 if (!p->is_vararg) /* regular function? */ 304 if (!p->is_vararg) /* regular function? */
@@ -388,20 +388,20 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
388 lua_lock(L); 388 lua_lock(L);
389 if (*what == '>') { 389 if (*what == '>') {
390 ci = NULL; 390 ci = NULL;
391 func = s2v(L->top - 1); 391 func = s2v(L->top.p - 1);
392 api_check(L, ttisfunction(func), "function expected"); 392 api_check(L, ttisfunction(func), "function expected");
393 what++; /* skip the '>' */ 393 what++; /* skip the '>' */
394 L->top--; /* pop function */ 394 L->top.p--; /* pop function */
395 } 395 }
396 else { 396 else {
397 ci = ar->i_ci; 397 ci = ar->i_ci;
398 func = s2v(ci->func); 398 func = s2v(ci->func.p);
399 lua_assert(ttisfunction(func)); 399 lua_assert(ttisfunction(func));
400 } 400 }
401 cl = ttisclosure(func) ? clvalue(func) : NULL; 401 cl = ttisclosure(func) ? clvalue(func) : NULL;
402 status = auxgetinfo(L, what, ar, cl, ci); 402 status = auxgetinfo(L, what, ar, cl, ci);
403 if (strchr(what, 'f')) { 403 if (strchr(what, 'f')) {
404 setobj2s(L, L->top, func); 404 setobj2s(L, L->top.p, func);
405 api_incr_top(L); 405 api_incr_top(L);
406 } 406 }
407 if (strchr(what, 'L')) 407 if (strchr(what, 'L'))
@@ -663,7 +663,7 @@ static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
663*/ 663*/
664static int isinstack (CallInfo *ci, const TValue *o) { 664static int isinstack (CallInfo *ci, const TValue *o) {
665 StkId pos; 665 StkId pos;
666 for (pos = ci->func + 1; pos < ci->top; pos++) { 666 for (pos = ci->func.p + 1; pos < ci->top.p; pos++) {
667 if (o == s2v(pos)) 667 if (o == s2v(pos))
668 return 1; 668 return 1;
669 } 669 }
@@ -681,7 +681,7 @@ static const char *getupvalname (CallInfo *ci, const TValue *o,
681 LClosure *c = ci_func(ci); 681 LClosure *c = ci_func(ci);
682 int i; 682 int i;
683 for (i = 0; i < c->nupvalues; i++) { 683 for (i = 0; i < c->nupvalues; i++) {
684 if (c->upvals[i]->v == o) { 684 if (c->upvals[i]->v.p == o) {
685 *name = upvalname(c->p, i); 685 *name = upvalname(c->p, i);
686 return "upvalue"; 686 return "upvalue";
687 } 687 }
@@ -710,7 +710,7 @@ static const char *varinfo (lua_State *L, const TValue *o) {
710 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ 710 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
711 if (!kind && isinstack(ci, o)) /* no? try a register */ 711 if (!kind && isinstack(ci, o)) /* no? try a register */
712 kind = getobjname(ci_func(ci)->p, currentpc(ci), 712 kind = getobjname(ci_func(ci)->p, currentpc(ci),
713 cast_int(cast(StkId, o) - (ci->func + 1)), &name); 713 cast_int(cast(StkId, o) - (ci->func.p + 1)), &name);
714 } 714 }
715 return formatvarinfo(L, kind, name); 715 return formatvarinfo(L, kind, name);
716} 716}
@@ -807,10 +807,10 @@ l_noret luaG_errormsg (lua_State *L) {
807 if (L->errfunc != 0) { /* is there an error handling function? */ 807 if (L->errfunc != 0) { /* is there an error handling function? */
808 StkId errfunc = restorestack(L, L->errfunc); 808 StkId errfunc = restorestack(L, L->errfunc);
809 lua_assert(ttisfunction(s2v(errfunc))); 809 lua_assert(ttisfunction(s2v(errfunc)));
810 setobjs2s(L, L->top, L->top - 1); /* move argument */ 810 setobjs2s(L, L->top.p, L->top.p - 1); /* move argument */
811 setobjs2s(L, L->top - 1, errfunc); /* push function */ 811 setobjs2s(L, L->top.p - 1, errfunc); /* push function */
812 L->top++; /* assume EXTRA_STACK */ 812 L->top.p++; /* assume EXTRA_STACK */
813 luaD_callnoyield(L, L->top - 2, 1); /* call it */ 813 luaD_callnoyield(L, L->top.p - 2, 1); /* call it */
814 } 814 }
815 luaD_throw(L, LUA_ERRRUN); 815 luaD_throw(L, LUA_ERRRUN);
816} 816}
@@ -826,8 +826,8 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
826 va_end(argp); 826 va_end(argp);
827 if (isLua(ci)) { /* if Lua function, add source:line information */ 827 if (isLua(ci)) { /* if Lua function, add source:line information */
828 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci)); 828 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci));
829 setobjs2s(L, L->top - 2, L->top - 1); /* remove 'msg' from the stack */ 829 setobjs2s(L, L->top.p - 2, L->top.p - 1); /* remove 'msg' */
830 L->top--; 830 L->top.p--;
831 } 831 }
832 luaG_errormsg(L); 832 luaG_errormsg(L);
833} 833}
@@ -872,7 +872,7 @@ static int changedline (const Proto *p, int oldpc, int newpc) {
872** invalid; if so, use zero as a valid value. (A wrong but valid 'oldpc' 872** invalid; if so, use zero as a valid value. (A wrong but valid 'oldpc'
873** at most causes an extra call to a line hook.) 873** at most causes an extra call to a line hook.)
874** This function is not "Protected" when called, so it should correct 874** This function is not "Protected" when called, so it should correct
875** 'L->top' before calling anything that can run the GC. 875** 'L->top.p' before calling anything that can run the GC.
876*/ 876*/
877int luaG_traceexec (lua_State *L, const Instruction *pc) { 877int luaG_traceexec (lua_State *L, const Instruction *pc) {
878 CallInfo *ci = L->ci; 878 CallInfo *ci = L->ci;
@@ -895,7 +895,7 @@ int luaG_traceexec (lua_State *L, const Instruction *pc) {
895 return 1; /* do not call hook again (VM yielded, so it did not move) */ 895 return 1; /* do not call hook again (VM yielded, so it did not move) */
896 } 896 }
897 if (!isIT(*(ci->u.l.savedpc - 1))) /* top not being used? */ 897 if (!isIT(*(ci->u.l.savedpc - 1))) /* top not being used? */
898 L->top = ci->top; /* correct top */ 898 L->top.p = ci->top.p; /* correct top */
899 if (counthook) 899 if (counthook)
900 luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */ 900 luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */
901 if (mask & LUA_MASKLINE) { 901 if (mask & LUA_MASKLINE) {
diff --git a/ldebug.h b/ldebug.h
index 974960e9..2c3074c6 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -15,7 +15,7 @@
15 15
16 16
17/* Active Lua function (given call info) */ 17/* Active Lua function (given call info) */
18#define ci_func(ci) (clLvalue(s2v((ci)->func))) 18#define ci_func(ci) (clLvalue(s2v((ci)->func.p)))
19 19
20 20
21#define resethookcount(L) (L->hookcount = L->basehookcount) 21#define resethookcount(L) (L->hookcount = L->basehookcount)
diff --git a/ldo.c b/ldo.c
index 419b3db9..d45c74da 100644
--- a/ldo.c
+++ b/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 */
@@ -160,13 +160,13 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
160static void correctstack (lua_State *L, StkId oldstack, StkId newstack) { 160static 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) {
253static int stackinuse (lua_State *L) { 252static 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
296void luaD_inctop (lua_State *L) { 295void 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*/
368static void rethook (lua_State *L, CallInfo *ci, int nres) { 367static 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) {
483l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, 482l_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*/
750static int resume_error (lua_State *L, const char *msg, int narg) { 749static 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*/
766static void resume (lua_State *L, void *ud) { 765static 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);
diff --git a/ldo.h b/ldo.h
index 4661aa00..1aa446ad 100644
--- a/ldo.h
+++ b/ldo.h
@@ -8,6 +8,7 @@
8#define ldo_h 8#define ldo_h
9 9
10 10
11#include "llimits.h"
11#include "lobject.h" 12#include "lobject.h"
12#include "lstate.h" 13#include "lstate.h"
13#include "lzio.h" 14#include "lzio.h"
@@ -23,7 +24,7 @@
23** at every check. 24** at every check.
24*/ 25*/
25#define luaD_checkstackaux(L,n,pre,pos) \ 26#define luaD_checkstackaux(L,n,pre,pos) \
26 if (l_unlikely(L->stack_last - L->top <= (n))) \ 27 if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
27 { pre; luaD_growstack(L, n, 1); pos; } \ 28 { pre; luaD_growstack(L, n, 1); pos; } \
28 else { condmovestack(L,pre,pos); } 29 else { condmovestack(L,pre,pos); }
29 30
@@ -32,8 +33,8 @@
32 33
33 34
34 35
35#define savestack(L,p) ((char *)(p) - (char *)L->stack) 36#define savestack(L,pt) (cast_charp(pt) - cast_charp(L->stack.p))
36#define restorestack(L,n) ((StkId)((char *)L->stack + (n))) 37#define restorestack(L,n) cast(StkId, cast_charp(L->stack.p) + (n))
37 38
38 39
39/* macro to check stack size, preserving 'p' */ 40/* macro to check stack size, preserving 'p' */
diff --git a/lfunc.c b/lfunc.c
index daba0abf..804bf9dc 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -50,8 +50,8 @@ void luaF_initupvals (lua_State *L, LClosure *cl) {
50 for (i = 0; i < cl->nupvalues; i++) { 50 for (i = 0; i < cl->nupvalues; i++) {
51 GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal)); 51 GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));
52 UpVal *uv = gco2upv(o); 52 UpVal *uv = gco2upv(o);
53 uv->v = &uv->u.value; /* make it closed */ 53 uv->v.p = &uv->u.value; /* make it closed */
54 setnilvalue(uv->v); 54 setnilvalue(uv->v.p);
55 cl->upvals[i] = uv; 55 cl->upvals[i] = uv;
56 luaC_objbarrier(L, cl, uv); 56 luaC_objbarrier(L, cl, uv);
57 } 57 }
@@ -66,7 +66,7 @@ static UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) {
66 GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal)); 66 GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));
67 UpVal *uv = gco2upv(o); 67 UpVal *uv = gco2upv(o);
68 UpVal *next = *prev; 68 UpVal *next = *prev;
69 uv->v = s2v(level); /* current value lives in the stack */ 69 uv->v.p = s2v(level); /* current value lives in the stack */
70 uv->tbc = tbc; 70 uv->tbc = tbc;
71 uv->u.open.next = next; /* link it to list of open upvalues */ 71 uv->u.open.next = next; /* link it to list of open upvalues */
72 uv->u.open.previous = prev; 72 uv->u.open.previous = prev;
@@ -106,12 +106,12 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
106** (This function assumes EXTRA_STACK.) 106** (This function assumes EXTRA_STACK.)
107*/ 107*/
108static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) { 108static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) {
109 StkId top = L->top; 109 StkId top = L->top.p;
110 const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE); 110 const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE);
111 setobj2s(L, top, tm); /* will call metamethod... */ 111 setobj2s(L, top, tm); /* will call metamethod... */
112 setobj2s(L, top + 1, obj); /* with 'self' as the 1st argument */ 112 setobj2s(L, top + 1, obj); /* with 'self' as the 1st argument */
113 setobj2s(L, top + 2, err); /* and error msg. as 2nd argument */ 113 setobj2s(L, top + 2, err); /* and error msg. as 2nd argument */
114 L->top = top + 3; /* add function and arguments */ 114 L->top.p = top + 3; /* add function and arguments */
115 if (yy) 115 if (yy)
116 luaD_call(L, top, 0); 116 luaD_call(L, top, 0);
117 else 117 else
@@ -126,7 +126,7 @@ static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) {
126static void checkclosemth (lua_State *L, StkId level) { 126static void checkclosemth (lua_State *L, StkId level) {
127 const TValue *tm = luaT_gettmbyobj(L, s2v(level), TM_CLOSE); 127 const TValue *tm = luaT_gettmbyobj(L, s2v(level), TM_CLOSE);
128 if (ttisnil(tm)) { /* no metamethod? */ 128 if (ttisnil(tm)) { /* no metamethod? */
129 int idx = cast_int(level - L->ci->func); /* variable index */ 129 int idx = cast_int(level - L->ci->func.p); /* variable index */
130 const char *vname = luaG_findlocal(L, L->ci, idx, NULL); 130 const char *vname = luaG_findlocal(L, L->ci, idx, NULL);
131 if (vname == NULL) vname = "?"; 131 if (vname == NULL) vname = "?";
132 luaG_runerror(L, "variable '%s' got a non-closable value", vname); 132 luaG_runerror(L, "variable '%s' got a non-closable value", vname);
@@ -160,23 +160,23 @@ static void prepcallclosemth (lua_State *L, StkId level, int status, int yy) {
160** is used.) 160** is used.)
161*/ 161*/
162#define MAXDELTA \ 162#define MAXDELTA \
163 ((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1) 163 ((256ul << ((sizeof(L->stack.p->tbclist.delta) - 1) * 8)) - 1)
164 164
165 165
166/* 166/*
167** Insert a variable in the list of to-be-closed variables. 167** Insert a variable in the list of to-be-closed variables.
168*/ 168*/
169void luaF_newtbcupval (lua_State *L, StkId level) { 169void luaF_newtbcupval (lua_State *L, StkId level) {
170 lua_assert(level > L->tbclist); 170 lua_assert(level > L->tbclist.p);
171 if (l_isfalse(s2v(level))) 171 if (l_isfalse(s2v(level)))
172 return; /* false doesn't need to be closed */ 172 return; /* false doesn't need to be closed */
173 checkclosemth(L, level); /* value must have a close method */ 173 checkclosemth(L, level); /* value must have a close method */
174 while (cast_uint(level - L->tbclist) > MAXDELTA) { 174 while (cast_uint(level - L->tbclist.p) > MAXDELTA) {
175 L->tbclist += MAXDELTA; /* create a dummy node at maximum delta */ 175 L->tbclist.p += MAXDELTA; /* create a dummy node at maximum delta */
176 L->tbclist->tbclist.delta = 0; 176 L->tbclist.p->tbclist.delta = 0;
177 } 177 }
178 level->tbclist.delta = cast(unsigned short, level - L->tbclist); 178 level->tbclist.delta = cast(unsigned short, level - L->tbclist.p);
179 L->tbclist = level; 179 L->tbclist.p = level;
180} 180}
181 181
182 182
@@ -196,10 +196,10 @@ void luaF_closeupval (lua_State *L, StkId level) {
196 StkId upl; /* stack index pointed by 'uv' */ 196 StkId upl; /* stack index pointed by 'uv' */
197 while ((uv = L->openupval) != NULL && (upl = uplevel(uv)) >= level) { 197 while ((uv = L->openupval) != NULL && (upl = uplevel(uv)) >= level) {
198 TValue *slot = &uv->u.value; /* new position for value */ 198 TValue *slot = &uv->u.value; /* new position for value */
199 lua_assert(uplevel(uv) < L->top); 199 lua_assert(uplevel(uv) < L->top.p);
200 luaF_unlinkupval(uv); /* remove upvalue from 'openupval' list */ 200 luaF_unlinkupval(uv); /* remove upvalue from 'openupval' list */
201 setobj(L, slot, uv->v); /* move value to upvalue slot */ 201 setobj(L, slot, uv->v.p); /* move value to upvalue slot */
202 uv->v = slot; /* now current value lives here */ 202 uv->v.p = slot; /* now current value lives here */
203 if (!iswhite(uv)) { /* neither white nor dead? */ 203 if (!iswhite(uv)) { /* neither white nor dead? */
204 nw2black(uv); /* closed upvalues cannot be gray */ 204 nw2black(uv); /* closed upvalues cannot be gray */
205 luaC_barrier(L, uv, slot); 205 luaC_barrier(L, uv, slot);
@@ -212,12 +212,12 @@ void luaF_closeupval (lua_State *L, StkId level) {
212** Remove first element from the tbclist plus its dummy nodes. 212** Remove first element from the tbclist plus its dummy nodes.
213*/ 213*/
214static void poptbclist (lua_State *L) { 214static void poptbclist (lua_State *L) {
215 StkId tbc = L->tbclist; 215 StkId tbc = L->tbclist.p;
216 lua_assert(tbc->tbclist.delta > 0); /* first element cannot be dummy */ 216 lua_assert(tbc->tbclist.delta > 0); /* first element cannot be dummy */
217 tbc -= tbc->tbclist.delta; 217 tbc -= tbc->tbclist.delta;
218 while (tbc > L->stack && tbc->tbclist.delta == 0) 218 while (tbc > L->stack.p && tbc->tbclist.delta == 0)
219 tbc -= MAXDELTA; /* remove dummy nodes */ 219 tbc -= MAXDELTA; /* remove dummy nodes */
220 L->tbclist = tbc; 220 L->tbclist.p = tbc;
221} 221}
222 222
223 223
@@ -228,8 +228,8 @@ static void poptbclist (lua_State *L) {
228StkId luaF_close (lua_State *L, StkId level, int status, int yy) { 228StkId luaF_close (lua_State *L, StkId level, int status, int yy) {
229 ptrdiff_t levelrel = savestack(L, level); 229 ptrdiff_t levelrel = savestack(L, level);
230 luaF_closeupval(L, level); /* first, close the upvalues */ 230 luaF_closeupval(L, level); /* first, close the upvalues */
231 while (L->tbclist >= level) { /* traverse tbc's down to that level */ 231 while (L->tbclist.p >= level) { /* traverse tbc's down to that level */
232 StkId tbc = L->tbclist; /* get variable index */ 232 StkId tbc = L->tbclist.p; /* get variable index */
233 poptbclist(L); /* remove it from list */ 233 poptbclist(L); /* remove it from list */
234 prepcallclosemth(L, tbc, status, yy); /* close variable */ 234 prepcallclosemth(L, tbc, status, yy); /* close variable */
235 level = restorestack(L, levelrel); 235 level = restorestack(L, levelrel);
diff --git a/lfunc.h b/lfunc.h
index 3d296971..3be265ef 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -29,10 +29,10 @@
29#define MAXUPVAL 255 29#define MAXUPVAL 255
30 30
31 31
32#define upisopen(up) ((up)->v != &(up)->u.value) 32#define upisopen(up) ((up)->v.p != &(up)->u.value)
33 33
34 34
35#define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v)) 35#define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p))
36 36
37 37
38/* 38/*
diff --git a/lgc.c b/lgc.c
index 317ea450..8e76ccd7 100644
--- a/lgc.c
+++ b/lgc.c
@@ -301,7 +301,7 @@ static void reallymarkobject (global_State *g, GCObject *o) {
301 set2gray(uv); /* open upvalues are kept gray */ 301 set2gray(uv); /* open upvalues are kept gray */
302 else 302 else
303 set2black(uv); /* closed upvalues are visited here */ 303 set2black(uv); /* closed upvalues are visited here */
304 markvalue(g, uv->v); /* mark its content */ 304 markvalue(g, uv->v.p); /* mark its content */
305 break; 305 break;
306 } 306 }
307 case LUA_VUSERDATA: { 307 case LUA_VUSERDATA: {
@@ -376,7 +376,7 @@ static int remarkupvals (global_State *g) {
376 work++; 376 work++;
377 if (!iswhite(uv)) { /* upvalue already visited? */ 377 if (!iswhite(uv)) { /* upvalue already visited? */
378 lua_assert(upisopen(uv) && isgray(uv)); 378 lua_assert(upisopen(uv) && isgray(uv));
379 markvalue(g, uv->v); /* mark its value */ 379 markvalue(g, uv->v.p); /* mark its value */
380 } 380 }
381 } 381 }
382 } 382 }
@@ -620,19 +620,19 @@ static int traverseLclosure (global_State *g, LClosure *cl) {
620*/ 620*/
621static int traversethread (global_State *g, lua_State *th) { 621static int traversethread (global_State *g, lua_State *th) {
622 UpVal *uv; 622 UpVal *uv;
623 StkId o = th->stack; 623 StkId o = th->stack.p;
624 if (isold(th) || g->gcstate == GCSpropagate) 624 if (isold(th) || g->gcstate == GCSpropagate)
625 linkgclist(th, g->grayagain); /* insert into 'grayagain' list */ 625 linkgclist(th, g->grayagain); /* insert into 'grayagain' list */
626 if (o == NULL) 626 if (o == NULL)
627 return 1; /* stack not completely built yet */ 627 return 1; /* stack not completely built yet */
628 lua_assert(g->gcstate == GCSatomic || 628 lua_assert(g->gcstate == GCSatomic ||
629 th->openupval == NULL || isintwups(th)); 629 th->openupval == NULL || isintwups(th));
630 for (; o < th->top; o++) /* mark live elements in the stack */ 630 for (; o < th->top.p; o++) /* mark live elements in the stack */
631 markvalue(g, s2v(o)); 631 markvalue(g, s2v(o));
632 for (uv = th->openupval; uv != NULL; uv = uv->u.open.next) 632 for (uv = th->openupval; uv != NULL; uv = uv->u.open.next)
633 markobject(g, uv); /* open upvalues cannot be collected */ 633 markobject(g, uv); /* open upvalues cannot be collected */
634 if (g->gcstate == GCSatomic) { /* final traversal? */ 634 if (g->gcstate == GCSatomic) { /* final traversal? */
635 for (; o < th->stack_last + EXTRA_STACK; o++) 635 for (; o < th->stack_last.p + EXTRA_STACK; o++)
636 setnilvalue(s2v(o)); /* clear dead stack slice */ 636 setnilvalue(s2v(o)); /* clear dead stack slice */
637 /* 'remarkupvals' may have removed thread from 'twups' list */ 637 /* 'remarkupvals' may have removed thread from 'twups' list */
638 if (!isintwups(th) && th->openupval != NULL) { 638 if (!isintwups(th) && th->openupval != NULL) {
@@ -892,7 +892,7 @@ static GCObject *udata2finalize (global_State *g) {
892 892
893static void dothecall (lua_State *L, void *ud) { 893static void dothecall (lua_State *L, void *ud) {
894 UNUSED(ud); 894 UNUSED(ud);
895 luaD_callnoyield(L, L->top - 2, 0); 895 luaD_callnoyield(L, L->top.p - 2, 0);
896} 896}
897 897
898 898
@@ -909,16 +909,16 @@ static void GCTM (lua_State *L) {
909 int oldgcstp = g->gcstp; 909 int oldgcstp = g->gcstp;
910 g->gcstp |= GCSTPGC; /* avoid GC steps */ 910 g->gcstp |= GCSTPGC; /* avoid GC steps */
911 L->allowhook = 0; /* stop debug hooks during GC metamethod */ 911 L->allowhook = 0; /* stop debug hooks during GC metamethod */
912 setobj2s(L, L->top++, tm); /* push finalizer... */ 912 setobj2s(L, L->top.p++, tm); /* push finalizer... */
913 setobj2s(L, L->top++, &v); /* ... and its argument */ 913 setobj2s(L, L->top.p++, &v); /* ... and its argument */
914 L->ci->callstatus |= CIST_FIN; /* will run a finalizer */ 914 L->ci->callstatus |= CIST_FIN; /* will run a finalizer */
915 status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); 915 status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top.p - 2), 0);
916 L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */ 916 L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */
917 L->allowhook = oldah; /* restore hooks */ 917 L->allowhook = oldah; /* restore hooks */
918 g->gcstp = oldgcstp; /* restore state */ 918 g->gcstp = oldgcstp; /* restore state */
919 if (l_unlikely(status != LUA_OK)) { /* error while running __gc? */ 919 if (l_unlikely(status != LUA_OK)) { /* error while running __gc? */
920 luaE_warnerror(L, "__gc"); 920 luaE_warnerror(L, "__gc");
921 L->top--; /* pops error object */ 921 L->top.p--; /* pops error object */
922 } 922 }
923 } 923 }
924} 924}
diff --git a/llex.c b/llex.c
index e9915178..b0dc0acc 100644
--- a/llex.c
+++ b/llex.c
@@ -138,12 +138,12 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
138 if (!ttisnil(o)) /* string already present? */ 138 if (!ttisnil(o)) /* string already present? */
139 ts = keystrval(nodefromval(o)); /* get saved copy */ 139 ts = keystrval(nodefromval(o)); /* get saved copy */
140 else { /* not in use yet */ 140 else { /* not in use yet */
141 TValue *stv = s2v(L->top++); /* reserve stack space for string */ 141 TValue *stv = s2v(L->top.p++); /* reserve stack space for string */
142 setsvalue(L, stv, ts); /* temporarily anchor the string */ 142 setsvalue(L, stv, ts); /* temporarily anchor the string */
143 luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */ 143 luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */
144 /* table is not a metatable, so it does not need to invalidate cache */ 144 /* table is not a metatable, so it does not need to invalidate cache */
145 luaC_checkGC(L); 145 luaC_checkGC(L);
146 L->top--; /* remove string from stack */ 146 L->top.p--; /* remove string from stack */
147 } 147 }
148 return ts; 148 return ts;
149} 149}
diff --git a/lobject.c b/lobject.c
index 03e2798c..f73ffc6d 100644
--- a/lobject.c
+++ b/lobject.c
@@ -413,8 +413,8 @@ typedef struct BuffFS {
413*/ 413*/
414static void pushstr (BuffFS *buff, const char *str, size_t lstr) { 414static void pushstr (BuffFS *buff, const char *str, size_t lstr) {
415 lua_State *L = buff->L; 415 lua_State *L = buff->L;
416 setsvalue2s(L, L->top, luaS_newlstr(L, str, lstr)); 416 setsvalue2s(L, L->top.p, luaS_newlstr(L, str, lstr));
417 L->top++; /* may use one slot from EXTRA_STACK */ 417 L->top.p++; /* may use one slot from EXTRA_STACK */
418 if (!buff->pushed) /* no previous string on the stack? */ 418 if (!buff->pushed) /* no previous string on the stack? */
419 buff->pushed = 1; /* now there is one */ 419 buff->pushed = 1; /* now there is one */
420 else /* join previous string with new one */ 420 else /* join previous string with new one */
@@ -542,7 +542,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
542 addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */ 542 addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */
543 clearbuff(&buff); /* empty buffer into the stack */ 543 clearbuff(&buff); /* empty buffer into the stack */
544 lua_assert(buff.pushed == 1); 544 lua_assert(buff.pushed == 1);
545 return svalue(s2v(L->top - 1)); 545 return svalue(s2v(L->top.p - 1));
546} 546}
547 547
548 548
diff --git a/lobject.h b/lobject.h
index 77cc606f..7af7bd89 100644
--- a/lobject.h
+++ b/lobject.h
@@ -157,6 +157,12 @@ typedef union StackValue {
157/* index to stack elements */ 157/* index to stack elements */
158typedef StackValue *StkId; 158typedef StackValue *StkId;
159 159
160
161typedef union {
162 StkId p; /* actual pointer */
163} StkIdRel;
164
165
160/* convert a 'StackValue' to a 'TValue' */ 166/* convert a 'StackValue' to a 'TValue' */
161#define s2v(o) (&(o)->val) 167#define s2v(o) (&(o)->val)
162 168
@@ -618,7 +624,9 @@ typedef struct Proto {
618typedef struct UpVal { 624typedef struct UpVal {
619 CommonHeader; 625 CommonHeader;
620 lu_byte tbc; /* true if it represents a to-be-closed variable */ 626 lu_byte tbc; /* true if it represents a to-be-closed variable */
621 TValue *v; /* points to stack or to its own value */ 627 union {
628 TValue *p; /* points to stack or to its own value */
629 } v;
622 union { 630 union {
623 struct { /* (when open) */ 631 struct { /* (when open) */
624 struct UpVal *next; /* linked list */ 632 struct UpVal *next; /* linked list */
diff --git a/lparser.c b/lparser.c
index fe693b57..24668c24 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1944,10 +1944,10 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
1944 LexState lexstate; 1944 LexState lexstate;
1945 FuncState funcstate; 1945 FuncState funcstate;
1946 LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */ 1946 LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */
1947 setclLvalue2s(L, L->top, cl); /* anchor it (to avoid being collected) */ 1947 setclLvalue2s(L, L->top.p, cl); /* anchor it (to avoid being collected) */
1948 luaD_inctop(L); 1948 luaD_inctop(L);
1949 lexstate.h = luaH_new(L); /* create table for scanner */ 1949 lexstate.h = luaH_new(L); /* create table for scanner */
1950 sethvalue2s(L, L->top, lexstate.h); /* anchor it */ 1950 sethvalue2s(L, L->top.p, lexstate.h); /* anchor it */
1951 luaD_inctop(L); 1951 luaD_inctop(L);
1952 funcstate.f = cl->p = luaF_newproto(L); 1952 funcstate.f = cl->p = luaF_newproto(L);
1953 luaC_objbarrier(L, cl, cl->p); 1953 luaC_objbarrier(L, cl, cl->p);
@@ -1961,7 +1961,7 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
1961 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); 1961 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
1962 /* all scopes should be correctly finished */ 1962 /* all scopes should be correctly finished */
1963 lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); 1963 lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
1964 L->top--; /* remove scanner's table */ 1964 L->top.p--; /* remove scanner's table */
1965 return cl; /* closure is on the stack, too */ 1965 return cl; /* closure is on the stack, too */
1966} 1966}
1967 1967
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";
diff --git a/lstate.h b/lstate.h
index 61e82cde..2e907818 100644
--- a/lstate.h
+++ b/lstate.h
@@ -139,7 +139,7 @@ struct lua_longjmp; /* defined in ldo.c */
139 139
140#define BASIC_STACK_SIZE (2*LUA_MINSTACK) 140#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
141 141
142#define stacksize(th) cast_int((th)->stack_last - (th)->stack) 142#define stacksize(th) cast_int((th)->stack_last.p - (th)->stack.p)
143 143
144 144
145/* kinds of Garbage Collection */ 145/* kinds of Garbage Collection */
@@ -170,8 +170,8 @@ typedef struct stringtable {
170** before the function starts or after it ends. 170** before the function starts or after it ends.
171*/ 171*/
172typedef struct CallInfo { 172typedef struct CallInfo {
173 StkId func; /* function index in the stack */ 173 StkIdRel func; /* function index in the stack */
174 StkId top; /* top for this function */ 174 StkIdRel top; /* top for this function */
175 struct CallInfo *previous, *next; /* dynamic call link */ 175 struct CallInfo *previous, *next; /* dynamic call link */
176 union { 176 union {
177 struct { /* only for Lua functions */ 177 struct { /* only for Lua functions */
@@ -306,13 +306,13 @@ struct lua_State {
306 lu_byte status; 306 lu_byte status;
307 lu_byte allowhook; 307 lu_byte allowhook;
308 unsigned short nci; /* number of items in 'ci' list */ 308 unsigned short nci; /* number of items in 'ci' list */
309 StkId top; /* first free slot in the stack */ 309 StkIdRel top; /* first free slot in the stack */
310 global_State *l_G; 310 global_State *l_G;
311 CallInfo *ci; /* call info for current function */ 311 CallInfo *ci; /* call info for current function */
312 StkId stack_last; /* end of stack (last element + 1) */ 312 StkIdRel stack_last; /* end of stack (last element + 1) */
313 StkId stack; /* stack base */ 313 StkIdRel stack; /* stack base */
314 UpVal *openupval; /* list of open upvalues in this stack */ 314 UpVal *openupval; /* list of open upvalues in this stack */
315 StkId tbclist; /* list of to-be-closed variables */ 315 StkIdRel tbclist; /* list of to-be-closed variables */
316 GCObject *gclist; 316 GCObject *gclist;
317 struct lua_State *twups; /* list of threads with open upvalues */ 317 struct lua_State *twups; /* list of threads with open upvalues */
318 struct lua_longjmp *errorJmp; /* current error recover point */ 318 struct lua_longjmp *errorJmp; /* current error recover point */
diff --git a/ltests.c b/ltests.c
index 734a96da..4a0a6af1 100644
--- a/ltests.c
+++ b/ltests.c
@@ -44,7 +44,7 @@
44void *l_Trick = 0; 44void *l_Trick = 0;
45 45
46 46
47#define obj_at(L,k) s2v(L->ci->func + (k)) 47#define obj_at(L,k) s2v(L->ci->func.p + (k))
48 48
49 49
50static int runC (lua_State *L, lua_State *L1, const char *pc); 50static int runC (lua_State *L, lua_State *L1, const char *pc);
@@ -57,7 +57,7 @@ static void setnameval (lua_State *L, const char *name, int val) {
57 57
58 58
59static void pushobject (lua_State *L, const TValue *o) { 59static void pushobject (lua_State *L, const TValue *o) {
60 setobj2s(L, L->top, o); 60 setobj2s(L, L->top.p, o);
61 api_incr_top(L); 61 api_incr_top(L);
62} 62}
63 63
@@ -419,7 +419,7 @@ static void checkLclosure (global_State *g, LClosure *cl) {
419 if (uv) { 419 if (uv) {
420 checkobjrefN(g, clgc, uv); 420 checkobjrefN(g, clgc, uv);
421 if (!upisopen(uv)) 421 if (!upisopen(uv))
422 checkvalref(g, obj2gco(uv), uv->v); 422 checkvalref(g, obj2gco(uv), uv->v.p);
423 } 423 }
424 } 424 }
425} 425}
@@ -428,7 +428,7 @@ static void checkLclosure (global_State *g, LClosure *cl) {
428static int lua_checkpc (CallInfo *ci) { 428static int lua_checkpc (CallInfo *ci) {
429 if (!isLua(ci)) return 1; 429 if (!isLua(ci)) return 1;
430 else { 430 else {
431 StkId f = ci->func; 431 StkId f = ci->func.p;
432 Proto *p = clLvalue(s2v(f))->p; 432 Proto *p = clLvalue(s2v(f))->p;
433 return p->code <= ci->u.l.savedpc && 433 return p->code <= ci->u.l.savedpc &&
434 ci->u.l.savedpc <= p->code + p->sizecode; 434 ci->u.l.savedpc <= p->code + p->sizecode;
@@ -441,19 +441,19 @@ static void checkstack (global_State *g, lua_State *L1) {
441 CallInfo *ci; 441 CallInfo *ci;
442 UpVal *uv; 442 UpVal *uv;
443 assert(!isdead(g, L1)); 443 assert(!isdead(g, L1));
444 if (L1->stack == NULL) { /* incomplete thread? */ 444 if (L1->stack.p == NULL) { /* incomplete thread? */
445 assert(L1->openupval == NULL && L1->ci == NULL); 445 assert(L1->openupval == NULL && L1->ci == NULL);
446 return; 446 return;
447 } 447 }
448 for (uv = L1->openupval; uv != NULL; uv = uv->u.open.next) 448 for (uv = L1->openupval; uv != NULL; uv = uv->u.open.next)
449 assert(upisopen(uv)); /* must be open */ 449 assert(upisopen(uv)); /* must be open */
450 assert(L1->top <= L1->stack_last); 450 assert(L1->top.p <= L1->stack_last.p);
451 assert(L1->tbclist <= L1->top); 451 assert(L1->tbclist.p <= L1->top.p);
452 for (ci = L1->ci; ci != NULL; ci = ci->previous) { 452 for (ci = L1->ci; ci != NULL; ci = ci->previous) {
453 assert(ci->top <= L1->stack_last); 453 assert(ci->top.p <= L1->stack_last.p);
454 assert(lua_checkpc(ci)); 454 assert(lua_checkpc(ci));
455 } 455 }
456 for (o = L1->stack; o < L1->stack_last; o++) 456 for (o = L1->stack.p; o < L1->stack_last.p; o++)
457 checkliveness(L1, s2v(o)); /* entire stack must have valid values */ 457 checkliveness(L1, s2v(o)); /* entire stack must have valid values */
458} 458}
459 459
@@ -465,7 +465,7 @@ static void checkrefs (global_State *g, GCObject *o) {
465 break; 465 break;
466 } 466 }
467 case LUA_VUPVAL: { 467 case LUA_VUPVAL: {
468 checkvalref(g, o, gco2upv(o)->v); 468 checkvalref(g, o, gco2upv(o)->v.p);
469 break; 469 break;
470 } 470 }
471 case LUA_VTABLE: { 471 case LUA_VTABLE: {
@@ -980,7 +980,7 @@ static int hash_query (lua_State *L) {
980 980
981static int stacklevel (lua_State *L) { 981static int stacklevel (lua_State *L) {
982 unsigned long a = 0; 982 unsigned long a = 0;
983 lua_pushinteger(L, (L->top - L->stack)); 983 lua_pushinteger(L, (L->top.p - L->stack.p));
984 lua_pushinteger(L, stacksize(L)); 984 lua_pushinteger(L, stacksize(L));
985 lua_pushinteger(L, L->nCcalls); 985 lua_pushinteger(L, L->nCcalls);
986 lua_pushinteger(L, L->nci); 986 lua_pushinteger(L, L->nci);
@@ -1040,7 +1040,7 @@ static int string_query (lua_State *L) {
1040 TString *ts; 1040 TString *ts;
1041 int n = 0; 1041 int n = 0;
1042 for (ts = tb->hash[s]; ts != NULL; ts = ts->u.hnext) { 1042 for (ts = tb->hash[s]; ts != NULL; ts = ts->u.hnext) {
1043 setsvalue2s(L, L->top, ts); 1043 setsvalue2s(L, L->top.p, ts);
1044 api_incr_top(L); 1044 api_incr_top(L);
1045 n++; 1045 n++;
1046 } 1046 }
diff --git a/ltm.c b/ltm.c
index b657b783..07a06081 100644
--- a/ltm.c
+++ b/ltm.c
@@ -102,12 +102,12 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) {
102 102
103void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 103void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
104 const TValue *p2, const TValue *p3) { 104 const TValue *p2, const TValue *p3) {
105 StkId func = L->top; 105 StkId func = L->top.p;
106 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 106 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */
107 setobj2s(L, func + 1, p1); /* 1st argument */ 107 setobj2s(L, func + 1, p1); /* 1st argument */
108 setobj2s(L, func + 2, p2); /* 2nd argument */ 108 setobj2s(L, func + 2, p2); /* 2nd argument */
109 setobj2s(L, func + 3, p3); /* 3rd argument */ 109 setobj2s(L, func + 3, p3); /* 3rd argument */
110 L->top = func + 4; 110 L->top.p = func + 4;
111 /* metamethod may yield only when called from Lua code */ 111 /* metamethod may yield only when called from Lua code */
112 if (isLuacode(L->ci)) 112 if (isLuacode(L->ci))
113 luaD_call(L, func, 0); 113 luaD_call(L, func, 0);
@@ -119,18 +119,18 @@ void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
119void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, 119void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1,
120 const TValue *p2, StkId res) { 120 const TValue *p2, StkId res) {
121 ptrdiff_t result = savestack(L, res); 121 ptrdiff_t result = savestack(L, res);
122 StkId func = L->top; 122 StkId func = L->top.p;
123 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 123 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */
124 setobj2s(L, func + 1, p1); /* 1st argument */ 124 setobj2s(L, func + 1, p1); /* 1st argument */
125 setobj2s(L, func + 2, p2); /* 2nd argument */ 125 setobj2s(L, func + 2, p2); /* 2nd argument */
126 L->top += 3; 126 L->top.p += 3;
127 /* metamethod may yield only when called from Lua code */ 127 /* metamethod may yield only when called from Lua code */
128 if (isLuacode(L->ci)) 128 if (isLuacode(L->ci))
129 luaD_call(L, func, 1); 129 luaD_call(L, func, 1);
130 else 130 else
131 luaD_callnoyield(L, func, 1); 131 luaD_callnoyield(L, func, 1);
132 res = restorestack(L, result); 132 res = restorestack(L, result);
133 setobjs2s(L, res, --L->top); /* move result to its place */ 133 setobjs2s(L, res, --L->top.p); /* move result to its place */
134} 134}
135 135
136 136
@@ -165,7 +165,7 @@ void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
165 165
166 166
167void luaT_tryconcatTM (lua_State *L) { 167void luaT_tryconcatTM (lua_State *L) {
168 StkId top = L->top; 168 StkId top = L->top.p;
169 if (l_unlikely(!callbinTM(L, s2v(top - 2), s2v(top - 1), top - 2, 169 if (l_unlikely(!callbinTM(L, s2v(top - 2), s2v(top - 1), top - 2,
170 TM_CONCAT))) 170 TM_CONCAT)))
171 luaG_concaterror(L, s2v(top - 2), s2v(top - 1)); 171 luaG_concaterror(L, s2v(top - 2), s2v(top - 1));
@@ -200,15 +200,15 @@ void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,
200*/ 200*/
201int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 201int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
202 TMS event) { 202 TMS event) {
203 if (callbinTM(L, p1, p2, L->top, event)) /* try original event */ 203 if (callbinTM(L, p1, p2, L->top.p, event)) /* try original event */
204 return !l_isfalse(s2v(L->top)); 204 return !l_isfalse(s2v(L->top.p));
205#if defined(LUA_COMPAT_LT_LE) 205#if defined(LUA_COMPAT_LT_LE)
206 else if (event == TM_LE) { 206 else if (event == TM_LE) {
207 /* try '!(p2 < p1)' for '(p1 <= p2)' */ 207 /* try '!(p2 < p1)' for '(p1 <= p2)' */
208 L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */ 208 L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
209 if (callbinTM(L, p2, p1, L->top, TM_LT)) { 209 if (callbinTM(L, p2, p1, L->top.p, TM_LT)) {
210 L->ci->callstatus ^= CIST_LEQ; /* clear mark */ 210 L->ci->callstatus ^= CIST_LEQ; /* clear mark */
211 return l_isfalse(s2v(L->top)); 211 return l_isfalse(s2v(L->top.p));
212 } 212 }
213 /* else error will remove this 'ci'; no need to clear mark */ 213 /* else error will remove this 'ci'; no need to clear mark */
214 } 214 }
@@ -238,20 +238,20 @@ int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
238void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci, 238void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci,
239 const Proto *p) { 239 const Proto *p) {
240 int i; 240 int i;
241 int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ 241 int actual = cast_int(L->top.p - ci->func.p) - 1; /* number of arguments */
242 int nextra = actual - nfixparams; /* number of extra arguments */ 242 int nextra = actual - nfixparams; /* number of extra arguments */
243 ci->u.l.nextraargs = nextra; 243 ci->u.l.nextraargs = nextra;
244 luaD_checkstack(L, p->maxstacksize + 1); 244 luaD_checkstack(L, p->maxstacksize + 1);
245 /* copy function to the top of the stack */ 245 /* copy function to the top of the stack */
246 setobjs2s(L, L->top++, ci->func); 246 setobjs2s(L, L->top.p++, ci->func.p);
247 /* move fixed parameters to the top of the stack */ 247 /* move fixed parameters to the top of the stack */
248 for (i = 1; i <= nfixparams; i++) { 248 for (i = 1; i <= nfixparams; i++) {
249 setobjs2s(L, L->top++, ci->func + i); 249 setobjs2s(L, L->top.p++, ci->func.p + i);
250 setnilvalue(s2v(ci->func + i)); /* erase original parameter (for GC) */ 250 setnilvalue(s2v(ci->func.p + i)); /* erase original parameter (for GC) */
251 } 251 }
252 ci->func += actual + 1; 252 ci->func.p += actual + 1;
253 ci->top += actual + 1; 253 ci->top.p += actual + 1;
254 lua_assert(L->top <= ci->top && ci->top <= L->stack_last); 254 lua_assert(L->top.p <= ci->top.p && ci->top.p <= L->stack_last.p);
255} 255}
256 256
257 257
@@ -261,10 +261,10 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) {
261 if (wanted < 0) { 261 if (wanted < 0) {
262 wanted = nextra; /* get all extra arguments available */ 262 wanted = nextra; /* get all extra arguments available */
263 checkstackGCp(L, nextra, where); /* ensure stack space */ 263 checkstackGCp(L, nextra, where); /* ensure stack space */
264 L->top = where + nextra; /* next instruction will need top */ 264 L->top.p = where + nextra; /* next instruction will need top */
265 } 265 }
266 for (i = 0; i < wanted && i < nextra; i++) 266 for (i = 0; i < wanted && i < nextra; i++)
267 setobjs2s(L, where + i, ci->func - nextra + i); 267 setobjs2s(L, where + i, ci->func.p - nextra + i);
268 for (; i < wanted; i++) /* complete required results with nil */ 268 for (; i < wanted; i++) /* complete required results with nil */
269 setnilvalue(s2v(where + i)); 269 setnilvalue(s2v(where + i));
270} 270}
diff --git a/lundump.c b/lundump.c
index 5aa55c44..aba93f82 100644
--- a/lundump.c
+++ b/lundump.c
@@ -120,10 +120,10 @@ static TString *loadStringN (LoadState *S, Proto *p) {
120 } 120 }
121 else { /* long string */ 121 else { /* long string */
122 ts = luaS_createlngstrobj(L, size); /* create string */ 122 ts = luaS_createlngstrobj(L, size); /* create string */
123 setsvalue2s(L, L->top, ts); /* anchor it ('loadVector' can GC) */ 123 setsvalue2s(L, L->top.p, ts); /* anchor it ('loadVector' can GC) */
124 luaD_inctop(L); 124 luaD_inctop(L);
125 loadVector(S, getstr(ts), size); /* load directly in final place */ 125 loadVector(S, getstr(ts), size); /* load directly in final place */
126 L->top--; /* pop string */ 126 L->top.p--; /* pop string */
127 } 127 }
128 luaC_objbarrier(L, p, ts); 128 luaC_objbarrier(L, p, ts);
129 return ts; 129 return ts;
@@ -321,7 +321,7 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
321 S.Z = Z; 321 S.Z = Z;
322 checkHeader(&S); 322 checkHeader(&S);
323 cl = luaF_newLclosure(L, loadByte(&S)); 323 cl = luaF_newLclosure(L, loadByte(&S));
324 setclLvalue2s(L, L->top, cl); 324 setclLvalue2s(L, L->top.p, cl);
325 luaD_inctop(L); 325 luaD_inctop(L);
326 cl->p = luaF_newproto(L); 326 cl->p = luaF_newproto(L);
327 luaC_objbarrier(L, cl, cl->p); 327 luaC_objbarrier(L, cl, cl->p);
diff --git a/lvm.c b/lvm.c
index 73a19ba9..2e84dc63 100644
--- a/lvm.c
+++ b/lvm.c
@@ -608,8 +608,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
608 if (tm == NULL) /* no TM? */ 608 if (tm == NULL) /* no TM? */
609 return 0; /* objects are different */ 609 return 0; /* objects are different */
610 else { 610 else {
611 luaT_callTMres(L, tm, t1, t2, L->top); /* call TM */ 611 luaT_callTMres(L, tm, t1, t2, L->top.p); /* call TM */
612 return !l_isfalse(s2v(L->top)); 612 return !l_isfalse(s2v(L->top.p));
613 } 613 }
614} 614}
615 615
@@ -633,13 +633,13 @@ static void copy2buff (StkId top, int n, char *buff) {
633 633
634/* 634/*
635** Main operation for concatenation: concat 'total' values in the stack, 635** Main operation for concatenation: concat 'total' values in the stack,
636** from 'L->top - total' up to 'L->top - 1'. 636** from 'L->top.p - total' up to 'L->top.p - 1'.
637*/ 637*/
638void luaV_concat (lua_State *L, int total) { 638void luaV_concat (lua_State *L, int total) {
639 if (total == 1) 639 if (total == 1)
640 return; /* "all" values already concatenated */ 640 return; /* "all" values already concatenated */
641 do { 641 do {
642 StkId top = L->top; 642 StkId top = L->top.p;
643 int n = 2; /* number of elements handled in this pass (at least 2) */ 643 int n = 2; /* number of elements handled in this pass (at least 2) */
644 if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) || 644 if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) ||
645 !tostring(L, s2v(top - 1))) 645 !tostring(L, s2v(top - 1)))
@@ -657,7 +657,7 @@ void luaV_concat (lua_State *L, int total) {
657 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { 657 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
658 size_t l = vslen(s2v(top - n - 1)); 658 size_t l = vslen(s2v(top - n - 1));
659 if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) { 659 if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) {
660 L->top = top - total; /* pop strings to avoid wasting stack */ 660 L->top.p = top - total; /* pop strings to avoid wasting stack */
661 luaG_runerror(L, "string length overflow"); 661 luaG_runerror(L, "string length overflow");
662 } 662 }
663 tl += l; 663 tl += l;
@@ -674,7 +674,7 @@ void luaV_concat (lua_State *L, int total) {
674 setsvalue2s(L, top - n, ts); /* create result */ 674 setsvalue2s(L, top - n, ts); /* create result */
675 } 675 }
676 total -= n - 1; /* got 'n' strings to create one new */ 676 total -= n - 1; /* got 'n' strings to create one new */
677 L->top -= n - 1; /* popped 'n' strings and pushed one */ 677 L->top.p -= n - 1; /* popped 'n' strings and pushed one */
678 } while (total > 1); /* repeat until only 1 result left */ 678 } while (total > 1); /* repeat until only 1 result left */
679} 679}
680 680
@@ -808,26 +808,26 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
808*/ 808*/
809void luaV_finishOp (lua_State *L) { 809void luaV_finishOp (lua_State *L) {
810 CallInfo *ci = L->ci; 810 CallInfo *ci = L->ci;
811 StkId base = ci->func + 1; 811 StkId base = ci->func.p + 1;
812 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ 812 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
813 OpCode op = GET_OPCODE(inst); 813 OpCode op = GET_OPCODE(inst);
814 switch (op) { /* finish its execution */ 814 switch (op) { /* finish its execution */
815 case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: { 815 case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
816 setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top); 816 setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top.p);
817 break; 817 break;
818 } 818 }
819 case OP_UNM: case OP_BNOT: case OP_LEN: 819 case OP_UNM: case OP_BNOT: case OP_LEN:
820 case OP_GETTABUP: case OP_GETTABLE: case OP_GETI: 820 case OP_GETTABUP: case OP_GETTABLE: case OP_GETI:
821 case OP_GETFIELD: case OP_SELF: { 821 case OP_GETFIELD: case OP_SELF: {
822 setobjs2s(L, base + GETARG_A(inst), --L->top); 822 setobjs2s(L, base + GETARG_A(inst), --L->top.p);
823 break; 823 break;
824 } 824 }
825 case OP_LT: case OP_LE: 825 case OP_LT: case OP_LE:
826 case OP_LTI: case OP_LEI: 826 case OP_LTI: case OP_LEI:
827 case OP_GTI: case OP_GEI: 827 case OP_GTI: case OP_GEI:
828 case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */ 828 case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */
829 int res = !l_isfalse(s2v(L->top - 1)); 829 int res = !l_isfalse(s2v(L->top.p - 1));
830 L->top--; 830 L->top.p--;
831#if defined(LUA_COMPAT_LT_LE) 831#if defined(LUA_COMPAT_LT_LE)
832 if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ 832 if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */
833 ci->callstatus ^= CIST_LEQ; /* clear mark */ 833 ci->callstatus ^= CIST_LEQ; /* clear mark */
@@ -840,11 +840,11 @@ void luaV_finishOp (lua_State *L) {
840 break; 840 break;
841 } 841 }
842 case OP_CONCAT: { 842 case OP_CONCAT: {
843 StkId top = L->top - 1; /* top when 'luaT_tryconcatTM' was called */ 843 StkId top = L->top.p - 1; /* top when 'luaT_tryconcatTM' was called */
844 int a = GETARG_A(inst); /* first element to concatenate */ 844 int a = GETARG_A(inst); /* first element to concatenate */
845 int total = cast_int(top - 1 - (base + a)); /* yet to concatenate */ 845 int total = cast_int(top - 1 - (base + a)); /* yet to concatenate */
846 setobjs2s(L, top - 2, top); /* put TM result in proper position */ 846 setobjs2s(L, top - 2, top); /* put TM result in proper position */
847 L->top = top - 1; /* top is one after last element (at top-2) */ 847 L->top.p = top - 1; /* top is one after last element (at top-2) */
848 luaV_concat(L, total); /* concat them (may yield again) */ 848 luaV_concat(L, total); /* concat them (may yield again) */
849 break; 849 break;
850 } 850 }
@@ -856,7 +856,7 @@ void luaV_finishOp (lua_State *L) {
856 StkId ra = base + GETARG_A(inst); 856 StkId ra = base + GETARG_A(inst);
857 /* adjust top to signal correct number of returns, in case the 857 /* adjust top to signal correct number of returns, in case the
858 return is "up to top" ('isIT') */ 858 return is "up to top" ('isIT') */
859 L->top = ra + ci->u2.nres; 859 L->top.p = ra + ci->u2.nres;
860 /* repeat instruction to close other vars. and complete the return */ 860 /* repeat instruction to close other vars. and complete the return */
861 ci->u.l.savedpc--; 861 ci->u.l.savedpc--;
862 break; 862 break;
@@ -1069,7 +1069,7 @@ void luaV_finishOp (lua_State *L) {
1069 1069
1070#define updatetrap(ci) (trap = ci->u.l.trap) 1070#define updatetrap(ci) (trap = ci->u.l.trap)
1071 1071
1072#define updatebase(ci) (base = ci->func + 1) 1072#define updatebase(ci) (base = ci->func.p + 1)
1073 1073
1074 1074
1075#define updatestack(ci) \ 1075#define updatestack(ci) \
@@ -1104,7 +1104,7 @@ void luaV_finishOp (lua_State *L) {
1104** Whenever code can raise errors, the global 'pc' and the global 1104** Whenever code can raise errors, the global 'pc' and the global
1105** 'top' must be correct to report occasional errors. 1105** 'top' must be correct to report occasional errors.
1106*/ 1106*/
1107#define savestate(L,ci) (savepc(L), L->top = ci->top) 1107#define savestate(L,ci) (savepc(L), L->top.p = ci->top.p)
1108 1108
1109 1109
1110/* 1110/*
@@ -1124,7 +1124,7 @@ void luaV_finishOp (lua_State *L) {
1124 1124
1125/* 'c' is the limit of live values in the stack */ 1125/* 'c' is the limit of live values in the stack */
1126#define checkGC(L,c) \ 1126#define checkGC(L,c) \
1127 { luaC_condGC(L, (savepc(L), L->top = (c)), \ 1127 { luaC_condGC(L, (savepc(L), L->top.p = (c)), \
1128 updatetrap(ci)); \ 1128 updatetrap(ci)); \
1129 luai_threadyield(L); } 1129 luai_threadyield(L); }
1130 1130
@@ -1155,7 +1155,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1155 startfunc: 1155 startfunc:
1156 trap = L->hookmask; 1156 trap = L->hookmask;
1157 returning: /* trap already set */ 1157 returning: /* trap already set */
1158 cl = clLvalue(s2v(ci->func)); 1158 cl = clLvalue(s2v(ci->func.p));
1159 k = cl->p->k; 1159 k = cl->p->k;
1160 pc = ci->u.l.savedpc; 1160 pc = ci->u.l.savedpc;
1161 if (l_unlikely(trap)) { 1161 if (l_unlikely(trap)) {
@@ -1167,7 +1167,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1167 } 1167 }
1168 ci->u.l.trap = 1; /* assume trap is on, for now */ 1168 ci->u.l.trap = 1; /* assume trap is on, for now */
1169 } 1169 }
1170 base = ci->func + 1; 1170 base = ci->func.p + 1;
1171 /* main loop of interpreter */ 1171 /* main loop of interpreter */
1172 for (;;) { 1172 for (;;) {
1173 Instruction i; /* instruction being executed */ 1173 Instruction i; /* instruction being executed */
@@ -1176,10 +1176,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1176 /* low-level line tracing for debugging Lua */ 1176 /* low-level line tracing for debugging Lua */
1177 printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p))); 1177 printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p)));
1178 #endif 1178 #endif
1179 lua_assert(base == ci->func + 1); 1179 lua_assert(base == ci->func.p + 1);
1180 lua_assert(base <= L->top && L->top <= L->stack_last); 1180 lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p);
1181 /* invalidate top for instructions not expecting it */ 1181 /* invalidate top for instructions not expecting it */
1182 lua_assert(isIT(i) || (cast_void(L->top = base), 1)); 1182 lua_assert(isIT(i) || (cast_void(L->top.p = base), 1));
1183 vmdispatch (GET_OPCODE(i)) { 1183 vmdispatch (GET_OPCODE(i)) {
1184 vmcase(OP_MOVE) { 1184 vmcase(OP_MOVE) {
1185 StkId ra = RA(i); 1185 StkId ra = RA(i);
@@ -1238,20 +1238,20 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1238 vmcase(OP_GETUPVAL) { 1238 vmcase(OP_GETUPVAL) {
1239 StkId ra = RA(i); 1239 StkId ra = RA(i);
1240 int b = GETARG_B(i); 1240 int b = GETARG_B(i);
1241 setobj2s(L, ra, cl->upvals[b]->v); 1241 setobj2s(L, ra, cl->upvals[b]->v.p);
1242 vmbreak; 1242 vmbreak;
1243 } 1243 }
1244 vmcase(OP_SETUPVAL) { 1244 vmcase(OP_SETUPVAL) {
1245 StkId ra = RA(i); 1245 StkId ra = RA(i);
1246 UpVal *uv = cl->upvals[GETARG_B(i)]; 1246 UpVal *uv = cl->upvals[GETARG_B(i)];
1247 setobj(L, uv->v, s2v(ra)); 1247 setobj(L, uv->v.p, s2v(ra));
1248 luaC_barrier(L, uv, s2v(ra)); 1248 luaC_barrier(L, uv, s2v(ra));
1249 vmbreak; 1249 vmbreak;
1250 } 1250 }
1251 vmcase(OP_GETTABUP) { 1251 vmcase(OP_GETTABUP) {
1252 StkId ra = RA(i); 1252 StkId ra = RA(i);
1253 const TValue *slot; 1253 const TValue *slot;
1254 TValue *upval = cl->upvals[GETARG_B(i)]->v; 1254 TValue *upval = cl->upvals[GETARG_B(i)]->v.p;
1255 TValue *rc = KC(i); 1255 TValue *rc = KC(i);
1256 TString *key = tsvalue(rc); /* key must be a string */ 1256 TString *key = tsvalue(rc); /* key must be a string */
1257 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { 1257 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
@@ -1306,7 +1306,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1306 } 1306 }
1307 vmcase(OP_SETTABUP) { 1307 vmcase(OP_SETTABUP) {
1308 const TValue *slot; 1308 const TValue *slot;
1309 TValue *upval = cl->upvals[GETARG_A(i)]->v; 1309 TValue *upval = cl->upvals[GETARG_A(i)]->v.p;
1310 TValue *rb = KB(i); 1310 TValue *rb = KB(i);
1311 TValue *rc = RKC(i); 1311 TValue *rc = RKC(i);
1312 TString *key = tsvalue(rb); /* key must be a string */ 1312 TString *key = tsvalue(rb); /* key must be a string */
@@ -1371,7 +1371,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1371 if (TESTARG_k(i)) /* non-zero extra argument? */ 1371 if (TESTARG_k(i)) /* non-zero extra argument? */
1372 c += GETARG_Ax(*pc) * (MAXARG_C + 1); /* add it to size */ 1372 c += GETARG_Ax(*pc) * (MAXARG_C + 1); /* add it to size */
1373 pc++; /* skip extra argument */ 1373 pc++; /* skip extra argument */
1374 L->top = ra + 1; /* correct top in case of emergency GC */ 1374 L->top.p = ra + 1; /* correct top in case of emergency GC */
1375 t = luaH_new(L); /* memory allocation */ 1375 t = luaH_new(L); /* memory allocation */
1376 sethvalue2s(L, ra, t); 1376 sethvalue2s(L, ra, t);
1377 if (b != 0 || c != 0) 1377 if (b != 0 || c != 0)
@@ -1578,9 +1578,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1578 vmcase(OP_CONCAT) { 1578 vmcase(OP_CONCAT) {
1579 StkId ra = RA(i); 1579 StkId ra = RA(i);
1580 int n = GETARG_B(i); /* number of elements to concatenate */ 1580 int n = GETARG_B(i); /* number of elements to concatenate */
1581 L->top = ra + n; /* mark the end of concat operands */ 1581 L->top.p = ra + n; /* mark the end of concat operands */
1582 ProtectNT(luaV_concat(L, n)); 1582 ProtectNT(luaV_concat(L, n));
1583 checkGC(L, L->top); /* 'luaV_concat' ensures correct top */ 1583 checkGC(L, L->top.p); /* 'luaV_concat' ensures correct top */
1584 vmbreak; 1584 vmbreak;
1585 } 1585 }
1586 vmcase(OP_CLOSE) { 1586 vmcase(OP_CLOSE) {
@@ -1674,7 +1674,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1674 int b = GETARG_B(i); 1674 int b = GETARG_B(i);
1675 int nresults = GETARG_C(i) - 1; 1675 int nresults = GETARG_C(i) - 1;
1676 if (b != 0) /* fixed number of arguments? */ 1676 if (b != 0) /* fixed number of arguments? */
1677 L->top = ra + b; /* top signals number of arguments */ 1677 L->top.p = ra + b; /* top signals number of arguments */
1678 /* else previous instruction set top */ 1678 /* else previous instruction set top */
1679 savepc(L); /* in case of errors */ 1679 savepc(L); /* in case of errors */
1680 if ((newci = luaD_precall(L, ra, nresults)) == NULL) 1680 if ((newci = luaD_precall(L, ra, nresults)) == NULL)
@@ -1693,19 +1693,19 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1693 /* delta is virtual 'func' - real 'func' (vararg functions) */ 1693 /* delta is virtual 'func' - real 'func' (vararg functions) */
1694 int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0; 1694 int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;
1695 if (b != 0) 1695 if (b != 0)
1696 L->top = ra + b; 1696 L->top.p = ra + b;
1697 else /* previous instruction set top */ 1697 else /* previous instruction set top */
1698 b = cast_int(L->top - ra); 1698 b = cast_int(L->top.p - ra);
1699 savepc(ci); /* several calls here can raise errors */ 1699 savepc(ci); /* several calls here can raise errors */
1700 if (TESTARG_k(i)) { 1700 if (TESTARG_k(i)) {
1701 luaF_closeupval(L, base); /* close upvalues from current call */ 1701 luaF_closeupval(L, base); /* close upvalues from current call */
1702 lua_assert(L->tbclist < base); /* no pending tbc variables */ 1702 lua_assert(L->tbclist.p < base); /* no pending tbc variables */
1703 lua_assert(base == ci->func + 1); 1703 lua_assert(base == ci->func.p + 1);
1704 } 1704 }
1705 if ((n = luaD_pretailcall(L, ci, ra, b, delta)) < 0) /* Lua function? */ 1705 if ((n = luaD_pretailcall(L, ci, ra, b, delta)) < 0) /* Lua function? */
1706 goto startfunc; /* execute the callee */ 1706 goto startfunc; /* execute the callee */
1707 else { /* C function? */ 1707 else { /* C function? */
1708 ci->func -= delta; /* restore 'func' (if vararg) */ 1708 ci->func.p -= delta; /* restore 'func' (if vararg) */
1709 luaD_poscall(L, ci, n); /* finish caller */ 1709 luaD_poscall(L, ci, n); /* finish caller */
1710 updatetrap(ci); /* 'luaD_poscall' can change hooks */ 1710 updatetrap(ci); /* 'luaD_poscall' can change hooks */
1711 goto ret; /* caller returns after the tail call */ 1711 goto ret; /* caller returns after the tail call */
@@ -1716,19 +1716,19 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1716 int n = GETARG_B(i) - 1; /* number of results */ 1716 int n = GETARG_B(i) - 1; /* number of results */
1717 int nparams1 = GETARG_C(i); 1717 int nparams1 = GETARG_C(i);
1718 if (n < 0) /* not fixed? */ 1718 if (n < 0) /* not fixed? */
1719 n = cast_int(L->top - ra); /* get what is available */ 1719 n = cast_int(L->top.p - ra); /* get what is available */
1720 savepc(ci); 1720 savepc(ci);
1721 if (TESTARG_k(i)) { /* may there be open upvalues? */ 1721 if (TESTARG_k(i)) { /* may there be open upvalues? */
1722 ci->u2.nres = n; /* save number of returns */ 1722 ci->u2.nres = n; /* save number of returns */
1723 if (L->top < ci->top) 1723 if (L->top.p < ci->top.p)
1724 L->top = ci->top; 1724 L->top.p = ci->top.p;
1725 luaF_close(L, base, CLOSEKTOP, 1); 1725 luaF_close(L, base, CLOSEKTOP, 1);
1726 updatetrap(ci); 1726 updatetrap(ci);
1727 updatestack(ci); 1727 updatestack(ci);
1728 } 1728 }
1729 if (nparams1) /* vararg function? */ 1729 if (nparams1) /* vararg function? */
1730 ci->func -= ci->u.l.nextraargs + nparams1; 1730 ci->func.p -= ci->u.l.nextraargs + nparams1;
1731 L->top = ra + n; /* set call for 'luaD_poscall' */ 1731 L->top.p = ra + n; /* set call for 'luaD_poscall' */
1732 luaD_poscall(L, ci, n); 1732 luaD_poscall(L, ci, n);
1733 updatetrap(ci); /* 'luaD_poscall' can change hooks */ 1733 updatetrap(ci); /* 'luaD_poscall' can change hooks */
1734 goto ret; 1734 goto ret;
@@ -1736,7 +1736,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1736 vmcase(OP_RETURN0) { 1736 vmcase(OP_RETURN0) {
1737 if (l_unlikely(L->hookmask)) { 1737 if (l_unlikely(L->hookmask)) {
1738 StkId ra = RA(i); 1738 StkId ra = RA(i);
1739 L->top = ra; 1739 L->top.p = ra;
1740 savepc(ci); 1740 savepc(ci);
1741 luaD_poscall(L, ci, 0); /* no hurry... */ 1741 luaD_poscall(L, ci, 0); /* no hurry... */
1742 trap = 1; 1742 trap = 1;
@@ -1744,16 +1744,16 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1744 else { /* do the 'poscall' here */ 1744 else { /* do the 'poscall' here */
1745 int nres; 1745 int nres;
1746 L->ci = ci->previous; /* back to caller */ 1746 L->ci = ci->previous; /* back to caller */
1747 L->top = base - 1; 1747 L->top.p = base - 1;
1748 for (nres = ci->nresults; l_unlikely(nres > 0); nres--) 1748 for (nres = ci->nresults; l_unlikely(nres > 0); nres--)
1749 setnilvalue(s2v(L->top++)); /* all results are nil */ 1749 setnilvalue(s2v(L->top.p++)); /* all results are nil */
1750 } 1750 }
1751 goto ret; 1751 goto ret;
1752 } 1752 }
1753 vmcase(OP_RETURN1) { 1753 vmcase(OP_RETURN1) {
1754 if (l_unlikely(L->hookmask)) { 1754 if (l_unlikely(L->hookmask)) {
1755 StkId ra = RA(i); 1755 StkId ra = RA(i);
1756 L->top = ra + 1; 1756 L->top.p = ra + 1;
1757 savepc(ci); 1757 savepc(ci);
1758 luaD_poscall(L, ci, 1); /* no hurry... */ 1758 luaD_poscall(L, ci, 1); /* no hurry... */
1759 trap = 1; 1759 trap = 1;
@@ -1762,13 +1762,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1762 int nres = ci->nresults; 1762 int nres = ci->nresults;
1763 L->ci = ci->previous; /* back to caller */ 1763 L->ci = ci->previous; /* back to caller */
1764 if (nres == 0) 1764 if (nres == 0)
1765 L->top = base - 1; /* asked for no results */ 1765 L->top.p = base - 1; /* asked for no results */
1766 else { 1766 else {
1767 StkId ra = RA(i); 1767 StkId ra = RA(i);
1768 setobjs2s(L, base - 1, ra); /* at least this result */ 1768 setobjs2s(L, base - 1, ra); /* at least this result */
1769 L->top = base; 1769 L->top.p = base;
1770 for (; l_unlikely(nres > 1); nres--) 1770 for (; l_unlikely(nres > 1); nres--)
1771 setnilvalue(s2v(L->top++)); /* complete missing results */ 1771 setnilvalue(s2v(L->top.p++)); /* complete missing results */
1772 } 1772 }
1773 } 1773 }
1774 ret: /* return from a Lua function */ 1774 ret: /* return from a Lua function */
@@ -1824,7 +1824,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1824 */ 1824 */
1825 /* push function, state, and control variable */ 1825 /* push function, state, and control variable */
1826 memcpy(ra + 4, ra, 3 * sizeof(*ra)); 1826 memcpy(ra + 4, ra, 3 * sizeof(*ra));
1827 L->top = ra + 4 + 3; 1827 L->top.p = ra + 4 + 3;
1828 ProtectNT(luaD_call(L, ra + 4, GETARG_C(i))); /* do the call */ 1828 ProtectNT(luaD_call(L, ra + 4, GETARG_C(i))); /* do the call */
1829 updatestack(ci); /* stack may have changed */ 1829 updatestack(ci); /* stack may have changed */
1830 i = *(pc++); /* go to next instruction */ 1830 i = *(pc++); /* go to next instruction */
@@ -1846,9 +1846,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1846 unsigned int last = GETARG_C(i); 1846 unsigned int last = GETARG_C(i);
1847 Table *h = hvalue(s2v(ra)); 1847 Table *h = hvalue(s2v(ra));
1848 if (n == 0) 1848 if (n == 0)
1849 n = cast_int(L->top - ra) - 1; /* get up to the top */ 1849 n = cast_int(L->top.p - ra) - 1; /* get up to the top */
1850 else 1850 else
1851 L->top = ci->top; /* correct top in case of emergency GC */ 1851 L->top.p = ci->top.p; /* correct top in case of emergency GC */
1852 last += n; 1852 last += n;
1853 if (TESTARG_k(i)) { 1853 if (TESTARG_k(i)) {
1854 last += GETARG_Ax(*pc) * (MAXARG_C + 1); 1854 last += GETARG_Ax(*pc) * (MAXARG_C + 1);