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-11-06 14:15:37 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-06 14:21:36 -0800
commitc157066cab02f91b2d5e53dbec09151936538578 (patch)
tree0125f6d42b84f470b79dc64b2b2c61364b2c2f0b /057static_dispatch.cc
parentf3760b0f2828250b4b5fb1a52601fe6b11ff328f (diff)
downloadmu-c157066cab02f91b2d5e53dbec09151936538578.tar.gz
2380 - done loading mu code
New assertions still failing during tests.

This whole implementation of generic recipes is like an extended spike.
I don't have nearly enough tests. Ideally I'd have confidence in
generics once layer 59 passed its tests.
Diffstat (limited to '057static_dispatch.cc')
-rw-r--r--057static_dispatch.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/057static_dispatch.cc b/057static_dispatch.cc
index 597ef4d0..69e6bdb5 100644
--- a/057static_dispatch.cc
+++ b/057static_dispatch.cc
@@ -29,24 +29,24 @@ for (map<string, vector<recipe_ordinal> >::iterator p = Recipe_variants.begin();
 
 :(before "End Load Recipe Header(result)")
 if (contains_key(Recipe_ordinal, result.name)) {
-  if ((Recipe.find(get(Recipe_ordinal, result.name)) == Recipe.end()
-          || get(Recipe, get(Recipe_ordinal, result.name)).has_header)
+  const recipe_ordinal r = get(Recipe_ordinal, result.name);
+  if ((!contains_key(Recipe, r) || get(Recipe, r).has_header)
       && !header_already_exists(result)) {
     string new_name = next_unused_recipe_name(result.name);
     put(Recipe_ordinal, new_name, Next_recipe_ordinal++);
-    Recipe_variants[result.name].push_back(get(Recipe_ordinal, new_name));
+    get(Recipe_variants, result.name).push_back(get(Recipe_ordinal, new_name));
     result.name = new_name;
   }
 }
 else {
   // save first variant
   put(Recipe_ordinal, result.name, Next_recipe_ordinal++);
-  Recipe_variants[result.name].push_back(get(Recipe_ordinal, result.name));
+  get_or_insert(Recipe_variants, result.name).push_back(get(Recipe_ordinal, result.name));
 }
 
 :(code)
 bool header_already_exists(const recipe& rr) {
-  const vector<recipe_ordinal>& variants = Recipe_variants[rr.name];
+  const vector<recipe_ordinal>& variants = get(Recipe_variants, rr.name);
   for (long long int i = 0; i < SIZE(variants); ++i) {
     if (Recipe.find(variants.at(i)) != Recipe.end()
         && all_reagents_match(rr, get(Recipe, variants.at(i)))) {
@@ -114,14 +114,14 @@ void resolve_ambiguous_calls(recipe_ordinal r) {
     instruction& inst = get(Recipe, r).steps.at(index);
     if (inst.is_label) continue;
     if (!contains_key(Recipe_variants, inst.name)) continue;
-    assert(!Recipe_variants[inst.name].empty());
+    assert(!get(Recipe_variants, inst.name).empty());
     replace_best_variant(inst);
   }
 }
 
 void replace_best_variant(instruction& inst) {
   trace(9992, "transform") << "instruction " << inst.name << end();
-  vector<recipe_ordinal>& variants = Recipe_variants[inst.name];
+  vector<recipe_ordinal>& variants = get(Recipe_variants, inst.name);
   long long int best_score = variant_score(inst, get(Recipe_ordinal, inst.name));
   for (long long int i = 0; i < SIZE(variants); ++i) {
     long long int current_score = variant_score(inst, variants.at(i));