made #solidify more resilient by adding per entity type retries
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 9 Feb 2021 14:03:43 +0000 (08:03 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 9 Feb 2021 14:03:43 +0000 (08:03 -0600)
bin/onyx
include/onyxastnodes.h
onyx.exe
progs/poly_solidify.onyx
src/onyx.c
src/onyxastnodes.c
src/onyxentities.c
src/onyxsymres.c

index 86d696fd0f8e7971b8d91e93f52cdab107ebe790..9ef4ddb892a548600ff5eb2733a5bd81e2d2f74c 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 069fdbfb1b9e8e1d762b7d66c8fa58211e9e2418..7ca8f47aed78297c0c0d9082a4d301c321e47d42 100644 (file)
@@ -935,7 +935,10 @@ extern const char* entity_type_strings[Entity_Type_Count];
 typedef struct Entity {
     EntityType type;
     EntityState state;
-    u32 attempts;
+
+    // TODO: Document this!
+    u16 macro_attempts;
+    u16 micro_attempts;
 
     b32 entered_in_queue : 1;
 
index febaea9b56054d6ed071be86666d79d4a89bf194..faabecef8fb3749912449cea678f51a749f5f564 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index d1ac05f42fbdcb3ece41eca954d1718f619cf533..021834b4fedb218b05405adeb5c3bd0f2f2906b2 100644 (file)
@@ -6,8 +6,8 @@ max_f32 :: #solidify math.max_poly { T = f32 };
 
 compose :: proc (a: $A, f: proc (A) -> $B, g: proc (B) -> $C) -> C do return g(f(a));
 
-specific_compose_1 :: #solidify specific_compose_0 { A = f32 };
 specific_compose_0 :: #solidify compose { B = f32 };
+specific_compose_1 :: #solidify specific_compose_0 { A = f32 };
 specific_compose_2 :: #solidify specific_compose_1 { C = f64 };
 
 main :: proc (args: [] cstr) {
index dfdbf4813748c12d19770100fae0c64e09ec058b..549b0f22812a9d9d3770cb9545953076be724bb9 100644 (file)
@@ -276,19 +276,21 @@ static void process_load_entity(Entity* ent) {
 static b32 process_entity(Entity* ent) {
     if (context.options->verbose_output == 3) {
         if (ent->expr && ent->expr->token)
-            printf("%s | %s (%d) | %s:%i:%i\n",
+            printf("%s | %s (%d, %d) | %s:%i:%i\n",
                    entity_state_strings[ent->state],
                    entity_type_strings[ent->type],
-                   (u32) ent->attempts,
+                   (u32) ent->macro_attempts,
+                   (u32) ent->micro_attempts,
                    ent->expr->token->pos.filename,
                    ent->expr->token->pos.line,
                    ent->expr->token->pos.column);
         
         else if (ent->expr)
-            printf("%s | %s (%d) \n",
+            printf("%s | %s (%d, %d) \n",
                    entity_state_strings[ent->state],
                    entity_type_strings[ent->type],
-                   (u32) ent->attempts);
+                   (u32) ent->macro_attempts,
+                   (u32) ent->micro_attempts);
     }
     
     // CLEANUP: There should be a nicer way to track if the builtins have
index b2f2596b9ed05eab5600d6c133374eba19b991ac..0e630b3e7d737e64cd19642326b8124725853a69 100644 (file)
@@ -121,6 +121,7 @@ const char* entity_state_strings[Entity_State_Count] = {
 
 const char* entity_type_strings[Entity_Type_Count] = {
     "Unknown",
+    "Error",
     "Add to Load Path",
     "Load File",
     "Binding (Declaration)",
index b965d57ec66352cd025436635d75ba565a590984..0b32a17f652765135b2babbafbcc71229ddc5d69 100644 (file)
@@ -16,11 +16,13 @@ static i32 entity_compare(Entity* e1, Entity* e2) {
     if (phase1 != phase2 || phase1 != 2) {
         if (e1->state != e2->state)
             return (i32) e1->state - (i32) e2->state;
-        else
+        else if (e1->type != e2->type)
             return (i32) e1->type - (i32) e2->type;
+        else
+            return (i32) (e1->micro_attempts - e2->micro_attempts);
 
     } else {
-        return (i32) e1->attempts - (i32) e2->attempts;
+        return (i32) e1->macro_attempts - (i32) e2->macro_attempts;
     }
 }
 
@@ -72,7 +74,8 @@ Entity* entity_heap_register(EntityHeap* entities, Entity e) {
     bh_allocator alloc = bh_arena_allocator(&entities->entity_arena);
     Entity* entity = bh_alloc_item(alloc, Entity);
     *entity = e;
-    entity->attempts = 0;
+    entity->macro_attempts = 0;
+    entity->micro_attempts = 0;
     entity->entered_in_queue = 0;
 
     return entity;
index 0778a940144c90c10c886e9c17d65f2fd859309a..fe65a42625c3e5886849354daa637ba10b34c297 100644 (file)
@@ -16,12 +16,17 @@ static b32 report_unresolved_symbols = 1;
     if (ss > Symres_Errors_Start) return ss;         \
     } while (0)
 
+#define SYMRES_IF_SYMBOL(node_ptr) do { \
+    if ((*(node_ptr))->kind == Ast_Kind_Symbol) SYMRES(expression, node_ptr); \
+    } while (0);
+
 typedef enum SymresStatus {
     Symres_Success,
     Symres_Complete,
 
     Symres_Errors_Start,
-    Symres_Yield,
+    Symres_Yield_Macro,
+    Symres_Yield_Micro,
     Symres_Error,
 } SymresStatus;
 
@@ -75,7 +80,7 @@ static SymresStatus symres_symbol(AstNode** symbol_node) {
 
             return Symres_Error;
         } else {
-            return Symres_Yield;
+            return Symres_Yield_Macro;
         }
 
     } else {
@@ -614,12 +619,17 @@ cannot_use:
 
 static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) {
     AstDirectiveSolidify* solid = *psolid;
-    if (solid->resolved_proc != NULL)
+    if (solid->resolved_proc != NULL) {
         *psolid = (AstDirectiveSolidify *) solid->resolved_proc;
+        return Symres_Success;
+    }
 
     SYMRES(expression, (AstTyped **) &solid->poly_proc);
     if (solid->poly_proc && solid->poly_proc->kind == Ast_Kind_Directive_Solidify) {
-        solid->poly_proc = (AstPolyProc *) ((AstDirectiveSolidify *) solid->poly_proc)->resolved_proc;
+        AstPolyProc* potentially_resolved_proc = (AstPolyProc *) ((AstDirectiveSolidify *) solid->poly_proc)->resolved_proc;
+        if (!potentially_resolved_proc) return Symres_Yield_Micro;
+
+        solid->poly_proc = potentially_resolved_proc;
     }
     
     if (!solid->poly_proc || solid->poly_proc->kind != Ast_Kind_Polymorphic_Proc) {
@@ -868,7 +878,7 @@ static SymresStatus symres_use_package(AstUsePackage* package) {
             onyx_report_error(package->package_name->pos, "package not found in included source files");
             return Symres_Error;
         } else {
-            return Symres_Yield;
+            return Symres_Yield_Macro;
         }
     }
 
@@ -893,7 +903,7 @@ static SymresStatus symres_use_package(AstUsePackage* package) {
                     onyx_report_error((*alias)->token->pos, "This symbol was not found in this package.");
                     return Symres_Error;
                 } else {
-                    return Symres_Yield;
+                    return Symres_Yield_Macro;
                 }
             }
 
@@ -1080,8 +1090,9 @@ void symres_entity(Entity* ent) {
         default: break;
     }
 
-    if (ss == Symres_Success) ent->state = next_state;
-    if (ss == Symres_Yield)   ent->attempts++;
+    if (ss == Symres_Success)     ent->state = next_state;
+    if (ss == Symres_Yield_Macro) ent->macro_attempts++;
+    if (ss == Symres_Yield_Micro) ent->micro_attempts++;
 
     if (ent->scope) curr_scope = old_scope;
     curr_package = NULL;