From c842d90bbc5ab8f4fb88fb89ebb02c0c12051396 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 27 Jul 2016 22:51:11 -0700 Subject: 3158 --- html/062rewrite_stash.cc.html | 86 +++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 27 deletions(-) (limited to 'html/062rewrite_stash.cc.html') diff --git a/html/062rewrite_stash.cc.html b/html/062rewrite_stash.cc.html index a5a67068..d40916b7 100644 --- a/html/062rewrite_stash.cc.html +++ b/html/062rewrite_stash.cc.html @@ -45,6 +45,15 @@ recipe main [ +transform: {stash_2_0: ("address" "array" "character")} <- to-text-line {n: "number"} +transform: stash {stash_2_0: ("address" "array" "character")} +:(scenario rewrite_traces_to_text) +recipe main [ + local-scope + n:number <- copy 34 + trace 2, [app], n +] ++transform: {trace_2_2: ("address" "array" "character")} <- to-text-line {n: "number"} ++transform: trace {2: "literal"}, {"app": "literal-string"}, {trace_2_2: ("address" "array" "character")} + //: special case: rewrite attempts to stash contents of most arrays to avoid //: passing addresses around @@ -65,7 +74,21 @@ recipe main [ ] +transform: stash {n: ("array" "number" "3")} -:(before "End Instruction Inserting/Deleting Transforms") +:(scenario rewrite_stashes_of_recipe_header_products) +container foo [ + x:number +] +recipe bar -> x:foo [ + local-scope + load-ingredients + x <- merge 34 + stash x +] ++transform: stash {stash_2_0: ("address" "array" "character")} + +//: misplaced; should be in instruction inserting/deleting transforms, but has +//: prerequisites: deduce_types_from_header and check_or_set_types_by_name +:(after "Transform.push_back(deduce_types_from_header)") Transform.push_back(rewrite_stashes_to_text); :(code) @@ -74,7 +97,6 @@ Transform.push_back((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); } @@ -84,32 +106,16 @@ Transform.push_back(.steps.at(i); if (inst.name == "stash") { for (int j = 0; j < SIZE(inst.ingredients); ++j) { - if (!inst.ingredients.at(j).type) { - // error; will be handled elsewhere - continue; - } - if (is_literal(inst.ingredients.at(j))) continue; - if (is_mu_string(inst.ingredients.at(j))) continue; - // don't try to extend static arrays - if (is_static_array(inst.ingredients.at(j))) continue; - instruction def; - if (is_lookup_of_address_of_array(inst.ingredients.at(j))) { - def.name = "array-to-text-line"; - reagent/*copy*/ 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:array:character"; - def.products.push_back(reagent(ingredient_name.str())); - trace(9993, "transform") << to_string(def) << end(); - new_instructions.push_back(def); - inst.ingredients.at(j).clear(); // reclaim old memory - inst.ingredients.at(j) = reagent(ingredient_name.str()); + rewrite_stash_to_text(inst.ingredients.at(j), new_instructions, ingredient_name.str()); + } + } + else if (inst.name == "trace") { + for (int j = /*skip*/2; j < SIZE(inst.ingredients); ++j) { + ostringstream ingredient_name; + ingredient_name << "trace_" << i << '_' << j << ":address:array:character"; + rewrite_stash_to_text(inst.ingredients.at(j), new_instructions, ingredient_name.str()); } } trace(9993, "transform") << to_string(inst) << end(); @@ -118,6 +124,32 @@ Transform.push_back(.steps.swap(new_instructions); } +// add an instruction to convert reagent 'r' to text in list 'out', then +// replace r with converted text +void rewrite_stash_to_text(reagent& r, vector<instruction>& out, const string& tmp_var) { + if (!r.type) return; // error; will be handled elsewhere + if (is_literal(r)) return; + if (is_mu_string(r)) return; + // don't try to extend static arrays + if (is_static_array(r)) return; + instruction def; + if (is_lookup_of_address_of_array(r)) { + def.name = "array-to-text-line"; + reagent/*copy*/ tmp = r; + drop_one_lookup(tmp); + def.ingredients.push_back(tmp); + } + else { + def.name = "to-text-line"; + def.ingredients.push_back(r); + } + def.products.push_back(reagent(tmp_var)); + trace(9993, "transform") << to_string(def) << end(); + out.push_back(def); + r.clear(); // reclaim old memory + r = reagent(tmp_var); +} + bool is_lookup_of_address_of_array(reagent/*copy*/ x) { if (x.type->name != "address") return false; if (!canonize_type(x)) return false; @@ -153,7 +185,7 @@ put(Recipe_ordinal,:(before "End Primitive Recipe Checks") case TO_TEXT: { if (SIZE(inst.ingredients) != 1) { - raise << maybe(get(Recipe, r).name) << "'to-text' requires a single ingredient, but got '" << to_original_string(inst) << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'to-text' requires a single ingredient, but got '" << inst.original_string << "'\n" << end(); break; } // can handle any type -- cgit 1.4.1-2-gfad0