about summary refs log tree commit diff stats
path: root/026call.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-02-25 00:17:46 -0800
committerKartik Agaram <vc@akkartik.com>2019-02-25 01:50:53 -0800
commitc442a5ad806b6cccbb3ec4c5744b14b0c1f31a01 (patch)
tree318fb1d56e7ee3c750635d3326ad0739dfdacefe /026call.cc
parente5998f74ac29bb4bf2aedfdd6fbea801ffdb08f6 (diff)
downloadmu-c442a5ad806b6cccbb3ec4c5744b14b0c1f31a01.tar.gz
4987 - support `browse_trace` tool in SubX
I've extracted it into a separate binary, independent of my Mu prototype.

I also cleaned up my tracing layer to be a little nicer. Major improvements:

- Realized that incremental tracing really ought to be the default.
  And to minimize printing traces to screen.

- Finally figured out how to combine layers and call stack frames in a
  single dimension of depth. The answer: optimize for the experience of
  `browse_trace`. Instructions occupy a range of depths based on their call
  stack frame, and minor details of an instruction lie one level deeper
  in each case.

Other than that, I spent some time adjusting levels everywhere to make
`browse_trace` useful.
Diffstat (limited to '026call.cc')
-rw-r--r--026call.cc24
1 files changed, 9 insertions, 15 deletions
diff --git a/026call.cc b/026call.cc
index c6077cd9..1f130ef5 100644
--- a/026call.cc
+++ b/026call.cc
@@ -60,11 +60,9 @@ struct routine {
 };
 :(code)
 routine::routine(recipe_ordinal r) {
-  if (Trace_stream) {
-    ++Trace_stream->callstack_depth;
-    trace("trace") << "new routine; incrementing callstack depth to " << Trace_stream->callstack_depth << end();
-    assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
-  }
+  ++Callstack_depth;
+  trace(Callstack_depth+1, "trace") << "new routine; incrementing callstack depth to " << Callstack_depth << end();
+  assert(Callstack_depth < Max_depth);
   calls.push_front(call(r));
   // End routine Constructor
 }
@@ -151,11 +149,9 @@ if (!contains_key(Recipe, inst.operation)) {
 default: {
   if (contains_key(Recipe, current_instruction().operation)) {  // error already raised in Checks above
     // not a primitive; look up the book of recipes
-    if (Trace_stream) {
-      ++Trace_stream->callstack_depth;
-      trace("trace") << "incrementing callstack depth to " << Trace_stream->callstack_depth << end();
-      assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
-    }
+    ++Callstack_depth;
+    trace(Callstack_depth+1, "trace") << "incrementing callstack depth to " << Callstack_depth << end();
+    assert(Callstack_depth < Max_depth);
     const call& caller_frame = current_call();
     Current_routine->calls.push_front(call(to_instruction(caller_frame).operation));
     finish_call_housekeeping(to_instruction(caller_frame), ingredients);
@@ -202,11 +198,9 @@ const vector<instruction>& routine::steps() const {
 // it, and the one below that, and so on
 while (current_step_index() >= SIZE(Current_routine->steps())) {
   // Falling Through End Of Recipe
-  if (Trace_stream) {
-    trace("trace") << "fall-through: exiting " << current_recipe_name() << "; decrementing callstack depth from " << Trace_stream->callstack_depth << end();
-    --Trace_stream->callstack_depth;
-    assert(Trace_stream->callstack_depth >= 0);
-  }
+  trace(Callstack_depth+1, "trace") << "fall-through: exiting " << current_recipe_name() << "; decrementing callstack depth from " << Callstack_depth << end();
+  --Callstack_depth;
+  assert(Callstack_depth >= 0);
   Current_routine->calls.pop_front();
   if (Current_routine->calls.empty()) goto stop_running_current_routine;
   // Complete Call Fallthrough