about summary refs log tree commit diff stats
path: root/058to_text.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-09-12 21:02:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-09-12 21:02:38 -0700
commitdb01afa844004406da3a6ab9b306219c807e057e (patch)
treedd74fb6acbb9f5163c8be10b8c6cea9d1295b390 /058to_text.cc
parente309b9e82ded3ece3985a214cbd432b45de1ba4d (diff)
downloadmu-db01afa844004406da3a6ab9b306219c807e057e.tar.gz
3343
Reorganize layers a bit so I can add a couple of scenarios testing
static dispatch *before* I add `stash` into the mix.
Diffstat (limited to '058to_text.cc')
-rw-r--r--058to_text.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/058to_text.cc b/058to_text.cc
new file mode 100644
index 00000000..75a6b295
--- /dev/null
+++ b/058to_text.cc
@@ -0,0 +1,23 @@
+//: Primitive to convert any type to text (array of characters).
+//: Later layers will allow us to override this to do something smarter for
+//: specific types.
+
+:(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 '" << inst.original_string << "'\n" << end();
+    break;
+  }
+  // can handle any type
+  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;
+}