aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-03-18 19:58:30 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2025-03-18 19:58:47 +0200
commit7b5abecd2bef6b7441b0d850f95d451b441a6f76 (patch)
tree73d86891a41a7bcdb99a4d74f4613dff1f62c995 /src/ast.c
parent26b79b88ed724d89211e8c3afdebc3c747ef3f67 (diff)
downloadek-7b5abecd2bef6b7441b0d850f95d451b441a6f76.tar.gz
ek-7b5abecd2bef6b7441b0d850f95d451b441a6f76.zip
move to generic conts
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/ast.c b/src/ast.c
index 5561745..6e6b849 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -15,11 +15,18 @@
#include <math.h>
#include <ek/ast.h>
-#include <ek/vec.h>
#include <ek/scope.h>
-static struct vec nodes = {0};
-static struct vec types = {0};
+#define VEC_NAME ast_vec
+#define VEC_TYPE struct ast *
+#include <conts/vec.h>
+
+#define VEC_NAME type_vec
+#define VEC_TYPE struct type *
+#include <conts/vec.h>
+
+static struct ast_vec nodes;
+static struct type_vec types;
static void destroy_ast_node(struct ast *n)
{
@@ -45,22 +52,20 @@ static void destroy_type(struct type *n)
void destroy_ast_nodes()
{
- foreach_vec(ni, nodes) {
- struct ast *n = vect_at(struct ast *, nodes, ni);
- destroy_ast_node(n);
+ foreach(ast_vec, n, &nodes) {
+ destroy_ast_node(*n);
}
- vec_destroy(&nodes);
+ ast_vec_destroy(&nodes);
}
void destroy_types()
{
- foreach_vec(ti, types) {
- struct type *t = vect_at(struct type *, types, ti);
- destroy_type(t);
+ foreach(type_vec, t, &types) {
+ destroy_type(*t);
}
- vec_destroy(&types);
+ type_vec_destroy(&types);
}
void destroy_allocs()
@@ -71,8 +76,8 @@ void destroy_allocs()
static struct ast *create_empty_ast()
{
- if (vec_uninit(nodes)) {
- nodes = vec_create(sizeof(struct ast *));
+ if (ast_vec_uninit(&nodes)) {
+ nodes = ast_vec_create(0);
}
struct ast *n = calloc(1, sizeof(struct ast));
@@ -81,14 +86,14 @@ static struct ast *create_empty_ast()
/* just to be safe */
n->k = AST_EMPTY;
- vect_append(struct ast *, nodes, &n);
+ ast_vec_append(&nodes, n);
return n;
}
static struct type *create_empty_type()
{
- if (vec_uninit(types)) {
- types = vec_create(sizeof(struct type *));
+ if (type_vec_uninit(&types)) {
+ types = type_vec_create(0);
}
struct type *n = calloc(1, sizeof(struct type));
@@ -98,7 +103,7 @@ static struct type *create_empty_type()
/* just to be safe */
n->k = TYPE_VOID;
n->size = -1;
- vect_append(struct ast *, types, &n);
+ type_vec_append(&types, n);
return n;
}