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:
2026-04-13 07:57:36 -06:00
parent fb27e1e34c
commit e4ec102cb9
8 changed files with 46 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
#include "evaluator.h"
#include "lexer.h"
#include <stdint.h>
#include <stdlib.h>
int64_t evaluate(ASTNode *tree) {
if (tree->type == NODE_BINARY_OP) {
@@ -9,8 +9,6 @@ int64_t evaluate(ASTNode *tree) {
ASTNode *left = tree->data.binary.left;
ASTNode *right = tree->data.binary.right;
free(tree);
switch (op) {
case OP_ADD:
return evaluate(left) + evaluate(right);
@@ -24,7 +22,6 @@ int64_t evaluate(ASTNode *tree) {
}
} else {
int64_t return_val = tree->data.integer;
free(tree);
return return_val;
}
}