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

Function codeeq

src/lcode.cpp:1808–1849  ·  view source on GitHub ↗

** Emit code for equality comparisons ('==', '~='). ** 'e1' was already put as RK by 'luaK_infix'. */

Source from the content-addressed store, hash-verified

1806** 'e1' was already put as RK by 'luaK_infix'.
1807*/
1808static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1809 int r1, r2;
1810 int im;
1811 int isfloat = 0; /* not needed here, but kept for symmetry */
1812 OpCode op;
1813 if (e1->k != VNONRELOC && e1->k != VSAFECALL) {
1814 lua_assert(vkisconst(e1->k) && !hasjumps(e1));
1815 swapexps(e1, e2);
1816 }
1817 if (vkisconst(e1->k) && vkisconst(e2->k) && !hasjumps(e1) && !hasjumps(e2)
1818 && (e1->k != VKINT || e2->k != VKFLT) && (e1->k != VKFLT || e2->k != VKINT) /* don't optimize comparisons between VKINT and VKFLT */
1819 ) {
1820 bool eq = false;
1821 if (e1->k == e2->k) {
1822 switch (e1->k) {
1823 default: eq = true; break;
1824 case VKFLT: eq = (e1->u.nval == e2->u.nval); break;
1825 case VKINT: eq = (e1->u.ival == e2->u.ival); break;
1826 case VKSTR: eq = (e1->u.strval == e2->u.strval); break;
1827 case VCONST: eq = (e1->u.info == e2->u.info); break;
1828 }
1829 }
1830 e1->k = ((eq ^ (opr != OPR_EQ)) ? VTRUE : VFALSE);
1831 return;
1832 }
1833 r1 = luaK_exp2anyreg(fs, e1); /* 1st expression must be in register */
1834 if (isSCnumber(e2, &im, &isfloat)) {
1835 op = OP_EQI;
1836 r2 = im; /* immediate operand */
1837 }
1838 else if (exp2RK(fs, e2)) { /* 2nd expression is constant? */
1839 op = OP_EQK;
1840 r2 = e2->u.info; /* constant index */
1841 }
1842 else {
1843 op = OP_EQ; /* will compare two registers */
1844 r2 = luaK_exp2anyreg(fs, e2);
1845 }
1846 freeexps(fs, e1, e2);
1847 e1->u.pc = condjump(fs, op, r1, r2, isfloat, (opr == OPR_EQ));
1848 e1->k = VJMP;
1849}
1850
1851
1852/*

Callers 1

luaK_posfixFunction · 0.85

Calls 7

vkisconstFunction · 0.85
swapexpsFunction · 0.85
luaK_exp2anyregFunction · 0.85
isSCnumberFunction · 0.85
exp2RKFunction · 0.85
freeexpsFunction · 0.85
condjumpFunction · 0.85

Tested by

no test coverage detected