** Try to "constant-fold" an operation; return 1 iff successful. ** (In this case, 'e1' has the final result.) */
| 976 | ** (In this case, 'e1' has the final result.) |
| 977 | */ |
| 978 | static int constfolding (FuncState *fs, int op, expdesc *e1, |
| 979 | const expdesc *e2) { |
| 980 | TValue v1, v2, res; |
| 981 | if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) |
| 982 | return 0; /* non-numeric operands or not safe to fold */ |
| 983 | luaO_arith(fs->ls->L, op, &v1, &v2, &res); /* does operation */ |
| 984 | if (ttisinteger(&res)) { |
| 985 | e1->k = VKINT; |
| 986 | e1->u.ival = ivalue(&res); |
| 987 | } |
| 988 | else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */ |
| 989 | lua_Number n = fltvalue(&res); |
| 990 | if (luai_numisnan(n) || n == 0) |
| 991 | return 0; |
| 992 | e1->k = VKFLT; |
| 993 | e1->u.nval = n; |
| 994 | } |
| 995 | return 1; |
| 996 | } |
| 997 | |
| 998 | |
| 999 | /* |
no test coverage detected