about summary refs log tree commit diff stats
path: root/057static_dispatch.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-31 23:09:04 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-31 23:12:39 -0700
commitbcd33d6dbfb1fb0325ac21910bec9847ca1dd8df (patch)
treed51c4841d69e7e4cafdd1a4f1fc3bdea37ecb0a9 /057static_dispatch.cc
parent3929c26cfc6e2dce8bfd119a722e4a8531886f96 (diff)
downloadmu-bcd33d6dbfb1fb0325ac21910bec9847ca1dd8df.tar.gz
2336
Minor tweak: track all recipe variants.
Diffstat (limited to '057static_dispatch.cc')
-rw-r--r--057static_dispatch.cc26
1 files changed, 18 insertions, 8 deletions
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<string, vector<recipe_ordinal> > 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);
   }
 }