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