about summary refs log tree commit diff stats
path: root/076continuation.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 /076continuation.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 '076continuation.cc')
-rw-r--r--076continuation.cc26
1 files changed, 10 insertions, 16 deletions
diff --git a/076continuation.cc b/076continuation.cc
index 7a328a11..49916ef2 100644
--- a/076continuation.cc
+++ b/076continuation.cc
@@ -132,11 +132,9 @@ case CALL_WITH_CONTINUATION_MARK: {
 case CALL_WITH_CONTINUATION_MARK: {
   // like call, but mark the current call as a 'base of continuation' call
   // before pushing the next one on it
-  if (Trace_stream) {
-    ++Trace_stream->callstack_depth;
-    trace("trace") << "delimited continuation; incrementing callstack depth to " << Trace_stream->callstack_depth << end();
-    assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
-  }
+  trace(Callstack_depth+1, "trace") << "delimited continuation; incrementing callstack depth to " << Callstack_depth << end();
+  ++Callstack_depth;
+  assert(Callstack_depth < Max_depth);
   instruction/*copy*/ caller_instruction = current_instruction();
   Current_routine->calls.front().continuation_mark_tag = current_instruction().ingredients.at(0).value;
   Current_routine->calls.push_front(call(ingredients.at(1).at(0)));
@@ -213,13 +211,11 @@ case RETURN_CONTINUATION_UNTIL_MARK: {
       raise << maybe(current_recipe_name()) << "  " << get(Recipe, p->running_recipe).name << '\n' << end();
     break;
   }
-  trace("run") << "creating continuation " << Next_delimited_continuation_id << end();
+  trace(Callstack_depth+1, "run") << "creating continuation " << Next_delimited_continuation_id << end();
   put(Delimited_continuation, Next_delimited_continuation_id, delimited_continuation(Current_routine->calls.begin(), base));
   while (Current_routine->calls.begin() != base) {
-    if (Trace_stream) {
-      --Trace_stream->callstack_depth;
-      assert(Trace_stream->callstack_depth >= 0);
-    }
+    --Callstack_depth;
+    assert(Callstack_depth >= 0);
     Current_routine->calls.pop_front();
   }
   // return it as the result of the marked call
@@ -243,17 +239,15 @@ call_stack::iterator find_base_of_continuation(call_stack& c, int mark_tag) {
 if (is_mu_continuation(current_instruction().ingredients.at(0))) {
   // copy multiple calls on to current call stack
   assert(scalar(ingredients.at(0)));
-  trace("run") << "calling continuation " << ingredients.at(0).at(0) << end();
+  trace(Callstack_depth+1, "run") << "calling continuation " << ingredients.at(0).at(0) << end();
   if (!contains_key(Delimited_continuation, ingredients.at(0).at(0)))
     raise << maybe(current_recipe_name()) << "no such delimited continuation " << current_instruction().ingredients.at(0).original_string << '\n' << end();
   const call_stack& new_frames = get(Delimited_continuation, ingredients.at(0).at(0)).frames;
   for (call_stack::const_reverse_iterator p = new_frames.rbegin(); p != new_frames.rend(); ++p)
     Current_routine->calls.push_front(*p);
-  if (Trace_stream) {
-    Trace_stream->callstack_depth += SIZE(new_frames);
-    trace("trace") << "calling delimited continuation; growing callstack depth to " << Trace_stream->callstack_depth << end();
-    assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
-  }
+  trace(Callstack_depth+1, "trace") << "calling delimited continuation; growing callstack depth to " << Callstack_depth+SIZE(new_frames) << end();
+  Callstack_depth += SIZE(new_frames);
+  assert(Callstack_depth < Max_depth);
   // no call housekeeping; continuations don't support next-ingredient
   copy(/*drop continuation*/++ingredients.begin(), ingredients.end(), inserter(products, products.begin()));
   break;  // record results of resuming 'return-continuation-until-mark' instruction