summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-03-02 13:04:52 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-03-02 13:04:52 -0300
commit6408bc0b7f23b580cb51b591277b82eac58f6e2e (patch)
tree4115261d82a14856ce9c193bc4408079c04564f6
parent91efb4b895cabb3ece67c92feb6db84b1fe7906c (diff)
downloadlua-6408bc0b7f23b580cb51b591277b82eac58f6e2e.tar.gz
lua-6408bc0b7f23b580cb51b591277b82eac58f6e2e.tar.bz2
lua-6408bc0b7f23b580cb51b591277b82eac58f6e2e.zip
new macros 'chgfltvalue'/'chgivalue' (numerical for loop does
not need to set the type of its internal variable at each iteration)
-rw-r--r--lobject.h8
-rw-r--r--lvm.c6
2 files changed, 10 insertions, 4 deletions
diff --git a/lobject.h b/lobject.h
index cb194105..2897deac 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.106 2015/01/05 13:52:37 roberto Exp roberto $ 2** $Id: lobject.h,v 2.107 2015/01/16 16:54:37 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -190,9 +190,15 @@ typedef struct lua_TValue TValue;
190#define setfltvalue(obj,x) \ 190#define setfltvalue(obj,x) \
191 { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); } 191 { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }
192 192
193#define chgfltvalue(obj,x) \
194 { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
195
193#define setivalue(obj,x) \ 196#define setivalue(obj,x) \
194 { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); } 197 { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }
195 198
199#define chgivalue(obj,x) \
200 { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
201
196#define setnilvalue(obj) settt_(obj, LUA_TNIL) 202#define setnilvalue(obj) settt_(obj, LUA_TNIL)
197 203
198#define setfvalue(obj,x) \ 204#define setfvalue(obj,x) \
diff --git a/lvm.c b/lvm.c
index f40c1e95..57e2b657 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.234 2015/02/05 17:15:33 roberto Exp roberto $ 2** $Id: lvm.c,v 2.235 2015/02/20 14:27:53 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*/
@@ -1040,7 +1040,7 @@ void luaV_execute (lua_State *L) {
1040 lua_Integer limit = ivalue(ra + 1); 1040 lua_Integer limit = ivalue(ra + 1);
1041 if ((0 < step) ? (idx <= limit) : (limit <= idx)) { 1041 if ((0 < step) ? (idx <= limit) : (limit <= idx)) {
1042 ci->u.l.savedpc += GETARG_sBx(i); /* jump back */ 1042 ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
1043 setivalue(ra, idx); /* update internal index... */ 1043 chgivalue(ra, idx); /* update internal index... */
1044 setivalue(ra + 3, idx); /* ...and external index */ 1044 setivalue(ra + 3, idx); /* ...and external index */
1045 } 1045 }
1046 } 1046 }
@@ -1051,7 +1051,7 @@ void luaV_execute (lua_State *L) {
1051 if (luai_numlt(0, step) ? luai_numle(idx, limit) 1051 if (luai_numlt(0, step) ? luai_numle(idx, limit)
1052 : luai_numle(limit, idx)) { 1052 : luai_numle(limit, idx)) {
1053 ci->u.l.savedpc += GETARG_sBx(i); /* jump back */ 1053 ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
1054 setfltvalue(ra, idx); /* update internal index... */ 1054 chgfltvalue(ra, idx); /* update internal index... */
1055 setfltvalue(ra + 3, idx); /* ...and external index */ 1055 setfltvalue(ra + 3, idx); /* ...and external index */
1056 } 1056 }
1057 } 1057 }