From: Brendan Hansen Date: Thu, 26 Aug 2021 15:25:46 +0000 (-0500) Subject: stabilized entity sorting so cycle detection works better X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=dfa3a9ce328a7ef09f81ae80d165037217ffc4cb;p=onyx.git stabilized entity sorting so cycle detection works better --- diff --git a/bin/onyx b/bin/onyx index daf84b19..293031ee 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 802fdea6..cfd5d1a5 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -1111,6 +1111,8 @@ typedef enum EntityType { extern const char* entity_type_strings[Entity_Type_Count]; typedef struct Entity { + u32 id; + EntityType type; EntityState state; @@ -1149,6 +1151,7 @@ typedef struct Entity { typedef struct EntityHeap { bh_arena entity_arena; bh_arr(Entity *) entities; + i32 next_id; i32 state_count[Entity_State_Count]; i32 type_count[Entity_Type_Count]; diff --git a/misc/onyx-linux.sublime-build b/misc/onyx-linux.sublime-build index 333000a3..070cd18e 100644 --- a/misc/onyx-linux.sublime-build +++ b/misc/onyx-linux.sublime-build @@ -1,6 +1,6 @@ { "target": "exec", - "shell_cmd": "/usr/bin/onyx -V -o \"${folder}/${file_base_name}.wasm\" \"$file\"", + "shell_cmd": "/usr/bin/onyx -V --no-colors -o \"${folder}/${file_base_name}.wasm\" \"$file\"", "working_dir": "${folder}", "selector": "source.onyx", "file_regex": "^\\(([^:]+):([0-9]+),([0-9]+)\\) (.*)", diff --git a/src/onyx.c b/src/onyx.c index 75d7797b..46c410a6 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -184,6 +184,7 @@ static void context_init(CompileOptions* opts) { bh_table_init(global_heap_allocator, context.packages, 16); // NOTE: This will be initialized upon the first call to entity_heap_insert. + context.entities.next_id = 0; context.entities.entities = NULL; onyx_errors_init(&context.loaded_files); diff --git a/src/onyxentities.c b/src/onyxentities.c index 2c52c1f2..1f3b84f5 100644 --- a/src/onyxentities.c +++ b/src/onyxentities.c @@ -21,9 +21,10 @@ static i32 entity_compare(Entity* e1, Entity* e2) { return (i32) e1->state - (i32) e2->state; else if (e1->type != e2->type) return (i32) e1->type - (i32) e2->type; - else + else if (e1->micro_attempts != e2->micro_attempts) return (i32) (e1->micro_attempts - e2->micro_attempts); - + else + return (i32) (e1->id - e2->id); } #define eh_parent(index) (((index) - 1) / 2) @@ -148,6 +149,7 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s Entity* entity; Entity ent; + ent.id = entities->next_id++; ent.state = Entity_State_Resolve_Symbols; ent.package = package; ent.scope = scope; @@ -189,6 +191,7 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s ENTITY_INSERT(ent); ((AstFunction *) node)->entity_header = entity; + ent.id = entities->next_id++; ent.type = Entity_Type_Function; ent.function = (AstFunction *) node; ENTITY_INSERT(ent); @@ -215,6 +218,7 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s ent.global = (AstGlobal *) node; ENTITY_INSERT(ent); + ent.id = entities->next_id++; ent.type = Entity_Type_Global; ent.global = (AstGlobal *) node; ENTITY_INSERT(ent); @@ -241,6 +245,8 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s ent.type_alias = (AstType *) node; ENTITY_INSERT(ent); ((AstStructType *) node)->entity_defaults = entity; + + ent.id = entities->next_id++; // fallthrough } @@ -282,6 +288,7 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s ent.mem_res = (AstMemRes *) node; ENTITY_INSERT(ent); + ent.id = entities->next_id++; ent.type = Entity_Type_Memory_Reservation; ent.mem_res = (AstMemRes *) node; ENTITY_INSERT(ent);