aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/lua/lfunc.c
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-12-02 10:40:09 +0800
committerLi Jin <dragon-fly@qq.com>2022-12-02 10:40:09 +0800
commit298b18dbe852300199cc529c942a181bead5f135 (patch)
treef4b5ae89b6920fa0a12c693118f85334f19754f8 /src/3rdParty/lua/lfunc.c
parenta6a65ba26a9d320611abcbfba49fa724edfb4dad (diff)
downloadyuescript-298b18dbe852300199cc529c942a181bead5f135.tar.gz
yuescript-298b18dbe852300199cc529c942a181bead5f135.tar.bz2
yuescript-298b18dbe852300199cc529c942a181bead5f135.zip
update Lua.
Diffstat (limited to 'src/3rdParty/lua/lfunc.c')
-rw-r--r--src/3rdParty/lua/lfunc.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/3rdParty/lua/lfunc.c b/src/3rdParty/lua/lfunc.c
index daba0ab..0945f24 100644
--- a/src/3rdParty/lua/lfunc.c
+++ b/src/3rdParty/lua/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 }
@@ -62,12 +62,11 @@ void luaF_initupvals (lua_State *L, LClosure *cl) {
62** Create a new upvalue at the given level, and link it to the list of 62** Create a new upvalue at the given level, and link it to the list of
63** open upvalues of 'L' after entry 'prev'. 63** open upvalues of 'L' after entry 'prev'.
64**/ 64**/
65static UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) { 65static UpVal *newupval (lua_State *L, 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;
71 uv->u.open.next = next; /* link it to list of open upvalues */ 70 uv->u.open.next = next; /* link it to list of open upvalues */
72 uv->u.open.previous = prev; 71 uv->u.open.previous = prev;
73 if (next) 72 if (next)
@@ -96,7 +95,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
96 pp = &p->u.open.next; 95 pp = &p->u.open.next;
97 } 96 }
98 /* not found: create a new upvalue after 'pp' */ 97 /* not found: create a new upvalue after 'pp' */
99 return newupval(L, 0, level, pp); 98 return newupval(L, level, pp);
100} 99}
101 100
102 101
@@ -106,12 +105,12 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
106** (This function assumes EXTRA_STACK.) 105** (This function assumes EXTRA_STACK.)
107*/ 106*/
108static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) { 107static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) {
109 StkId top = L->top; 108 StkId top = L->top.p;
110 const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE); 109 const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE);
111 setobj2s(L, top, tm); /* will call metamethod... */ 110 setobj2s(L, top, tm); /* will call metamethod... */
112 setobj2s(L, top + 1, obj); /* with 'self' as the 1st argument */ 111 setobj2s(L, top + 1, obj); /* with 'self' as the 1st argument */
113 setobj2s(L, top + 2, err); /* and error msg. as 2nd argument */ 112 setobj2s(L, top + 2, err); /* and error msg. as 2nd argument */
114 L->top = top + 3; /* add function and arguments */ 113 L->top.p = top + 3; /* add function and arguments */
115 if (yy) 114 if (yy)
116 luaD_call(L, top, 0); 115 luaD_call(L, top, 0);
117 else 116 else
@@ -126,7 +125,7 @@ static void callclosemethod (lua_State *L, TValue *obj, TValue *err, int yy) {
126static void checkclosemth (lua_State *L, StkId level) { 125static void checkclosemth (lua_State *L, StkId level) {
127 const TValue *tm = luaT_gettmbyobj(L, s2v(level), TM_CLOSE); 126 const TValue *tm = luaT_gettmbyobj(L, s2v(level), TM_CLOSE);
128 if (ttisnil(tm)) { /* no metamethod? */ 127 if (ttisnil(tm)) { /* no metamethod? */
129 int idx = cast_int(level - L->ci->func); /* variable index */ 128 int idx = cast_int(level - L->ci->func.p); /* variable index */
130 const char *vname = luaG_findlocal(L, L->ci, idx, NULL); 129 const char *vname = luaG_findlocal(L, L->ci, idx, NULL);
131 if (vname == NULL) vname = "?"; 130 if (vname == NULL) vname = "?";
132 luaG_runerror(L, "variable '%s' got a non-closable value", vname); 131 luaG_runerror(L, "variable '%s' got a non-closable value", vname);
@@ -160,23 +159,23 @@ static void prepcallclosemth (lua_State *L, StkId level, int status, int yy) {
160** is used.) 159** is used.)
161*/ 160*/
162#define MAXDELTA \ 161#define MAXDELTA \
163 ((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1) 162 ((256ul << ((sizeof(L->stack.p->tbclist.delta) - 1) * 8)) - 1)
164 163
165 164
166/* 165/*
167** Insert a variable in the list of to-be-closed variables. 166** Insert a variable in the list of to-be-closed variables.
168*/ 167*/
169void luaF_newtbcupval (lua_State *L, StkId level) { 168void luaF_newtbcupval (lua_State *L, StkId level) {
170 lua_assert(level > L->tbclist); 169 lua_assert(level > L->tbclist.p);
171 if (l_isfalse(s2v(level))) 170 if (l_isfalse(s2v(level)))
172 return; /* false doesn't need to be closed */ 171 return; /* false doesn't need to be closed */
173 checkclosemth(L, level); /* value must have a close method */ 172 checkclosemth(L, level); /* value must have a close method */
174 while (cast_uint(level - L->tbclist) > MAXDELTA) { 173 while (cast_uint(level - L->tbclist.p) > MAXDELTA) {
175 L->tbclist += MAXDELTA; /* create a dummy node at maximum delta */ 174 L->tbclist.p += MAXDELTA; /* create a dummy node at maximum delta */
176 L->tbclist->tbclist.delta = 0; 175 L->tbclist.p->tbclist.delta = 0;
177 } 176 }
178 level->tbclist.delta = cast(unsigned short, level - L->tbclist); 177 level->tbclist.delta = cast(unsigned short, level - L->tbclist.p);
179 L->tbclist = level; 178 L->tbclist.p = level;
180} 179}
181 180
182 181
@@ -196,10 +195,10 @@ void luaF_closeupval (lua_State *L, StkId level) {
196 StkId upl; /* stack index pointed by 'uv' */ 195 StkId upl; /* stack index pointed by 'uv' */
197 while ((uv = L->openupval) != NULL && (upl = uplevel(uv)) >= level) { 196 while ((uv = L->openupval) != NULL && (upl = uplevel(uv)) >= level) {
198 TValue *slot = &uv->u.value; /* new position for value */ 197 TValue *slot = &uv->u.value; /* new position for value */
199 lua_assert(uplevel(uv) < L->top); 198 lua_assert(uplevel(uv) < L->top.p);
200 luaF_unlinkupval(uv); /* remove upvalue from 'openupval' list */ 199 luaF_unlinkupval(uv); /* remove upvalue from 'openupval' list */
201 setobj(L, slot, uv->v); /* move value to upvalue slot */ 200 setobj(L, slot, uv->v.p); /* move value to upvalue slot */
202 uv->v = slot; /* now current value lives here */ 201 uv->v.p = slot; /* now current value lives here */
203 if (!iswhite(uv)) { /* neither white nor dead? */ 202 if (!iswhite(uv)) { /* neither white nor dead? */
204 nw2black(uv); /* closed upvalues cannot be gray */ 203 nw2black(uv); /* closed upvalues cannot be gray */
205 luaC_barrier(L, uv, slot); 204 luaC_barrier(L, uv, slot);
@@ -212,12 +211,12 @@ void luaF_closeupval (lua_State *L, StkId level) {
212** Remove first element from the tbclist plus its dummy nodes. 211** Remove first element from the tbclist plus its dummy nodes.
213*/ 212*/
214static void poptbclist (lua_State *L) { 213static void poptbclist (lua_State *L) {
215 StkId tbc = L->tbclist; 214 StkId tbc = L->tbclist.p;
216 lua_assert(tbc->tbclist.delta > 0); /* first element cannot be dummy */ 215 lua_assert(tbc->tbclist.delta > 0); /* first element cannot be dummy */
217 tbc -= tbc->tbclist.delta; 216 tbc -= tbc->tbclist.delta;
218 while (tbc > L->stack && tbc->tbclist.delta == 0) 217 while (tbc > L->stack.p && tbc->tbclist.delta == 0)
219 tbc -= MAXDELTA; /* remove dummy nodes */ 218 tbc -= MAXDELTA; /* remove dummy nodes */
220 L->tbclist = tbc; 219 L->tbclist.p = tbc;
221} 220}
222 221
223 222
@@ -228,8 +227,8 @@ static void poptbclist (lua_State *L) {
228StkId luaF_close (lua_State *L, StkId level, int status, int yy) { 227StkId luaF_close (lua_State *L, StkId level, int status, int yy) {
229 ptrdiff_t levelrel = savestack(L, level); 228 ptrdiff_t levelrel = savestack(L, level);
230 luaF_closeupval(L, level); /* first, close the upvalues */ 229 luaF_closeupval(L, level); /* first, close the upvalues */
231 while (L->tbclist >= level) { /* traverse tbc's down to that level */ 230 while (L->tbclist.p >= level) { /* traverse tbc's down to that level */
232 StkId tbc = L->tbclist; /* get variable index */ 231 StkId tbc = L->tbclist.p; /* get variable index */
233 poptbclist(L); /* remove it from list */ 232 poptbclist(L); /* remove it from list */
234 prepcallclosemth(L, tbc, status, yy); /* close variable */ 233 prepcallclosemth(L, tbc, status, yy); /* close variable */
235 level = restorestack(L, levelrel); 234 level = restorestack(L, levelrel);