History

Lua 5.3.0-rc3

Lua Team committed 11 years ago

Commit 48416b81 parent f4a972718 files · +220 −181Browse files

Showing the changes to src/lcode.c (1 of 18 files). Show all

Unified · Split

src/lcode.c+10−24
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -33,14 +33,6 @@ · 27 unmodified lines
3333 #define MAXREGS 250
3434
3535
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−
4436 #define hasjumps(e) ((e)->t != (e)->f)
4537
4638
@@ -364,14 +356,8 @@ int luaK_intK (FuncState *fs, lua_Integer n) { · 317 unmodified lines
364356 }
365357
366358
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−*/
372359 static int luaK_numberK (FuncState *fs, lua_Number r) {
373360 TValue o;
374− lua_assert(!luai_numisnan(r) && !isminuszero(r));
375361 setfltvalue(&o, r);
376362 return addk(fs, &o, &o);
377363 }
@@ -761,14 +747,14 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { · 383 unmodified lines
761747 ** return false if folding can raise an error
762748 */
763749 static int validop (int op, TValue *v1, TValue *v2) {
764− lua_Integer i;
765− if (luai_numinvalidop(op, nvalue(v1), nvalue(v2))) return 0;
766750 switch (op) {
767751 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;
769754 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);
772758 default: return 1; /* everything else is valid */
773759 }
774760 }
@@ -781,15 +767,15 @@ static int constfolding (FuncState *fs, int op, expdesc *e1, expdesc *e2) { · 6 unmodified lines
781767 TValue v1, v2, res;
782768 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
783769 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 */
785771 if (ttisinteger(&res)) {
786772 e1->k = VKINT;
787773 e1->u.ival = ivalue(&res);
788774 }
789− else {
775+ else { /* folds neither NaN nor 0.0 (to avoid collapsing with -0.0) */
790776 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;
793779 e1->k = VKFLT;
794780 e1->u.nval = n;
795781 }