about summary refs log tree commit diff stats
path: root/cpp/025trace.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/025trace.cc')
-rw-r--r--cpp/025trace.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/cpp/025trace.cc b/cpp/025trace.cc
new file mode 100644
index 00000000..ae06cb8b
--- /dev/null
+++ b/cpp/025trace.cc
@@ -0,0 +1,21 @@
+//: Allow mu programs to log facts just like we've been doing in C++ so far.
+
+:(scenario trace)
+recipe main [
+  trace [foo], [this is a trace in mu]
+]
++foo: this is a trace in mu
+
+:(before "End Primitive Recipe Declarations")
+TRACE,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["trace"] = TRACE;
+:(before "End Primitive Recipe Implementations")
+case TRACE: {
+  assert(isa_literal(current_instruction().ingredients[0]));
+  string label = current_instruction().ingredients[0].name;
+  assert(isa_literal(current_instruction().ingredients[1]));
+  string message = current_instruction().ingredients[1].name;
+  trace(label) << message;
+  break;
+}