diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-03-21 02:53:34 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-03-21 02:53:34 -0700 |
commit | d57bf669c20f1936af8674d549bfb01c01f68f4f (patch) | |
tree | 0d10ba2f55f1d7725c193871900ffb3152564d66 /071rewrite_stash.cc | |
parent | acc4792d2f7c787aad064876a1eb2d00bdf076b2 (diff) | |
download | mu-d57bf669c20f1936af8674d549bfb01c01f68f4f.tar.gz |
2804 - support stashing arrays
Now to extend 'stash' for arrays, just extend array-to-text-line instead and perform the lookup inside it.
Diffstat (limited to '071rewrite_stash.cc')
-rw-r--r-- | 071rewrite_stash.cc | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/071rewrite_stash.cc b/071rewrite_stash.cc index a41fa72f..a1a3deef 100644 --- a/071rewrite_stash.cc +++ b/071rewrite_stash.cc @@ -8,7 +8,19 @@ recipe main [ n:number <- copy 34 stash n ] -+transform: {stash_2_0: ("address" "shared" "array" "character")} <- to-text-line {n: ()} ++transform: {stash_2_0: ("address" "shared" "array" "character")} <- to-text-line {n: "number"} ++transform: stash {stash_2_0: ("address" "shared" "array" "character")} + +//: special case: rewrite attempts to stash contents of most arrays to avoid +//: passing addresses around + +:(scenario rewrite_stashes_of_arrays) +recipe main [ + local-scope + n:address:shared:array:number <- new number:type, 3 + stash *n +] ++transform: {stash_2_0: ("address" "shared" "array" "character")} <- array-to-text-line {n: ("address" "shared" "array" "number")} +transform: stash {stash_2_0: ("address" "shared" "array" "character")} :(before "End Instruction Inserting/Deleting Transforms") @@ -20,6 +32,7 @@ void rewrite_stashes_to_text(recipe_ordinal r) { trace(9991, "transform") << "--- rewrite 'stash' instructions in recipe " << caller.name << end(); // in recipes without named locations, 'stash' is still not extensible if (contains_numeric_locations(caller)) return; + check_or_set_types_by_name(r); // prerequisite rewrite_stashes_to_text(caller); } @@ -29,11 +42,20 @@ void rewrite_stashes_to_text(recipe& caller) { instruction& inst = caller.steps.at(i); if (inst.name == "stash") { for (int j = 0; j < SIZE(inst.ingredients); ++j) { + assert(inst.ingredients.at(j).type); if (is_literal(inst.ingredients.at(j))) continue; if (is_mu_string(inst.ingredients.at(j))) continue; instruction def; - def.name = "to-text-line"; - def.ingredients.push_back(inst.ingredients.at(j)); + if (is_address_of_array(inst.ingredients.at(j))) { + def.name = "array-to-text-line"; + reagent tmp = inst.ingredients.at(j); + drop_one_lookup(tmp); + def.ingredients.push_back(tmp); + } + else { + def.name = "to-text-line"; + def.ingredients.push_back(inst.ingredients.at(j)); + } ostringstream ingredient_name; ingredient_name << "stash_" << i << '_' << j << ":address:shared:array:character"; def.products.push_back(reagent(ingredient_name.str())); @@ -49,6 +71,11 @@ void rewrite_stashes_to_text(recipe& caller) { caller.steps.swap(new_instructions); } +bool is_address_of_array(reagent x) { + if (!canonize_type(x)) return false; + return x.type->name == "array"; +} + //: Make sure that the new system is strictly better than just the 'stash' //: primitive by itself. |