| 4302 | |
| 4303 | |
| 4304 | static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { |
| 4305 | lua_Number v1, v2, r; |
| 4306 | if (!isnumeral(e1) || !isnumeral(e2)) return 0; |
| 4307 | v1 = e1->u.nval; |
| 4308 | v2 = e2->u.nval; |
| 4309 | switch (op) { |
| 4310 | case OP_ADD: r = luai_numadd(v1, v2); break; |
| 4311 | case OP_SUB: r = luai_numsub(v1, v2); break; |
| 4312 | case OP_MUL: r = luai_nummul(v1, v2); break; |
| 4313 | case OP_DIV: |
| 4314 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ |
| 4315 | r = luai_numdiv(v1, v2); break; |
| 4316 | case OP_MOD: |
| 4317 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ |
| 4318 | r = luai_nummod(v1, v2); break; |
| 4319 | case OP_POW: r = luai_numpow(v1, v2); break; |
| 4320 | case OP_UNM: r = luai_numunm(v1); break; |
| 4321 | case OP_LEN: return 0; /* no constant folding for 'len' */ |
| 4322 | default: lua_assert(0); r = 0; break; |
| 4323 | } |
| 4324 | if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ |
| 4325 | e1->u.nval = r; |
| 4326 | return 1; |
| 4327 | } |
| 4328 | |
| 4329 | |
| 4330 | static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { |