diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-07 15:06:53 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-07 15:29:13 -0700 |
commit | 0487a30e7078861ed7de42bdb21b5c71fb9b54a1 (patch) | |
tree | f7ccc4040b510403da90477947c1cf07ea91b627 /045closure_name.cc | |
parent | 94fa5c95ad9c8beead183bb7c4b88c7c2c7ca6ec (diff) | |
download | mu-0487a30e7078861ed7de42bdb21b5c71fb9b54a1.tar.gz |
1298 - better ingredient/product handling
All primitives now always write to all their products. If a product is not used that's fine, but if an instruction seems to expect too many products mu will complain. In the process, many primitives can operate on more than two ingredients where it seems intuitive. You can add or divide more than two numbers together, copy or negate multiple corresponding locations, etc. There's one remaining bit of ugliness. Some instructions like get/get-address, index/index-address, wait-for-location, these can unnecessarily load values from memory when they don't need to. Useful vim commands: %s/ingredients\[\([^\]]*\)\]/ingredients.at(\1)/gc %s/products\[\([^\]]*\)\]/products.at(\1)/gc .,$s/\[\(.\)]/.at(\1)/gc
Diffstat (limited to '045closure_name.cc')
-rw-r--r-- | 045closure_name.cc | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/045closure_name.cc b/045closure_name.cc index 3f90f308..6273e880 100644 --- a/045closure_name.cc +++ b/045closure_name.cc @@ -46,20 +46,20 @@ void collect_surrounding_spaces(const recipe_number r) { const instruction& inst = Recipe[r].steps[i]; if (inst.is_label) continue; for (index_t j = 0; j < inst.products.size(); ++j) { - if (isa_literal(inst.products[j])) continue; - if (inst.products[j].name != "0") continue; - if (inst.products[j].types.size() != 3 - || inst.products[j].types[0] != Type_number["address"] - || inst.products[j].types[1] != Type_number["array"] - || inst.products[j].types[2] != Type_number["location"]) { - raise << "slot 0 should always have type address:array:location, but is " << inst.products[j].to_string() << '\n'; + if (isa_literal(inst.products.at(j))) continue; + if (inst.products.at(j).name != "0") continue; + if (inst.products.at(j).types.size() != 3 + || inst.products.at(j).types.at(0) != Type_number["address"] + || inst.products.at(j).types.at(1) != Type_number["array"] + || inst.products.at(j).types.at(2) != Type_number["location"]) { + raise << "slot 0 should always have type address:array:location, but is " << inst.products.at(j).to_string() << '\n'; continue; } - vector<string> s = property(inst.products[j], "names"); + vector<string> s = property(inst.products.at(j), "names"); if (s.empty()) raise << "slot 0 requires a /names property in recipe " << Recipe[r].name << die(); - if (s.size() > 1) raise << "slot 0 should have a single value in /names, got " << inst.products[j].to_string() << '\n'; - string surrounding_recipe_name = s[0]; + if (s.size() > 1) raise << "slot 0 should have a single value in /names, got " << inst.products.at(j).to_string() << '\n'; + string surrounding_recipe_name = s.at(0); if (Surrounding_space.find(r) != Surrounding_space.end() && Surrounding_space[r] != Recipe_number[surrounding_recipe_name]) { raise << "recipe " << Recipe[r].name << " can have only one 'surrounding' recipe but has " << Recipe[Surrounding_space[r]].name << " and " << surrounding_recipe_name << '\n'; @@ -84,7 +84,7 @@ index_t lookup_name(const reagent& x, const recipe_number default_recipe) { } vector<string> p = property(x, "space"); if (p.size() != 1) raise << "/space property should have exactly one (non-negative integer) value\n"; - int n = to_int(p[0]); + int n = to_int(p.at(0)); assert(n >= 0); recipe_number surrounding_recipe = lookup_surrounding_recipe(default_recipe, n); set<recipe_number> done; @@ -99,9 +99,9 @@ index_t lookup_name(const reagent& x, const recipe_number r, set<recipe_number>& if (done.find(r) != done.end()) { raise << "can't compute address of " << x.to_string() << " because "; for (index_t i = 1; i < path.size(); ++i) { - raise << path[i-1] << " requires computing names of " << path[i] << '\n'; + raise << path.at(i-1) << " requires computing names of " << path.at(i) << '\n'; } - raise << path[path.size()-1] << " requires computing names of " << r << "..ad infinitum\n" << die(); + raise << path.at(path.size()-1) << " requires computing names of " << r << "..ad infinitum\n" << die(); return 0; } done.insert(r); @@ -127,7 +127,7 @@ bool already_transformed(const reagent& r, const map<string, index_t>& names) { if (has_property(r, "space")) { vector<string> p = property(r, "space"); assert(p.size() == 1); - if (p[0] != "0") return true; + if (p.at(0) != "0") return true; } return names.find(r.name) != names.end(); } |