about summary refs log tree commit diff stats
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
parent3929c26cfc6e2dce8bfd119a722e4a8531886f96 (diff)
downloadmu-bcd33d6dbfb1fb0325ac21910bec9847ca1dd8df.tar.gz
2336
Minor tweak: track all recipe variants.
-rw-r--r--056recipe_header.cc5
-rw-r--r--057static_dispatch.cc26
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<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);
   }
 }