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-13 16:53:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-13 16:53:32 -0700
commit65b3db5d597d7478be7bd6c38708ddc857719503 (patch)
treeb4a48a435696bae0d5b39bf0a73c705af3972b98 /029tools.cc
parent590ccda599b2ba57b896305f6974abb11589558f (diff)
downloadmu-65b3db5d597d7478be7bd6c38708ddc857719503.tar.gz
1990 - extra ingredient for 'trace' depth
Now we can make use of all the depths from 1 to 99.
Diffstat (limited to '029tools.cc')
-rw-r--r--029tools.cc26
1 files changed, 18 insertions, 8 deletions
diff --git a/029tools.cc b/029tools.cc
index 63addeb9..50e17643 100644
--- a/029tools.cc
+++ b/029tools.cc
@@ -2,7 +2,7 @@
 
 :(scenario trace)
 recipe main [
-  trace [foo], [this is a trace in mu]
+  trace 1, [foo], [this is a trace in mu]
 ]
 +foo: this is a trace in mu
 
@@ -12,15 +12,25 @@ TRACE,
 Recipe_ordinal["trace"] = TRACE;
 :(before "End Primitive Recipe Implementations")
 case TRACE: {
-  if (SIZE(current_instruction().ingredients) != 2) {
-    raise << current_recipe_name() << ": 'trace' takes two ingredients rather than '" << current_instruction().to_string() << "'\n" << end();
+  if (SIZE(current_instruction().ingredients) < 3) {
+    raise << current_recipe_name() << ": 'trace' takes three or more ingredients rather than '" << current_instruction().to_string() << "'\n" << end();
     break;
   }
-  assert(is_literal(current_instruction().ingredients.at(0)));
-  string label = current_instruction().ingredients.at(0).name;
-  assert(is_literal(current_instruction().ingredients.at(1)));
-  string message = current_instruction().ingredients.at(1).name;
-  trace(1, label) << message << end();
+  if (!scalar(ingredients.at(0))) {
+    raise << current_recipe_name() << ": first ingredient of 'trace' should be a number (depth), but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
+    break;
+  }
+  long long int depth = ingredients.at(0).at(0);
+  if (!is_literal_string(current_instruction().ingredients.at(1))) {
+    raise << current_recipe_name() << ": second ingredient of 'trace' should be a literal string (label), but got " << current_instruction().ingredients.at(1).original_string << '\n' << end();
+    break;
+  }
+  string label = current_instruction().ingredients.at(1).name;
+  ostringstream out;
+  for (long long int i = 2; i < SIZE(current_instruction().ingredients); ++i) {
+    out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i));
+  }
+  trace(depth, label) << out.str() << end();
   break;
 }