From: Brendan Hansen Date: Sat, 10 Oct 2020 20:59:07 +0000 (-0500) Subject: bugfix with including folders X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=c3251d8451f40a9e0ba383882eed718e0b5742b3;p=onyx.git bugfix with including folders --- diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index e3ee250f..c9ee9716 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -704,6 +704,8 @@ typedef enum EntityState { Entity_State_Count, } EntityState; +extern const char* entity_state_strings[Entity_State_Count]; + // NOTE: An Entity represents something will need to be // processed later down the pipeline. typedef enum EntityType { @@ -730,6 +732,8 @@ typedef enum EntityType { Entity_Type_Count, } EntityType; +extern const char* entity_type_strings[Entity_Type_Count]; + typedef struct Entity { EntityType type; EntityState state; diff --git a/onyx b/onyx index 3ff6901b..6d9efa59 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyx.c b/src/onyx.c index d961cf5f..a65e53a7 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -218,8 +218,7 @@ static void compiler_state_free(CompilerState* cs) { // another time. -brendanfh 2020/10/09 static char* lookup_included_file(CompilerState* cs, char* filename) { static char path[256]; - fori (i, 0, 256) - path[i] = 0; + fori (i, 0, 256) path[i] = 0; static char fn[128]; fori (i, 0, 128) fn[i] = 0; @@ -260,8 +259,8 @@ static ParseResults parse_source_file(CompilerState* compiler_state, bh_file_con static void merge_parse_results(CompilerState* compiler_state, ParseResults* results) { bh_arr_each(AstInclude *, include, results->includes) { EntityType et = Entity_Type_Include_File; - if ((*include)->kind == Ast_Kind_Include_Folder) - et = Entity_Type_Include_Folder; + + if ((*include)->kind == Ast_Kind_Include_Folder) et = Entity_Type_Include_Folder; entity_heap_insert(&compiler_state->prog_info.entities, (Entity) { .state = Entity_State_Parse, @@ -388,10 +387,6 @@ static void merge_parse_results(CompilerState* compiler_state, ParseResults* res static CompilerProgress process_source_file(CompilerState* compiler_state, char* filename) { if (bh_table_has(bh_file_contents, compiler_state->loaded_files, filename)) return ONYX_COMPILER_PROGRESS_SUCCESS; -#ifdef REPORT_TIMES - timer_stack_push(bh_aprintf(global_heap_allocator, "Parsing '%s'", filename)); -#endif - bh_file file; bh_file_error err = bh_file_open(&file, filename); @@ -424,10 +419,6 @@ static CompilerProgress process_source_file(CompilerState* compiler_state, char* ParseResults results = parse_source_file(compiler_state, &fc); merge_parse_results(compiler_state, &results); -#ifdef REPORT_TIMES - timer_stack_pop(); -#endif - if (onyx_has_errors()) { return ONYX_COMPILER_PROGRESS_FAILED_PARSE; } else { @@ -441,8 +432,8 @@ static b32 process_include_entity(CompilerState* compiler_state, Entity* ent) { if (include->kind == Ast_Kind_Include_File) { char* filename = lookup_included_file(compiler_state, include->name); - char* formatted_name = bh_strdup(global_heap_allocator, filename); + process_source_file(compiler_state, formatted_name); } else if (include->kind == Ast_Kind_Include_Folder) { @@ -453,6 +444,10 @@ static b32 process_include_entity(CompilerState* compiler_state, Entity* ent) { } static b32 process_entity(CompilerState* compiler_state, Entity* ent) { + // bh_printf("Processing entity: %s %s\n", + // entity_state_strings[ent->state], + // entity_type_strings[ent->type]); + i32 changed = 1; switch (ent->state) { @@ -489,33 +484,25 @@ static i32 onyx_compile(CompilerState* compiler_state) { Entity ent = entity_heap_top(&compiler_state->prog_info.entities); assert(ent.state == Entity_State_Parse_Builtin); - DEBUG_HERE; process_entity(compiler_state, &ent); - if (onyx_has_errors()) return ONYX_COMPILER_PROGRESS_ERROR; entity_heap_remove_top(&compiler_state->prog_info.entities); initialize_builtins(compiler_state->ast_alloc, &compiler_state->prog_info); - semstate.program = &compiler_state->prog_info; } while (!bh_arr_is_empty(compiler_state->prog_info.entities.entities)) { Entity ent = entity_heap_top(&compiler_state->prog_info.entities); + entity_heap_remove_top(&compiler_state->prog_info.entities); b32 changed = process_entity(compiler_state, &ent); - if (onyx_has_errors()) { - return ONYX_COMPILER_PROGRESS_ERROR; - } + if (onyx_has_errors()) return ONYX_COMPILER_PROGRESS_ERROR; - if (changed) { - if (ent.state == Entity_State_Finalized) { - entity_heap_remove_top(&compiler_state->prog_info.entities); - } else { - entity_heap_change_top(&compiler_state->prog_info.entities, ent); - } + if (changed && ent.state != Entity_State_Finalized) { + entity_heap_insert(&compiler_state->prog_info.entities, ent); } } diff --git a/src/onyxentities.c b/src/onyxentities.c index 55a5a800..428b4bb2 100644 --- a/src/onyxentities.c +++ b/src/onyxentities.c @@ -29,13 +29,13 @@ static void eh_shift_down(EntityHeap* entities, i32 index) { i32 l = eh_lchild(index); if (l < bh_arr_length(entities->entities) - && entity_compare(&entities->entities[l], &entities->entities[min_index]) <= 0) { + && entity_compare(&entities->entities[l], &entities->entities[min_index]) < 0) { min_index = l; } i32 r = eh_rchild(index); if (r < bh_arr_length(entities->entities) - && entity_compare(&entities->entities[r], &entities->entities[min_index]) <= 0) { + && entity_compare(&entities->entities[r], &entities->entities[min_index]) < 0) { min_index = r; } diff --git a/src/onyxutils.c b/src/onyxutils.c index 2aa7b5e4..99c904c0 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -95,6 +95,37 @@ const char* onyx_ast_node_kind_string(AstKind kind) { return ast_node_names[kind]; } +const char* entity_state_strings[Entity_State_Count] = { + "Error", + "Parse Builtin", + "Parse", + "Resolve_Symbols", + "Check_Types", + "Code_Gen", + "Finalized", +}; + +const char* entity_type_strings[Entity_Type_Count] = { + "Unknown", + "Include Folder", + "Include File", + "Use Package", + "String Literal", + "File Contents", + "Enum", + "Type Alias", + "Memory Reservation", + "Polymorphic Proc", + "Foreign_Function Header", + "Foreign_Global Header", + "Function Header", + "Global Header", + "Expression", + "Global", + "Overloaded_Function", + "Function", +}; + void program_info_init(ProgramInfo* prog, bh_allocator alloc) { prog->global_scope = scope_create(alloc, NULL, (OnyxFilePos) { 0 });