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 /040brace.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 '040brace.cc')
-rw-r--r-- | 040brace.cc | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/040brace.cc b/040brace.cc index 0b3f6f1b..90826e2e 100644 --- a/040brace.cc +++ b/040brace.cc @@ -63,83 +63,89 @@ void transform_braces(const recipe_number r) { ; // do nothing else if (inst.operation == Recipe_number["loop"]) { inst.operation = Recipe_number["jump"]; - if (inst.ingredients.size() > 0 && isa_literal(inst.ingredients[0])) { + if (inst.ingredients.size() > 0 && isa_literal(inst.ingredients.at(0))) { // explicit target; a later phase will handle it - trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; + trace("after-brace") << "jump " << inst.ingredients.at(0).name << ":offset"; } else { reagent ing; ing.set_value(open_braces.top()-index); + ing.types.push_back(Type_number["offset"]); inst.ingredients.push_back(ing); trace("after-brace") << "jump " << ing.value << ":offset"; trace("after-brace") << index << ": " << ing.to_string(); - trace("after-brace") << index << ": " << Recipe[r].steps[index].ingredients[0].to_string(); + trace("after-brace") << index << ": " << Recipe[r].steps[index].ingredients.at(0).to_string(); } } else if (inst.operation == Recipe_number["break"]) { inst.operation = Recipe_number["jump"]; - if (inst.ingredients.size() > 0 && isa_literal(inst.ingredients[0])) { + if (inst.ingredients.size() > 0 && isa_literal(inst.ingredients.at(0))) { // explicit target; a later phase will handle it - trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; + trace("after-brace") << "jump " << inst.ingredients.at(0).name << ":offset"; } else { reagent ing; ing.set_value(matching_brace(open_braces.top(), braces) - index - 1); + ing.types.push_back(Type_number["offset"]); inst.ingredients.push_back(ing); trace("after-brace") << "jump " << ing.value << ":offset"; } } else if (inst.operation == Recipe_number["loop-if"]) { inst.operation = Recipe_number["jump-if"]; - if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it - trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; + trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } else { reagent ing; ing.set_value(open_braces.top()-index); + ing.types.push_back(Type_number["offset"]); inst.ingredients.push_back(ing); - trace("after-brace") << "jump-if " << inst.ingredients[0].name << ", " << ing.value << ":offset"; + trace("after-brace") << "jump-if " << inst.ingredients.at(0).name << ", " << ing.value << ":offset"; } } else if (inst.operation == Recipe_number["break-if"]) { inst.operation = Recipe_number["jump-if"]; - if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it - trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; + trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } else { reagent ing; ing.set_value(matching_brace(open_braces.top(), braces) - index - 1); + ing.types.push_back(Type_number["offset"]); inst.ingredients.push_back(ing); - trace("after-brace") << "jump-if " << inst.ingredients[0].name << ", " << ing.value << ":offset"; + trace("after-brace") << "jump-if " << inst.ingredients.at(0).name << ", " << ing.value << ":offset"; } } else if (inst.operation == Recipe_number["loop-unless"]) { inst.operation = Recipe_number["jump-unless"]; - if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it - trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; + trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } else { reagent ing; ing.set_value(open_braces.top()-index); + ing.types.push_back(Type_number["offset"]); inst.ingredients.push_back(ing); - trace("after-brace") << "jump-unless " << inst.ingredients[0].name << ", " << ing.value << ":offset"; + trace("after-brace") << "jump-unless " << inst.ingredients.at(0).name << ", " << ing.value << ":offset"; } } else if (inst.operation == Recipe_number["break-unless"]) { //? cout << "AAA break-unless\n"; //? 1 inst.operation = Recipe_number["jump-unless"]; - if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it - trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; + trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } else { reagent ing; ing.set_value(matching_brace(open_braces.top(), braces) - index - 1); + ing.types.push_back(Type_number["offset"]); inst.ingredients.push_back(ing); - trace("after-brace") << "jump-unless " << inst.ingredients[0].name << ", " << ing.value << ":offset"; + trace("after-brace") << "jump-unless " << inst.ingredients.at(0).name << ", " << ing.value << ":offset"; } } else { @@ -368,6 +374,7 @@ recipe main [ //: test how things actually run :(scenarios run) :(scenario brace_conversion_and_run) +#? % Trace_stream->dump_layer = "run"; recipe test-factorial [ 1:integer <- copy 5:literal 2:integer <- copy 1:literal |