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 @@
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** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -33,14 +33,6 @@ · 27 unmodified lines
33#define MAXREGS 25033#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#define hasjumps(e) ((e)->t != (e)->f)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*/
372static int luaK_numberK (FuncState *fs, lua_Number r) {359static int luaK_numberK (FuncState *fs, lua_Number r) {
373 TValue o;360 TValue o;
374 lua_assert(!luai_numisnan(r) && !isminuszero(r));
375 setfltvalue(&o, r);361 setfltvalue(&o, r);
376 return addk(fs, &o, &o);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** return false if folding can raise an error747** return false if folding can raise an error
762*/748*/
763static int validop (int op, TValue *v1, TValue *v2) {749static int validop (int op, TValue *v1, TValue *v2) {
764 lua_Integer i;
765 if (luai_numinvalidop(op, nvalue(v1), nvalue(v2))) return 0;
766 switch (op) {750 switch (op) {
767 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: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 return (tointeger(v1, &i) && tointeger(v2, &i));754 return (tointeger(v1, &i) && tointeger(v2, &i));
770 case LUA_OPIDIV: case LUA_OPMOD: /* integer division by 0 */755 }
771 return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0);756 case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */
757 return (nvalue(v2) != 0);
772 default: return 1; /* everything else is valid */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 TValue v1, v2, res;767 TValue v1, v2, res;
782 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))768 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
783 return 0; /* non-numeric operands or not safe to fold */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 if (ttisinteger(&res)) {771 if (ttisinteger(&res)) {
786 e1->k = VKINT;772 e1->k = VKINT;
787 e1->u.ival = ivalue(&res);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 lua_Number n = fltvalue(&res);776 lua_Number n = fltvalue(&res);
791 if (luai_numisnan(n) || isminuszero(n))777 if (luai_numisnan(n) || n == 0)
792 return 0; /* folds neither NaN nor -0 */778 return 0;
793 e1->k = VKFLT;779 e1->k = VKFLT;
794 e1->u.nval = n;780 e1->u.nval = n;
795 }781 }