Showing the changes to src/lcode.c (1 of 18 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.c,v 2.98 2014/12/19 13:36:32 roberto Exp $ | |
| 2 | +** $Id: lcode.c,v 2.99 2014/12/29 16:49:25 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -33,14 +33,6 @@ · 27 unmodified lines | ||
| 33 | 33 | #define MAXREGS 250 |
| 34 | 34 | |
| 35 | 35 | |
| 36 | −/* test for x == -0 ('signbit' needs 'math.h') */ | |
| 37 | −#if defined(signbit) | |
| 38 | −#define isminuszero(x) ((x) == 0.0 && signbit(x)) | |
| 39 | −#else | |
| 40 | −#define isminuszero(x) ((x) == 0.0 && 1.0/(x) < 0.0) | |
| 41 | −#endif | |
| 42 | − | |
| 43 | − | |
| 44 | 36 | #define hasjumps(e) ((e)->t != (e)->f) |
| 45 | 37 | |
| 46 | 38 | |
| @@ -364,14 +356,8 @@ int luaK_intK (FuncState *fs, lua_Integer n) { · 317 unmodified lines | ||
| 364 | 356 | } |
| 365 | 357 | |
| 366 | 358 | |
| 367 | −/* | |
| 368 | −** Both NaN and -0.0 should not go to the constant table, as they have | |
| 369 | −** problems with the hashing. (NaN is not a valid key, -0.0 collides | |
| 370 | −** with +0.0.) | |
| 371 | −*/ | |
| 372 | 359 | static int luaK_numberK (FuncState *fs, lua_Number r) { |
| 373 | 360 | TValue o; |
| 374 | − lua_assert(!luai_numisnan(r) && !isminuszero(r)); | |
| 375 | 361 | setfltvalue(&o, r); |
| 376 | 362 | return addk(fs, &o, &o); |
| 377 | 363 | } |
| @@ -761,14 +747,14 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { · 383 unmodified lines | ||
| 761 | 747 | ** return false if folding can raise an error |
| 762 | 748 | */ |
| 763 | 749 | static int validop (int op, TValue *v1, TValue *v2) { |
| 764 | − lua_Integer i; | |
| 765 | − if (luai_numinvalidop(op, nvalue(v1), nvalue(v2))) return 0; | |
| 766 | 750 | switch (op) { |
| 767 | 751 | case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: |
| 768 | − case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: /* conversion errors */ | |
| 752 | + case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: { /* conversion errors */ | |
| 753 | + lua_Integer i; | |
| 769 | 754 | return (tointeger(v1, &i) && tointeger(v2, &i)); |
| 770 | − case LUA_OPIDIV: case LUA_OPMOD: /* integer division by 0 */ | |
| 771 | − return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0); | |
| 755 | + } | |
| 756 | + case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */ | |
| 757 | + return (nvalue(v2) != 0); | |
| 772 | 758 | default: return 1; /* everything else is valid */ |
| 773 | 759 | } |
| 774 | 760 | } |
| @@ -781,15 +767,15 @@ static int constfolding (FuncState *fs, int op, expdesc *e1, expdesc *e2) { · 6 unmodified lines | ||
| 781 | 767 | TValue v1, v2, res; |
| 782 | 768 | if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) |
| 783 | 769 | return 0; /* non-numeric operands or not safe to fold */ |
| 784 | − luaO_arith(fs->ls->L, op, &v1, &v2, &res); | |
| 770 | + luaO_arith(fs->ls->L, op, &v1, &v2, &res); /* does operation */ | |
| 785 | 771 | if (ttisinteger(&res)) { |
| 786 | 772 | e1->k = VKINT; |
| 787 | 773 | e1->u.ival = ivalue(&res); |
| 788 | 774 | } |
| 789 | − else { | |
| 775 | + else { /* folds neither NaN nor 0.0 (to avoid collapsing with -0.0) */ | |
| 790 | 776 | lua_Number n = fltvalue(&res); |
| 791 | − if (luai_numisnan(n) || isminuszero(n)) | |
| 792 | − return 0; /* folds neither NaN nor -0 */ | |
| 777 | + if (luai_numisnan(n) || n == 0) | |
| 778 | + return 0; | |
| 793 | 779 | e1->k = VKFLT; |
| 794 | 780 | e1->u.nval = n; |
| 795 | 781 | } |