stage1 新的ast结构 使用pest描述语法

This commit is contained in:
zzy committed 2026-09-08 13:14:29 +08:00
1 parent 34df303b56
commit 98b35a98e3
12 files changed
+3344 -2168

No files matched your search

+54 -54
View File
@@ -79,7 +79,7 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
}
spl_ast_t ast;
spl_ast_init(&ast, &toks);
spl_ast_prase(&ast);
spl_ast_parse(&ast);
if (ast.parsed < 0) {
printf("parse failed, no output\n");
// memory leak
@@ -91,63 +91,63 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
// memory leak
return 0;
}
spl_sema_t sema;
spl_type_t type;
spl_scope_t scope;
spl_type_init(&type);
spl_scope_init(&scope);
spl_sema_init(&sema, &ast, &type, &scope);
sema.ast = &ast;
spl_sema_run(&sema);
if (sema.error_count) {
printf("sema errors=%d, no output\n", sema.error_count);
// memory leak
return 1;
}
if (dump == DUMP_SEMA) {
spl_sema_dump(&sema);
spl_ast_dump(&ast, ast.root);
// memory leak
return 0;
}
// spl_sema_t sema;
// spl_type_t type;
// spl_scope_t scope;
// spl_type_init(&type);
// spl_scope_init(&scope);
// spl_sema_init(&sema, &ast, &type, &scope);
// sema.ast = &ast;
// spl_sema_run(&sema);
// if (sema.error_count) {
// printf("sema errors=%d, no output\n", sema.error_count);
// // memory leak
// return 1;
// }
// if (dump == DUMP_SEMA) {
// spl_sema_dump(&sema);
// spl_ast_dump(&ast, ast.root);
// // memory leak
// return 0;
// }
spl_ast2ir_t a2ir;
spl_ir_builder_t ir_builder;
spl_ir_builder_init(&ir_builder);
spl_ast2ir_init(&a2ir, &ir_builder, &sema);
spl_ast2ir_run(&a2ir);
if (a2ir.err_count) {
printf("ast2ir errors=%d, no output\n", a2ir.err_count);
spl_ast2ir_drop(&a2ir);
spl_sema_drop(&sema);
spl_ast_drop(&ast);
return 1;
}
if (dump == DUMP_IR) {
spl_ir_dump(&ir_builder.ir, &type);
// memory leak
return 0;
}
// spl_ast2ir_t a2ir;
// spl_ir_builder_t ir_builder;
// spl_ir_builder_init(&ir_builder);
// spl_ast2ir_init(&a2ir, &ir_builder, &sema);
// spl_ast2ir_run(&a2ir);
// if (a2ir.err_count) {
// printf("ast2ir errors=%d, no output\n", a2ir.err_count);
// spl_ast2ir_drop(&a2ir);
// spl_sema_drop(&sema);
// spl_ast_drop(&ast);
// return 1;
// }
// if (dump == DUMP_IR) {
// spl_ir_dump(&ir_builder.ir, &type);
// // memory leak
// return 0;
// }
spl_ir2vm_t ir2vm;
spl_ir2vm_init(&ir2vm, &a2ir.ir->ir, sema.type);
int rc = spl_ir2vm_run(&ir2vm);
if (rc != 0) {
printf("ir2vm error %d", rc);
return rc;
}
if (dump == DUMP_VM) {
spl_prog_dump(&ir2vm.prog);
// memory leak
return 0;
}
// spl_ir2vm_t ir2vm;
// spl_ir2vm_init(&ir2vm, &a2ir.ir->ir, sema.type);
// int rc = spl_ir2vm_run(&ir2vm);
// if (rc != 0) {
// printf("ir2vm error %d", rc);
// return rc;
// }
// if (dump == DUMP_VM) {
// spl_prog_dump(&ir2vm.prog);
// // memory leak
// return 0;
// }
spl_prog_store_to_file(outpath, &ir2vm.prog);
// spl_prog_store_to_file(outpath, &ir2vm.prog);
spl_ir2vm_drop(&ir2vm);
spl_ast2ir_drop(&a2ir);
spl_sema_drop(&sema);
spl_ast_drop(&ast);
// spl_ir2vm_drop(&ir2vm);
// spl_ast2ir_drop(&a2ir);
// spl_sema_drop(&sema);
// spl_ast_drop(&ast);
return 0;
}