aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-06 11:38:31 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-06 11:38:31 -0300
commit5ff408d2189c6c24fdf8908db4a31432bbdd6f15 (patch)
treebcd83d7547dab0d5418116eb10f9c601f2f2d3b9 /lvm.c
parente3c83835e7b396ab7db538fb3b052f02d7807dee (diff)
downloadlua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.tar.gz
lua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.tar.bz2
lua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.zip
Changed internal representation of booleans
Instead of an explicit value (field 'b'), true and false use different tag variants. This avoids reading an extra field and results in more direct code. (Most code that uses booleans needs to distinguish between true and false anyway.)
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lvm.c b/lvm.c
index 78c0ebe7..656def81 100644
--- a/lvm.c
+++ b/lvm.c
@@ -577,10 +577,9 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
577 } 577 }
578 /* values have same type and same variant */ 578 /* values have same type and same variant */
579 switch (ttypetag(t1)) { 579 switch (ttypetag(t1)) {
580 case LUA_TNIL: return 1; 580 case LUA_TNIL: case LUA_TFALSE: case LUA_TTRUE: return 1;
581 case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2)); 581 case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));
582 case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2)); 582 case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
583 case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1! */
584 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); 583 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
585 case LUA_TLCF: return fvalue(t1) == fvalue(t2); 584 case LUA_TLCF: return fvalue(t1) == fvalue(t2);
586 case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); 585 case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
@@ -1182,9 +1181,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1182 setobj2s(L, ra, rb); 1181 setobj2s(L, ra, rb);
1183 vmbreak; 1182 vmbreak;
1184 } 1183 }
1185 vmcase(OP_LOADBOOL) { 1184 vmcase(OP_LOADFALSE) {
1186 setbvalue(s2v(ra), GETARG_B(i)); 1185 setbfvalue(s2v(ra));
1187 if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ 1186 if (GETARG_B(i)) pc++; /* if B, skip next instruction */
1187 vmbreak;
1188 }
1189 vmcase(OP_LOADTRUE) {
1190 setbtvalue(s2v(ra));
1188 vmbreak; 1191 vmbreak;
1189 } 1192 }
1190 vmcase(OP_LOADNIL) { 1193 vmcase(OP_LOADNIL) {
@@ -1503,8 +1506,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1503 } 1506 }
1504 vmcase(OP_NOT) { 1507 vmcase(OP_NOT) {
1505 TValue *rb = vRB(i); 1508 TValue *rb = vRB(i);
1506 int nrb = l_isfalse(rb); /* next assignment may change this value */ 1509 if (l_isfalse(rb))
1507 setbvalue(s2v(ra), nrb); 1510 setbtvalue(s2v(ra));
1511 else
1512 setbfvalue(s2v(ra));
1508 vmbreak; 1513 vmbreak;
1509 } 1514 }
1510 vmcase(OP_LEN) { 1515 vmcase(OP_LEN) {