From c442a5ad806b6cccbb3ec4c5744b14b0c1f31a01 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 25 Feb 2019 00:17:46 -0800 Subject: 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. --- 076continuation.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to '076continuation.cc') 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 -- cgit 1.4.1-2-gfad0