aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-21 10:15:57 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-21 10:15:57 -0200
commit5fbd40dbe5d6d3f7bd4717073eb2beacc8ebe7c9 (patch)
tree20b9b2cb5fe46d59dc97193429436d5110f23f8f
parent049cf14cf9f82a07387df4d0c9bdba5ba2fef22f (diff)
downloadlua-5fbd40dbe5d6d3f7bd4717073eb2beacc8ebe7c9.tar.gz
lua-5fbd40dbe5d6d3f7bd4717073eb2beacc8ebe7c9.tar.bz2
lua-5fbd40dbe5d6d3f7bd4717073eb2beacc8ebe7c9.zip
'x//y' extended to floats
-rw-r--r--lcode.c6
-rw-r--r--lobject.c9
-rw-r--r--ltm.c6
3 files changed, 10 insertions, 11 deletions
diff --git a/lcode.c b/lcode.c
index acf637c9..f2d876fe 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.94 2014/10/30 18:53:28 roberto Exp roberto $ 2** $Id: lcode.c,v 2.95 2014/11/02 19:19:04 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -768,12 +768,10 @@ static int validop (int op, TValue *v1, TValue *v2) {
768 (cast_void(tonumber(v2, &b)), b))) 768 (cast_void(tonumber(v2, &b)), b)))
769 return 0; 769 return 0;
770 switch (op) { 770 switch (op) {
771 case LUA_OPIDIV: /* division by 0 and conversion errors */
772 return (tointeger(v1, &i) && tointeger(v2, &i) && i != 0);
773 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: 771 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
774 case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: /* conversion errors */ 772 case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: /* conversion errors */
775 return (tointeger(v1, &i) && tointeger(v2, &i)); 773 return (tointeger(v1, &i) && tointeger(v2, &i));
776 case LUA_OPMOD: /* integer module by 0 */ 774 case LUA_OPIDIV: case LUA_OPMOD: /* integer division by 0 */
777 return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0); 775 return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0);
778 default: return 1; /* everything else is valid */ 776 default: return 1; /* everything else is valid */
779 } 777 }
diff --git a/lobject.c b/lobject.c
index 39a77fe0..8f9f8465 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.98 2014/11/02 19:19:04 roberto Exp roberto $ 2** $Id: lobject.c,v 2.99 2014/11/04 19:16:25 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -101,6 +101,7 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1,
101 case LUA_OPMUL: return luai_nummul(L, v1, v2); 101 case LUA_OPMUL: return luai_nummul(L, v1, v2);
102 case LUA_OPDIV: return luai_numdiv(L, v1, v2); 102 case LUA_OPDIV: return luai_numdiv(L, v1, v2);
103 case LUA_OPPOW: return luai_numpow(L, v1, v2); 103 case LUA_OPPOW: return luai_numpow(L, v1, v2);
104 case LUA_OPIDIV: return luai_numidiv(L, v1, v2);
104 case LUA_OPUNM: return luai_numunm(L, v1); 105 case LUA_OPUNM: return luai_numunm(L, v1);
105 case LUA_OPMOD: { 106 case LUA_OPMOD: {
106 lua_Number m; 107 lua_Number m;
@@ -115,9 +116,9 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1,
115void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, 116void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
116 TValue *res) { 117 TValue *res) {
117 switch (op) { 118 switch (op) {
118 case LUA_OPIDIV: case LUA_OPBAND: case LUA_OPBOR: 119 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
119 case LUA_OPBXOR: case LUA_OPSHL: case LUA_OPSHR: 120 case LUA_OPSHL: case LUA_OPSHR:
120 case LUA_OPBNOT: { /* operates only on integers */ 121 case LUA_OPBNOT: { /* operate only on integers */
121 lua_Integer i1; lua_Integer i2; 122 lua_Integer i1; lua_Integer i2;
122 if (tointeger(p1, &i1) && tointeger(p2, &i2)) { 123 if (tointeger(p1, &i1) && tointeger(p2, &i2)) {
123 setivalue(res, intarith(L, op, i1, i2)); 124 setivalue(res, intarith(L, op, i1, i2));
diff --git a/ltm.c b/ltm.c
index 78d98dfc..5f1ba58d 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.31 2014/11/10 14:46:05 roberto Exp roberto $ 2** $Id: ltm.c,v 2.32 2014/11/10 17:24:43 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -117,12 +117,12 @@ void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
117 switch (event) { 117 switch (event) {
118 case TM_CONCAT: 118 case TM_CONCAT:
119 luaG_concaterror(L, p1, p2); 119 luaG_concaterror(L, p1, p2);
120 case TM_IDIV: case TM_BAND: case TM_BOR: case TM_BXOR: 120 case TM_BAND: case TM_BOR: case TM_BXOR:
121 case TM_SHL: case TM_SHR: case TM_BNOT: { 121 case TM_SHL: case TM_SHR: case TM_BNOT: {
122 lua_Number dummy; 122 lua_Number dummy;
123 if (tonumber(p1, &dummy) && tonumber(p2, &dummy)) 123 if (tonumber(p1, &dummy) && tonumber(p2, &dummy))
124 luaG_tointerror(L, p1, p2); 124 luaG_tointerror(L, p1, p2);
125 else if (event != TM_IDIV) 125 else
126 luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 126 luaG_opinterror(L, p1, p2, "perform bitwise operation on");
127 /* else go through */ 127 /* else go through */
128 } 128 }