feat: implement AST walker

This commit is contained in:
samsonium
2026-10-10 02:40:53 +03:00
parent 2fabd0ec2d
commit e979a22739
9 changed files with 469 additions and 17 deletions
+24
View File
@@ -1,6 +1,7 @@
#include <compiler/fzl_debug.h>
#include <compiler/fzl_parser.h>
#include <compiler/fzl_reader.h>
#include <compiler/fzl_walker.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -155,12 +156,35 @@ int main(int argc, char **argv)
{
printf("ok!\n");
fzl_debug_print_ast(parser->root);
printf("-> walking AST...");
}
fzl_walker_t *walker = fzl_mkwalker(parser->root);
result = fzl_walk(walker);
if (result != 0)
{
printf("Error: %s\n", fzl_walker_geterror());
return -1;
}
if (args->verbose)
{
printf("ok!\n");
printf("--> Constants table:\n");
for (size_t i = 0; i < walker->consts->size; i++)
printf("---> %s\n", walker->consts->array[i].as.string.chars);
printf("--> Ops:\n");
for (size_t i = 0; i < walker->op_count; i++)
printf("---> %lu\n", walker->ops[i]);
}
free(args);
fzl_freereader(rd);
fzl_freeparser(parser);
fzl_freeast(parser->root);
fzl_freewalker(walker);
printf("done.\n");
return 0;