MCPcopy Create free account
hub / github.com/BigPig0/RelayLive / constfolding

Function constfolding

ThirdParty/lua/lua/lcode.c:766–783  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

codeexpvalFunction · 0.85

Calls 3

tonumeralFunction · 0.85
validopFunction · 0.85
luaO_arithFunction · 0.85

Tested by

no test coverage detected