From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>,
Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang 2/5] scope: make scope a bi-directional tree
Date: Sat, 21 Sep 2024 01:12:57 +0000 (UTC) [thread overview]
Message-ID: <20240921011234.191248-3-carlos@maniero.me> (raw)
In-Reply-To: <20240921011234.191248-1-carlos@maniero.me>
In x86 architecture it is needed to reserve the stack space for local
variables. The code generators needs to compute this value from diving into
the tree from the function scope to the deepest level. So a
bi-directional scope are required.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
Co-authored-by: Johnny Richard <johnny@johnnyrichard.com>
---
src/scope.c | 14 ++++++++++++++
src/scope.h | 2 ++
2 files changed, 16 insertions(+)
diff --git a/src/scope.c b/src/scope.c
index 3271856..b23e865 100644
--- a/src/scope.c
+++ b/src/scope.c
@@ -33,6 +33,18 @@ scope_new(arena_t *arena)
}
scope->arena = arena;
scope->symbols = map_new(arena);
+
+ // FIXME: create a list_new function to avoid spreading this.
+ list_t *children = (list_t *)arena_alloc(arena, sizeof(list_t));
+
+ if (children == NULL) {
+ fprintf(stderr, "[FATAL] Out of memory: scope_new: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ list_init(children, arena);
+
+ scope->children = children;
return scope;
}
@@ -89,6 +101,8 @@ scope_push(scope_t *scope)
scope_t *child = scope_new(scope->arena);
child->parent = scope;
+ list_append(scope->children, child);
+
return child;
}
diff --git a/src/scope.h b/src/scope.h
index ddb0cd0..7f7eaae 100644
--- a/src/scope.h
+++ b/src/scope.h
@@ -18,6 +18,7 @@
#define SCOPE_H
#include "arena.h"
+#include "list.h"
#include "map.h"
#include "string_view.h"
@@ -29,6 +30,7 @@ typedef struct symbol
typedef struct scope
{
struct scope *parent;
+ list_t *children;
arena_t *arena;
map_t *symbols;
} scope_t;
--
2.34.1
next prev parent reply other threads:[~2024-09-21 1:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-21 1:12 [PATCH olang 0/5] fix multiple variables Carlos Maniero
2024-09-21 1:12 ` [PATCH olang 1/5] map: add function to retrieve all key-value pairs Carlos Maniero
2024-09-21 1:12 ` Carlos Maniero [this message]
2024-09-21 1:13 ` [PATCH olang 3/5] ast: checker: add function scope Carlos Maniero
2024-09-21 1:13 ` [PATCH olang 4/5] codegen: reset variable offset on block leave Carlos Maniero
2024-09-21 1:13 ` [PATCH olang 5/5] codegen: preserve function's variable stack location Carlos Maniero
2024-09-21 1:13 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-21 1:25 ` [PATCH olang 0/5] fix multiple variables Johnny Richard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240921011234.191248-3-carlos@maniero.me \
--to=carlos@maniero.me \
--cc=johnny@johnnyrichard.com \
--cc=~johnnyrichard/olang-devel@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox