diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-06 11:06:58 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-06 11:17:25 -0800 |
commit | 795f5244abc9b9f26ff621fd1997db427289d2ba (patch) | |
tree | 7018937b9d11ad07dab840789c444ca82ba22333 /039wait.cc | |
parent | 90e9eb3d4fa431ed0e7864caead19cd2e06b2c65 (diff) | |
download | mu-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 '039wait.cc')
-rw-r--r-- | 039wait.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/039wait.cc b/039wait.cc index 27412901..ef3d30e5 100644 --- a/039wait.cc +++ b/039wait.cc @@ -33,7 +33,7 @@ waiting_on_location = old_value_of_waiting_location = 0; :(before "End Primitive Recipe Declarations") WAIT_FOR_LOCATION, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["wait-for-location"] = WAIT_FOR_LOCATION; +put(Recipe_ordinal, "wait-for-location", WAIT_FOR_LOCATION); :(before "End Primitive Recipe Checks") case WAIT_FOR_LOCATION: { break; @@ -44,8 +44,8 @@ case WAIT_FOR_LOCATION: { canonize(loc); Current_routine->state = WAITING; Current_routine->waiting_on_location = loc.value; - Current_routine->old_value_of_waiting_location = Memory[loc.value]; - trace(9998, "run") << "waiting for location " << loc.value << " to change from " << no_scientific(Memory[loc.value]) << end(); + Current_routine->old_value_of_waiting_location = get_or_insert(Memory, loc.value); + trace(9998, "run") << "waiting for location " << loc.value << " to change from " << no_scientific(get_or_insert(Memory, loc.value)) << end(); break; } @@ -55,7 +55,7 @@ case WAIT_FOR_LOCATION: { for (long long int i = 0; i < SIZE(Routines); ++i) { if (Routines.at(i)->state != WAITING) continue; if (Routines.at(i)->waiting_on_location && - Memory[Routines.at(i)->waiting_on_location] != Routines.at(i)->old_value_of_waiting_location) { + get_or_insert(Memory, Routines.at(i)->waiting_on_location) != Routines.at(i)->old_value_of_waiting_location) { trace(9999, "schedule") << "waking up routine\n" << end(); Routines.at(i)->state = RUNNING; Routines.at(i)->waiting_on_location = Routines.at(i)->old_value_of_waiting_location = 0; @@ -92,15 +92,15 @@ waiting_on_routine = 0; :(before "End Primitive Recipe Declarations") WAIT_FOR_ROUTINE, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["wait-for-routine"] = WAIT_FOR_ROUTINE; +put(Recipe_ordinal, "wait-for-routine", WAIT_FOR_ROUTINE); :(before "End Primitive Recipe Checks") case WAIT_FOR_ROUTINE: { if (SIZE(inst.ingredients) != 1) { - raise_error << maybe(Recipe[r].name) << "'wait-for-routine' requires exactly one ingredient, but got " << inst.to_string() << '\n' << end(); + raise_error << maybe(get(Recipe, r).name) << "'wait-for-routine' requires exactly one ingredient, but got " << inst.to_string() << '\n' << end(); break; } if (!is_mu_number(inst.ingredients.at(0))) { - raise_error << maybe(Recipe[r].name) << "first ingredient of 'wait-for-routine' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end(); + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'wait-for-routine' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } break; @@ -138,7 +138,7 @@ for (long long int i = 0; i < SIZE(Routines); ++i) { :(before "End Primitive Recipe Declarations") SWITCH, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["switch"] = SWITCH; +put(Recipe_ordinal, "switch", SWITCH); :(before "End Primitive Recipe Checks") case SWITCH: { break; |