about summary refs log tree commit diff stats
path: root/029tools.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-10 23:15:00 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-10 23:15:00 -0700
commit9edabeaa21186c089a9b11f63ba3164f9fa753fb (patch)
treebf02bd60f67c53ea49ecd15fb67f3fd58b7138f2 /029tools.cc
parentae2b59cf25e2cae2694af1974e550dd1bc5dd137 (diff)
downloadmu-9edabeaa21186c089a9b11f63ba3164f9fa753fb.tar.gz
1975 - let's start using traces in lessons
More friendly way to 'stash' stuff in the trace so that you can toggle
lines of code to see their stashed traces.
Diffstat (limited to '029tools.cc')
-rw-r--r--029tools.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/029tools.cc b/029tools.cc
index 9b090eb2..05753e4b 100644
--- a/029tools.cc
+++ b/029tools.cc
@@ -37,6 +37,53 @@ recipe main [
 ]
 +app: foo
 
+//: a smarter but more limited version of 'trace'
+
+:(before "End Primitive Recipe Declarations")
+STASH,
+:(before "End Primitive Recipe Numbers")
+Recipe_ordinal["stash"] = STASH;
+:(before "End Primitive Recipe Implementations")
+case STASH: {
+  ostringstream out;
+  for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
+    out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i));
+  }
+  trace(1, "app") << out.str() << end();
+  break;
+}
+
+:(scenario stash_literal_string)
+recipe main [
+  stash [foo]
+]
++app: foo
+
+:(scenario stash_literal_number)
+recipe main [
+  stash [foo: ], 4
+]
++app: foo: 4
+
+:(scenario stash_number)
+recipe main [
+  1:number <- copy 34
+  stash [foo: ], 1:number
+]
++app: foo: 34
+
+:(code)
+string print_mu(const reagent& r, const vector<double>& data) {
+  if (is_literal(r))
+    return r.name;
+  // End print Special-cases(reagent r, data)
+  ostringstream out;
+  for (long long i = 0; i < SIZE(data); ++i) {
+    out << data.at(i) << ' ';
+  }
+  return out.str();
+}
+
 :(before "End Primitive Recipe Declarations")
 HIDE_WARNINGS,
 :(before "End Primitive Recipe Numbers")