rework: AST now uses an arena for allocation
For now it works but i dont really like that i use ParseResult, i mean is necessary but i think i will try to make it cleaner so that i can just directly use like parse and pass tath into evaluate, that would require to move the main evaluate funciton into evaluate_tree or something and evaluate takes the arena, uses evaluate_tree and frees the arena, will try that the next commit but for now this version works perfectly.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "arena.h"
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
#include <stdarg.h>
|
||||
@@ -17,7 +18,8 @@ static void test_parsing_basic_expression(void **state) {
|
||||
assert_int_equal(tokenize(expr, &tokens), LEXER_OK);
|
||||
assert_int_equal(tokens.len, 7);
|
||||
|
||||
AST tree = parse(&tokens);
|
||||
ParseResult result = parse(&tokens);
|
||||
AST tree = result.tree;
|
||||
// Assert head is +
|
||||
assert_int_equal(tree.head->type, NODE_BINARY_OP);
|
||||
assert_int_equal(tree.head->data.binary.op, OP_ADD);
|
||||
@@ -68,6 +70,7 @@ static void test_parsing_basic_expression(void **state) {
|
||||
tree.head->data.binary.right->data.binary.left->data.binary.left->data.integer,
|
||||
3
|
||||
);
|
||||
arena_destroy(result.arena);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
Reference in New Issue
Block a user