macros luai_num* take a state L (when available) as argument, to allow

them to generate errors (and other facilities)
This commit is contained in:
Roberto Ierusalimschy
2006-08-07 16:14:30 -03:00
parent ca7e5b5cb6
commit dfe2f1eeff
4 changed files with 38 additions and 38 deletions

18
lcode.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp roberto $
** $Id: lcode.c,v 2.26 2006/06/22 16:12:59 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -637,21 +637,21 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
v1 = e1->u.nval;
v2 = e2->u.nval;
switch (op) {
case OP_ADD: r = luai_numadd(v1, v2); break;
case OP_SUB: r = luai_numsub(v1, v2); break;
case OP_MUL: r = luai_nummul(v1, v2); break;
case OP_ADD: r = luai_numadd(NULL, v1, v2); break;
case OP_SUB: r = luai_numsub(NULL, v1, v2); break;
case OP_MUL: r = luai_nummul(NULL, v1, v2); break;
case OP_DIV:
if (v2 == 0) return 0; /* do not attempt to divide by 0 */
r = luai_numdiv(v1, v2); break;
r = luai_numdiv(NULL, v1, v2); break;
case OP_MOD:
if (v2 == 0) return 0; /* do not attempt to divide by 0 */
r = luai_nummod(v1, v2); break;
case OP_POW: r = luai_numpow(v1, v2); break;
case OP_UNM: r = luai_numunm(v1); break;
r = luai_nummod(NULL, v1, v2); break;
case OP_POW: r = luai_numpow(NULL, v1, v2); break;
case OP_UNM: r = luai_numunm(NULL, v1); break;
case OP_LEN: return 0; /* no constant folding for 'len' */
default: lua_assert(0); r = 0; break;
}
if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */
if (luai_numisnan(NULL, r)) return 0; /* do not attempt to produce NaN */
e1->u.nval = r;
return 1;
}