about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-03-20 17:04:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-03-21 00:50:17 -0700
commitdad3bedd1ca78162f87a235c10b036a06492a5f5 (patch)
tree42ebec181fea603cf05332cab66ec22320ac58b0
parent093b45e7ffcc56569141b71428e6f9f4215c6b2f (diff)
downloadmu-dad3bedd1ca78162f87a235c10b036a06492a5f5.tar.gz
2802 - default support for stashing new types
Don't let rewrite_stash transform working programs into non-working
ones.
-rw-r--r--071rewrite_stash.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/071rewrite_stash.cc b/071rewrite_stash.cc
index ea7c140f..058bd481 100644
--- a/071rewrite_stash.cc
+++ b/071rewrite_stash.cc
@@ -48,3 +48,39 @@ void rewrite_stashes_to_text(recipe& caller) {
   }
   caller.steps.swap(new_instructions);
 }
+
+//: Make sure that the new system is strictly better than just the 'stash'
+//: primitive by itself.
+
+:(scenarios run)
+:(scenario rewrite_stash_continues_to_fall_back_to_default_implementation)
+# type without a to-text implementation
+container foo [
+  x:number
+  y:number
+]
+recipe main [
+  local-scope
+  x:foo <- merge 34, 35
+  stash x
+]
++app: 34 35
+
+:(before "End Primitive Recipe Declarations")
+TO_TEXT,
+:(before "End Primitive Recipe Numbers")
+put(Recipe_ordinal, "to-text", TO_TEXT);
+:(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_string(inst) << "'\n" << end();
+    break;
+  }
+  break;
+}
+:(before "End Primitive Recipe Implementations")
+case TO_TEXT: {
+  products.resize(1);
+  products.at(0).push_back(new_mu_string(print_mu(current_instruction().ingredients.at(0), ingredients.at(0))));
+  break;
+}