aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-10-29 12:06:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-10-29 12:06:37 -0300
commit413a393e6222482f46599e138bebac162610a572 (patch)
tree181517f8ec8d56f9101de33f4891729044f244de /ltm.c
parentba089bcb08a0efc6c26fb5c1e3c9d61c00cc012c (diff)
downloadlua-413a393e6222482f46599e138bebac162610a572.tar.gz
lua-413a393e6222482f46599e138bebac162610a572.tar.bz2
lua-413a393e6222482f46599e138bebac162610a572.zip
Stack indices changed to union's
That will allow to change pointers to offsets while reallocating the stack.
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c38
1 files changed, 19 insertions, 19 deletions
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}