diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-29 12:06:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-10-29 12:06:37 -0300 |
commit | 413a393e6222482f46599e138bebac162610a572 (patch) | |
tree | 181517f8ec8d56f9101de33f4891729044f244de /lfunc.c | |
parent | ba089bcb08a0efc6c26fb5c1e3c9d61c00cc012c (diff) | |
download | lua-413a393e6222482f46599e138bebac162610a572.tar.gz lua-413a393e6222482f46599e138bebac162610a572.tar.bz2 lua-413a393e6222482f46599e138bebac162610a572.zip |
Stack indices changed to union's
That will allow to change pointers to offsets while reallocating
the stack.
Diffstat (limited to 'lfunc.c')
-rw-r--r-- | lfunc.c | 42 |
1 files changed, 21 insertions, 21 deletions
@@ -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 | */ |
108 | static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) { | 108 | static 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) { | |||
126 | static void checkclosemth (lua_State *L, StkId level) { | 126 | static 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 | */ |
169 | void luaF_newtbcupval (lua_State *L, StkId level) { | 169 | void 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 | */ |
214 | static void poptbclist (lua_State *L) { | 214 | static 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) { | |||
228 | StkId luaF_close (lua_State *L, StkId level, int status, int yy) { | 228 | StkId 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); |