summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-17 03:02:27 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-17 03:02:27 -0400
commit595cc484e5f8c8017a22fc441239cc747129de97 (patch)
treed21cea996c706dcb423158684e897cc54a0a078f
parenta103dc81cfab8938ca3c822d2357fa6834f0dcfc (diff)
subscope fix
-rw-r--r--compiler.c20
1 files 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;