** Return false if folding can raise an error. ** Bitwise operations need operands convertible to integers; division ** operations cannot have 0 as divisor. */
| 956 | ** operations cannot have 0 as divisor. |
| 957 | */ |
| 958 | static int validop (int op, TValue *v1, TValue *v2) { |
| 959 | switch (op) { |
| 960 | case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: |
| 961 | case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: { /* conversion errors */ |
| 962 | lua_Integer i; |
| 963 | return (tointeger(v1, &i) && tointeger(v2, &i)); |
| 964 | } |
| 965 | case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */ |
| 966 | return (nvalue(v2) != 0); |
| 967 | default: return 1; /* everything else is valid */ |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | |
| 972 | /* |