about summary refs log tree commit diff stats
path: root/035call_ingredient.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-06 11:06:58 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-06 11:17:25 -0800
commit795f5244abc9b9f26ff621fd1997db427289d2ba (patch)
tree7018937b9d11ad07dab840789c444ca82ba22333 /035call_ingredient.cc
parent90e9eb3d4fa431ed0e7864caead19cd2e06b2c65 (diff)
downloadmu-795f5244abc9b9f26ff621fd1997db427289d2ba.tar.gz
2377 - stop using operator[] in map
I'm still seeing all sorts of failures in turning on layer 11 of edit/,
so I'm backing away and nailing down every culprit I run into. First up:
stop accidentally inserting empty objects into maps during lookups.

Commands run:
  $ sed -i 's/\(Recipe_ordinal\|Recipe\|Type_ordinal\|Type\|Memory\)\[\([^]]*\)\] = \(.*\);/put(\1, \2, \3);/' 0[1-9]*
  $ vi 075scenario_console.cc  # manually fix up Memory[Memory[CONSOLE]]
  $ sed -i 's/\(Memory\)\[\([^]]*\)\]/get_or_insert(\1, \2)/' 0[1-9]*
  $ sed -i 's/\(Recipe_ordinal\|Type_ordinal\)\[\([^]]*\)\]/get(\1, \2)/' 0[1-9]*
  $ sed -i 's/\(Recipe\|Type\)\[\([^]]*\)\]/get(\1, \2)/' 0[1-9]*

Now mu dies pretty quickly because of all the places I try to lookup a
missing value.
Diffstat (limited to '035call_ingredient.cc')
-rw-r--r--035call_ingredient.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/035call_ingredient.cc b/035call_ingredient.cc
index eb899899..6bba2b23 100644
--- a/035call_ingredient.cc
+++ b/035call_ingredient.cc
@@ -43,11 +43,11 @@ for (long long int i = 0; i < SIZE(ingredient_types); ++i) {
 :(before "End Primitive Recipe Declarations")
 NEXT_INGREDIENT,
 :(before "End Primitive Recipe Numbers")
-Recipe_ordinal["next-ingredient"] = NEXT_INGREDIENT;
+put(Recipe_ordinal, "next-ingredient", NEXT_INGREDIENT);
 :(before "End Primitive Recipe Checks")
 case NEXT_INGREDIENT: {
   if (!inst.ingredients.empty()) {
-    raise_error << maybe(Recipe[r].name) << "'next-ingredient' didn't expect any ingredients in '" << inst.to_string() << "'\n" << end();
+    raise_error << maybe(get(Recipe, r).name) << "'next-ingredient' didn't expect any ingredients in '" << inst.to_string() << "'\n" << end();
     break;
   }
   break;
@@ -113,7 +113,7 @@ recipe f [
 :(before "End Primitive Recipe Declarations")
 REWIND_INGREDIENTS,
 :(before "End Primitive Recipe Numbers")
-Recipe_ordinal["rewind-ingredients"] = REWIND_INGREDIENTS;
+put(Recipe_ordinal, "rewind-ingredients", REWIND_INGREDIENTS);
 :(before "End Primitive Recipe Checks")
 case REWIND_INGREDIENTS: {
   break;
@@ -138,15 +138,15 @@ recipe f [
 :(before "End Primitive Recipe Declarations")
 INGREDIENT,
 :(before "End Primitive Recipe Numbers")
-Recipe_ordinal["ingredient"] = INGREDIENT;
+put(Recipe_ordinal, "ingredient", INGREDIENT);
 :(before "End Primitive Recipe Checks")
 case INGREDIENT: {
   if (SIZE(inst.ingredients) != 1) {
-    raise_error << maybe(Recipe[r].name) << "'ingredient' expects exactly one ingredient, but got '" << inst.to_string() << "'\n" << end();
+    raise_error << maybe(get(Recipe, r).name) << "'ingredient' expects exactly one ingredient, but got '" << inst.to_string() << "'\n" << end();
     break;
   }
   if (!is_literal(inst.ingredients.at(0)) && !is_mu_number(inst.ingredients.at(0))) {
-    raise_error << maybe(Recipe[r].name) << "'ingredient' expects a literal ingredient, but got " << inst.ingredients.at(0).original_string << '\n' << end();
+    raise_error << maybe(get(Recipe, r).name) << "'ingredient' expects a literal ingredient, but got " << inst.ingredients.at(0).original_string << '\n' << end();
     break;
   }
   break;