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

Function constfolding

third-party/lua-5.5.0/src/lcode.c:1418–1436  ·  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

1416** (In this case, 'e1' has the final result.)
1417*/
1418static int constfolding (FuncState *fs, int op, expdesc *e1,
1419 const expdesc *e2) {
1420 TValue v1, v2, res;
1421 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
1422 return 0; /* non-numeric operands or not safe to fold */
1423 luaO_rawarith(fs->ls->L, op, &v1, &v2, &res); /* does operation */
1424 if (ttisinteger(&res)) {
1425 e1->k = VKINT;
1426 e1->u.ival = ivalue(&res);
1427 }
1428 else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */
1429 lua_Number n = fltvalue(&res);
1430 if (luai_numisnan(n) || n == 0)
1431 return 0;
1432 e1->k = VKFLT;
1433 e1->u.nval = n;
1434 }
1435 return 1;
1436}
1437
1438
1439/*

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