diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 112 |
1 files changed, 53 insertions, 59 deletions
@@ -281,15 +281,13 @@ static int floatforloop (StkId ra) { | |||
281 | 281 | ||
282 | /* | 282 | /* |
283 | ** Finish the table access 'val = t[key]'. | 283 | ** Finish the table access 'val = t[key]'. |
284 | ** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to | ||
285 | ** t[k] entry (which must be empty). | ||
286 | */ | 284 | */ |
287 | void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, StkId val, | 285 | void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, |
288 | int aux) { | 286 | int hres) { |
289 | int loop; /* counter to avoid infinite loops */ | 287 | int loop; /* counter to avoid infinite loops */ |
290 | const TValue *tm; /* metamethod */ | 288 | const TValue *tm; /* metamethod */ |
291 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 289 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
292 | if (aux == HNOTATABLE) { /* 't' is not a table? */ | 290 | if (hres == HNOTATABLE) { /* 't' is not a table? */ |
293 | lua_assert(!ttistable(t)); | 291 | lua_assert(!ttistable(t)); |
294 | tm = luaT_gettmbyobj(L, t, TM_INDEX); | 292 | tm = luaT_gettmbyobj(L, t, TM_INDEX); |
295 | if (l_unlikely(notm(tm))) | 293 | if (l_unlikely(notm(tm))) |
@@ -309,8 +307,8 @@ void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
309 | return; | 307 | return; |
310 | } | 308 | } |
311 | t = tm; /* else try to access 'tm[key]' */ | 309 | t = tm; /* else try to access 'tm[key]' */ |
312 | luaV_fastget1(t, key, s2v(val), luaH_get1, aux); | 310 | luaV_fastget(t, key, s2v(val), luaH_get, hres); |
313 | if (aux == HOK) | 311 | if (hres == HOK) |
314 | return; /* done */ | 312 | return; /* done */ |
315 | /* else repeat (tail call 'luaV_finishget') */ | 313 | /* else repeat (tail call 'luaV_finishget') */ |
316 | } | 314 | } |
@@ -320,21 +318,17 @@ void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
320 | 318 | ||
321 | /* | 319 | /* |
322 | ** Finish a table assignment 't[key] = val'. | 320 | ** Finish a table assignment 't[key] = val'. |
323 | ** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points | ||
324 | ** to the entry 't[key]', or to a value with an absent key if there | ||
325 | ** is no such entry. (The value at 'slot' must be empty, otherwise | ||
326 | ** 'luaV_fastget' would have done the job.) | ||
327 | */ | 321 | */ |
328 | void luaV_finishset1 (lua_State *L, const TValue *t, TValue *key, | 322 | void luaV_finishset (lua_State *L, const TValue *t, TValue *key, |
329 | TValue *val, int aux) { | 323 | TValue *val, int hres) { |
330 | int loop; /* counter to avoid infinite loops */ | 324 | int loop; /* counter to avoid infinite loops */ |
331 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 325 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
332 | const TValue *tm; /* '__newindex' metamethod */ | 326 | const TValue *tm; /* '__newindex' metamethod */ |
333 | if (aux != HNOTATABLE) { /* is 't' a table? */ | 327 | if (hres != HNOTATABLE) { /* is 't' a table? */ |
334 | Table *h = hvalue(t); /* save 't' table */ | 328 | Table *h = hvalue(t); /* save 't' table */ |
335 | tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */ | 329 | tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */ |
336 | if (tm == NULL) { /* no metamethod? */ | 330 | if (tm == NULL) { /* no metamethod? */ |
337 | luaH_finishset1(L, h, key, val, aux); /* set new value */ | 331 | luaH_finishset(L, h, key, val, hres); /* set new value */ |
338 | invalidateTMcache(h); | 332 | invalidateTMcache(h); |
339 | luaC_barrierback(L, obj2gco(h), val); | 333 | luaC_barrierback(L, obj2gco(h), val); |
340 | return; | 334 | return; |
@@ -352,8 +346,8 @@ void luaV_finishset1 (lua_State *L, const TValue *t, TValue *key, | |||
352 | return; | 346 | return; |
353 | } | 347 | } |
354 | t = tm; /* else repeat assignment over 'tm' */ | 348 | t = tm; /* else repeat assignment over 'tm' */ |
355 | luaV_fastset1(t, key, val, aux, luaH_set1); | 349 | luaV_fastset(t, key, val, hres, luaH_pset); |
356 | if (aux == HOK) | 350 | if (hres == HOK) |
357 | return; /* done */ | 351 | return; /* done */ |
358 | /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */ | 352 | /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */ |
359 | } | 353 | } |
@@ -1249,36 +1243,36 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1249 | TValue *upval = cl->upvals[GETARG_B(i)]->v.p; | 1243 | TValue *upval = cl->upvals[GETARG_B(i)]->v.p; |
1250 | TValue *rc = KC(i); | 1244 | TValue *rc = KC(i); |
1251 | TString *key = tsvalue(rc); /* key must be a string */ | 1245 | TString *key = tsvalue(rc); /* key must be a string */ |
1252 | int aux; | 1246 | int hres; |
1253 | luaV_fastget1(upval, key, s2v(ra), luaH_getshortstr1, aux); | 1247 | luaV_fastget(upval, key, s2v(ra), luaH_getshortstr, hres); |
1254 | if (aux != HOK) | 1248 | if (hres != HOK) |
1255 | Protect(luaV_finishget1(L, upval, rc, ra, aux)); | 1249 | Protect(luaV_finishget(L, upval, rc, ra, hres)); |
1256 | vmbreak; | 1250 | vmbreak; |
1257 | } | 1251 | } |
1258 | vmcase(OP_GETTABLE) { | 1252 | vmcase(OP_GETTABLE) { |
1259 | StkId ra = RA(i); | 1253 | StkId ra = RA(i); |
1260 | TValue *rb = vRB(i); | 1254 | TValue *rb = vRB(i); |
1261 | TValue *rc = vRC(i); | 1255 | TValue *rc = vRC(i); |
1262 | int aux; | 1256 | int hres; |
1263 | if (ttisinteger(rc)) { /* fast track for integers? */ | 1257 | if (ttisinteger(rc)) { /* fast track for integers? */ |
1264 | luaV_fastgeti1(rb, ivalue(rc), s2v(ra), aux); | 1258 | luaV_fastgeti(rb, ivalue(rc), s2v(ra), hres); |
1265 | } | 1259 | } |
1266 | else | 1260 | else |
1267 | luaV_fastget1(rb, rc, s2v(ra), luaH_get1, aux); | 1261 | luaV_fastget(rb, rc, s2v(ra), luaH_get, hres); |
1268 | if (aux != HOK) /* fast track for integers? */ | 1262 | if (hres != HOK) /* fast track for integers? */ |
1269 | Protect(luaV_finishget1(L, rb, rc, ra, aux)); | 1263 | Protect(luaV_finishget(L, rb, rc, ra, hres)); |
1270 | vmbreak; | 1264 | vmbreak; |
1271 | } | 1265 | } |
1272 | vmcase(OP_GETI) { | 1266 | vmcase(OP_GETI) { |
1273 | StkId ra = RA(i); | 1267 | StkId ra = RA(i); |
1274 | TValue *rb = vRB(i); | 1268 | TValue *rb = vRB(i); |
1275 | int c = GETARG_C(i); | 1269 | int c = GETARG_C(i); |
1276 | int aux; | 1270 | int hres; |
1277 | luaV_fastgeti1(rb, c, s2v(ra), aux); | 1271 | luaV_fastgeti(rb, c, s2v(ra), hres); |
1278 | if (aux != HOK) { | 1272 | if (hres != HOK) { |
1279 | TValue key; | 1273 | TValue key; |
1280 | setivalue(&key, c); | 1274 | setivalue(&key, c); |
1281 | Protect(luaV_finishget1(L, rb, &key, ra, aux)); | 1275 | Protect(luaV_finishget(L, rb, &key, ra, hres)); |
1282 | } | 1276 | } |
1283 | vmbreak; | 1277 | vmbreak; |
1284 | } | 1278 | } |
@@ -1287,68 +1281,68 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1287 | TValue *rb = vRB(i); | 1281 | TValue *rb = vRB(i); |
1288 | TValue *rc = KC(i); | 1282 | TValue *rc = KC(i); |
1289 | TString *key = tsvalue(rc); /* key must be a string */ | 1283 | TString *key = tsvalue(rc); /* key must be a string */ |
1290 | int aux; | 1284 | int hres; |
1291 | luaV_fastget1(rb, key, s2v(ra), luaH_getshortstr1, aux); | 1285 | luaV_fastget(rb, key, s2v(ra), luaH_getshortstr, hres); |
1292 | if (aux != HOK) | 1286 | if (hres != HOK) |
1293 | Protect(luaV_finishget1(L, rb, rc, ra, aux)); | 1287 | Protect(luaV_finishget(L, rb, rc, ra, hres)); |
1294 | vmbreak; | 1288 | vmbreak; |
1295 | } | 1289 | } |
1296 | vmcase(OP_SETTABUP) { | 1290 | vmcase(OP_SETTABUP) { |
1297 | int aux; | 1291 | int hres; |
1298 | TValue *upval = cl->upvals[GETARG_A(i)]->v.p; | 1292 | TValue *upval = cl->upvals[GETARG_A(i)]->v.p; |
1299 | TValue *rb = KB(i); | 1293 | TValue *rb = KB(i); |
1300 | TValue *rc = RKC(i); | 1294 | TValue *rc = RKC(i); |
1301 | TString *key = tsvalue(rb); /* key must be a string */ | 1295 | TString *key = tsvalue(rb); /* key must be a string */ |
1302 | luaV_fastset1(upval, key, rc, aux, luaH_setshortstr1); | 1296 | luaV_fastset(upval, key, rc, hres, luaH_psetshortstr); |
1303 | if (aux == HOK) | 1297 | if (hres == HOK) |
1304 | luaV_finishfastset1(L, upval, rc); | 1298 | luaV_finishfastset(L, upval, rc); |
1305 | else | 1299 | else |
1306 | Protect(luaV_finishset1(L, upval, rb, rc, aux)); | 1300 | Protect(luaV_finishset(L, upval, rb, rc, hres)); |
1307 | vmbreak; | 1301 | vmbreak; |
1308 | } | 1302 | } |
1309 | vmcase(OP_SETTABLE) { | 1303 | vmcase(OP_SETTABLE) { |
1310 | StkId ra = RA(i); | 1304 | StkId ra = RA(i); |
1311 | int aux; | 1305 | int hres; |
1312 | TValue *rb = vRB(i); /* key (table is in 'ra') */ | 1306 | TValue *rb = vRB(i); /* key (table is in 'ra') */ |
1313 | TValue *rc = RKC(i); /* value */ | 1307 | TValue *rc = RKC(i); /* value */ |
1314 | if (ttisinteger(rb)) { /* fast track for integers? */ | 1308 | if (ttisinteger(rb)) { /* fast track for integers? */ |
1315 | luaV_fastseti1(s2v(ra), ivalue(rb), rc, aux); | 1309 | luaV_fastseti(s2v(ra), ivalue(rb), rc, hres); |
1316 | } | 1310 | } |
1317 | else { | 1311 | else { |
1318 | luaV_fastset1(s2v(ra), rb, rc, aux, luaH_set1); | 1312 | luaV_fastset(s2v(ra), rb, rc, hres, luaH_pset); |
1319 | } | 1313 | } |
1320 | if (aux == HOK) | 1314 | if (hres == HOK) |
1321 | luaV_finishfastset1(L, s2v(ra), rc); | 1315 | luaV_finishfastset(L, s2v(ra), rc); |
1322 | else | 1316 | else |
1323 | Protect(luaV_finishset1(L, s2v(ra), rb, rc, aux)); | 1317 | Protect(luaV_finishset(L, s2v(ra), rb, rc, hres)); |
1324 | vmbreak; | 1318 | vmbreak; |
1325 | } | 1319 | } |
1326 | vmcase(OP_SETI) { | 1320 | vmcase(OP_SETI) { |
1327 | StkId ra = RA(i); | 1321 | StkId ra = RA(i); |
1328 | int aux; | 1322 | int hres; |
1329 | int b = GETARG_B(i); | 1323 | int b = GETARG_B(i); |
1330 | TValue *rc = RKC(i); | 1324 | TValue *rc = RKC(i); |
1331 | luaV_fastseti1(s2v(ra), b, rc, aux); | 1325 | luaV_fastseti(s2v(ra), b, rc, hres); |
1332 | if (aux == HOK) | 1326 | if (hres == HOK) |
1333 | luaV_finishfastset1(L, s2v(ra), rc); | 1327 | luaV_finishfastset(L, s2v(ra), rc); |
1334 | else { | 1328 | else { |
1335 | TValue key; | 1329 | TValue key; |
1336 | setivalue(&key, b); | 1330 | setivalue(&key, b); |
1337 | Protect(luaV_finishset1(L, s2v(ra), &key, rc, aux)); | 1331 | Protect(luaV_finishset(L, s2v(ra), &key, rc, hres)); |
1338 | } | 1332 | } |
1339 | vmbreak; | 1333 | vmbreak; |
1340 | } | 1334 | } |
1341 | vmcase(OP_SETFIELD) { | 1335 | vmcase(OP_SETFIELD) { |
1342 | StkId ra = RA(i); | 1336 | StkId ra = RA(i); |
1343 | int aux; | 1337 | int hres; |
1344 | TValue *rb = KB(i); | 1338 | TValue *rb = KB(i); |
1345 | TValue *rc = RKC(i); | 1339 | TValue *rc = RKC(i); |
1346 | TString *key = tsvalue(rb); /* key must be a string */ | 1340 | TString *key = tsvalue(rb); /* key must be a string */ |
1347 | luaV_fastset1(s2v(ra), key, rc, aux, luaH_setshortstr1); | 1341 | luaV_fastset(s2v(ra), key, rc, hres, luaH_psetshortstr); |
1348 | if (aux == HOK) | 1342 | if (hres == HOK) |
1349 | luaV_finishfastset1(L, s2v(ra), rc); | 1343 | luaV_finishfastset(L, s2v(ra), rc); |
1350 | else | 1344 | else |
1351 | Protect(luaV_finishset1(L, s2v(ra), rb, rc, aux)); | 1345 | Protect(luaV_finishset(L, s2v(ra), rb, rc, hres)); |
1352 | vmbreak; | 1346 | vmbreak; |
1353 | } | 1347 | } |
1354 | vmcase(OP_NEWTABLE) { | 1348 | vmcase(OP_NEWTABLE) { |
@@ -1372,14 +1366,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1372 | } | 1366 | } |
1373 | vmcase(OP_SELF) { | 1367 | vmcase(OP_SELF) { |
1374 | StkId ra = RA(i); | 1368 | StkId ra = RA(i); |
1375 | int aux; | 1369 | int hres; |
1376 | TValue *rb = vRB(i); | 1370 | TValue *rb = vRB(i); |
1377 | TValue *rc = RKC(i); | 1371 | TValue *rc = RKC(i); |
1378 | TString *key = tsvalue(rc); /* key must be a string */ | 1372 | TString *key = tsvalue(rc); /* key must be a string */ |
1379 | setobj2s(L, ra + 1, rb); | 1373 | setobj2s(L, ra + 1, rb); |
1380 | luaV_fastget1(rb, key, s2v(ra), luaH_getstr1, aux); | 1374 | luaV_fastget(rb, key, s2v(ra), luaH_getstr, hres); |
1381 | if (aux != HOK) | 1375 | if (hres != HOK) |
1382 | Protect(luaV_finishget1(L, rb, rc, ra, aux)); | 1376 | Protect(luaV_finishget(L, rb, rc, ra, hres)); |
1383 | vmbreak; | 1377 | vmbreak; |
1384 | } | 1378 | } |
1385 | vmcase(OP_ADDI) { | 1379 | vmcase(OP_ADDI) { |