summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-07-10 12:25:53 +0100
committerubq323 <ubq323@ubq323.website>2023-07-10 12:25:53 +0100
commiteeea75fa7820f1a7ee4958b65667d0078e01f3bd (patch)
tree75850c0a3c1cbfb8b74740b208bfdaf9e8297009 /ast.c
initial
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/ast.c b/ast.c
new file mode 100644
index 0000000..07c0f34
--- /dev/null
+++ b/ast.c
@@ -0,0 +1,46 @@
+#include "ast.h"
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdio.h>
+
+AstVec astvec_new() {
+ AstNode *vals = malloc(2 * sizeof(AstNode));
+ return (AstVec){
+ .len = 0,
+ .cap = 2,
+ vals = vals
+ };
+}
+
+void astvec_append(AstVec *v, AstNode val) {
+ if (v->len == v->cap) {
+ size_t newcap = v->cap * 2;
+ printf("%ld to %ld\n", v->cap, newcap);
+ v->vals = realloc(v->vals, newcap * sizeof(AstNode));
+ v->cap = newcap;
+ }
+ v->vals[v->len] = val;
+ v->len ++;
+}
+
+AstNode astnode_new_num(int n) {
+ return (AstNode){
+ .ty = AST_NUM,
+ .as = {
+ .num = n,
+ },
+ };
+}
+
+AstNode astnode_new_list() {
+ return (AstNode){
+ .ty = AST_LIST,
+ .as = {
+ .list = astvec_new()
+ }
+ };
+}
+
+
+
+