diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-04 17:32:31 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-04 17:32:31 -0500 |
commit | d2b60a4be9e6b2172a267c6a9554567f1c54211a (patch) | |
tree | 323157ab71e25fb3c20a417b8bccf570998cafa9 /decls_cgen.c | |
parent | 75fc567dfdb4a6500990d79dc3f167d3262a96c5 (diff) |
more namespaces
Diffstat (limited to 'decls_cgen.c')
-rw-r--r-- | decls_cgen.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/decls_cgen.c b/decls_cgen.c index f815c13..797443d 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -197,7 +197,7 @@ static bool cgen_decls_decl(CGenerator *g, Declaration *d) { if (!cgen_decls_expr(g, &d->expr)) return false; } - if (g->block == NULL && g->fn == NULL) { + if ((g->block == NULL || (g->block->flags & BLOCK_IS_NMS)) && g->fn == NULL) { for (int i = 0, n_idents = (int)arr_len(d->idents); i < n_idents; ++i) { Identifier ident = d->idents[i]; Type *type = decl_type_at_index(d, i); @@ -209,6 +209,18 @@ static bool cgen_decls_decl(CGenerator *g, Declaration *d) { cgen_ident(g, ident); if (!cgen_type_post(g, type, d->where)) return false; + if (g->block) { + assert(g->block->flags & BLOCK_IS_NMS); + if (d->flags & DECL_HAS_EXPR) { + Value *val = decl_val_at_index(d, i); + cgen_write(g, " = "); + if (!cgen_val(g, *val, type, d->where)) + return false; + } else { + cgen_write(g, " = "); + cgen_zero_value(g, type); + } + } cgen_write(g, ";"); cgen_nl(g); } |