]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
+= operator implemented
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 14 Aug 2012 15:30:55 +0000 (17:30 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 14 Aug 2012 15:30:55 +0000 (17:30 +0200)
data/parsing.qc
parser.c

index a2a0416625a1402724a8eab6d527ae1d4fdc6d23..2e202ce562d14d16494459476554a1f3e1466b14 100644 (file)
@@ -47,4 +47,12 @@ void() main = {
         print("Foo\n");
         a = a - 1;
     } while (a);
+
+    float b;
+    a = 5;
+    print3("a = ", ftos(a), "\n");
+    b = (a += 7);
+    print("adding\n");
+    print3("a = ", ftos(a), "\n");
+    print3("b = ", ftos(a), "\n");
 };
index 72b6851e0602273aeb1699e9e18f0632be0142fe..e65eff3fde8425282a74154f3db268fc18ab8f5c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -624,12 +624,16 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
                            type_name[exprs[1]->expression.vtype]);
                 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];
             switch (exprs[0]->expression.vtype) {
                 case TYPE_FLOAT:
-                    out = (ast_expression*)ast_binstore_new(ctx, INSTR_ADD_F, exprs[0], exprs[1]);
+                    out = (ast_expression*)ast_binstore_new(ctx, assignop, INSTR_ADD_F, exprs[0], exprs[1]);
                     break;
                 case TYPE_VECTOR:
-                    out = (ast_expression*)ast_binstore_new(ctx, INSTR_ADD_V, exprs[0], exprs[1]);
+                    out = (ast_expression*)ast_binstore_new(ctx, assignop, INSTR_ADD_V, exprs[0], exprs[1]);
                     break;
                 default:
                     parseerror(parser, "invalid types used in expression: cannot add type %s and %s",