MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / constfolding

Function constfolding

Source/Misc/lua/src/lua.c:4304–4327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4302
4303
4304static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
4305lua_Number v1, v2, r;
4306if (!isnumeral(e1) || !isnumeral(e2)) return 0;
4307v1 = e1->u.nval;
4308v2 = e2->u.nval;
4309switch (op) {
4310case OP_ADD: r = luai_numadd(v1, v2); break;
4311case OP_SUB: r = luai_numsub(v1, v2); break;
4312case OP_MUL: r = luai_nummul(v1, v2); break;
4313case OP_DIV:
4314if (v2 == 0) return 0; /* do not attempt to divide by 0 */
4315r = luai_numdiv(v1, v2); break;
4316case OP_MOD:
4317if (v2 == 0) return 0; /* do not attempt to divide by 0 */
4318r = luai_nummod(v1, v2); break;
4319case OP_POW: r = luai_numpow(v1, v2); break;
4320case OP_UNM: r = luai_numunm(v1); break;
4321case OP_LEN: return 0; /* no constant folding for 'len' */
4322default: lua_assert(0); r = 0; break;
4323}
4324if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */
4325e1->u.nval = r;
4326return 1;
4327}
4328
4329
4330static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {

Callers 1

codearithFunction · 0.85

Calls 1

isnumeralFunction · 0.85

Tested by

no test coverage detected