aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-03-14 13:54:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-03-14 13:54:08 -0300
commit9f3f5b6f4106966eb68f9c54dca9653bf3539bf9 (patch)
treed11f49871a46222863cd09300ab0d52f3a395459
parenta39489194edf4c16642fc8518aa0017090a082f8 (diff)
downloadlua-9f3f5b6f4106966eb68f9c54dca9653bf3539bf9.tar.gz
lua-9f3f5b6f4106966eb68f9c54dca9653bf3539bf9.tar.bz2
lua-9f3f5b6f4106966eb68f9c54dca9653bf3539bf9.zip
details
-rw-r--r--lvm.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/lvm.c b/lvm.c
index 2a5689f9..c2b82aed 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.187 2014/03/06 16:15:18 roberto Exp roberto $ 2** $Id: lvm.c,v 2.188 2014/03/07 16:19:00 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*/
@@ -899,7 +899,7 @@ void luaV_execute (lua_State *L) {
899 } 899 }
900 ) 900 )
901 vmcase(OP_FORLOOP, 901 vmcase(OP_FORLOOP,
902 if (ttisinteger(ra)) { /* integer count? */ 902 if (ttisinteger(ra)) { /* integer loop? */
903 lua_Integer step = ivalue(ra + 2); 903 lua_Integer step = ivalue(ra + 2);
904 lua_Integer idx = ivalue(ra) + step; /* increment index */ 904 lua_Integer idx = ivalue(ra) + step; /* increment index */
905 lua_Integer limit = ivalue(ra + 1); 905 lua_Integer limit = ivalue(ra + 1);
@@ -909,7 +909,7 @@ void luaV_execute (lua_State *L) {
909 setivalue(ra + 3, idx); /* ...and external index */ 909 setivalue(ra + 3, idx); /* ...and external index */
910 } 910 }
911 } 911 }
912 else { /* floating count */ 912 else { /* floating loop */
913 lua_Number step = fltvalue(ra + 2); 913 lua_Number step = fltvalue(ra + 2);
914 lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */ 914 lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */
915 lua_Number limit = fltvalue(ra + 1); 915 lua_Number limit = fltvalue(ra + 1);
@@ -925,10 +925,11 @@ void luaV_execute (lua_State *L) {
925 TValue *init = ra; 925 TValue *init = ra;
926 TValue *plimit = ra + 1; 926 TValue *plimit = ra + 1;
927 TValue *pstep = ra + 2; 927 TValue *pstep = ra + 2;
928 if (ttisinteger(ra) && ttisinteger(ra + 1) && ttisinteger(ra + 2)) { 928 if (ttisinteger(init) && ttisinteger(plimit) && ttisinteger(pstep)) {
929 setivalue(ra, ivalue(ra) - ivalue(pstep)); 929 /* all values are integer */
930 setivalue(init, ivalue(init) - ivalue(pstep));
930 } 931 }
931 else { /* try with floats */ 932 else { /* try making all values floats */
932 lua_Number ninit; lua_Number nlimit; lua_Number nstep; 933 lua_Number ninit; lua_Number nlimit; lua_Number nstep;
933 if (!tonumber(plimit, &nlimit)) 934 if (!tonumber(plimit, &nlimit))
934 luaG_runerror(L, LUA_QL("for") " limit must be a number"); 935 luaG_runerror(L, LUA_QL("for") " limit must be a number");
@@ -938,7 +939,7 @@ void luaV_execute (lua_State *L) {
938 setnvalue(pstep, nstep); 939 setnvalue(pstep, nstep);
939 if (!tonumber(init, &ninit)) 940 if (!tonumber(init, &ninit))
940 luaG_runerror(L, LUA_QL("for") " initial value must be a number"); 941 luaG_runerror(L, LUA_QL("for") " initial value must be a number");
941 setnvalue(ra, luai_numsub(L, ninit, nstep)); 942 setnvalue(init, luai_numsub(L, ninit, nstep));
942 } 943 }
943 ci->u.l.savedpc += GETARG_sBx(i); 944 ci->u.l.savedpc += GETARG_sBx(i);
944 ) 945 )