** Emit SELF instruction or equivalent: the code will convert ** expression 'e' into 'e.key(e,'. */
| 1461 | ** expression 'e' into 'e.key(e,'. |
| 1462 | */ |
| 1463 | void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { |
| 1464 | int ereg, base; |
| 1465 | luaK_exp2anyreg(fs, e); |
| 1466 | ereg = e->u.info; /* register where 'e' (the receiver) was placed */ |
| 1467 | freeexp(fs, e); |
| 1468 | base = e->u.info = fs->freereg; /* base register for op_self */ |
| 1469 | e->k = VNONRELOC; /* self expression has a fixed register */ |
| 1470 | luaK_reserveregs(fs, 2); /* method and 'self' produced by op_self */ |
| 1471 | lua_assert(key->k == VKSTR); |
| 1472 | /* is method name a short string in a valid K index? */ |
| 1473 | if (strisshr(key->u.strval) && luaK_exp2K(fs, key)) { |
| 1474 | /* can use 'self' opcode */ |
| 1475 | luaK_codeABCk(fs, OP_SELF, base, ereg, key->u.info, 1); |
| 1476 | } |
| 1477 | else { /* cannot use 'self' opcode; use move+gettable */ |
| 1478 | luaK_exp2anyreg(fs, key); /* put method name in a register */ |
| 1479 | luaK_codeABC(fs, OP_MOVE, base + 1, ereg, 0); /* copy self to base+1 */ |
| 1480 | luaK_codeABCk(fs, OP_GETTABLE, base, ereg, key->u.info, 1); /* get method */ |
| 1481 | } |
| 1482 | freeexp(fs, key); |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | /* auxiliary function to define indexing expressions */ |
no test coverage detected