MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / constfolding

Function constfolding

libraries/AP_Scripting/lua/src/lcode.c:985–1003  ·  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

983** (In this case, 'e1' has the final result.)
984*/
985static int constfolding (FuncState *fs, int op, expdesc *e1,
986 const expdesc *e2) {
987 TValue v1, v2, res;
988 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
989 return 0; /* non-numeric operands or not safe to fold */
990 luaO_arith(fs->ls->L, op, &v1, &v2, &res); /* does operation */
991 if (ttisinteger(&res)) {
992 e1->k = VKINT;
993 e1->u.ival = ivalue(&res);
994 }
995 else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */
996 lua_Number n = fltvalue(&res);
997 if (luai_numisnan(n) || n == 0)
998 return 0;
999 e1->k = VKFLT;
1000 e1->u.nval = n;
1001 }
1002 return 1;
1003}
1004
1005
1006/*

Callers 2

luaK_prefixFunction · 0.85
luaK_posfixFunction · 0.85

Calls 3

tonumeralFunction · 0.85
validopFunction · 0.85
luaO_arithFunction · 0.85

Tested by

no test coverage detected