harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit dac4cd7c49c8d0539e8aefda4a812dff522c86a9
parent 1ef711c09431043fad0f27e1bd86c07d0afc4e01
Author: Alexey Yerin <yyp@disroot.org>
Date:   Tue, 13 Sep 2022 13:53:46 +0300

gen: support tuples in gen_expr_const_at

Fixes harec abort when using a def array of tuples.

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Msrc/gen.c | 23+++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -1884,6 +1884,26 @@ gen_const_tagged_at(struct gen_context *ctx, } static void +gen_const_tuple_at(struct gen_context *ctx, + const struct expression *expr, struct gen_value out) +{ + // TODO: Merge me into constant expressions + struct qbe_value base = mkqval(ctx, &out); + + struct gen_value ftemp = mkgtemp(ctx, &builtin_type_void, "field.%d"); + for (const struct tuple_constant *field = expr->constant.tuple; field; + field = field->next) { + assert(field->value); + + struct qbe_value offs = constl(field->field->offset); + ftemp.type = field->value->result; + struct qbe_value ptr = mklval(ctx, &ftemp); + pushi(ctx->current, &ptr, Q_ADD, &base, &offs, NULL); + gen_expr_at(ctx, field->value, ftemp); + } +} + +static void gen_expr_const_at(struct gen_context *ctx, const struct expression *expr, struct gen_value out) { @@ -1905,6 +1925,9 @@ gen_expr_const_at(struct gen_context *ctx, case STORAGE_TAGGED: gen_const_tagged_at(ctx, expr, out); break; + case STORAGE_TUPLE: + gen_const_tuple_at(ctx, expr, out); + break; default: abort(); // Invariant }