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 /041jump_target.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 '041jump_target.cc')
-rw-r--r-- | 041jump_target.cc | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/041jump_target.cc b/041jump_target.cc index d395cd97..d7ff717a 100644 --- a/041jump_target.cc +++ b/041jump_target.cc @@ -16,7 +16,7 @@ recipe main [ -mem: storing 0 in location 1 :(before "End Mu Types Initialization") -Type_ordinal["label"] = 0; +put(Type_ordinal, "label", 0); :(before "Transform.push_back(transform_braces)") Transform.push_back(transform_labels); @@ -24,21 +24,21 @@ Transform.push_back(transform_labels); :(code) void transform_labels(const recipe_ordinal r) { map<string, long long int> offset; - for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) { - const instruction& inst = Recipe[r].steps.at(i); + for (long long int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { + const instruction& inst = get(Recipe, r).steps.at(i); if (!inst.label.empty() && inst.label.at(0) == '+') { if (offset.find(inst.label) == offset.end()) { offset[inst.label] = i; } else { - raise_error << maybe(Recipe[r].name) << "duplicate label '" << inst.label << "'" << end(); + raise_error << maybe(get(Recipe, r).name) << "duplicate label '" << inst.label << "'" << end(); // have all jumps skip some random but noticeable and deterministic amount of code offset[inst.label] = 9999; } } } - for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) { - instruction& inst = Recipe[r].steps.at(i); + for (long long int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { + instruction& inst = get(Recipe, r).steps.at(i); if (inst.name == "jump") { replace_offset(inst.ingredients.at(0), offset, i, r); } @@ -60,19 +60,19 @@ void transform_labels(const recipe_ordinal r) { :(code) void replace_offset(reagent& x, /*const*/ map<string, long long int>& offset, const long long int current_offset, const recipe_ordinal r) { if (!is_literal(x)) { - raise_error << maybe(Recipe[r].name) << "jump target must be offset or label but is " << x.original_string << '\n' << end(); + raise_error << maybe(get(Recipe, r).name) << "jump target must be offset or label but is " << x.original_string << '\n' << end(); x.set_value(0); // no jump by default return; } assert(!x.initialized); if (is_integer(x.name)) return; // non-labels will be handled like other number operands if (!is_jump_target(x.name)) { - raise_error << maybe(Recipe[r].name) << "can't jump to label " << x.name << '\n' << end(); + raise_error << maybe(get(Recipe, r).name) << "can't jump to label " << x.name << '\n' << end(); x.set_value(0); // no jump by default return; } if (offset.find(x.name) == offset.end()) { - raise_error << maybe(Recipe[r].name) << "can't find label " << x.name << '\n' << end(); + raise_error << maybe(get(Recipe, r).name) << "can't find label " << x.name << '\n' << end(); x.set_value(0); // no jump by default return; } |