commit b346834a09c086affce6308c7917a8f6af310d11
parent 61a036eaa5918bdf5d7f01443b43288030337d20
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 28 Jun 2001 11:48:22 -0300
new macros for changing numbers
Diffstat:
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/lobject.h b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 1.106 2001/06/15 20:36:57 roberto Exp roberto $
+** $Id: lobject.h,v 1.107 2001/06/26 13:20:45 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -55,6 +55,8 @@ typedef struct lua_TObject {
#define setnvalue(obj,x) \
{ TObject *_o=(obj); _o->tt=LUA_TNUMBER; _o->value.n=(x); }
+#define chgnvalue(obj,x) ((obj)->value.n=(x))
+
#define setsvalue(obj,x) \
{ TObject *_o=(obj); _o->tt=LUA_TSTRING; _o->value.ts=(x); }
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.187 2001/06/20 17:22:46 roberto Exp roberto $
+** $Id: lvm.c,v 1.188 2001/06/26 13:20:45 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -39,9 +39,10 @@ static void luaV_checkGC (lua_State *L, StkId top) {
const TObject *luaV_tonumber (const TObject *obj, TObject *n) {
+ lua_Number num;
if (ttype(obj) == LUA_TNUMBER) return obj;
- if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &nvalue(n))) {
- setttype(n, LUA_TNUMBER);
+ if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &num)) {
+ setnvalue(n, num);
return n;
}
else
@@ -580,10 +581,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
luaD_error(L, l_s("`for' limit must be a number"));
if (luaV_tonumber(ra+2, ra+2) == NULL)
luaD_error(L, l_s("`for' step must be a number"));
- nvalue(ra) -= nvalue(ra+2);/* decrement index (to be incremented) */
+ /* decrement index (to be incremented) */
+ chgnvalue(ra, nvalue(ra) - nvalue(ra+2));
pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */
/* store in `ra+1' total number of repetitions */
- nvalue(ra+1) = ((nvalue(ra+1)-nvalue(ra))/nvalue(ra+2));
+ chgnvalue(ra+1, (nvalue(ra+1)-nvalue(ra))/nvalue(ra+2));
/* go through */
}
case OP_FORLOOP: {
@@ -591,8 +593,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
ttype(ra+2) == LUA_TNUMBER);
if (ttype(ra) != LUA_TNUMBER)
luaD_error(L, l_s("`for' index must be a number"));
- if (--nvalue(ra+1) >= 0) {
- nvalue(ra) += nvalue(ra+2); /* increment index */
+ chgnvalue(ra+1, nvalue(ra+1) - 1); /* decrement counter */
+ if (nvalue(ra+1) >= 0) {
+ chgnvalue(ra, nvalue(ra) + nvalue(ra+2)); /* increment index */
dojump(pc, i); /* repeat loop */
}
break;