about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-10 20:14:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-10 20:14:50 -0800
commitd11bf88295f03debbf39a51e329a11a9de087580 (patch)
treeb1c90f32643be92d1350c80b7a3b453cd4625419
parent0c1791a950f6ba1cdfdab9b5104f80fad85cb8e8 (diff)
downloadmu-d11bf88295f03debbf39a51e329a11a9de087580.tar.gz
2419
-rw-r--r--056recipe_header.cc96
-rw-r--r--059generic_recipe.cc38
2 files changed, 67 insertions, 67 deletions
diff --git a/056recipe_header.cc b/056recipe_header.cc
index f59c26a4..c7b361d6 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -138,18 +138,18 @@ Transform.push_back(check_reply_instructions_against_header);  // idempotent
 
 :(code)
 void check_reply_instructions_against_header(const recipe_ordinal r) {
-  const recipe& rr = get(Recipe, r);
-  if (rr.products.empty()) return;
-  trace(9991, "transform") << "--- checking reply instructions against header for " << rr.name << end();
-//?   cerr << "--- checking reply instructions against header for " << rr.name << '\n';
-  for (long long int i = 0; i < SIZE(rr.steps); ++i) {
-    const instruction& inst = rr.steps.at(i);
+  const recipe& caller_recipe = get(Recipe, r);
+  if (caller_recipe.products.empty()) return;
+  trace(9991, "transform") << "--- checking reply instructions against header for " << caller_recipe.name << end();
+//?   cerr << "--- checking reply instructions against header for " << caller_recipe.name << '\n';
+  for (long long int i = 0; i < SIZE(caller_recipe.steps); ++i) {
+    const instruction& inst = caller_recipe.steps.at(i);
     if (inst.name != "reply") continue;
-    if (SIZE(rr.products) != SIZE(inst.ingredients))
-      raise_error << maybe(rr.name) << "tried to reply the wrong number of products in '" << inst.to_string() << "'\n" << end();
-    for (long long int i = 0; i < SIZE(rr.products); ++i) {
-      if (!types_match(rr.products.at(i), inst.ingredients.at(i)))
-        raise_error << maybe(rr.name) << "replied with the wrong type at '" << inst.to_string() << "'\n" << end();
+    if (SIZE(caller_recipe.products) != SIZE(inst.ingredients))
+      raise_error << maybe(caller_recipe.name) << "tried to reply the wrong number of products in '" << inst.to_string() << "'\n" << end();
+    for (long long int i = 0; i < SIZE(caller_recipe.products); ++i) {
+      if (!types_match(caller_recipe.products.at(i), inst.ingredients.at(i)))
+        raise_error << maybe(caller_recipe.name) << "replied with the wrong type at '" << inst.to_string() << "'\n" << end();
     }
   }
 }
@@ -171,13 +171,13 @@ Transform.push_back(check_and_update_header_reagents);  // idempotent
 
 :(code)
 void check_and_update_header_reagents(const recipe_ordinal r) {
-  recipe& rr = get(Recipe, r);
-  if (rr.products.empty()) return;
-  trace(9991, "transform") << "--- checking reply instructions against header for " << rr.name << end();
-  for (long long int i = 0; i < SIZE(rr.ingredients); ++i) {
-    if (contains_key(rr.ingredient_index, rr.ingredients.at(i).name))
-      raise_error << maybe(rr.name) << rr.ingredients.at(i).name << " can't repeat in the ingredients\n" << end();
-    put(rr.ingredient_index, rr.ingredients.at(i).name, i);
+  recipe& caller_recipe = get(Recipe, r);
+  if (caller_recipe.products.empty()) return;
+  trace(9991, "transform") << "--- checking reply instructions against header for " << caller_recipe.name << end();
+  for (long long int i = 0; i < SIZE(caller_recipe.ingredients); ++i) {
+    if (contains_key(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name))
+      raise_error << maybe(caller_recipe.name) << caller_recipe.ingredients.at(i).name << " can't repeat in the ingredients\n" << end();
+    put(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name, i);
   }
 }
 
@@ -201,29 +201,29 @@ Transform.push_back(deduce_types_from_header);  // idempotent
 
 :(code)
 void deduce_types_from_header(const recipe_ordinal r) {
-  recipe& rr = get(Recipe, r);
-  if (rr.products.empty()) return;
-  trace(9991, "transform") << "--- deduce types from header for " << rr.name << end();
-//?   cerr << "--- deduce types from header for " << rr.name << '\n';
+  recipe& caller_recipe = get(Recipe, r);
+  if (caller_recipe.products.empty()) return;
+  trace(9991, "transform") << "--- deduce types from header for " << caller_recipe.name << end();
+//?   cerr << "--- deduce types from header for " << caller_recipe.name << '\n';
   map<string, const type_tree*> header_type;
   map<string, const string_tree*> header_type_name;
-  for (long long int i = 0; i < SIZE(rr.ingredients); ++i) {
-    put(header_type, rr.ingredients.at(i).name, rr.ingredients.at(i).type);
-    put(header_type_name, rr.ingredients.at(i).name, rr.ingredients.at(i).properties.at(0).second);
-    trace(9993, "transform") << "type of " << rr.ingredients.at(i).name << " is " << debug_string(rr.ingredients.at(i).type) << end();
+  for (long long int i = 0; i < SIZE(caller_recipe.ingredients); ++i) {
+    put(header_type, caller_recipe.ingredients.at(i).name, caller_recipe.ingredients.at(i).type);
+    put(header_type_name, caller_recipe.ingredients.at(i).name, caller_recipe.ingredients.at(i).properties.at(0).second);
+    trace(9993, "transform") << "type of " << caller_recipe.ingredients.at(i).name << " is " << debug_string(caller_recipe.ingredients.at(i).type) << end();
   }
-  for (long long int i = 0; i < SIZE(rr.products); ++i) {
-    put(header_type, rr.products.at(i).name, rr.products.at(i).type);
-    put(header_type_name, rr.products.at(i).name, rr.products.at(i).properties.at(0).second);
-    trace(9993, "transform") << "type of " << rr.products.at(i).name << " is " << debug_string(rr.products.at(i).type) << end();
+  for (long long int i = 0; i < SIZE(caller_recipe.products); ++i) {
+    put(header_type, caller_recipe.products.at(i).name, caller_recipe.products.at(i).type);
+    put(header_type_name, caller_recipe.products.at(i).name, caller_recipe.products.at(i).properties.at(0).second);
+    trace(9993, "transform") << "type of " << caller_recipe.products.at(i).name << " is " << debug_string(caller_recipe.products.at(i).type) << end();
   }
-  for (long long int i = 0; i < SIZE(rr.steps); ++i) {
-    instruction& inst = rr.steps.at(i);
+  for (long long int i = 0; i < SIZE(caller_recipe.steps); ++i) {
+    instruction& inst = caller_recipe.steps.at(i);
     trace(9992, "transform") << "instruction: " << inst.to_string() << end();
     for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
       if (inst.ingredients.at(i).type) continue;
       if (header_type.find(inst.ingredients.at(i).name) == header_type.end()) {
-        raise << maybe(rr.name) << "unknown variable " << inst.ingredients.at(i).name << " in '" << inst.to_string() << "'\n" << end();
+        raise << maybe(caller_recipe.name) << "unknown variable " << inst.ingredients.at(i).name << " in '" << inst.to_string() << "'\n" << end();
         continue;
       }
       if (!inst.ingredients.at(i).type)
@@ -236,7 +236,7 @@ void deduce_types_from_header(const recipe_ordinal r) {
       trace(9993, "transform") << "  product: " << debug_string(inst.products.at(i)) << end();
       if (inst.products.at(i).type) continue;
       if (header_type.find(inst.products.at(i).name) == header_type.end()) {
-        raise << maybe(rr.name) << "unknown variable " << inst.products.at(i).name << " in '" << inst.to_string() << "'\n" << end();
+        raise << maybe(caller_recipe.name) << "unknown variable " << inst.products.at(i).name << " in '" << inst.to_string() << "'\n" << end();
         continue;
       }
       if (!inst.products.at(i).type)
@@ -268,34 +268,34 @@ Transform.push_back(fill_in_reply_ingredients);  // idempotent
 
 :(code)
 void fill_in_reply_ingredients(recipe_ordinal r) {
-  recipe& rr = get(Recipe, r);
-  if (!rr.has_header) return;
-  trace(9991, "transform") << "--- fill in reply ingredients from header for recipe " << rr.name << end();
-  for (long long int i = 0; i < SIZE(rr.steps); ++i) {
-    instruction& inst = rr.steps.at(i);
+  recipe& caller_recipe = get(Recipe, r);
+  if (!caller_recipe.has_header) return;
+  trace(9991, "transform") << "--- fill in reply ingredients from header for recipe " << caller_recipe.name << end();
+  for (long long int i = 0; i < SIZE(caller_recipe.steps); ++i) {
+    instruction& inst = caller_recipe.steps.at(i);
     if (inst.name == "reply" && inst.ingredients.empty())
-      add_header_products(inst, rr);
+      add_header_products(inst, caller_recipe);
   }
   // fall through reply
-  if (rr.steps.at(SIZE(rr.steps)-1).name != "reply") {
+  if (caller_recipe.steps.at(SIZE(caller_recipe.steps)-1).name != "reply") {
     instruction inst;
     inst.name = "reply";
-    add_header_products(inst, rr);
-    rr.steps.push_back(inst);
+    add_header_products(inst, caller_recipe);
+    caller_recipe.steps.push_back(inst);
   }
 }
 
-void add_header_products(instruction& inst, const recipe& rr) {
+void add_header_products(instruction& inst, const recipe& caller_recipe) {
   assert(inst.name == "reply");
   // collect any products with the same names as ingredients
-  for (long long int i = 0; i < SIZE(rr.products); ++i) {
+  for (long long int i = 0; i < SIZE(caller_recipe.products); ++i) {
     // if the ingredient is missing, add it from the header
     if (SIZE(inst.ingredients) == i)
-      inst.ingredients.push_back(rr.products.at(i));
+      inst.ingredients.push_back(caller_recipe.products.at(i));
     // if it's missing /same_as_ingredient, try to fill it in
-    if (contains_key(rr.ingredient_index, rr.products.at(i).name) && !has_property(inst.ingredients.at(i), "same_as_ingredient")) {
+    if (contains_key(caller_recipe.ingredient_index, caller_recipe.products.at(i).name) && !has_property(inst.ingredients.at(i), "same_as_ingredient")) {
       ostringstream same_as_ingredient;
-      same_as_ingredient << get(rr.ingredient_index, rr.products.at(i).name);
+      same_as_ingredient << get(caller_recipe.ingredient_index, caller_recipe.products.at(i).name);
       inst.ingredients.at(i).properties.push_back(pair<string, string_tree*>("same-as-ingredient", new string_tree(same_as_ingredient.str())));
     }
   }
diff --git a/059generic_recipe.cc b/059generic_recipe.cc
index 87b1151c..5ff8adba 100644
--- a/059generic_recipe.cc
+++ b/059generic_recipe.cc
@@ -194,44 +194,44 @@ void save_or_deduce_type_name(reagent& x, map<string, string_tree*>& type_name)
 
 void compute_type_ingredient_mappings(const recipe& exemplar, const instruction& inst, map<string, const string_tree*>& mappings, const recipe& caller_recipe, bool* error) {
   for (long long int i = 0; i < SIZE(exemplar.ingredients); ++i) {
-    const reagent& base = exemplar.ingredients.at(i);
+    const reagent& exemplar_reagent = exemplar.ingredients.at(i);
     reagent ingredient = inst.ingredients.at(i);
     assert(ingredient.properties.at(0).second);
     canonize_type(ingredient);
-    accumulate_type_ingredients(base, ingredient, mappings, exemplar, inst, caller_recipe, error);
+    accumulate_type_ingredients(exemplar_reagent, ingredient, mappings, exemplar, inst, caller_recipe, error);
   }
   for (long long int i = 0; i < SIZE(exemplar.products); ++i) {
-    const reagent& base = exemplar.products.at(i);
+    const reagent& exemplar_reagent = exemplar.products.at(i);
     reagent product = inst.products.at(i);
     assert(product.properties.at(0).second);
     canonize_type(product);
-    accumulate_type_ingredients(base, product, mappings, exemplar, inst, caller_recipe, error);
+    accumulate_type_ingredients(exemplar_reagent, product, mappings, exemplar, inst, caller_recipe, error);
   }
 }
 
-void accumulate_type_ingredients(const reagent& base, reagent& refinement, map<string, const string_tree*>& mappings, const recipe& exemplar, const instruction& call_instruction, const recipe& caller_recipe, bool* error) {
+void accumulate_type_ingredients(const reagent& exemplar_reagent, reagent& refinement, map<string, const string_tree*>& mappings, const recipe& exemplar, const instruction& call_instruction, const recipe& caller_recipe, bool* error) {
   assert(refinement.properties.at(0).second);
-  accumulate_type_ingredients(base.properties.at(0).second, refinement.properties.at(0).second, mappings, exemplar, base, call_instruction, caller_recipe, error);
+  accumulate_type_ingredients(exemplar_reagent.properties.at(0).second, refinement.properties.at(0).second, mappings, exemplar, exemplar_reagent, call_instruction, caller_recipe, error);
 }
 
-void accumulate_type_ingredients(const string_tree* base, const string_tree* refinement, map<string, const string_tree*>& mappings, const recipe& exemplar, const reagent& r, const instruction& call_instruction, const recipe& caller_recipe, bool* error) {
-  if (!base) return;
-  if (!refinement) {
-    raise_error << maybe(exemplar.name) << "missing type ingredient in " << r.original_string << '\n' << end();
+void accumulate_type_ingredients(const string_tree* exemplar_type, const string_tree* refinement_type, map<string, const string_tree*>& mappings, const recipe& exemplar, const reagent& exemplar_reagent, const instruction& call_instruction, const recipe& caller_recipe, bool* error) {
+  if (!exemplar_type) return;
+  if (!refinement_type) {
+    raise_error << maybe(exemplar.name) << "missing type ingredient in " << exemplar_reagent.original_string << '\n' << end();
     return;
   }
-  if (!base->value.empty() && base->value.at(0) == '_') {
-    assert(!refinement->value.empty());
-    if (base->right) {
+  if (!exemplar_type->value.empty() && exemplar_type->value.at(0) == '_') {
+    assert(!refinement_type->value.empty());
+    if (exemplar_type->right) {
       raise_error << "type_ingredients in non-last position not currently supported\n" << end();
       return;
     }
-    if (!contains_key(mappings, base->value)) {
-      trace(9993, "transform") << "adding mapping from " << base->value << " to " << debug_string(refinement) << end();
-      put(mappings, base->value, new string_tree(*refinement));
+    if (!contains_key(mappings, exemplar_type->value)) {
+      trace(9993, "transform") << "adding mapping from " << exemplar_type->value << " to " << debug_string(refinement_type) << end();
+      put(mappings, exemplar_type->value, new string_tree(*refinement_type));
     }
     else {
-      if (!deeply_equal(get(mappings, base->value), refinement)) {
+      if (!deeply_equal(get(mappings, exemplar_type->value), refinement_type)) {
         raise_error << maybe(caller_recipe.name) << "no call found for '" << call_instruction.to_string() << "'\n" << end();
         *error = true;
         return;
@@ -239,9 +239,9 @@ void accumulate_type_ingredients(const string_tree* base, const string_tree* ref
     }
   }
   else {
-    accumulate_type_ingredients(base->left, refinement->left, mappings, exemplar, r, call_instruction, caller_recipe, error);
+    accumulate_type_ingredients(exemplar_type->left, refinement_type->left, mappings, exemplar, exemplar_reagent, call_instruction, caller_recipe, error);
   }
-  accumulate_type_ingredients(base->right, refinement->right, mappings, exemplar, r, call_instruction, caller_recipe, error);
+  accumulate_type_ingredients(exemplar_type->right, refinement_type->right, mappings, exemplar, exemplar_reagent, call_instruction, caller_recipe, error);
 }
 
 void replace_type_ingredients(recipe& new_recipe, const map<string, const string_tree*>& mappings) {