From 75a00270150172cd8095a70da175512861399eec Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 12 Sep 2015 15:33:21 -0700 Subject: 2186 - kill the current routine on first error Exception: allow run-interactive to continue even if it encounters errors in parsing its ingredient as mu code. --- 038scheduler.cc | 25 +++++++++++++++++++++++++ 081run_interactive.cc | 14 ++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/038scheduler.cc b/038scheduler.cc index f6fc3a3c..ef0b335a 100644 --- a/038scheduler.cc +++ b/038scheduler.cc @@ -106,6 +106,7 @@ string current_routine_label() { for (long long int i = 0; i < SIZE(Routines); ++i) delete Routines.at(i); Routines.clear(); +Current_routine = NULL; //: special case for the very first routine :(replace{} "void run_main(int argc, char* argv[])") @@ -261,6 +262,30 @@ recipe f1 [ +schedule: f1 -run: idle +//:: Errors in a routine cause it to terminate. + +:(scenario scheduler_terminates_routines_after_errors) +% Hide_warnings = true; +% Scheduling_interval = 2; +recipe f1 [ + start-running f2:recipe + 1:number <- copy 0 + 2:number <- copy 0 +] +recipe f2 [ + # divide by 0 twice + 3:number <- divide-with-remainder 4, 0 + 4:number <- divide-with-remainder 4, 0 +] +# f2 should stop after first divide by 0 ++warn: f2: divide by zero in '3:number <- divide-with-remainder 4, 0' +-warn: f2: divide by zero in '4:number <- divide-with-remainder 4, 0' + +:(after "operator<<(ostream& os, unused end)") + if (Trace_stream->curr_layer == "warn" && Current_routine) { + Current_routine->state = COMPLETED; + } + //:: Routines are marked completed when their parent completes. :(scenario scheduler_kills_orphans) diff --git a/081run_interactive.cc b/081run_interactive.cc index c41a3f51..ec7f9206 100644 --- a/081run_interactive.cc +++ b/081run_interactive.cc @@ -78,6 +78,9 @@ bool run_interactive(long long int address) { Trace_stream->collect_layers.insert("warn"); Trace_stream->collect_layers.insert("app"); } + // don't kill the current routine on parse errors + routine* save_current_routine = Current_routine; + Current_routine = NULL; // call run(string) but without the scheduling load(string("recipe interactive [\n") + "local-scope\n" + @@ -88,6 +91,7 @@ bool run_interactive(long long int address) { "reply screen\n" + "]\n"); transform_all(); + Current_routine = save_current_routine; if (trace_count("warn") > 0) return false; // now call 'sandbox' which will run 'interactive' in a separate routine, // and wait for it @@ -209,9 +213,9 @@ recipe main [ recipe main [ # try to interactively add 2 and 2 1:address:array:character <- new [ - 100:address:array:character <- new [a] - 101:address:array:character <- new [b] - 102:address:array:character <- string-append 100:address:array:character, 101:address:array:character + x:address:array:character <- new [a] + y:address:array:character <- new [b] + z:address:array:character <- string-append x:address:array:character, y:address:array:character ] 2:address:array:character <- run-interactive 1:address:array:character 10:array:character <- copy 2:address:array:character/lookup @@ -223,7 +227,8 @@ recipe main [ :(scenario "run_interactive_returns_warnings") recipe main [ # run a command that generates a warning - 1:address:array:character <- new [get 1234:number, foo:offset] + 1:address:array:character <- new [x:number <- copy 34 +get x:number, foo:offset] 2:address:array:character, 3:address:array:character <- run-interactive 1:address:array:character 10:array:character <- copy 3:address:array:character/lookup ] @@ -232,6 +237,7 @@ recipe main [ +mem: storing 110 in location 12 +mem: storing 107 in location 13 +mem: storing 110 in location 14 +# ... :(before "End Globals") string Most_recent_products; -- cgit 1.4.1-2-gfad0