harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7d173b3f6d558ad24bce75f4bd6336ebfe4f14bf
parent b71aacaed809d5c0e3e7c2037108b5940f92fd9e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun,  3 Jan 2021 15:15:11 -0500

Fix assignments to aggregate indicies

Diffstat:
Msrc/gen.c | 13++++++++-----
Mtests/01-arrays.ha | 5+++--
2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -430,13 +430,16 @@ gen_expr_assign(struct gen_context *ctx, qtype_for_type(ctx, value->result, false); const struct qbe_type *otype = qtype_for_type(ctx, objtype, false); - struct qbe_value v = {0}; - gen_temp(ctx, &v, vtype, "assign.value.%d"); - gen_expression(ctx, value, &v); - if (expr->assign.op == BIN_LEQUAL) { - gen_store(ctx, &src, &v); + if (!type_is_aggregate(value->result)) { + qval_deref(&src); + } + gen_expression(ctx, value, &src); } else { + struct qbe_value v = {0}; + gen_temp(ctx, &v, vtype, "assign.value.%d"); + gen_expression(ctx, value, &v); + struct qbe_value result; gen_temp(ctx, &result, otype, "assign.result.%d"); diff --git a/tests/01-arrays.ha b/tests/01-arrays.ha @@ -77,8 +77,9 @@ fn nested() void = { assert(x[1][0] == 3); assert(x[1][1] == 4); assert(len(x[0]) == 2z); - // TODO: Assignment to nested array - // x[1] = [5, 6]; + x[1] = [5, 6]; + assert(x[1][0] == 5); + assert(x[1][1] == 6); }; export fn main() void = {