aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-27 15:59:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-27 15:59:08 -0300
commit1b100335839e13021b4731f0407b87e4f7544dc0 (patch)
tree085979000de158de7d034c34d208b1318bbea90f
parent00e728af885d2781e365071557530a6685110d7e (diff)
downloadlua-1b100335839e13021b4731f0407b87e4f7544dc0.tar.gz
lua-1b100335839e13021b4731f0407b87e4f7544dc0.tar.bz2
lua-1b100335839e13021b4731f0407b87e4f7544dc0.zip
new function 'luaT_trybiniTM'
to handle tag methods for instructions with immediate integer arguments
-rw-r--r--ltm.c14
-rw-r--r--ltm.h4
-rw-r--r--lvm.c13
3 files changed, 19 insertions, 12 deletions
diff --git a/ltm.c b/ltm.c
index cbc4cc5e..2de75a31 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.42 2017/06/29 15:06:44 roberto Exp roberto $ 2** $Id: ltm.c,v 2.43 2017/07/27 13:50:16 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -167,6 +167,18 @@ void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
167} 167}
168 168
169 169
170void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2,
171 int inv, StkId res, TMS event) {
172 TValue aux; TValue *p2;
173 setivalue(&aux, i2);
174 if (inv) { /* arguments were exchanged? */
175 p2 = p1; p1 = &aux; /* correct them */
176 }
177 else p2 = &aux;
178 luaT_trybinTM(L, p1, p2, res, event);
179}
180
181
170int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 182int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
171 TMS event) { 183 TMS event) {
172 if (!callbinTM(L, p1, p2, L->top, event)) 184 if (!callbinTM(L, p1, p2, L->top, event))
diff --git a/ltm.h b/ltm.h
index c98b1037..31454a5c 100644
--- a/ltm.h
+++ b/ltm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.h,v 2.24 2017/05/13 12:57:20 roberto Exp roberto $ 2** $Id: ltm.h,v 2.25 2017/06/29 15:06:44 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -68,6 +68,8 @@ LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f,
68 const TValue *p1, const TValue *p2, StkId p3); 68 const TValue *p1, const TValue *p2, StkId p3);
69LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 69LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
70 StkId res, TMS event); 70 StkId res, TMS event);
71LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2,
72 int inv, StkId res, TMS event);
71LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 73LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,
72 const TValue *p2, TMS event); 74 const TValue *p2, TMS event);
73 75
diff --git a/lvm.c b/lvm.c
index 75eb8fe4..f34f3dfe 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.293 2017/09/19 18:38:14 roberto Exp roberto $ 2** $Id: lvm.c,v 2.294 2017/09/26 18:14: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*/
@@ -999,15 +999,8 @@ void luaV_execute (lua_State *L) {
999 else if (tonumberns(rb, nb)) { 999 else if (tonumberns(rb, nb)) {
1000 setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic))); 1000 setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic)));
1001 } 1001 }
1002 else { 1002 else
1003 TValue aux; TValue *rc; 1003 Protect(luaT_trybiniTM(L, rb, ic, GETARG_Bk(i), ra, TM_ADD));
1004 setivalue(&aux, ic);
1005 if (GETARG_Bk(i)) { /* arguments were exchanged? */
1006 rc = rb; rb = &aux; /* correct them */
1007 }
1008 else rc = &aux;
1009 Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD));
1010 }
1011 vmbreak; 1004 vmbreak;
1012 } 1005 }
1013 vmcase(OP_ADD) { 1006 vmcase(OP_ADD) {