aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-23 17:18:10 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-23 17:18:10 -0200
commit73abfde2ef16223b12cf04800f6e53bfc68ad356 (patch)
treec22c497cfd37ab9153e20ab32730bf8a0a4a54ab
parent194a4f9710130cdb90df9f4094d81813bdb8ad6b (diff)
downloadlua-73abfde2ef16223b12cf04800f6e53bfc68ad356.tar.gz
lua-73abfde2ef16223b12cf04800f6e53bfc68ad356.tar.bz2
lua-73abfde2ef16223b12cf04800f6e53bfc68ad356.zip
small simplifications around 'luaT_callorderTM'
-rw-r--r--ltm.c17
-rw-r--r--lvm.c23
2 files changed, 19 insertions, 21 deletions
diff --git a/ltm.c b/ltm.c
index 4c03d2e4..873c2be4 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.47 2017/11/07 13:25:26 roberto Exp roberto $ 2** $Id: ltm.c,v 2.48 2017/11/08 14:50:23 roberto Exp $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -180,10 +180,19 @@ void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2,
180 180
181int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 181int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
182 TMS event) { 182 TMS event) {
183 if (!callbinTM(L, p1, p2, L->top, event)) 183 if (callbinTM(L, p1, p2, L->top, event)) /* try original event */
184 return -1; /* no metamethod */
185 else
186 return !l_isfalse(s2v(L->top)); 184 return !l_isfalse(s2v(L->top));
185 else if (event == TM_LE) {
186 /* try '!(p2 < p1)' for '(p1 <= p2)' */
187 L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
188 if (callbinTM(L, p2, p1, L->top, TM_LT)) {
189 L->ci->callstatus ^= CIST_LEQ; /* clear mark */
190 return l_isfalse(s2v(L->top));
191 }
192 /* else error will remove this 'ci'; no need to clear mark */
193 }
194 luaG_ordererror(L, p1, p2); /* no metamethod found */
195 return 0; /* to avoid warnings */
187} 196}
188 197
189 198
diff --git a/lvm.c b/lvm.c
index ca65c798..5d9440a6 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,8 +1,8 @@
1/* 1/*
2<<<<<<< lvm.c 2<<<<<<< lvm.c
3** $Id: lvm.c,v 2.313 2017/11/21 14:17:35 roberto Exp roberto $ 3** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $
4======= 4=======
5** $Id: lvm.c,v 2.315 2017/11/22 19:15:44 roberto Exp $ 5** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $
6>>>>>>> 2.315 6>>>>>>> 2.315
7** Lua virtual machine 7** Lua virtual machine
8** See Copyright Notice in lua.h 8** See Copyright Notice in lua.h
@@ -378,13 +378,11 @@ static int LEnum (const TValue *l, const TValue *r) {
378** return 'l < r' for non-numbers. 378** return 'l < r' for non-numbers.
379*/ 379*/
380static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) { 380static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) {
381 int res;
382 lua_assert(!ttisnumber(l) || !ttisnumber(r)); 381 lua_assert(!ttisnumber(l) || !ttisnumber(r));
383 if (ttisstring(l) && ttisstring(r)) /* both are strings? */ 382 if (ttisstring(l) && ttisstring(r)) /* both are strings? */
384 return l_strcmp(tsvalue(l), tsvalue(r)) < 0; 383 return l_strcmp(tsvalue(l), tsvalue(r)) < 0;
385 else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) /* no metamethod? */ 384 else
386 luaG_ordererror(L, l, r); /* error */ 385 return luaT_callorderTM(L, l, r, TM_LT);
387 return res;
388} 386}
389 387
390 388
@@ -407,20 +405,11 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
407** keeps that information. 405** keeps that information.
408*/ 406*/
409static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) { 407static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) {
410 int res;
411 lua_assert(!ttisnumber(l) || !ttisnumber(r)); 408 lua_assert(!ttisnumber(l) || !ttisnumber(r));
412 if (ttisstring(l) && ttisstring(r)) /* both are strings? */ 409 if (ttisstring(l) && ttisstring(r)) /* both are strings? */
413 return l_strcmp(tsvalue(l), tsvalue(r)) <= 0; 410 return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;
414 else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */ 411 else
415 return res; 412 return luaT_callorderTM(L, l, r, TM_LE);
416 else { /* try 'lt': */
417 L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
418 res = luaT_callorderTM(L, r, l, TM_LT);
419 L->ci->callstatus ^= CIST_LEQ; /* clear mark */
420 if (res < 0)
421 luaG_ordererror(L, l, r);
422 return !res; /* result is negated */
423 }
424} 413}
425 414
426 415