From 76755b2836b0dadd88f82635f661f9d9df77604d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 10 Nov 2015 21:35:42 -0800 Subject: 2423 - describe shape-shifting in html docs --- html/038scheduler.cc.html | 157 +++++++++++++++++++++++++++++----------------- 1 file changed, 100 insertions(+), 57 deletions(-) (limited to 'html/038scheduler.cc.html') diff --git a/html/038scheduler.cc.html b/html/038scheduler.cc.html index 3a258741..16b3efbb 100644 --- a/html/038scheduler.cc.html +++ b/html/038scheduler.cc.html @@ -13,15 +13,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.SalientComment { color: #00ffff; } +.traceContains { color: #008000; } .traceAbsent { color: #c00000; } +.SalientComment { color: #00ffff; } .cSpecial { color: #008000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } .Constant { color: #00a0a0; } -.traceContains { color: #008000; } --> @@ -93,7 +93,7 @@ void run(routine* rr)(); assert(Current_routine); assert(Current_routine->state == RUNNING); - trace("schedule") << current_routine_label() << end(); + trace(9990, "schedule") << current_routine_label() << end(); run_current_routine(Scheduling_interval); // Scheduler State Transitions if (Current_routine->completed()) @@ -129,10 +129,10 @@ void skip_to_next_routine() () { ostringstream result; - call_stack calls = Current_routine->calls; - for (call_stack::iterator p = calls.begin(); p != calls.end(); ++p) { + const call_stack& calls = Current_routine->calls; + for (call_stack::const_iterator p = calls.begin(); p != calls.end(); ++p) { if (p != calls.begin()) result << '/'; - result << Recipe[p->running_recipe].name; + result << get(Recipe, p->running_recipe).name; } return result.str(); } @@ -141,22 +141,16 @@ string current_routine_label() (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[])") void run_main(int argc, char* argv[]) { - recipe_ordinal r = Recipe_ordinal[string("main")]; + recipe_ordinal r = get(Recipe_ordinal, string("main")); if (r) { - // pass in commandline args as ingredients to main - // todo: test this - routine* rr = new routine(r); - Current_routine = rr; - for (long long int i = 1; i < argc; ++i) { - vector<double> arg; - arg.push_back(new_mu_string(argv[i])); - Current_routine->calls.front().ingredient_atoms.push_back(arg); - } - run(rr); + routine* main_routine = new routine(r); + // Update main_routine + run(main_routine); } } @@ -184,26 +178,31 @@ parent_index = -1; :(before "End Primitive Recipe Declarations") START_RUNNING, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["start-running"] = START_RUNNING; -:(before "End Primitive Recipe Implementations") +put(Recipe_ordinal, "start-running", START_RUNNING); +:(before "End Primitive Recipe Checks") case START_RUNNING: { - if (ingredients.empty()) { - raise << "'start-running' requires at least one ingredient: the recipe to start running\n" << end(); + if (inst.ingredients.empty()) { + raise_error << maybe(get(Recipe, r).name) << "'start-running' requires at least one ingredient: the recipe to start running\n" << end(); break; } - if (!scalar(ingredients.at(0))) { - raise << "first ingredient of 'start-running' should be a recipe, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); - break; - } - if (!ingredients.at(0).at(0)) { - raise << "'start-running' received non-existent recipe: '" << current_instruction().to_string() << "'\n" << end(); + if (!is_mu_recipe(inst.ingredients.at(0))) { + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'start-running' should be a recipe, but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case START_RUNNING: { routine* new_routine = new routine(ingredients.at(0).at(0)); new_routine->parent_index = Current_routine_index; // populate ingredients - for (long long int i = 1; i < SIZE(current_instruction().ingredients); ++i) + for (long long int i = 1; i < SIZE(current_instruction().ingredients); ++i) { new_routine->calls.front().ingredient_atoms.push_back(ingredients.at(i)); + reagent ingredient = current_instruction().ingredients.at(i); + canonize_type(ingredient); + new_routine->calls.front().ingredient_types.push_back(ingredient.type); + ingredient.type = NULL; // release long-lived pointer + } Routines.push_back(new_routine); products.resize(1); products.at(0).push_back(new_routine->id); @@ -243,7 +242,7 @@ recipe f2 [ +schedule: f1 +run: 2:number <- copy 0 -:(scenario start_running_takes_args) +:(scenario start_running_takes_ingredients) recipe f1 [ start-running f2:recipe, 3 # wait for f2 to run @@ -296,6 +295,30 @@ recipe f1 [ +schedule: f1 -run: idle +//:: Errors in a routine cause it to terminate. + +:(scenario scheduler_terminates_routines_after_errors) +% Hide_errors = 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 ++error: f2: divide by zero in '3:number <- divide-with-remainder 4, 0' +-error: f2: divide by zero in '4:number <- divide-with-remainder 4, 0' + +:(after "operator<<(ostream& os, unused end)") + if (Trace_stream && Trace_stream->curr_label == "error" && Current_routine) { + Current_routine->state = COMPLETED; + } + //:: Routines are marked completed when their parent completes. :(scenario scheduler_kills_orphans) @@ -346,17 +369,21 @@ recipe f2 [ :(before "End Primitive Recipe Declarations") ROUTINE_STATE, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["routine-state"] = ROUTINE_STATE; -:(before "End Primitive Recipe Implementations") +put(Recipe_ordinal, "routine-state", ROUTINE_STATE); +:(before "End Primitive Recipe Checks") case ROUTINE_STATE: { - if (SIZE(ingredients) != 1) { - raise << current_recipe_name() << ": 'routine-state' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); + if (SIZE(inst.ingredients) != 1) { + raise_error << maybe(get(Recipe, r).name) << "'routine-state' requires exactly one ingredient, but got " << inst.to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(0))) { - raise << current_recipe_name() << ": first ingredient of 'routine-state' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + if (!is_mu_number(inst.ingredients.at(0))) { + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'routine-state' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case ROUTINE_STATE: { long long int id = ingredients.at(0).at(0); long long int result = -1; for (long long int i = 0; i < SIZE(Routines); ++i) { @@ -375,17 +402,21 @@ case ROUTINE_STATE: { :(before "End Primitive Recipe Declarations") RESTART, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["restart"] = RESTART; -:(before "End Primitive Recipe Implementations") +put(Recipe_ordinal, "restart", RESTART); +:(before "End Primitive Recipe Checks") case RESTART: { - if (SIZE(ingredients) != 1) { - raise << current_recipe_name() << ": 'restart' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); + if (SIZE(inst.ingredients) != 1) { + raise_error << maybe(get(Recipe, r).name) << "'restart' requires exactly one ingredient, but got " << inst.to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(0))) { - raise << current_recipe_name() << ": first ingredient of 'restart' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + if (!is_mu_number(inst.ingredients.at(0))) { + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'restart' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case RESTART: { long long int id = ingredients.at(0).at(0); for (long long int i = 0; i < SIZE(Routines); ++i) { if (Routines.at(i)->id == id) { @@ -399,17 +430,21 @@ case RESTART: { :(before "End Primitive Recipe Declarations") STOP, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["stop"] = STOP; -:(before "End Primitive Recipe Implementations") +put(Recipe_ordinal, "stop", STOP); +:(before "End Primitive Recipe Checks") case STOP: { - if (SIZE(ingredients) != 1) { - raise << current_recipe_name() << ": 'stop' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); + if (SIZE(inst.ingredients) != 1) { + raise_error << maybe(get(Recipe, r).name) << "'stop' requires exactly one ingredient, but got " << inst.to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(0))) { - raise << current_recipe_name() << ": first ingredient of 'stop' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + if (!is_mu_number(inst.ingredients.at(0))) { + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'stop' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case STOP: { long long int id = ingredients.at(0).at(0); for (long long int i = 0; i < SIZE(Routines); ++i) { if (Routines.at(i)->id == id) { @@ -423,7 +458,11 @@ case STOP: { :(before "End Primitive Recipe Declarations") _DUMP_ROUTINES, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["$dump-routines"] = _DUMP_ROUTINES; +put(Recipe_ordinal, "$dump-routines", _DUMP_ROUTINES); +:(before "End Primitive Recipe Checks") +case _DUMP_ROUTINES: { + break; +} :(before "End Primitive Recipe Implementations") case _DUMP_ROUTINES: { for (long long int i = 0; i < SIZE(Routines); ++i) { @@ -456,7 +495,7 @@ DISCONTINUED, :(before "End Scheduler State Transitions") if (Current_routine->limit >= 0) { if (Current_routine->limit <= Scheduling_interval) { - trace("schedule") << "discontinuing routine " << Current_routine->id << end(); + trace(9999, "schedule") << "discontinuing routine " << Current_routine->id << end(); Current_routine->state = DISCONTINUED; Current_routine->limit = 0; } @@ -473,21 +512,25 @@ limit = -1; :(before "End Primitive Recipe Declarations") LIMIT_TIME, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["limit-time"] = LIMIT_TIME; -:(before "End Primitive Recipe Implementations") +put(Recipe_ordinal, "limit-time", LIMIT_TIME); +:(before "End Primitive Recipe Checks") case LIMIT_TIME: { - if (SIZE(ingredients) != 2) { - raise << current_recipe_name() << ": 'limit-time' requires exactly two ingredient, but got " << current_instruction().to_string() << '\n' << end(); + if (SIZE(inst.ingredients) != 2) { + raise_error << maybe(get(Recipe, r).name) << "'limit-time' requires exactly two ingredient, but got " << inst.to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(0))) { - raise << current_recipe_name() << ": first ingredient of 'limit-time' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + if (!is_mu_number(inst.ingredients.at(0))) { + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'limit-time' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } - if (!scalar(ingredients.at(1))) { - raise << current_recipe_name() << ": second ingredient of 'limit-time' should be a number (of instructions to run for), but got " << current_instruction().ingredients.at(1).original_string << '\n' << end(); + if (!is_mu_number(inst.ingredients.at(1))) { + raise_error << maybe(get(Recipe, r).name) << "second ingredient of 'limit-time' should be a number (of instructions to run for), but got " << inst.ingredients.at(1).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case LIMIT_TIME: { long long int id = ingredients.at(0).at(0); for (long long int i = 0; i < SIZE(Routines); ++i) { if (Routines.at(i)->id == id) { -- cgit 1.4.1-2-gfad0