** Try to "constant-fold" an operation; return 1 iff successful. ** (In this case, 'e1' has the final result.) */
| 1313 | ** (In this case, 'e1' has the final result.) |
| 1314 | */ |
| 1315 | static int constfolding (FuncState *fs, int op, expdesc *e1, |
| 1316 | const expdesc *e2) { |
| 1317 | TValue v1, v2, res; |
| 1318 | if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) |
| 1319 | return 0; /* non-numeric operands or not safe to fold */ |
| 1320 | luaO_rawarith(fs->ls->L, op, &v1, &v2, &res); /* does operation */ |
| 1321 | if (ttisinteger(&res)) { |
| 1322 | e1->k = VKINT; |
| 1323 | e1->u.ival = ivalue(&res); |
| 1324 | } |
| 1325 | else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */ |
| 1326 | lua_Number n = fltvalue(&res); |
| 1327 | if (luai_numisnan(n) || n == 0) |
| 1328 | return 0; |
| 1329 | e1->k = VKFLT; |
| 1330 | e1->u.nval = n; |
| 1331 | } |
| 1332 | return 1; |
| 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | /* |
no test coverage detected