From: Brendan Hansen Date: Tue, 9 Feb 2021 14:03:43 +0000 (-0600) Subject: made #solidify more resilient by adding per entity type retries X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=a8a51a783405f74cc65a2f5c8d8c956b63f932f5;p=onyx.git made #solidify more resilient by adding per entity type retries --- diff --git a/bin/onyx b/bin/onyx index 86d696fd..9ef4ddb8 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 069fdbfb..7ca8f47a 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -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; diff --git a/onyx.exe b/onyx.exe index febaea9b..faabecef 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/progs/poly_solidify.onyx b/progs/poly_solidify.onyx index d1ac05f4..021834b4 100644 --- a/progs/poly_solidify.onyx +++ b/progs/poly_solidify.onyx @@ -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) { diff --git a/src/onyx.c b/src/onyx.c index dfdbf481..549b0f22 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -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 diff --git a/src/onyxastnodes.c b/src/onyxastnodes.c index b2f2596b..0e630b3e 100644 --- a/src/onyxastnodes.c +++ b/src/onyxastnodes.c @@ -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)", diff --git a/src/onyxentities.c b/src/onyxentities.c index b965d57e..0b32a17f 100644 --- a/src/onyxentities.c +++ b/src/onyxentities.c @@ -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; diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 0778a940..fe65a426 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -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;