Compiler restructure, now can call compiler to compile files, fix error where strict type

was equal it's original type, working on examples
This commit is contained in:
Krzosa Karol
2022-06-27 13:13:32 +02:00
parent b4f38caabe
commit 2597e66135
9 changed files with 399 additions and 322 deletions

View File

@@ -184,6 +184,7 @@ For modules it's a bit different cause they should be distributed as valid.
#include "parsing.cpp"
#include "typechecking.h"
#include "typechecking.cpp"
#include "compiler.cpp"
#include "c_language_codegen.cpp"
#include "intermediate_representation.cpp"
@@ -222,50 +223,11 @@ int main(int argument_count, char **arguments){
test_bucket_arrays();
emit_line_directives = true;
String program_name = "programs/main.kl"_s;
String program_name = "examples/types_as_first_class_values.kl"_s;
if(argument_count > 1){
program_name = string_from_cstring(arguments[1]);
}
F64 total_time = os_time();
begin_compilation();
{
Ast_Module *module = add_module(0, pctx->intern("language.kl"_s));
insert_builtin_types_into_scope(module);
pctx->language_base_module = module;
parse_all_modules();
resolve_everything_in_module(module);
// @note: language stuff needs to be declared before type_info data
// so we mark where it ends
pctx->base_language_ordered_decl_len = pctx->ordered_decls.len;
Ast_Decl *any_decl = search_for_decl(module, pctx->intern("Any"_s));
assert(any_decl->type == type_type);
type_any = any_decl->type_val;
}
Ast_Module *module = add_module(0, pctx->intern(program_name), true);
parse_all_modules();
assert(module);
resolve_everything_in_module(module);
arena_clear(&pctx->stage_arena);
String result = get_compilation_result();
assert(os_write_file("program.c"_s, result));
{
Scratch scratch;
F64 begin = os_time();
String compiler_call = string_fmt(scratch, "clang.exe program.c -Wall -Wno-parentheses-equality -g -o a.exe -lgdi32 -luser32 -lwinmm");
system((const char *)compiler_call.str);
printf("\nclang = %f", os_time() - begin);
}
printf("\ntotal = %f", os_time() - total_time);
printf("\nparsing = %f", parsing_time_end - parsing_time_begin);
printf("\nresolving = %f", resolving_time_end - resolving_time_begin);
printf("\ngeneratin = %f", generating_time_end - generating_time_begin);
compile_file(program_name);
__debugbreak();
}