]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
operators &= and |=
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 23 Nov 2012 13:28:11 +0000 (14:28 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 23 Nov 2012 13:28:11 +0000 (14:28 +0100)
parser.c
tests/operators.qc
tests/operators.tmpl

index c8d1c11241c3c70247e0a2bb49e7572a7bc48307..67d72023fda748f2967f097af249729132947e21 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1015,6 +1015,23 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
                     return false;
             };
             break;
+        case opid2('&','='):
+        case opid2('|','='):
+            if (NotSameType(TYPE_FLOAT)) {
+                ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+                ast_type_to_string(exprs[1], ty2, sizeof(ty2));
+                parseerror(parser, "invalid types used in expression: %s and %s",
+                           ty1, ty2);
+                return false;
+            }
+            if (ast_istype(exprs[0], ast_entfield))
+                assignop = type_storep_instr[exprs[0]->expression.vtype];
+            else
+                assignop = type_store_instr[exprs[0]->expression.vtype];
+            out = (ast_expression*)ast_binstore_new(ctx, assignop,
+                                                    (op->id == opid2('&','=') ? INSTR_BITAND : INSTR_BITOR),
+                                                    exprs[0], exprs[1]);
+            break;
     }
 #undef NotSameType
 
index e440ec54d77ca1b322ac1abfe6ada7506d193b98..e1464e381c6b2740529c814f89ceb292791e9433 100644 (file)
@@ -51,4 +51,9 @@ void main() {
        v = '3 4 5';
        print(vtos(v *= 2), " = '6 8 10'\n");
        print(vtos(v /= 2), " = '3 4 5'\n");
+
+       // bit compounds
+       a = 1;
+       print(ftos(a |= 2), " = 3\n");
+       print(ftos(a &= 6), " = 2\n");
 }
index 06426ac1b06c4a37b6945118b99ebc552188389e..fcf9afd56c810f56b2e0365ba784dbfecdfa6e22 100644 (file)
@@ -16,3 +16,5 @@ M: 6 = 6
 M: 3 = 3
 M: '6 8 10' = '6 8 10'
 M: '3 4 5' = '3 4 5'
+M: 3 = 3
+M: 2 = 2