Compile string, working on scopes

This commit is contained in:
Krzosa Karol
2022-05-25 15:17:08 +02:00
parent b945f3affd
commit f4c05923c9
9 changed files with 125 additions and 136 deletions

View File

@@ -1,6 +1,6 @@
#define genln(...) do{printf("\n"); gen_indent(); gen(__VA_ARGS__); }while(0)
#define gen(...) printf(__VA_ARGS__)
#define gen(...) pctx->gen.addf(__VA_ARGS__)
#define genln(...) do{gen("\n"); gen_indent(); gen(__VA_ARGS__); }while(0)
global S32 global_indent;
function void
@@ -34,7 +34,7 @@ gen_simple_decl_prefix(Ast_Resolved_Type *ast){
function void
gen_simple_decl_postfix(Ast_Resolved_Type *ast){
switch(ast->kind){
switch(ast->kind){
case TYPE_Int: break;
case TYPE_Bool: break;
case TYPE_Unsigned: break;
@@ -195,7 +195,7 @@ gen_ast(Ast *ast){
}
Ast_Begin(AST_CONST, Ast_Decl){
Sym *sym = sym_get(node->name);
Sym *sym = resolved_get(node);
if(sym->type->kind == TYPE_Lambda){
if(node->var.expr->kind == AST_LAMBDA){
@@ -246,19 +246,36 @@ gen_ast(Ast *ast){
}
}
function void
test_gen(){
TEST_PARSER();
String filename = "globals.kl"_s;
String file_content = os_read_file(scratch, filename);
lex_restream(&ctx, file_content, filename);
function String
compile_string(String filecontent, String filename = "default_name"_s){
Scratch scratch(thread_ctx.scratch);
OS_Heap heap = win32_os_heap_create(false, mib(4), 0);
Parse_Ctx ctx = {};
ctx.init(scratch, &heap);
pctx = &ctx;
lex_restream(&ctx, filecontent, filename);
Ast_Package *result = parse_file();
sym_insert_builtins();
eval_decl(result);
gen(R"==(
gen(R"==(//-------------------------------
#define NULL_POINTER 0
#define NULL_LAMBDA 0
)==");
//-------------------------------)==");
eval_decl(result);
gen_ast(result);
__debugbreak();
exp_destroy(&heap);
String string_result = string_flatten(scratch, &pctx->gen);
return string_result;
}
function String
compile_file(String filename){
Scratch scratch;
String filecontent = os_read_file(scratch, filename);
String result = compile_string(filecontent, filename);
return result;
}