harec

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

commit 90985fa53892ae81271c594da33be9dca9da4885
parent eebcc41e4044ab817fe35c7ab9a1e87cd5a3c8de
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 10 Aug 2021 09:53:37 +0200

gen: implement static bindings

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 16++++++++++++++++
Mtests/configure | 2+-
2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/gen.c b/src/gen.c @@ -24,6 +24,8 @@ static void gen_expr_at(struct gen_context *ctx, static struct gen_value gen_expr_with(struct gen_context *ctx, const struct expression *expr, struct gen_value *out); +static void gen_global_decl(struct gen_context *ctx, + const struct declaration *decl); static void gen_defers(struct gen_context *ctx) @@ -636,6 +638,20 @@ gen_expr_binding(struct gen_context *ctx, const struct expression *expr) { for (const struct expression_binding *binding = &expr->binding; binding; binding = binding->next) { + if (binding->object->otype == O_DECL) { + // static binding + struct declaration decl = { + .type = DECL_GLOBAL, + .ident = binding->object->ident, + .global = { + .type = binding->object->type, + .value = binding->initializer, + }, + }; + gen_global_decl(ctx, &decl); + continue; + } + const struct type *type = binding->initializer->result; struct gen_binding *gb = xcalloc(1, sizeof(struct gen_binding)); gb->value.kind = GV_TEMP; diff --git a/tests/configure b/tests/configure @@ -49,6 +49,7 @@ EOF 07-aliases \ 09-funcs \ 10-binarithms \ + 11-globals \ 14-switch \ 17-alloc \ 20-if \ @@ -59,7 +60,6 @@ EOF # Disabled tests #08-slices \ - #11-globals \ #12-loops \ #13-tagged \ #15-enums \