From bcd33d6dbfb1fb0325ac21910bec9847ca1dd8df Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 31 Oct 2015 23:09:04 -0700 Subject: 2336 Minor tweak: track all recipe variants. --- 056recipe_header.cc | 5 +++-- 057static_dispatch.cc | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/056recipe_header.cc b/056recipe_header.cc index 59ea721d..ddb2ccd1 100644 --- a/056recipe_header.cc +++ b/056recipe_header.cc @@ -74,8 +74,7 @@ if (result.has_header) { trace(9999, "parse") << "recipe " << result.name << " has a header" << end(); } -//: Now rewrite 'load-ingredients' to instructions to create all reagents in -//: the header. +//: Rewrite 'load-ingredients' to instructions to create all reagents in the header. :(before "End Rewrite Instruction(curr, recipe result)") if (curr.name == "load-ingredients") { @@ -89,6 +88,8 @@ if (curr.name == "load-ingredients") { } } +//:: Check types going in and out of all recipes with headers. + :(scenarios transform) :(scenario recipe_headers_are_checked) % Hide_errors = true; diff --git a/057static_dispatch.cc b/057static_dispatch.cc index cc99f5ed..6a86beba 100644 --- a/057static_dispatch.cc +++ b/057static_dispatch.cc @@ -19,16 +19,24 @@ recipe test a:number, b:number -> z:number [ :(before "End Globals") map > Recipe_variants; +:(before "End Setup") +Recipe_variants.clear(); :(before "End Load Recipe Header(result)") -if (Recipe_ordinal.find(result.name) != Recipe_ordinal.end() - && (Recipe.find(Recipe_ordinal[result.name]) == Recipe.end() - || Recipe[Recipe_ordinal[result.name]].has_header) - && !header_already_exists(result)) { - string new_name = next_unused_recipe_name(result.name); - Recipe_ordinal[new_name] = Next_recipe_ordinal++; - Recipe_variants[result.name].push_back(Recipe_ordinal[new_name]); - result.name = new_name; +if (Recipe_ordinal.find(result.name) != Recipe_ordinal.end()) { + if ((Recipe.find(Recipe_ordinal[result.name]) == Recipe.end() + || Recipe[Recipe_ordinal[result.name]].has_header) + && !header_already_exists(result)) { + string new_name = next_unused_recipe_name(result.name); + Recipe_ordinal[new_name] = Next_recipe_ordinal++; + Recipe_variants[result.name].push_back(Recipe_ordinal[new_name]); + result.name = new_name; + } +} +else { + // save first variant + Recipe_ordinal[result.name] = Next_recipe_ordinal++; + Recipe_variants[result.name].push_back(Recipe_ordinal[result.name]); } :(code) @@ -99,6 +107,8 @@ void resolve_ambiguous_calls(recipe_ordinal r) { instruction& inst = Recipe[r].steps.at(index); if (inst.is_label) continue; if (Recipe_variants.find(inst.name) == Recipe_variants.end()) continue; + assert(!Recipe_variants[inst.name].empty()); + if (++Recipe_variants[inst.name].begin() == Recipe_variants[inst.name].end()) continue; replace_best_variant(inst); } } -- cgit 1.4.1-2-gfad0