MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / luaK_self

Function luaK_self

src/lcode.cpp:1463–1483  ·  view source on GitHub ↗

** Emit SELF instruction or equivalent: the code will convert ** expression 'e' into 'e.key(e,'. */

Source from the content-addressed store, hash-verified

1461** expression 'e' into 'e.key(e,'.
1462*/
1463void 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 */

Callers 3

safe_navigationFunction · 0.85
selfexpFunction · 0.85
expsuffixFunction · 0.85

Calls 5

luaK_exp2anyregFunction · 0.85
freeexpFunction · 0.85
luaK_reserveregsFunction · 0.85
luaK_exp2KFunction · 0.85
luaK_codeABCkFunction · 0.85

Tested by

no test coverage detected