diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-28 11:48:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-28 11:48:44 -0300 |
commit | b346834a09c086affce6308c7917a8f6af310d11 (patch) | |
tree | 960750333f506d0dc88e0b92e68dbda48234b176 /lvm.c | |
parent | 61a036eaa5918bdf5d7f01443b43288030337d20 (diff) | |
download | lua-b346834a09c086affce6308c7917a8f6af310d11.tar.gz lua-b346834a09c086affce6308c7917a8f6af310d11.tar.bz2 lua-b346834a09c086affce6308c7917a8f6af310d11.zip |
new macros for changing numbers
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.187 2001/06/20 17:22:46 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.188 2001/06/26 13:20:45 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -39,9 +39,10 @@ static void luaV_checkGC (lua_State *L, StkId top) { | |||
39 | 39 | ||
40 | 40 | ||
41 | const TObject *luaV_tonumber (const TObject *obj, TObject *n) { | 41 | const TObject *luaV_tonumber (const TObject *obj, TObject *n) { |
42 | lua_Number num; | ||
42 | if (ttype(obj) == LUA_TNUMBER) return obj; | 43 | if (ttype(obj) == LUA_TNUMBER) return obj; |
43 | if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &nvalue(n))) { | 44 | if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &num)) { |
44 | setttype(n, LUA_TNUMBER); | 45 | setnvalue(n, num); |
45 | return n; | 46 | return n; |
46 | } | 47 | } |
47 | else | 48 | else |
@@ -580,10 +581,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
580 | luaD_error(L, l_s("`for' limit must be a number")); | 581 | luaD_error(L, l_s("`for' limit must be a number")); |
581 | if (luaV_tonumber(ra+2, ra+2) == NULL) | 582 | if (luaV_tonumber(ra+2, ra+2) == NULL) |
582 | luaD_error(L, l_s("`for' step must be a number")); | 583 | luaD_error(L, l_s("`for' step must be a number")); |
583 | nvalue(ra) -= nvalue(ra+2);/* decrement index (to be incremented) */ | 584 | /* decrement index (to be incremented) */ |
585 | chgnvalue(ra, nvalue(ra) - nvalue(ra+2)); | ||
584 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ | 586 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ |
585 | /* store in `ra+1' total number of repetitions */ | 587 | /* store in `ra+1' total number of repetitions */ |
586 | nvalue(ra+1) = ((nvalue(ra+1)-nvalue(ra))/nvalue(ra+2)); | 588 | chgnvalue(ra+1, (nvalue(ra+1)-nvalue(ra))/nvalue(ra+2)); |
587 | /* go through */ | 589 | /* go through */ |
588 | } | 590 | } |
589 | case OP_FORLOOP: { | 591 | case OP_FORLOOP: { |
@@ -591,8 +593,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
591 | ttype(ra+2) == LUA_TNUMBER); | 593 | ttype(ra+2) == LUA_TNUMBER); |
592 | if (ttype(ra) != LUA_TNUMBER) | 594 | if (ttype(ra) != LUA_TNUMBER) |
593 | luaD_error(L, l_s("`for' index must be a number")); | 595 | luaD_error(L, l_s("`for' index must be a number")); |
594 | if (--nvalue(ra+1) >= 0) { | 596 | chgnvalue(ra+1, nvalue(ra+1) - 1); /* decrement counter */ |
595 | nvalue(ra) += nvalue(ra+2); /* increment index */ | 597 | if (nvalue(ra+1) >= 0) { |
598 | chgnvalue(ra, nvalue(ra) + nvalue(ra+2)); /* increment index */ | ||
596 | dojump(pc, i); /* repeat loop */ | 599 | dojump(pc, i); /* repeat loop */ |
597 | } | 600 | } |
598 | break; | 601 | break; |