MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / constfolding

Function constfolding

lib/lua/src/lcode.c:1336–1354  ·  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

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

Callers 2

luaK_prefixFunction · 0.85
luaK_posfixFunction · 0.85

Calls 3

tonumeralFunction · 0.85
validopFunction · 0.85
luaO_rawarithFunction · 0.85

Tested by

no test coverage detected