simple-lisp/bootstrap/main.c

40 lines
1.2 KiB
C
Raw Normal View History

#include <stdio.h>
#include "parse.h"
#include "ast.h"
2024-09-24 07:03:52 -07:00
#include "compile.h"
int main(int argc, const char **argv) {
ast_init_parser();
FILE *file = fopen("bootstrap/test.sl", "r");
if (!file) {
perror("fopen");
}
TokenStream *stream = make_token_stream(file);
2024-09-24 07:03:52 -07:00
COMPILE_FORMAT = COMPILE_FORMAT_ASM;
CompileEnvironment *env = make_compile_environment();
AstErrorList *ast_errs;
CompileError *comp_errs;
while (!token_stream_is_eof(stream)) {
2024-09-24 07:03:52 -07:00
AstNode *node = ast_next_toplevel(stream, &ast_errs);
while (ast_errs) {
AstErrorList *err = ast_error_list_pop(&ast_errs);
ast_format_error(err, "test.sl", stderr);
ast_error_list_free_one(err);
}
2024-09-24 07:03:52 -07:00
if (node) {
ssize_t ninst = byte_compile_form(env, node, stdout, &comp_errs);
while (comp_errs) {
CompileError *err = compile_error_pop(&comp_errs);
compile_format_error(err, "test.sl", stderr);
compile_error_free_one(err);
}
}
destroy_ast_node(node);
}
2024-09-24 07:03:52 -07:00
destroy_compile_environment(env);
destroy_token_stream(stream);
ast_deinit_parser();
return 0;
}