From a04d318e45ff1e8d1ab322a8e10674dca4163ca1 Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Mon, 14 Apr 2025 08:58:41 -0400 Subject: [PATCH] Started implementing the linked env scope. --- src/ast.c | 13 +++++++++++++ src/include/ast.h | 4 ++++ test/Unity | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ast.c b/src/ast.c index c115f08..8c60e6a 100644 --- a/src/ast.c +++ b/src/ast.c @@ -2,6 +2,7 @@ #include "include/ast.h" #include "include/dstr.h" +#include "include/htab.h" #include "include/util.h" extern AST* root; @@ -22,6 +23,17 @@ AST* ast_init(ASTType type, void* data) { ast->type = type; ast->data = data; + ast->scope = NULL; + + return ast; +} + +AST* ast_init_scope(ASTType type, void* data, HTab* scope) { + AST* ast = malloc(sizeof(AST)); + + ast->type = type; + ast->data = data; + ast->scope = scope; return ast; } @@ -42,6 +54,7 @@ void ast_destroy(AST* ast) { } free(ast); + htab_destroy(ast->scope); } void ast_print(AST* ast) { ast_print_i(ast, 0); } diff --git a/src/include/ast.h b/src/include/ast.h index 00d3051..00da251 100644 --- a/src/include/ast.h +++ b/src/include/ast.h @@ -1,6 +1,7 @@ #ifndef AST_H #define AST_H +#include "htab.h" #include // The type of an `AST`. @@ -31,10 +32,13 @@ typedef enum { typedef struct { ASTType type; // The type of the `AST`. void* data; // The data of the `AST`. + HTab* scope; // The scope of the `AST`. } AST; // Create a new `AST`. AST* ast_init(ASTType type, void* data); +// Create a new `AST` with a specified scope. +AST* ast_init_scope(ASTType type, void* data, HTab* scope); // Destroy an `AST`, recursively. void ast_destroy(AST* ast); // Print an `AST`, recursively. diff --git a/test/Unity b/test/Unity index 73237c5..cdf1d02 160000 --- a/test/Unity +++ b/test/Unity @@ -1 +1 @@ -Subproject commit 73237c5d224169c7b4d2ec8321f9ac92e8071708 +Subproject commit cdf1d0297effc2736ee847e557b4275b4f02310b