From a574da7df88b8946a1a35bd89fc73c1890202164 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Tue, 14 Aug 2012 17:30:55 +0200 Subject: [PATCH] += operator implemented --- data/parsing.qc | 8 ++++++++ parser.c | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/data/parsing.qc b/data/parsing.qc index a2a0416..2e202ce 100644 --- a/data/parsing.qc +++ b/data/parsing.qc @@ -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"); }; diff --git a/parser.c b/parser.c index 72b6851..e65eff3 100644 --- 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",