bugfix with including folders
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 10 Oct 2020 20:59:07 +0000 (15:59 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 10 Oct 2020 20:59:07 +0000 (15:59 -0500)
include/onyxastnodes.h
onyx
src/onyx.c
src/onyxentities.c
src/onyxutils.c

index e3ee250f03d89006fddb909fd59f213d27ce0b63..c9ee971650e52c65cd14053b94e67a809f8c9f1c 100644 (file)
@@ -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 3ff6901b7c8a7deccb05300f89e0af85ac22e438..6d9efa5920ce9895e7bacfb48bbb486db2408001 100755 (executable)
Binary files a/onyx and b/onyx differ
index d961cf5fa123d762f9a30c9c31fe4be221bd1d52..a65e53a7559ecb9faeae8966102971b53739a6c5 100644 (file)
@@ -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);
         }
     }
 
index 55a5a8003580e417033cd9dc19c8393a40976977..428b4bb2b05394d5e1bd4e8691cf4f708ab4194b 100644 (file)
@@ -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;
        }
 
index 2aa7b5e4f974d10f7ff02f5564c8abd2d66f0b8a..99c904c01fb4f7960f8abba89aea14495ccda9a4 100644 (file)
@@ -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 });