aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/lvm.c b/lvm.c
index a251f423..cfa9961b 100644
--- a/lvm.c
+++ b/lvm.c
@@ -285,13 +285,12 @@ static int floatforloop (StkId ra) {
285 285
286 286
287/* 287/*
288** Finish the table access 'val = t[key]'. 288** Finish the table access 'val = t[key]' and return the tag of the result.
289*/ 289*/
290void luaV_finishget_ (lua_State *L, const TValue *t, TValue *key, StkId val, 290int luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
291 int tag) { 291 int tag) {
292 int loop; /* counter to avoid infinite loops */ 292 int loop; /* counter to avoid infinite loops */
293 const TValue *tm; /* metamethod */ 293 const TValue *tm; /* metamethod */
294 TValue aux;
295 for (loop = 0; loop < MAXTAGLOOP; loop++) { 294 for (loop = 0; loop < MAXTAGLOOP; loop++) {
296 if (tag == LUA_VNOTABLE) { /* 't' is not a table? */ 295 if (tag == LUA_VNOTABLE) { /* 't' is not a table? */
297 lua_assert(!ttistable(t)); 296 lua_assert(!ttistable(t));
@@ -304,22 +303,22 @@ void luaV_finishget_ (lua_State *L, const TValue *t, TValue *key, StkId val,
304 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ 303 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
305 if (tm == NULL) { /* no metamethod? */ 304 if (tm == NULL) { /* no metamethod? */
306 setnilvalue(s2v(val)); /* result is nil */ 305 setnilvalue(s2v(val)); /* result is nil */
307 return; 306 return LUA_VNIL;
308 } 307 }
309 /* else will try the metamethod */ 308 /* else will try the metamethod */
310 } 309 }
311 if (ttisfunction(tm)) { /* is metamethod a function? */ 310 if (ttisfunction(tm)) { /* is metamethod a function? */
312 luaT_callTMres(L, tm, t, key, val); /* call it */ 311 luaT_callTMres(L, tm, t, key, val); /* call it */
313 return; 312 return ttypetag(s2v(val));
314 } 313 }
315 t = tm; /* else try to access 'tm[key]' */ 314 t = tm; /* else try to access 'tm[key]' */
316 luaV_fastget(t, key, s2v(val), luaH_get, aux); 315 luaV_fastget(t, key, s2v(val), luaH_get, tag);
317 if (!isemptyV(aux)) 316 if (!tagisempty(tag))
318 return; /* done */ 317 return tag; /* done */
319 /* else repeat (tail call 'luaV_finishget') */ 318 /* else repeat (tail call 'luaV_finishget') */
320 tag = ttypetagV(aux);
321 } 319 }
322 luaG_runerror(L, "'__index' chain too long; possible loop"); 320 luaG_runerror(L, "'__index' chain too long; possible loop");
321 return 0; /* to avoid warnings */
323} 322}
324 323
325 324
@@ -1247,36 +1246,36 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1247 TValue *upval = cl->upvals[GETARG_B(i)]->v.p; 1246 TValue *upval = cl->upvals[GETARG_B(i)]->v.p;
1248 TValue *rc = KC(i); 1247 TValue *rc = KC(i);
1249 TString *key = tsvalue(rc); /* key must be a short string */ 1248 TString *key = tsvalue(rc); /* key must be a short string */
1250 TValue aux; 1249 int tag;
1251 luaV_fastget(upval, key, s2v(ra), luaH_getshortstr, aux); 1250 luaV_fastget(upval, key, s2v(ra), luaH_getshortstr, tag);
1252 if (isemptyV(aux)) 1251 if (tagisempty(tag))
1253 Protect(luaV_finishget(L, upval, rc, ra, aux)); 1252 Protect(luaV_finishget(L, upval, rc, ra, tag));
1254 vmbreak; 1253 vmbreak;
1255 } 1254 }
1256 vmcase(OP_GETTABLE) { 1255 vmcase(OP_GETTABLE) {
1257 StkId ra = RA(i); 1256 StkId ra = RA(i);
1258 TValue *rb = vRB(i); 1257 TValue *rb = vRB(i);
1259 TValue *rc = vRC(i); 1258 TValue *rc = vRC(i);
1260 TValue aux; 1259 int tag;
1261 if (ttisinteger(rc)) { /* fast track for integers? */ 1260 if (ttisinteger(rc)) { /* fast track for integers? */
1262 luaV_fastgeti(rb, ivalue(rc), s2v(ra), aux); 1261 luaV_fastgeti(rb, ivalue(rc), s2v(ra), tag);
1263 } 1262 }
1264 else 1263 else
1265 luaV_fastget(rb, rc, s2v(ra), luaH_get, aux); 1264 luaV_fastget(rb, rc, s2v(ra), luaH_get, tag);
1266 if (isemptyV(aux)) /* fast track for integers? */ 1265 if (tagisempty(tag))
1267 Protect(luaV_finishget(L, rb, rc, ra, aux)); 1266 Protect(luaV_finishget(L, rb, rc, ra, tag));
1268 vmbreak; 1267 vmbreak;
1269 } 1268 }
1270 vmcase(OP_GETI) { 1269 vmcase(OP_GETI) {
1271 StkId ra = RA(i); 1270 StkId ra = RA(i);
1272 TValue *rb = vRB(i); 1271 TValue *rb = vRB(i);
1273 int c = GETARG_C(i); 1272 int c = GETARG_C(i);
1274 TValue aux; 1273 int tag;
1275 luaV_fastgeti(rb, c, s2v(ra), aux); 1274 luaV_fastgeti(rb, c, s2v(ra), tag);
1276 if (isemptyV(aux)) { 1275 if (tagisempty(tag)) {
1277 TValue key; 1276 TValue key;
1278 setivalue(&key, c); 1277 setivalue(&key, c);
1279 Protect(luaV_finishget(L, rb, &key, ra, aux)); 1278 Protect(luaV_finishget(L, rb, &key, ra, tag));
1280 } 1279 }
1281 vmbreak; 1280 vmbreak;
1282 } 1281 }
@@ -1285,10 +1284,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1285 TValue *rb = vRB(i); 1284 TValue *rb = vRB(i);
1286 TValue *rc = KC(i); 1285 TValue *rc = KC(i);
1287 TString *key = tsvalue(rc); /* key must be a short string */ 1286 TString *key = tsvalue(rc); /* key must be a short string */
1288 TValue aux; 1287 int tag;
1289 luaV_fastget(rb, key, s2v(ra), luaH_getshortstr, aux); 1288 luaV_fastget(rb, key, s2v(ra), luaH_getshortstr, tag);
1290 if (isemptyV(aux)) 1289 if (tagisempty(tag))
1291 Protect(luaV_finishget(L, rb, rc, ra, aux)); 1290 Protect(luaV_finishget(L, rb, rc, ra, tag));
1292 vmbreak; 1291 vmbreak;
1293 } 1292 }
1294 vmcase(OP_SETTABUP) { 1293 vmcase(OP_SETTABUP) {
@@ -1370,14 +1369,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1370 } 1369 }
1371 vmcase(OP_SELF) { 1370 vmcase(OP_SELF) {
1372 StkId ra = RA(i); 1371 StkId ra = RA(i);
1373 TValue aux; 1372 int tag;
1374 TValue *rb = vRB(i); 1373 TValue *rb = vRB(i);
1375 TValue *rc = RKC(i); 1374 TValue *rc = RKC(i);
1376 TString *key = tsvalue(rc); /* key must be a string */ 1375 TString *key = tsvalue(rc); /* key must be a string */
1377 setobj2s(L, ra + 1, rb); 1376 setobj2s(L, ra + 1, rb);
1378 luaV_fastget(rb, key, s2v(ra), luaH_getstr, aux); 1377 luaV_fastget(rb, key, s2v(ra), luaH_getstr, tag);
1379 if (isemptyV(aux)) 1378 if (tagisempty(tag))
1380 Protect(luaV_finishget(L, rb, rc, ra, aux)); 1379 Protect(luaV_finishget(L, rb, rc, ra, tag));
1381 vmbreak; 1380 vmbreak;
1382 } 1381 }
1383 vmcase(OP_ADDI) { 1382 vmcase(OP_ADDI) {