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:
32
lvm.c
32
lvm.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 2.65 2006/07/14 14:40:12 roberto Exp $
|
||||
** $Id: lvm.c,v 2.65 2006/07/14 16:22:24 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -225,7 +225,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
|
||||
if (ttype(l) != ttype(r))
|
||||
return luaG_ordererror(L, l, r);
|
||||
else if (ttisnumber(l))
|
||||
return luai_numlt(nvalue(l), nvalue(r));
|
||||
return luai_numlt(L, nvalue(l), nvalue(r));
|
||||
else if (ttisstring(l))
|
||||
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
|
||||
else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
|
||||
@@ -239,7 +239,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
|
||||
if (ttype(l) != ttype(r))
|
||||
return luaG_ordererror(L, l, r);
|
||||
else if (ttisnumber(l))
|
||||
return luai_numle(nvalue(l), nvalue(r));
|
||||
return luai_numle(L, nvalue(l), nvalue(r));
|
||||
else if (ttisstring(l))
|
||||
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
|
||||
else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
|
||||
@@ -318,13 +318,13 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb,
|
||||
(c = luaV_tonumber(rc, &tempc)) != NULL) {
|
||||
lua_Number nb = nvalue(b), nc = nvalue(c);
|
||||
switch (op) {
|
||||
case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
|
||||
case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
|
||||
case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
|
||||
case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
|
||||
case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
|
||||
case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
|
||||
case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
|
||||
case TM_ADD: setnvalue(ra, luai_numadd(L, nb, nc)); break;
|
||||
case TM_SUB: setnvalue(ra, luai_numsub(L, nb, nc)); break;
|
||||
case TM_MUL: setnvalue(ra, luai_nummul(L, nb, nc)); break;
|
||||
case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break;
|
||||
case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break;
|
||||
case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break;
|
||||
case TM_UNM: setnvalue(ra, luai_numunm(L, nb)); break;
|
||||
default: lua_assert(0); break;
|
||||
}
|
||||
}
|
||||
@@ -362,7 +362,7 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb,
|
||||
TValue *rc = RKC(i); \
|
||||
if (ttisnumber(rb) && ttisnumber(rc)) { \
|
||||
lua_Number nb = nvalue(rb), nc = nvalue(rc); \
|
||||
setnvalue(ra, op(nb, nc)); \
|
||||
setnvalue(ra, op(L, nb, nc)); \
|
||||
} \
|
||||
else \
|
||||
Protect(Arith(L, ra, rb, rc, tm)); \
|
||||
@@ -498,7 +498,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
TValue *rb = RB(i);
|
||||
if (ttisnumber(rb)) {
|
||||
lua_Number nb = nvalue(rb);
|
||||
setnvalue(ra, luai_numunm(nb));
|
||||
setnvalue(ra, luai_numunm(L, nb));
|
||||
}
|
||||
else {
|
||||
Protect(Arith(L, ra, rb, rb, TM_UNM));
|
||||
@@ -652,10 +652,10 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
}
|
||||
case OP_FORLOOP: {
|
||||
lua_Number step = nvalue(ra+2);
|
||||
lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
|
||||
lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */
|
||||
lua_Number limit = nvalue(ra+1);
|
||||
if (luai_numlt(0, step) ? luai_numle(idx, limit)
|
||||
: luai_numle(limit, idx)) {
|
||||
if (luai_numlt(L, 0, step) ? luai_numle(L, idx, limit)
|
||||
: luai_numle(L, limit, idx)) {
|
||||
dojump(L, pc, GETARG_sBx(i)); /* jump back */
|
||||
setnvalue(ra, idx); /* update internal index... */
|
||||
setnvalue(ra+3, idx); /* ...and external index */
|
||||
@@ -673,7 +673,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
||||
luaG_runerror(L, LUA_QL("for") " limit must be a number");
|
||||
else if (!tonumber(pstep, ra+2))
|
||||
luaG_runerror(L, LUA_QL("for") " step must be a number");
|
||||
setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
|
||||
setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep)));
|
||||
dojump(L, pc, GETARG_sBx(i));
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user