MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / constfolding

Function constfolding

src/Chain/libraries/glua/lcode.cpp:767–784  ·  view source on GitHub ↗

** Try to "constant-fold" an operation; return 1 iff successful */

Source from the content-addressed store, hash-verified

765** Try to "constant-fold" an operation; return 1 iff successful
766*/
767static int constfolding(FuncState *fs, int op, expdesc *e1, expdesc *e2) {
768 TValue v1, v2, res;
769 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
770 return 0; /* non-numeric operands or not safe to fold */
771 luaO_arith(fs->ls->L, op, &v1, &v2, &res); /* does operation */
772 if (ttisinteger(&res)) {
773 e1->k = VKINT;
774 e1->u.ival = ivalue(&res);
775 }
776 else { /* folds neither NaN nor 0.0 (to avoid collapsing with -0.0) */
777 lua_Number n = fltvalue(&res);
778 if (luai_numisnan(n) || n == 0)
779 return 0;
780 e1->k = VKFLT;
781 e1->u.nval = n;
782 }
783 return 1;
784}
785
786
787/*

Callers 1

codeexpvalFunction · 0.85

Calls 3

tonumeralFunction · 0.85
validopFunction · 0.85
luaO_arithFunction · 0.85

Tested by

no test coverage detected