fix: fix parser/generator issues
This commit is contained in:
+23
-18
@@ -1,9 +1,9 @@
|
||||
#include <common/fzl_colors.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_debug.h>
|
||||
#include <compiler/fzl_gen.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_reader.h>
|
||||
#include <compiler/fzl_walker.h>
|
||||
#include <compiler/fzl_writer.h>
|
||||
#include <compiler/utils/fzl_linked.h>
|
||||
#include <compiler/utils/fzl_options.h>
|
||||
@@ -122,7 +122,6 @@ int main(int argc, char **argv)
|
||||
{
|
||||
printf("%sok%s!\n", FZL_COK, FZL_CRST);
|
||||
fzl_debug_print_ast(parser->root);
|
||||
printf("%s> building%s\n", FZL_CDEBUG, FZL_CRST);
|
||||
printf("%s-> analyzing AST...%s", FZL_CDEBUG, FZL_CRST);
|
||||
}
|
||||
|
||||
@@ -159,10 +158,16 @@ int main(int argc, char **argv)
|
||||
analyzer->warnings[i]);
|
||||
}
|
||||
|
||||
fzl_walker_t *walker = fzl_mkwalker(parser->root);
|
||||
if (!walker)
|
||||
if (opts->verbose)
|
||||
{
|
||||
printf("%sError%s: failed to allocate writer\n", FZL_CERROR, FZL_CRST);
|
||||
printf("%sok%s!\n", FZL_COK, FZL_CRST);
|
||||
printf("%s> generate\n-> generating bytecode...%s", FZL_CDEBUG, FZL_CRST);
|
||||
}
|
||||
|
||||
fzl_gen_t *gen = fzl_mkgen(parser->root);
|
||||
if (!gen)
|
||||
{
|
||||
printf("%sError%s: failed to allocate generator\n", FZL_CERROR, FZL_CRST);
|
||||
fzl_freeoptions(opts);
|
||||
fzl_freeast(parser->root);
|
||||
fzl_freeanalyzer(analyzer);
|
||||
@@ -172,12 +177,12 @@ int main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = fzl_walk(walker);
|
||||
if (result != 0)
|
||||
bool gen_res = fzl_gen_run(gen);
|
||||
if (!gen_res)
|
||||
{
|
||||
printf("%sError%s: %s\n", FZL_CERROR, FZL_CRST, fzl_walker_geterror());
|
||||
printf("%sError%s: couldn't generate operations\n", FZL_CERROR, FZL_CRST);
|
||||
fzl_freeoptions(opts);
|
||||
fzl_freewalker(walker);
|
||||
fzl_freegen(gen);
|
||||
fzl_freeast(parser->root);
|
||||
fzl_freeanalyzer(analyzer);
|
||||
fzl_freeparser(parser);
|
||||
@@ -191,16 +196,16 @@ int main(int argc, char **argv)
|
||||
printf("%sok%s!\n", FZL_COK, FZL_CRST);
|
||||
|
||||
printf("%s--> Constants table%s:\n", FZL_CDEBUG, FZL_CRST);
|
||||
for (size_t i = 0; i < walker->consts->size; i++)
|
||||
printf("---> %s\n", walker->consts->array[i].as.string.chars);
|
||||
for (size_t i = 0; i < gen->consts->size; i++)
|
||||
printf("---> %s\n", gen->consts->array[i].as.string.chars);
|
||||
|
||||
printf("%s--> Ops%s:\n", FZL_CDEBUG, FZL_CRST);
|
||||
printf("---> ");
|
||||
for (size_t i = 0; i < walker->op_count; i++)
|
||||
for (size_t i = 0; i < gen->ops_count; i++)
|
||||
{
|
||||
if (i > 0 && i < walker->op_count)
|
||||
if (i > 0 && i < gen->ops_count)
|
||||
printf("->");
|
||||
printf("%lX", walker->ops[i]);
|
||||
printf("%lX", gen->ops[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
@@ -224,7 +229,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
printf("%sError%s: failed to allocate writer\n", FZL_CERROR, FZL_CRST);
|
||||
fzl_freeoptions(opts);
|
||||
fzl_freewalker(walker);
|
||||
fzl_freegen(gen);
|
||||
fzl_freeast(parser->root);
|
||||
fzl_freeanalyzer(analyzer);
|
||||
fzl_freeparser(parser);
|
||||
@@ -233,13 +238,13 @@ int main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = fzl_write(writer, walker);
|
||||
result = fzl_write(writer, gen);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("%sError%s: %s\n", FZL_CERROR, FZL_CRST, fzl_writer_geterror());
|
||||
fzl_freeoptions(opts);
|
||||
fzl_freewriter(writer);
|
||||
fzl_freewalker(walker);
|
||||
fzl_freegen(gen);
|
||||
fzl_freeast(parser->root);
|
||||
fzl_freeanalyzer(analyzer);
|
||||
fzl_freeparser(parser);
|
||||
@@ -257,7 +262,7 @@ int main(int argc, char **argv)
|
||||
fzl_freeast(parser->root);
|
||||
fzl_freeanalyzer(analyzer);
|
||||
fzl_freeparser(parser);
|
||||
fzl_freewalker(walker);
|
||||
fzl_freegen(gen);
|
||||
fzl_freewriter(writer);
|
||||
|
||||
printf("%sCompiled successfully%s.\n", FZL_COK, FZL_CRST);
|
||||
|
||||
Reference in New Issue
Block a user