diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-12-14 01:30:56 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-12-15 10:20:41 -0800 |
commit | 601ff75bc76b5cdc76d54a399dd764cf399822e3 (patch) | |
tree | c92fd13ea83e0d666f1986f52ffc032b3955ec91 /057static_dispatch.cc | |
parent | e167fdf43cedea8b96690246734d652643fe1bd1 (diff) | |
download | mu-601ff75bc76b5cdc76d54a399dd764cf399822e3.tar.gz |
three bugs fixed
- notes bug in edit/ triggers in immutable but not master branch bug triggered by changes to layer 059: we're finding an unspecialized call to 'length' in 'append_6' hard to debug because trace isn't complete just bring out the big hammer: use a new log file length_2 from recipes.mu is not being deleted (bug #1) so reload doesn't switch length to length_2 when variant_already_exists (bug #2) so we end up saving in Recipe for a primitive ordinal so no valid specialization is found for 'length' (bug #3) why doesn't it trigger in a non-interactive scenario? argh, wasn't checking for an empty line at end. ok, confidence restored.
Diffstat (limited to '057static_dispatch.cc')
-rw-r--r-- | 057static_dispatch.cc | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/057static_dispatch.cc b/057static_dispatch.cc index 60221453..222bd97f 100644 --- a/057static_dispatch.cc +++ b/057static_dispatch.cc @@ -21,10 +21,10 @@ recipe test a:number, b:number -> z:number [ map<string, vector<recipe_ordinal> > Recipe_variants; :(before "End One-time Setup") put(Recipe_variants, "main", vector<recipe_ordinal>()); // since we manually added main to Recipe_ordinal -:(before "End Setup") +:(before "Clear Other State For Recently_added_recipes") for (map<string, vector<recipe_ordinal> >::iterator p = Recipe_variants.begin(); p != Recipe_variants.end(); ++p) { for (long long int i = 0; i < SIZE(p->second); ++i) { - if (p->second.at(i) >= Reserved_for_tests) + if (find(Recently_added_recipes.begin(), Recently_added_recipes.end(), p->second.at(i)) != Recently_added_recipes.end()) p->second.at(i) = -1; // just leave a ghost } } @@ -32,30 +32,41 @@ for (map<string, vector<recipe_ordinal> >::iterator p = Recipe_variants.begin(); :(before "End Load Recipe Header(result)") if (contains_key(Recipe_ordinal, result.name)) { const recipe_ordinal r = get(Recipe_ordinal, result.name); - if ((!contains_key(Recipe, r) || get(Recipe, r).has_header) - && !variant_already_exists(result)) { - string new_name = next_unused_recipe_name(result.name); - put(Recipe_ordinal, new_name, Next_recipe_ordinal++); - get_or_insert(Recipe_variants, result.name).push_back(get(Recipe_ordinal, new_name)); +//? LOG << "checking " << r << " " << result.name << '\n'; +//? cerr << result.name << ": " << contains_key(Recipe, r) << (contains_key(Recipe, r) ? get(Recipe, r).has_header : 0) << matching_variant_name(result) << '\n'; + if (!contains_key(Recipe, r) || get(Recipe, r).has_header) { + string new_name = matching_variant_name(result); + if (new_name.empty()) { + // variant doesn't already exist + new_name = next_unused_recipe_name(result.name); +//? LOG << "adding a variant of " << result.name << ": " << new_name << " is now " << Next_recipe_ordinal << '\n'; + put(Recipe_ordinal, new_name, Next_recipe_ordinal++); + get_or_insert(Recipe_variants, result.name).push_back(get(Recipe_ordinal, new_name)); + } result.name = new_name; +//? cerr << "=> " << new_name << '\n'; } } else { // save first variant +//? LOG << "saving first variant of " << result.name << ": " << Next_recipe_ordinal << '\n'; put(Recipe_ordinal, result.name, Next_recipe_ordinal++); get_or_insert(Recipe_variants, result.name).push_back(get(Recipe_ordinal, result.name)); } :(code) -bool variant_already_exists(const recipe& rr) { +string matching_variant_name(const recipe& rr) { const vector<recipe_ordinal>& variants = get_or_insert(Recipe_variants, rr.name); for (long long int i = 0; i < SIZE(variants); ++i) { - if (contains_key(Recipe, variants.at(i)) - && all_reagents_match(rr, get(Recipe, variants.at(i)))) { - return true; - } +//? LOG << "checking variant " << variants.at(i) << " of " << rr.name << '\n'; + if (!contains_key(Recipe, variants.at(i))) continue; + const recipe& candidate = get(Recipe, variants.at(i)); + if (!all_reagents_match(rr, candidate)) continue; +//? LOG << " exists\n"; + return candidate.name; } - return false; +//? LOG << " does not exist\n"; + return ""; } bool all_reagents_match(const recipe& r1, const recipe& r2) { @@ -457,3 +468,27 @@ string header_label(recipe_ordinal r) { out << ' ' << caller.products.at(i).original_string; return out.str(); } + +:(scenario reload_variant_retains_other_variants) +recipe main [ + 1:number <- copy 34 + 2:number <- foo 1:number +] +recipe foo x:number -> y:number [ + local-scope + load-ingredients + reply 34 +] +recipe foo x:address:number -> y:number [ + local-scope + load-ingredients + reply 35 +] +recipe! foo x:address:number -> y:number [ + local-scope + load-ingredients + reply 36 +] ++mem: storing 34 in location 2 +$error: 0 +$warn: 0 |