about summary refs log tree commit diff stats
path: root/034call.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 /034call.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 '034call.cc')
-rw-r--r--034call.cc8
1 files changed, 4 insertions, 4 deletions
diff --git a/034call.cc b/034call.cc
index b6793c72..80d142d7 100644
--- a/034call.cc
+++ b/034call.cc
@@ -82,7 +82,7 @@ inline long long int& current_step_index() {
 :(replace{} "inline const string& current_recipe_name()")
 inline const string& current_recipe_name() {
   assert(!Current_routine->calls.empty());
-  return Recipe[current_call().running_recipe].name;
+  return get(Recipe, current_call().running_recipe).name;
 }
 :(replace{} "inline const instruction& current_instruction()")
 inline const instruction& current_instruction() {
@@ -91,13 +91,13 @@ inline const instruction& current_instruction() {
 }
 :(code)
 inline const instruction& to_instruction(const call& call) {
-  return Recipe[call.running_recipe].steps.at(call.running_step_index);
+  return get(Recipe, call.running_recipe).steps.at(call.running_step_index);
 }
 
 :(after "Defined Recipe Checks")
 // not a primitive; check that it's present in the book of recipes
 if (Recipe.find(inst.operation) == Recipe.end()) {
-  raise_error << maybe(Recipe[r].name) << "undefined operation in '" << inst.to_string() << "'\n" << end();
+  raise_error << maybe(get(Recipe, r).name) << "undefined operation in '" << inst.to_string() << "'\n" << end();
   break;
 }
 :(replace{} "default:" following "End Primitive Recipe Implementations")
@@ -142,7 +142,7 @@ inline bool routine::completed() const {
 
 inline const vector<instruction>& routine::steps() const {
   assert(!calls.empty());
-  return Recipe[calls.front().running_recipe].steps;
+  return get(Recipe, calls.front().running_recipe).steps;
 }
 
 :(before "Running One Instruction")