diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-12-28 13:02:06 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-12-28 13:02:06 -0800 |
commit | 5a49cfeccb068b0e1cbe6eef539eda2eacd6273f (patch) | |
tree | c96a2b8478fd6afb336d13fd710005766c3866f6 | |
parent | 2ef4400dfeae13d02165a551551c5e4b1d399470 (diff) | |
download | mu-5a49cfeccb068b0e1cbe6eef539eda2eacd6273f.tar.gz |
2553 - keep failed specializations from generating spurious errors
Thanks Caleb Couch.
-rw-r--r-- | 011load.cc | 2 | ||||
-rw-r--r-- | 057static_dispatch.cc | 6 | ||||
-rw-r--r-- | 059shape_shifting_recipe.cc | 10 | ||||
-rw-r--r-- | 080display.cc | 1 | ||||
-rw-r--r-- | 091run_interactive.cc | 1 |
5 files changed, 3 insertions, 17 deletions
diff --git a/011load.cc b/011load.cc index 59d667a9..95631151 100644 --- a/011load.cc +++ b/011load.cc @@ -61,7 +61,6 @@ long long int slurp_recipe(istream& in) { // End recipe Body(result) get_or_insert(Recipe, get(Recipe_ordinal, result.name)) = result; // track added recipes because we may need to undo them in tests; see below -//? LOG << "recently added recipe: " << result.name << ' ' << get(Recipe_ordinal, result.name) << '\n'; Recently_added_recipes.push_back(get(Recipe_ordinal, result.name)); return get(Recipe_ordinal, result.name); } @@ -245,7 +244,6 @@ void clear_recently_added_recipes() { if (Recently_added_recipes.at(i) >= Reserved_for_tests // don't renumber existing recipes, like 'interactive' && contains_key(Recipe, Recently_added_recipes.at(i))) // in case previous test had duplicate definitions Recipe_ordinal.erase(get(Recipe, Recently_added_recipes.at(i)).name); -//? LOG << "erase recipe " << Recently_added_recipes.at(i) << ' ' << get(Recipe, Recently_added_recipes.at(i)).name << '\n'; Recipe.erase(Recently_added_recipes.at(i)); } // Clear Other State For Recently_added_recipes diff --git a/057static_dispatch.cc b/057static_dispatch.cc index b57ff4c9..ed656f0c 100644 --- a/057static_dispatch.cc +++ b/057static_dispatch.cc @@ -32,14 +32,12 @@ 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); -//? 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)); } @@ -49,7 +47,6 @@ if (contains_key(Recipe_ordinal, result.name)) { } 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)); } @@ -58,14 +55,11 @@ else { 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) { -//? 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; } -//? LOG << " does not exist\n"; return ""; } diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc index 1edaf32b..6cce844f 100644 --- a/059shape_shifting_recipe.cc +++ b/059shape_shifting_recipe.cc @@ -74,32 +74,28 @@ if (best_score == -1) { if (exemplar) { //? cerr << "specializing " << inst.name << '\n'; trace(9992, "transform") << "found variant to specialize: " << exemplar << ' ' << get(Recipe, exemplar).name << end(); -//? LOG << "found variant to specialize: " << exemplar << ' ' << header(get(Recipe, exemplar)) << '\n'; recipe_ordinal new_recipe_ordinal = new_variant(exemplar, inst, caller_recipe); + if (new_recipe_ordinal == 0) goto done_constructing_variant; variants.push_back(new_recipe_ordinal); // perform all transforms on the new specialization const string& new_name = get(Recipe, variants.back()).name; trace(9992, "transform") << "transforming new specialization: " << new_name << end(); -//? LOG << "transforming new specialization: " << header(get(Recipe, variants.back())) << '\n'; for (long long int t = 0; t < SIZE(Transform); ++t) { (*Transform.at(t))(new_recipe_ordinal); } get(Recipe, new_recipe_ordinal).transformed_until = SIZE(Transform)-1; -//? LOG << "replacing " << inst.name << " with " << get(Recipe, variants.back()).name << '\n'; inst.name = get(Recipe, variants.back()).name; trace(9992, "transform") << "new specialization: " << inst.name << end(); -//? LOG << "new specialization: " << inst.name << '\n'; } + done_constructing_variant:; } //: make sure we have no unspecialized shape-shifting recipes being called //: before running mu programs :(before "End Instruction Operation Checks") -//? LOG << inst.operation << " " << contains_key(Recipe, inst.operation) << '\n'; if (contains_key(Recipe, inst.operation) && inst.operation >= MAX_PRIMITIVE_RECIPES && any_type_ingredient_in_header(inst.operation)) { -//? LOG << header(caller) << "instruction " << inst.name << " has no valid specialization\n"; raise_error << maybe(caller.name) << "instruction " << inst.name << " has no valid specialization\n" << end(); return; } @@ -284,7 +280,7 @@ recipe_ordinal new_variant(recipe_ordinal exemplar, const instruction& inst, con if (!error) replace_type_ingredients(new_recipe, mappings); for (map<string, const string_tree*>::iterator p = mappings.begin(); p != mappings.end(); ++p) delete p->second; - if (error) return exemplar; + if (error) return 0; // todo: delete new_recipe_ordinal from Recipes and other global state } ensure_all_concrete_types(new_recipe, get(Recipe, exemplar)); return new_recipe_ordinal; diff --git a/080display.cc b/080display.cc index 6f92a0f6..7a807c62 100644 --- a/080display.cc +++ b/080display.cc @@ -414,7 +414,6 @@ case CHECK_FOR_INTERACTION: { products.at(0).push_back(/*text event*/0); if (event.key == TB_KEY_CTRL_C) { tb_shutdown(); -//? LOG << "exit\n"; exit(1); } if (event.key == TB_KEY_BACKSPACE2) event.key = TB_KEY_BACKSPACE; diff --git a/091run_interactive.cc b/091run_interactive.cc index 28c87994..352d2d23 100644 --- a/091run_interactive.cc +++ b/091run_interactive.cc @@ -478,7 +478,6 @@ case RELOAD: { } } for (long long int i = 0; i < SIZE(Recently_added_shape_shifting_recipes); ++i) { -//? LOG << "erasing " << get(Recipe, Recently_added_shape_shifting_recipes.at(i)).name << '\n'; Recipe_ordinal.erase(get(Recipe, Recently_added_shape_shifting_recipes.at(i)).name); Recipe.erase(Recently_added_shape_shifting_recipes.at(i)); } |