Compiling and testing multiple files

This commit is contained in:
Krzosa Karol
2022-06-27 14:01:22 +02:00
parent 7b343ca642
commit a363a5e982
4 changed files with 62 additions and 31 deletions

View File

@@ -10,7 +10,7 @@ function void
begin_compilation(){ begin_compilation(){
init_ctx_time_begin = os_time(); init_ctx_time_begin = os_time();
OS_Heap *heap = exp_alloc_type(&pernament_arena, OS_Heap, AF_ZeroMemory); OS_Heap *heap = exp_alloc_type(&pernament_arena, OS_Heap, AF_ZeroMemory);
*heap = win32_os_heap_create(false, mib(4), 0); *heap = win32_os_heap_create(false, mib(4), 0, "Compiler heap"_s);
Parse_Ctx *ctx = exp_alloc_type(&pernament_arena, Parse_Ctx, AF_ZeroMemory); Parse_Ctx *ctx = exp_alloc_type(&pernament_arena, Parse_Ctx, AF_ZeroMemory);
parse_init(ctx, &pernament_arena, heap); parse_init(ctx, &pernament_arena, heap);
init_ctx_time_end = os_time(); init_ctx_time_end = os_time();
@@ -20,6 +20,7 @@ function void
destroy_compiler(){ destroy_compiler(){
exp_destroy(pctx->heap); exp_destroy(pctx->heap);
exp_free_all(pctx->perm); exp_free_all(pctx->perm);
exp_destroy(&pctx->stage_arena);
} }
function void function void
@@ -225,11 +226,17 @@ compile_file_to_string(String filename){
return result; return result;
} }
const U32 COMPILE_NULL = 0x0; const U32 COMPILE_NULL = 0x0;
const U32 COMPILE_PRINT_STATS = 0x1; const U32 COMPILE_PRINT_STATS = 0x1;
const U32 COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY = 0x2;
const U32 COMPILE_AND_RUN = 0x4;
function void function void
compile_file(String filename, U32 compile_flags = COMPILE_NULL){ compile_file(String filename, U32 compile_flags = COMPILE_NULL){
if(is_flag_set(compile_flags, COMPILE_AND_RUN)){
log_info("\n%Q - ", filename);
}
String result = compile_file_to_string(filename); String result = compile_file_to_string(filename);
assert(os_write_file("program.c"_s, result)); assert(os_write_file("program.c"_s, result));
@@ -239,12 +246,33 @@ compile_file(String filename, U32 compile_flags = COMPILE_NULL){
system((const char *)compiler_call.str); system((const char *)compiler_call.str);
F64 end = os_time(); F64 end = os_time();
if(compile_flags & COMPILE_PRINT_STATS){ if(is_flag_set(compile_flags, COMPILE_PRINT_STATS)){
printf("\ntotal = %f", os_time() - total_time); log_info("\ntotal = %f", os_time() - total_time);
printf("\nclang = %f", end - begin); log_info("\nclang = %f", end - begin);
printf("\nparsing = %f", parsing_time_end - parsing_time_begin); log_info("\nparsing = %f", parsing_time_end - parsing_time_begin);
printf("\nresolving = %f", resolving_time_end - resolving_time_begin); log_info("\nresolving = %f", resolving_time_end - resolving_time_begin);
printf("\ngeneratin = %f", generating_time_end - generating_time_begin); log_info("\ngeneratin = %f", generating_time_end - generating_time_begin);
} }
if(is_flag_set(compile_flags, COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY)){
Arena *p = (Arena *)pctx->perm;
Arena *stage = (Arena *)&pctx->stage_arena;
log_info("\nPernament arena len: %llu commit: %llu", p->len, p->memory.commit);
log_info("\nStage arena len: %llu commit: %llu", stage->len, stage->memory.commit);
log_info("\nScratch1 len: %llu commit: %llu", thread_ctx.scratch[0].len, thread_ctx.scratch[0].memory.commit);
log_info("\nScratch2 len: %llu commit: %llu", thread_ctx.scratch[1].len, thread_ctx.scratch[1].memory.commit);
}
if(is_flag_set(compile_flags, COMPILE_AND_RUN)){
int result = system("a.exe");
assert(result != -1);
if(result == 0){
log_info(PRINTF_GREEN "OK!" PRINTF_RESET);
}
if(result != 0){
log_info(PRINTF_RED "ERROR!" PRINTF_RESET);
}
}
destroy_compiler(); destroy_compiler();
} }

View File

@@ -21,30 +21,32 @@ main :: (): int
else;; assert(false, "We expected S64 here! What a boomer!") else;; assert(false, "We expected S64 here! What a boomer!")
//
// @todo: This should work
//
// any_thing: Any = 10
// _gcvt :: #foreign (value: F64, digits: int, buffer: *char): *char //
// print_float :: (value: F64) // Any type allows us to combine a value pointer and
// buff: [100]char // it's corresponding type_id
// _gcvt(value, 10, &buff[0]) //
// OutputDebugStringA(&buff[0]) value_to_be_wrapped := 10
any_value: Any = value_to_be_wrapped
if any_value.type == S64
// Void pointers get implicitly cast
value: *S64 = any_value.data
*value = 20
elif any_value.type == int
value: *int = any_value.data
*value = 30
elif any_value.type == char;; assert(false, "No bueno")
assert(value_to_be_wrapped == 20)
// print_type :: (t: Type)
// type_info := get_type_info(t)
// if !type_info
// return
// switch type_info.kind
// Type_Info_Kind.S64, Type_Info_Kind.S32, Type_Info_Kind.S16, Type_Info_Kind.S8, Type_Info_Kind.INT
// OutputDebugStringA("Integer")
// Type_Info_Kind.U64, Type_Info_Kind.U32, Type_Info_Kind.U16, Type_Info_Kind.U8
// OutputDebugStringA("Unsigned")
// Type_Info_Kind.F64, Type_Info_Kind.F32
// OutputDebugStringA("Float")
// Type_Info_Kind.POINTER
// OutputDebugStringA("*")
// print_type(type_info.base_type)
// default;; OutputDebugStringA("Unknown")
// print :: (a: Any) // print :: (a: Any)
// type_info := get_type_info(a.type) // type_info := get_type_info(a.type)

View File

@@ -228,7 +228,7 @@ int main(int argument_count, char **arguments){
program_name = string_from_cstring(arguments[1]); program_name = string_from_cstring(arguments[1]);
} }
compile_file("examples/runtime_type_information.kl"_s); compile_file("examples/runtime_type_information.kl"_s, COMPILE_AND_RUN);
compile_file("examples/types_as_first_class_values.kl"_s); compile_file("examples/types_as_first_class_values.kl"_s, COMPILE_AND_RUN);
__debugbreak(); __debugbreak();
} }

View File

@@ -4,6 +4,7 @@ function void
print_token_line(Token *token){ print_token_line(Token *token){
if(!token) return; if(!token) return;
#define PRINTF_GREEN "\033[32m"
#define PRINTF_RED "\033[31m" #define PRINTF_RED "\033[31m"
#define PRINTF_RESET "\033[0m" #define PRINTF_RESET "\033[0m"