diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-06 13:15:18 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-06 13:15:18 -0300 |
commit | 5ff1c18a715b842a6146a6a07d99c84f48cac999 (patch) | |
tree | b90579a688fd971f80e7628cba179fdf389a27c8 /lobject.c | |
parent | 99ac4a260fc1bf958515c1816d866852194493f2 (diff) | |
download | lua-5ff1c18a715b842a6146a6a07d99c84f48cac999.tar.gz lua-5ff1c18a715b842a6146a6a07d99c84f48cac999.tar.bz2 lua-5ff1c18a715b842a6146a6a07d99c84f48cac999.zip |
back with 'L' for macros 'luai_num*', but now with a new macro
'luai_numinvalidop' to protect constant folding
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 2.73 2014/02/06 15:59:24 roberto Exp $ | 2 | ** $Id: lobject.c,v 2.74 2014/02/26 15:27:56 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 | */ |
@@ -91,15 +91,16 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, | |||
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | static lua_Number numarith (int op, lua_Number v1, lua_Number v2) { | 94 | static lua_Number numarith (lua_State *L, int op, lua_Number v1, |
95 | lua_Number v2) { | ||
95 | switch (op) { | 96 | switch (op) { |
96 | case LUA_OPADD: return luai_numadd(v1, v2); | 97 | case LUA_OPADD: return luai_numadd(L, v1, v2); |
97 | case LUA_OPSUB: return luai_numsub(v1, v2); | 98 | case LUA_OPSUB: return luai_numsub(L, v1, v2); |
98 | case LUA_OPMUL: return luai_nummul(v1, v2); | 99 | case LUA_OPMUL: return luai_nummul(L, v1, v2); |
99 | case LUA_OPDIV: return luai_numdiv(v1, v2); | 100 | case LUA_OPDIV: return luai_numdiv(L, v1, v2); |
100 | case LUA_OPMOD: return luai_nummod(v1, v2); | 101 | case LUA_OPMOD: return luai_nummod(L, v1, v2); |
101 | case LUA_OPPOW: return luai_numpow(v1, v2); | 102 | case LUA_OPPOW: return luai_numpow(L, v1, v2); |
102 | case LUA_OPUNM: return luai_numunm(v1); | 103 | case LUA_OPUNM: return luai_numunm(L, v1); |
103 | default: lua_assert(0); return 0; | 104 | default: lua_assert(0); return 0; |
104 | } | 105 | } |
105 | } | 106 | } |
@@ -121,7 +122,7 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, | |||
121 | case LUA_OPDIV: { /* operates only on floats */ | 122 | case LUA_OPDIV: { /* operates only on floats */ |
122 | lua_Number n1; lua_Number n2; | 123 | lua_Number n1; lua_Number n2; |
123 | if (tonumber(p1, &n1) && tonumber(p2, &n2)) { | 124 | if (tonumber(p1, &n1) && tonumber(p2, &n2)) { |
124 | setnvalue(res, numarith(op, n1, n2)); | 125 | setnvalue(res, numarith(L, op, n1, n2)); |
125 | return; | 126 | return; |
126 | } | 127 | } |
127 | else break; /* go to the end */ | 128 | else break; /* go to the end */ |
@@ -133,7 +134,7 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, | |||
133 | return; | 134 | return; |
134 | } | 135 | } |
135 | else if (tonumber(p1, &n1) && tonumber(p2, &n2)) { | 136 | else if (tonumber(p1, &n1) && tonumber(p2, &n2)) { |
136 | setnvalue(res, numarith(op, n1, n2)); | 137 | setnvalue(res, numarith(L, op, n1, n2)); |
137 | return; | 138 | return; |
138 | } | 139 | } |
139 | else break; /* go to the end */ | 140 | else break; /* go to the end */ |