MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / constfolding

Function constfolding

third-party/lua-5.4.6/src/lcode.c:1337–1355  ·  view source on GitHub ↗

** Try to "constant-fold" an operation; return 1 iff successful. ** (In this case, 'e1' has the final result.) */

Source from the content-addressed store, hash-verified

1335** (In this case, 'e1' has the final result.)
1336*/
1337static int constfolding (FuncState *fs, int op, expdesc *e1,
1338 const expdesc *e2) {
1339 TValue v1, v2, res;
1340 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
1341 return 0; /* non-numeric operands or not safe to fold */
1342 luaO_rawarith(fs->ls->L, op, &v1, &v2, &res); /* does operation */
1343 if (ttisinteger(&res)) {
1344 e1->k = VKINT;
1345 e1->u.ival = ivalue(&res);
1346 }
1347 else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */
1348 lua_Number n = fltvalue(&res);
1349 if (luai_numisnan(n) || n == 0)
1350 return 0;
1351 e1->k = VKFLT;
1352 e1->u.nval = n;
1353 }
1354 return 1;
1355}
1356
1357
1358/*

Callers 2

luaK_prefixFunction · 0.70
luaK_posfixFunction · 0.70

Calls 3

tonumeralFunction · 0.70
validopFunction · 0.70
luaO_rawarithFunction · 0.70

Tested by

no test coverage detected