From ac259bcc952929dd07a1c9244b2c3518c31b42f2 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 26 Dec 2021 22:33:33 +0100 Subject: [PATCH] rulegen:: queue extensions --- rulegen.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/rulegen.cpp b/rulegen.cpp index 5e1d6534..cdbed19f 100644 --- a/rulegen.cpp +++ b/rulegen.cpp @@ -81,6 +81,7 @@ static const flagtype w_known_distances = Flag(20); /*< with, use the actual dis static const flagtype w_no_smart_shortcuts = Flag(21); /*< disable the 'smart shortcut' optimization */ static const flagtype w_less_smart_retrace = Flag(22); /*< stop early when examining smart shortcut retraction */ static const flagtype w_less_smart_advance = Flag(23); /*< stop early when examining smart shortcut advancement */ +static const flagtype w_no_queued_extensions = Flag(24); /*< consider extensions one by one */ #endif EX flagtype flags = 0; @@ -1037,9 +1038,12 @@ void extend_analyzer(twalker cw_target, int dir, int id, int mism, twalker rg) { } gid = next_gid; } - if(mism == 0 && !added) - /* in rare cases this happens due to unification or something */ - throw rulegen_retry("no extension"); + if(mism == 0 && !added) { + if(debugflags & DF_GEOM) println(hlog, "no extension"); + if(flags & w_no_queued_extensions) + /* in rare cases this happens due to unification or something */ + throw rulegen_retry("no extension"); + } } #if HDR @@ -1305,6 +1309,14 @@ vector gen_rule(twalker cwmain, int id) { return cids; } +vector queued_extensions; + +void handle_queued_extensions() { + if(queued_extensions.empty()) return; + for(auto& r: queued_extensions) r(); + throw rulegen_retry("mismatch error"); + } + void rules_iteration_for(twalker& cw) { indenter ri(2); ufind(cw); @@ -1361,6 +1373,13 @@ void rules_iteration_for(twalker& cw) { println(hlog, "cellcount = ", tcellcount, "-", tunified, " codes discovered = ", isize(treestates)); } + auto& a = get_analyzer(cw); + int q = isize(a.spread); + if(!(flags & w_no_queued_extensions)) { + queued_extensions.push_back([&a, q, cwmain, z, k, mismatches, id] { extend_analyzer(cwmain, z, k, mismatches, treestates[id].giver); }); + return; + } + extend_analyzer(cwmain, z, k, mismatches, treestates[id].giver); mismatches++; @@ -1690,6 +1709,8 @@ EX void rules_iteration() { try_count++; debuglist = {}; + queued_extensions.clear(); + if((try_count & (try_count-1)) == 0) if(!(flags & w_no_restart)) { clean_data(); clean_parents(); @@ -1711,7 +1732,7 @@ EX void rules_iteration() { for(int i=0; i