about summary refs log blame commit diff stats
path: root/html/086scenario_console_test.mu.html
blob: f36290b3d5f376741f8a161a85b2ebbf49473ad1 (plain) (tree)
n>'_' << j << ":address:array:character"; convert_ingredient_to_text(inst.ingredients.at(j), new_instructions, ingredient_name.str()); } } } trace(9993, "transform") << to_string(inst) << end(); new_instructions.push_back(inst); } caller.steps.swap(new_instructions); } // add an instruction to convert reagent 'r' to text in list 'out', then // replace r with converted text void convert_ingredient_to_text(reagent& r, vector<instruction>& out, const string& tmp_var) { if (!r.type) return; // error; will be handled elsewhere if (is_mu_text(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->atom) return false; if (x.type->left->name != "address") return false; if (!canonize_type(x)) return false; return is_mu_array(x); } bool is_static_array(const reagent& x) { // no canonize_type() return !x.type->atom && x.type->left->atom && x.type->left->name == "array"; } //: Supporting 'append' above requires remembering what name an instruction //: had before any rewrites or transforms. :(before "End instruction Fields") string name_before_rewrite; :(before "End instruction Clear") name_before_rewrite.clear(); :(before "End next_instruction(curr)") curr->name_before_rewrite = curr->name; :(scenarios run) :(scenario append_other_types_to_text) def main [ local-scope n:num <- copy 11 c:char <- copy 111/o a:text <- append [abc], 10, n, c expected:text <- new [abc1011o] 10:bool/raw <- equal a, expected ] //: Make sure that the new system is strictly better than just the 'stash' //: primitive by itself. :(scenario rewrite_stash_continues_to_fall_back_to_default_implementation) # type without a to-text implementation container foo [ x:num y:num ] def main [ local-scope x:foo <- merge 34, 35 stash x ] +app: 34 35