Started implementing the linked env scope.
This commit is contained in:
13
src/ast.c
13
src/ast.c
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "include/ast.h"
|
#include "include/ast.h"
|
||||||
#include "include/dstr.h"
|
#include "include/dstr.h"
|
||||||
|
#include "include/htab.h"
|
||||||
#include "include/util.h"
|
#include "include/util.h"
|
||||||
|
|
||||||
extern AST* root;
|
extern AST* root;
|
||||||
@@ -22,6 +23,17 @@ AST* ast_init(ASTType type, void* data) {
|
|||||||
|
|
||||||
ast->type = type;
|
ast->type = type;
|
||||||
ast->data = data;
|
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;
|
return ast;
|
||||||
}
|
}
|
||||||
@@ -42,6 +54,7 @@ void ast_destroy(AST* ast) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(ast);
|
free(ast);
|
||||||
|
htab_destroy(ast->scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_print(AST* ast) { ast_print_i(ast, 0); }
|
void ast_print(AST* ast) { ast_print_i(ast, 0); }
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#ifndef AST_H
|
#ifndef AST_H
|
||||||
#define AST_H
|
#define AST_H
|
||||||
|
|
||||||
|
#include "htab.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// The type of an `AST`.
|
// The type of an `AST`.
|
||||||
@@ -31,10 +32,13 @@ typedef enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
ASTType type; // The type of the `AST`.
|
ASTType type; // The type of the `AST`.
|
||||||
void* data; // The data of the `AST`.
|
void* data; // The data of the `AST`.
|
||||||
|
HTab* scope; // The scope of the `AST`.
|
||||||
} AST;
|
} AST;
|
||||||
|
|
||||||
// Create a new `AST`.
|
// Create a new `AST`.
|
||||||
AST* ast_init(ASTType type, void* data);
|
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.
|
// Destroy an `AST`, recursively.
|
||||||
void ast_destroy(AST* ast);
|
void ast_destroy(AST* ast);
|
||||||
// Print an `AST`, recursively.
|
// Print an `AST`, recursively.
|
||||||
|
Submodule test/Unity updated: 73237c5d22...cdf1d0297e
Reference in New Issue
Block a user