harec

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

commit ce632ca7fb51173bec8ef6c95dcbd3428b10b8c7
parent 268cd3286197a84ddb631140b5f249d2bf240cef
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  4 Feb 2021 16:07:58 -0500

eval: implement default values for arrays

Diffstat:
Msrc/emit.c | 1+
Msrc/eval.c | 10+++++++++-
Msrc/gen.c | 1+
3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/emit.c b/src/emit.c @@ -7,6 +7,7 @@ static void emit_qtype(const struct qbe_type *type, bool aggr, FILE *out) { + assert(type); switch (type->stype) { case Q_BYTE: case Q_HALF: diff --git a/src/eval.c b/src/eval.c @@ -411,8 +411,16 @@ constant_default(struct context *ctx, struct expression *v) v->constant.string.value = strdup(""); v->constant.string.len = 0; break; - case TYPE_STORAGE_TAGGED: case TYPE_STORAGE_ARRAY: + v->constant.array = xcalloc(1, sizeof(struct array_constant)); + v->constant.array->expand = true; + v->constant.array->value = xcalloc(1, sizeof(struct expression)); + v->constant.array->value->type = EXPR_CONSTANT; + v->constant.array->value->result = + type_dealias(v->result)->array.members; + constant_default(ctx, v->constant.array->value); + break; + case TYPE_STORAGE_TAGGED: case TYPE_STORAGE_SLICE: assert(0); // TODO case TYPE_STORAGE_ALIAS: diff --git a/src/gen.c b/src/gen.c @@ -2399,6 +2399,7 @@ gen_data_item(struct gen_context *ctx, struct expression *expr, assert(0); // Invariant } + assert(item->value.type); return item; }