** Try to "constant-fold" an operation; return 1 iff successful. ** (In this case, 'e1' has the final result.) */
| 1416 | ** (In this case, 'e1' has the final result.) |
| 1417 | */ |
| 1418 | static int constfolding (FuncState *fs, int op, expdesc *e1, |
| 1419 | const expdesc *e2) { |
| 1420 | TValue v1, v2, res; |
| 1421 | if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) |
| 1422 | return 0; /* non-numeric operands or not safe to fold */ |
| 1423 | luaO_rawarith(fs->ls->L, op, &v1, &v2, &res); /* does operation */ |
| 1424 | if (ttisinteger(&res)) { |
| 1425 | e1->k = VKINT; |
| 1426 | e1->u.ival = ivalue(&res); |
| 1427 | } |
| 1428 | else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */ |
| 1429 | lua_Number n = fltvalue(&res); |
| 1430 | if (luai_numisnan(n) || n == 0) |
| 1431 | return 0; |
| 1432 | e1->k = VKFLT; |
| 1433 | e1->u.nval = n; |
| 1434 | } |
| 1435 | return 1; |
| 1436 | } |
| 1437 | |
| 1438 | |
| 1439 | /* |
no test coverage detected