From 595cc484e5f8c8017a22fc441239cc747129de97 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sun, 17 Mar 2024 03:02:27 -0400 Subject: subscope fix --- compiler.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/compiler.c b/compiler.c index 8aac480..2cfd3fe 100644 --- a/compiler.c +++ b/compiler.c @@ -3628,8 +3628,15 @@ char *scope_gen_const_label(Scope *s) { // Sub scopes Scope scope_subscope(Scope *s, char *name) { - Scope out = scope_init(name, s->current); + Vector n = vect_from_string(name); + vect_push_free_string(&n, int_to_str(s->next_const)); + s->next_const++; + + Scope out = scope_init(vect_as_string(&n), s->current); out.parent = s; + + vect_end(&n); + return out; } @@ -5038,14 +5045,17 @@ void p2_compile_control(Scope *s, CompData *out, Vector *tokens, size_t *pos, Ve *pos += 1; t = vect_get(tokens, *pos); - if (tok_str_eq(t, "loop")) { - } else if (t->type != TT_KEYWORD) { + Scope wrap = {0}; + Scope sub; + + if (tok_str_eq(t, "if")) { + wrap = scope_subscope(s); + sub = scope_subscope(&wrap); + } else if (t->type != TT_KEYWORD || !tok_str_eq(t, "loop")) { printf("ERROR: Expected control block type ('loop' or 'if'), found \"%s\" (%d:%d)\n", t->data, t->line, t->col); p2_error = true; *pos = end; return; - } else { - // if block } int build = -1; -- cgit v1.2.3