stabilized entity sorting so cycle detection works better
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 26 Aug 2021 15:25:46 +0000 (10:25 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 26 Aug 2021 15:25:46 +0000 (10:25 -0500)
bin/onyx
include/onyxastnodes.h
misc/onyx-linux.sublime-build
src/onyx.c
src/onyxentities.c

index daf84b19fb9b26b1f329d2d04049e4d887bcd0ab..293031eefca239f98dc5ed2401c6fce20b697f8e 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 802fdea6b6077956b286c1a917ce6f3daa4b9e10..cfd5d1a55cc255d415826e067fcefdbf758955dc 100644 (file)
@@ -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];
index 333000a3177f22d2dbb5c70830c11fe67d7e7c6b..070cd18eb1f0e274f145894ba1266ac430ad20bc 100644 (file)
@@ -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]+)\\) (.*)",
index 75d7797baa566c381319aa96ad660a14f822d1ce..46c410a6a6246634677ff7ee42e35841b121456a 100644 (file)
@@ -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);
index 2c52c1f2ca39f76088d39554012a869c96f1d55f..1f3b84f5ce201103cf80c69ee37fe9dc292d71a5 100644 (file)
@@ -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);