aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-12-30 18:47:58 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-12-30 18:47:58 -0200
commit1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51 (patch)
treebdedb3205963f8db43391aaef5be853cdeb59df4 /lcode.c
parentf5133aa1a55cee96b535ff788764437deacdc26a (diff)
downloadlua-1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51.tar.gz
lua-1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51.tar.bz2
lua-1ea2d20f74cea9c61817d4a5ed67c4fc47cafb51.zip
first implementation of '<<', '>>', and '~' (bitwise not)
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lcode.c b/lcode.c
index 8b54d71d..2da5e73a 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.75 2013/12/18 14:12:03 roberto Exp roberto $ 2** $Id: lcode.c,v 2.76 2013/12/18 18:44:42 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -756,7 +756,8 @@ static int validop (OpCode op, TValue *v1, TValue *v2) {
756 switch (op) { 756 switch (op) {
757 case OP_IDIV: /* division by 0 and conversion errors */ 757 case OP_IDIV: /* division by 0 and conversion errors */
758 return (tointeger(v1, &i) && tointeger(v2, &i) && i != 0); 758 return (tointeger(v1, &i) && tointeger(v2, &i) && i != 0);
759 case OP_BAND: case OP_BOR: case OP_BXOR: /* conversion errors */ 759 case OP_BAND: case OP_BOR: case OP_BXOR:
760 case OP_SHL: case OP_SHR: case OP_BNOT: /* conversion errors */
760 return (tointeger(v1, &i) && tointeger(v2, &i)); 761 return (tointeger(v1, &i) && tointeger(v2, &i));
761 case OP_MOD: /* integer module by 0 */ 762 case OP_MOD: /* integer module by 0 */
762 return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0); 763 return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0);
@@ -771,7 +772,6 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
771 TValue v1, v2, res; 772 TValue v1, v2, res;
772 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) 773 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
773 return 0; /* non-numeric operands or not safe to fold */ 774 return 0; /* non-numeric operands or not safe to fold */
774 lua_assert(OP_IDIV - OP_ADD + LUA_OPADD == LUA_OPIDIV);
775 luaO_arith(NULL, op - OP_ADD + LUA_OPADD, &v1, &v2, &res); 775 luaO_arith(NULL, op - OP_ADD + LUA_OPADD, &v1, &v2, &res);
776 if (ttisinteger(&res)) { 776 if (ttisinteger(&res)) {
777 e1->k = VKINT; 777 e1->k = VKINT;
@@ -792,7 +792,7 @@ static void codearith (FuncState *fs, OpCode op,
792 expdesc *e1, expdesc *e2, int line) { 792 expdesc *e1, expdesc *e2, int line) {
793 if (!constfolding(op, e1, e2)) { /* could not fold operation? */ 793 if (!constfolding(op, e1, e2)) { /* could not fold operation? */
794 int o1, o2; 794 int o1, o2;
795 if (op == OP_UNM || op == OP_LEN) { 795 if (op == OP_UNM || op == OP_BNOT || op == OP_LEN) {
796 o2 = 0; 796 o2 = 0;
797 o1 = luaK_exp2anyreg(fs, e1); /* cannot operate on constants */ 797 o1 = luaK_exp2anyreg(fs, e1); /* cannot operate on constants */
798 } 798 }
@@ -835,7 +835,7 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
835 expdesc e2; 835 expdesc e2;
836 e2.t = e2.f = NO_JUMP; e2.k = VKINT; e2.u.ival = 0; 836 e2.t = e2.f = NO_JUMP; e2.k = VKINT; e2.u.ival = 0;
837 switch (op) { 837 switch (op) {
838 case OPR_MINUS: case OPR_LEN: { 838 case OPR_MINUS: case OPR_BNOT: case OPR_LEN: {
839 codearith(fs, op - OPR_MINUS + OP_UNM, e, &e2, line); 839 codearith(fs, op - OPR_MINUS + OP_UNM, e, &e2, line);
840 break; 840 break;
841 } 841 }
@@ -862,7 +862,8 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
862 case OPR_ADD: case OPR_SUB: 862 case OPR_ADD: case OPR_SUB:
863 case OPR_MUL: case OPR_DIV: case OPR_IDIV: 863 case OPR_MUL: case OPR_DIV: case OPR_IDIV:
864 case OPR_MOD: case OPR_POW: 864 case OPR_MOD: case OPR_POW:
865 case OPR_BAND: case OPR_BOR: case OPR_BXOR: { 865 case OPR_BAND: case OPR_BOR: case OPR_BXOR:
866 case OPR_SHL: case OPR_SHR: {
866 if (!tonumeral(v, NULL)) luaK_exp2RK(fs, v); 867 if (!tonumeral(v, NULL)) luaK_exp2RK(fs, v);
867 break; 868 break;
868 } 869 }
@@ -907,7 +908,8 @@ void luaK_posfix (FuncState *fs, BinOpr op,
907 } 908 }
908 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: 909 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
909 case OPR_IDIV: case OPR_MOD: case OPR_POW: 910 case OPR_IDIV: case OPR_MOD: case OPR_POW:
910 case OPR_BAND: case OPR_BOR: case OPR_BXOR: { 911 case OPR_BAND: case OPR_BOR: case OPR_BXOR:
912 case OPR_SHL: case OPR_SHR: {
911 codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line); 913 codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);
912 break; 914 break;
913 } 915 }