harec

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

commit dfb6a9caec6f2810a4431e521f29a0fae581c574
parent 5356bf2c33b559bab2fb96b8fabb5abb00b83c1e
Author: Armin Weigl <tb46305@gmail.com>
Date:   Wed,  3 Aug 2022 19:32:46 +0200

eval_const: implement tagged unions

Signed-off-by: Armin Weigl <tb46305@gmail.com>

Diffstat:
Msrc/eval.c | 6+++++-
Mtests/13-tagged.ha | 2++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/eval.c b/src/eval.c @@ -370,9 +370,13 @@ eval_const(struct context *ctx, struct expression *in, struct expression *out) in->constant.string.value, in->constant.string.len); break; + case STORAGE_TAGGED: + out->constant.tagged.tag = in->constant.tagged.tag; + out->constant.tagged.value = xcalloc(sizeof(struct expression), 1); + return eval_expr(ctx, in->constant.tagged.value, + out->constant.tagged.value); case STORAGE_STRUCT: case STORAGE_UNION: - case STORAGE_TAGGED: case STORAGE_TUPLE: assert(0); // TODO case STORAGE_BOOL: diff --git a/tests/13-tagged.ha b/tests/13-tagged.ha @@ -238,9 +238,11 @@ fn reject() void = { }; def val1: integer = 8u8; +def val2: integer = val1; fn translation() void = { assert(val1 as u8 == 8u8); + assert(val2 as u8 == 8u8); }; export fn main() void = {