** Create expression 't[k]'. 't' must have its final result already in a ** register or upvalue. Upvalues can only be indexed by literal strings. ** Keys can be literal strings in the constant table or arbitrary ** values in registers. */
| 1355 | ** values in registers. |
| 1356 | */ |
| 1357 | void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { |
| 1358 | int keystr = -1; |
| 1359 | if (k->k == VKSTR) |
| 1360 | keystr = str2K(fs, k); |
| 1361 | lua_assert(!hasjumps(t) && |
| 1362 | (t->k == VLOCAL || t->k == VVARGVAR || |
| 1363 | t->k == VNONRELOC || t->k == VUPVAL)); |
| 1364 | if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */ |
| 1365 | luaK_exp2anyreg(fs, t); /* put it in a register */ |
| 1366 | if (t->k == VUPVAL) { |
| 1367 | lu_byte temp = cast_byte(t->u.info); /* upvalue index */ |
| 1368 | t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */ |
| 1369 | lua_assert(isKstr(fs, k)); |
| 1370 | fillidxk(t, k->u.info, VINDEXUP); /* literal short string */ |
| 1371 | } |
| 1372 | else if (t->k == VVARGVAR) { /* indexing the vararg parameter? */ |
| 1373 | int kreg = luaK_exp2anyreg(fs, k); /* put key in some register */ |
| 1374 | lu_byte vreg = cast_byte(t->u.var.ridx); /* register with vararg param. */ |
| 1375 | lua_assert(vreg == fs->f->numparams); |
| 1376 | t->u.ind.t = vreg; /* (avoid a direct assignment; values may overlap) */ |
| 1377 | fillidxk(t, kreg, VVARGIND); /* 't' represents 'vararg[k]' */ |
| 1378 | } |
| 1379 | else { |
| 1380 | /* register index of the table */ |
| 1381 | t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info); |
| 1382 | if (isKstr(fs, k)) |
| 1383 | fillidxk(t, k->u.info, VINDEXSTR); /* literal short string */ |
| 1384 | else if (isCint(k)) /* int. constant in proper range? */ |
| 1385 | fillidxk(t, cast_int(k->u.ival), VINDEXI); |
| 1386 | else |
| 1387 | fillidxk(t, luaK_exp2anyreg(fs, k), VINDEXED); /* register */ |
| 1388 | } |
| 1389 | t->u.ind.keystr = keystr; /* string index in 'k' */ |
| 1390 | t->u.ind.ro = 0; /* by default, not read-only */ |
| 1391 | } |
| 1392 | |
| 1393 | |
| 1394 | /* |
no test coverage detected