From 11ae0eb82c431adafc10e165241f34879602ef2c Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 22 May 2022 16:04:21 -0500 Subject: [PATCH] changed how '#defined' works to be more reliable --- include/astnodes.h | 1 + src/onyx.c | 9 ++++++++- src/symres.c | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/astnodes.h b/include/astnodes.h index d0cdca9f..b337faa4 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -1534,6 +1534,7 @@ struct Context { // NOTE: This is defined in onyxwasm.h struct OnyxWasmModule* wasm_module; + b32 cycle_almost_detected : 1; b32 cycle_detected : 1; }; diff --git a/src/onyx.c b/src/onyx.c index c73d01ef..4343c816 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -234,6 +234,7 @@ static void context_init(CompileOptions* opts) { context.options = opts; context.cycle_detected = 0; + context.cycle_almost_detected = 0; OnyxFilePos internal_location = { 0 }; internal_location.filename = ""; @@ -607,7 +608,12 @@ static i32 onyx_compile() { else if (watermarked_node == ent) { if (ent->macro_attempts > highest_watermark) { entity_heap_insert_existing(&context.entities, ent); - dump_cycles(); + + if (context.cycle_almost_detected) { + dump_cycles(); + } else { + context.cycle_almost_detected = 1; + } } } else if (watermarked_node->macro_attempts < ent->macro_attempts) { @@ -616,6 +622,7 @@ static i32 onyx_compile() { } } else { watermarked_node = NULL; + context.cycle_almost_detected = 0; } if (onyx_has_errors()) return ONYX_COMPILER_PROGRESS_ERROR; diff --git a/src/symres.c b/src/symres.c index 5b3ea1bb..ad71c40e 100644 --- a/src/symres.c +++ b/src/symres.c @@ -899,11 +899,11 @@ static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) { static SymresStatus symres_directive_defined(AstDirectiveDefined** pdefined) { AstDirectiveDefined* defined = *pdefined; - b32 use_package_count = (context.entities.type_count[Entity_Type_Use_Package] == 0); + b32 has_to_be_resolved = context.cycle_almost_detected; resolved_a_symbol = 0; SymresStatus ss = symres_expression(&defined->expr); - if (use_package_count && ss != Symres_Success && !resolved_a_symbol) { + if (has_to_be_resolved && ss != Symres_Success && !resolved_a_symbol) { // The symbol definitely was not found and there is no chance that it could be found. defined->is_defined = 0; return Symres_Success; -- 2.25.1