about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--003trace.cc27
-rw-r--r--029tools.cc13
-rw-r--r--081run_interactive.cc26
-rw-r--r--chessboard.mu2
-rw-r--r--edit/004-programming-environment.mu12
-rw-r--r--edit/005-sandbox.mu6
-rw-r--r--edit/006-sandbox-edit.mu4
-rw-r--r--edit/007-sandbox-delete.mu2
-rw-r--r--edit/008-sandbox-test.mu2
-rw-r--r--edit/009-sandbox-trace.mu4
-rw-r--r--edit/010-warnings.mu20
-rw-r--r--sandbox/005-sandbox.mu4
-rw-r--r--sandbox/006-sandbox-edit.mu4
-rw-r--r--sandbox/007-sandbox-delete.mu2
-rw-r--r--sandbox/009-sandbox-trace.mu4
-rw-r--r--sandbox/010-warnings.mu6
16 files changed, 61 insertions, 77 deletions
diff --git a/003trace.cc b/003trace.cc
index 86bd53ec..39a5644d 100644
--- a/003trace.cc
+++ b/003trace.cc
@@ -89,6 +89,11 @@ struct trace_line {
   trace_line(int d, string l, string c) :depth(d), label(l), contents(c) {}
 };
 
+:(before "End Globals")
+const int Max_depth = 9999;
+const int Error_depth = 0;  // definitely always print the error that caused death
+const int Warning_depth = 1;
+const int App_depth = 2;  // temporarily where all mu code will trace to
 :(before "End Tracing")
 bool Hide_errors = false;
 bool Hide_warnings = false;
@@ -103,31 +108,23 @@ struct trace_stream {
   ostringstream* curr_stream;
   string curr_label;
   int curr_depth;
-  set<string> collect_layers;  // if not empty, ignore all absent layers
+  int collect_depth;
   ofstream null_stream;  // never opens a file, so writes silently fail
-  trace_stream() :curr_stream(NULL), curr_depth(0) {}
+  trace_stream() :curr_stream(NULL), curr_depth(0), collect_depth(Max_depth) {}
   ~trace_stream() { if (curr_stream) delete curr_stream; }
 
   ostream& stream(string label) {
-    return stream(0, label);
+    return stream(Max_depth, label);
   }
 
   ostream& stream(int depth, string label) {
-    if (!is_collecting(label)) return null_stream;
+    if (depth > collect_depth) return null_stream;
     curr_stream = new ostringstream;
     curr_label = label;
     curr_depth = depth;
     return *curr_stream;
   }
 
-  bool is_collecting(const string& label) {
-    return collect_layers.empty() || collect_layers.find(label) != collect_layers.end();
-  }
-
-  bool is_narrowly_collecting(const string& label) {
-    return collect_layers.find(label) != collect_layers.end();
-  }
-
   // be sure to call this before messing with curr_stream or curr_label
   void newline() {
     if (!curr_stream) return;
@@ -141,7 +138,7 @@ struct trace_stream {
     delete curr_stream;
     curr_stream = NULL;
     curr_label.clear();
-    curr_depth = 0;
+    curr_depth = Max_depth;
   }
 
   // Useful for debugging.
@@ -166,8 +163,8 @@ trace_stream* Trace_stream = NULL;
 #define trace(...)  !Trace_stream ? cerr /*print nothing*/ : Trace_stream->stream(__VA_ARGS__)
 // Errors and warnings should go straight to cerr by default since calls to trace() have
 // some unfriendly constraints (they delay printing, they can't nest)
-#define raise  ((!Trace_stream || !Hide_warnings) ? (tb_shutdown(),cerr) /*do print*/ : Trace_stream->stream("warn"))
-#define raise_error  ((!Trace_stream || !Hide_errors) ? (tb_shutdown(),cerr) /*do print*/ : Trace_stream->stream("error"))
+#define raise  ((!Trace_stream || !Hide_warnings) ? (tb_shutdown(),cerr) /*do print*/ : Trace_stream->stream(Warning_depth, "warn"))
+#define raise_error  ((!Trace_stream || !Hide_errors) ? (tb_shutdown(),cerr) /*do print*/ : Trace_stream->stream(Error_depth, "error"))
 
 :(before "End Types")
 struct end {};
diff --git a/029tools.cc b/029tools.cc
index d17c9b81..48e62466 100644
--- a/029tools.cc
+++ b/029tools.cc
@@ -54,7 +54,7 @@ case STASH: {
   for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
     out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i));
   }
-  trace(1, "app") << out.str() << end();
+  trace(2, "app") << out.str() << end();
   break;
 }
 
@@ -118,18 +118,17 @@ case SHOW_ERRORS: {
 }
 
 :(before "End Primitive Recipe Declarations")
-_CLOSE_TRACE,
+TRACE_UNTIL,
 :(before "End Primitive Recipe Numbers")
-Recipe_ordinal["$close-trace"] = _CLOSE_TRACE;
+Recipe_ordinal["trace-until"] = TRACE_UNTIL;
 :(before "End Primitive Recipe Checks")
-case _CLOSE_TRACE: {
+case TRACE_UNTIL: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case _CLOSE_TRACE: {
+case TRACE_UNTIL: {
   if (Trace_stream) {
-    delete Trace_stream;
-    Trace_stream = NULL;
+    Trace_stream->collect_depth = ingredients.at(0).at(0);
   }
   break;
 }
diff --git a/081run_interactive.cc b/081run_interactive.cc
index 7eb0cc8c..e4c847f1 100644
--- a/081run_interactive.cc
+++ b/081run_interactive.cc
@@ -46,7 +46,7 @@ case RUN_INTERACTIVE: {
     products.at(0).push_back(0);
     products.at(1).push_back(trace_error_warning_contents());
     products.at(2).push_back(0);
-    products.at(3).push_back(trace_contents("app"));
+    products.at(3).push_back(trace_app_contents());
     products.at(4).push_back(1);  // completed
     run_code_end();
     break;  // done with this instruction
@@ -110,9 +110,7 @@ void run_code_begin() {
   Save_trace_file = Trace_file;
   Trace_file = "";
   Trace_stream = new trace_stream;
-  Trace_stream->collect_layers.insert("error");
-  Trace_stream->collect_layers.insert("warn");
-  Trace_stream->collect_layers.insert("app");
+  Trace_stream->collect_depth = App_depth;
 }
 
 void run_code_end() {
@@ -160,15 +158,6 @@ add 2, 2]
 ]
 +mem: storing 52 in location 4
 
-:(scenario run_interactive_just_comments_without_trace)
-recipe main [
-  $close-trace
-  1:address:array:character <- new [# ab
-]
-  2:address:array:character <- run-interactive 1:address:array:character
-  3:array:character <- copy *2:address:array:character
-]
-
 :(before "End Primitive Recipe Declarations")
 _START_TRACKING_PRODUCTS,
 :(before "End Primitive Recipe Numbers")
@@ -238,7 +227,7 @@ case SAVE_TRACE: {
 :(before "End Primitive Recipe Implementations")
 case SAVE_TRACE: {
   products.resize(1);
-  products.at(0).push_back(trace_contents(current_instruction().ingredients.at(0).name));
+  products.at(0).push_back(trace_app_contents());
   break;
 }
 
@@ -358,7 +347,7 @@ long long int trace_error_warning_contents() {
   if (!Trace_stream) return 0;
   ostringstream out;
   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
-    if (p->label != "warn" && p->label != "error") continue;
+    if (p->depth > Warning_depth) continue;
     out << p->contents;
     if (*--p->contents.end() != '\n') out << '\n';
   }
@@ -368,17 +357,16 @@ long long int trace_error_warning_contents() {
   return new_mu_string(result);
 }
 
-long long int trace_contents(const string& layer) {
+long long int trace_app_contents() {
   if (!Trace_stream) return 0;
-  if (trace_count(layer) <= 0) return 0;
   ostringstream out;
   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
-    if (p->label != layer) continue;
+    if (p->depth != App_depth) continue;
     out << p->contents;
     if (*--p->contents.end() != '\n') out << '\n';
   }
   string result = out.str();
-  assert(!result.empty());
+  if (result.empty()) return 0;
   truncate(result);
   return new_mu_string(result);
 }
diff --git a/chessboard.mu b/chessboard.mu
index 57c70a45..359ac9d3 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -25,7 +25,7 @@ recipe main [
 ## But enough about mu. Here's what it looks like to run the chessboard program.
 
 scenario print-board-and-read-move [
-  $close-trace  # administrivia: most scenarios save and check traces, but this one gets too large/slow
+  trace-until 100/app
   # we'll make the screen really wide because the program currently prints out a long line
   assume-screen 120/width, 20/height
   # initialize keyboard to type in a move
diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu
index 95b7ca62..2be7112e 100644
--- a/edit/004-programming-environment.mu
+++ b/edit/004-programming-environment.mu
@@ -216,7 +216,7 @@ recipe resize [
 ]
 
 scenario point-at-multiple-editors [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 30/width, 5/height
   # initialize both halves of screen
   1:address:array:character <- new [abc]
@@ -242,7 +242,7 @@ scenario point-at-multiple-editors [
 ]
 
 scenario edit-multiple-editors [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 30/width, 5/height
   # initialize both halves of screen
   1:address:array:character <- new [abc]
@@ -286,7 +286,7 @@ scenario edit-multiple-editors [
 ]
 
 scenario multiple-editors-cover-only-their-own-areas [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 60/width, 10/height
   run [
     1:address:array:character <- new [abc]
@@ -305,7 +305,7 @@ scenario multiple-editors-cover-only-their-own-areas [
 ]
 
 scenario editor-in-focus-keeps-cursor [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 30/width, 5/height
   1:address:array:character <- new [abc]
   2:address:array:character <- new [def]
@@ -342,7 +342,7 @@ scenario editor-in-focus-keeps-cursor [
 ]
 
 scenario backspace-in-sandbox-editor-joins-lines [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 30/width, 5/height
   # initialize sandbox side with two lines
   1:address:array:character <- new []
@@ -630,7 +630,7 @@ after <global-type> [
 # ctrl-x - maximize/unmaximize the side with focus
 
 scenario maximize-side [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 30/width, 5/height
   # initialize both halves of screen
   1:address:array:character <- new [abc]
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index c255865a..c7b55773 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -34,7 +34,7 @@ container sandbox-data [
 ]
 
 scenario run-and-show-results [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 15/height
   # recipe editor is empty
   1:address:array:character <- new []
@@ -404,7 +404,7 @@ recipe render-screen [
 ]
 
 scenario run-updates-results [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 12/height
   # define a recipe (no indent for the 'add' line below so column numbers are more obvious)
   1:address:array:character <- new [ 
@@ -453,7 +453,7 @@ z:number <- add 2, 2
 ]
 
 scenario run-instruction-manages-screen-per-sandbox [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 20/height
   # left editor is empty
   1:address:array:character <- new []
diff --git a/edit/006-sandbox-edit.mu b/edit/006-sandbox-edit.mu
index 861d9bcd..81487b62 100644
--- a/edit/006-sandbox-edit.mu
+++ b/edit/006-sandbox-edit.mu
@@ -1,7 +1,7 @@
 ## editing sandboxes after they've been created
 
 scenario clicking-on-a-sandbox-moves-it-to-editor [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 40/width, 10/height
   # basic recipe
   1:address:array:character <- new [ 
@@ -127,7 +127,7 @@ recipe extract-sandbox [
 ]
 
 scenario sandbox-with-print-can-be-edited [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 20/height
   # left editor is empty
   1:address:array:character <- new []
diff --git a/edit/007-sandbox-delete.mu b/edit/007-sandbox-delete.mu
index 12c84adf..92d86f45 100644
--- a/edit/007-sandbox-delete.mu
+++ b/edit/007-sandbox-delete.mu
@@ -1,7 +1,7 @@
 ## deleting sandboxes
 
 scenario deleting-sandboxes [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 15/height
   1:address:array:character <- new []
   2:address:array:character <- new []
diff --git a/edit/008-sandbox-test.mu b/edit/008-sandbox-test.mu
index 63da5822..5de70b41 100644
--- a/edit/008-sandbox-test.mu
+++ b/edit/008-sandbox-test.mu
@@ -1,7 +1,7 @@
 ## clicking on sandbox results to 'fix' them and turn sandboxes into tests
 
 scenario sandbox-click-on-result-toggles-color-to-green [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 40/width, 10/height
   # basic recipe
   1:address:array:character <- new [ 
diff --git a/edit/009-sandbox-trace.mu b/edit/009-sandbox-trace.mu
index a7a9b2e0..8039ed1d 100644
--- a/edit/009-sandbox-trace.mu
+++ b/edit/009-sandbox-trace.mu
@@ -1,7 +1,7 @@
 ## clicking on the code typed into a sandbox toggles its trace
 
 scenario sandbox-click-on-code-toggles-app-trace [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 40/width, 10/height
   # basic recipe
   1:address:array:character <- new [ 
@@ -74,7 +74,7 @@ recipe foo [
 ]
 
 scenario sandbox-shows-app-trace-and-result [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 40/width, 10/height
   # basic recipe
   1:address:array:character <- new [ 
diff --git a/edit/010-warnings.mu b/edit/010-warnings.mu
index 2bdcead2..6c4af999 100644
--- a/edit/010-warnings.mu
+++ b/edit/010-warnings.mu
@@ -76,7 +76,7 @@ after <render-sandbox-trace-done> [
 ]
 
 scenario run-shows-warnings-in-get [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 15/height
   1:address:array:character <- new [ 
 recipe foo [
@@ -116,7 +116,7 @@ recipe foo [
 ]
 
 scenario run-shows-missing-type-warnings [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 15/height
   1:address:array:character <- new [ 
 recipe foo [
@@ -144,7 +144,7 @@ recipe foo [
 ]
 
 scenario run-shows-unbalanced-bracket-warnings [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 15/height
   # recipe is incomplete (unbalanced '[')
   1:address:array:character <- new [ 
@@ -173,7 +173,7 @@ recipe foo «
 ]
 
 scenario run-shows-get-on-non-container-warnings [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 15/height
   1:address:array:character <- new [ 
 recipe foo [
@@ -203,7 +203,7 @@ recipe foo [
 ]
 
 scenario run-shows-non-literal-get-argument-warnings [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 15/height
   1:address:array:character <- new [ 
 recipe foo [
@@ -237,7 +237,7 @@ recipe foo [
 ]
 
 scenario run-shows-warnings-everytime [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   # try to run a file with an error
   assume-screen 100/width, 15/height
   1:address:array:character <- new [ 
@@ -282,7 +282,7 @@ recipe foo [
 ]
 
 scenario run-instruction-and-print-warnings [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 10/height
   # left editor is empty
   1:address:array:character <- new []
@@ -345,7 +345,7 @@ scenario run-instruction-and-print-warnings [
 ]
 
 scenario run-instruction-and-print-warnings-only-once [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 10/height
   # left editor is empty
   1:address:array:character <- new []
@@ -376,7 +376,7 @@ scenario run-instruction-and-print-warnings-only-once [
 ]
 
 scenario sandbox-can-handle-infinite-loop [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 20/height
   # left editor is empty
   1:address:array:character <- new [recipe foo [
@@ -407,7 +407,7 @@ scenario sandbox-can-handle-infinite-loop [
 ]
 
 scenario sandbox-with-warnings-shows-trace [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 100/width, 10/height
   # generate a stash and a warning
   1:address:array:character <- new [recipe foo [
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index a06f3076..cc21a284 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -21,7 +21,7 @@ container sandbox-data [
 ]
 
 scenario run-and-show-results [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 50/width, 15/height
   # sandbox editor contains an instruction without storing outputs
   1:address:array:character <- new [divide-with-remainder 11, 3]
@@ -388,7 +388,7 @@ recipe render-screen [
 ]
 
 scenario run-instruction-manages-screen-per-sandbox [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 50/width, 20/height
   # editor contains an instruction
   1:address:array:character <- new [print-integer screen, 4]
diff --git a/sandbox/006-sandbox-edit.mu b/sandbox/006-sandbox-edit.mu
index 5a628f3a..db12cc57 100644
--- a/sandbox/006-sandbox-edit.mu
+++ b/sandbox/006-sandbox-edit.mu
@@ -1,7 +1,7 @@
 ## editing sandboxes after they've been created
 
 scenario clicking-on-a-sandbox-moves-it-to-editor [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 40/width, 10/height
   # run something
   1:address:array:character <- new [add 2, 2]
@@ -125,7 +125,7 @@ recipe extract-sandbox [
 ]
 
 scenario sandbox-with-print-can-be-edited [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 50/width, 20/height
   # run a print instruction
   1:address:array:character <- new [print-integer screen, 4]
diff --git a/sandbox/007-sandbox-delete.mu b/sandbox/007-sandbox-delete.mu
index a84da4fa..224ac923 100644
--- a/sandbox/007-sandbox-delete.mu
+++ b/sandbox/007-sandbox-delete.mu
@@ -1,7 +1,7 @@
 ## deleting sandboxes
 
 scenario deleting-sandboxes [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 50/width, 15/height
   1:address:array:character <- new []
   2:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character
diff --git a/sandbox/009-sandbox-trace.mu b/sandbox/009-sandbox-trace.mu
index 8c5b87d8..88b4e877 100644
--- a/sandbox/009-sandbox-trace.mu
+++ b/sandbox/009-sandbox-trace.mu
@@ -1,7 +1,7 @@
 ## clicking on the code typed into a sandbox toggles its trace
 
 scenario sandbox-click-on-code-toggles-app-trace [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 40/width, 10/height
   # run a stash instruction
   1:address:array:character <- new [stash [abc]]
@@ -69,7 +69,7 @@ scenario sandbox-click-on-code-toggles-app-trace [
 ]
 
 scenario sandbox-shows-app-trace-and-result [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 40/width, 10/height
   # run a stash instruction and some code
   1:address:array:character <- new [stash [abc]
diff --git a/sandbox/010-warnings.mu b/sandbox/010-warnings.mu
index e8fed050..ece806c3 100644
--- a/sandbox/010-warnings.mu
+++ b/sandbox/010-warnings.mu
@@ -64,7 +64,7 @@ after <render-sandbox-trace-done> [
 ]
 
 scenario run-instruction-and-print-warnings [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 50/width, 15/height
   1:address:array:character <- new [get 1:address:point, 1:offset]
   2:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character
@@ -99,7 +99,7 @@ scenario run-instruction-and-print-warnings [
 ]
 
 scenario run-instruction-and-print-warnings-only-once [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 50/width, 10/height
   # editor contains an illegal instruction
   1:address:array:character <- new [get 1234:number, foo:offset]
@@ -128,7 +128,7 @@ scenario run-instruction-and-print-warnings-only-once [
 ]
 
 scenario sandbox-can-handle-infinite-loop [
-  $close-trace  # trace too long
+  trace-until 100/app  # trace too long
   assume-screen 50/width, 20/height
   # editor contains an infinite loop
   1:address:array:character <- new [{