about summary refs log tree commit diff stats
path: root/034call.cc
diff options
context:
space:
mode:
Diffstat (limited to '034call.cc')
-rw-r--r--034call.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/034call.cc b/034call.cc
index ebfb9534..11dc326e 100644
--- a/034call.cc
+++ b/034call.cc
@@ -55,6 +55,11 @@ 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
+  }
   calls.push_front(call(r));
   // End routine Constructor
 }
@@ -91,10 +96,13 @@ default: {
     continue;
   }
   // 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
+  }
   Current_routine->calls.push_front(call(current_instruction().operation));
   call_housekeeping:
-  ++Callstack_depth;
-  assert(Callstack_depth < 9000);  // 9998-101 plus cushion
   continue;  // not done with caller; don't increment current_step_index()
 }
 
@@ -129,7 +137,11 @@ inline 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
-  --Callstack_depth;
+  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);
+  }
   Current_routine->calls.pop_front();
   if (Current_routine->calls.empty()) return;
   // Complete Call Fallthrough