From 9542bb112419d575190a72baf7f964c3e32df223 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 25 Jul 2015 22:15:51 -0700 Subject: 1853 --- html/039wait.cc.html | 80 +++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 38 deletions(-) (limited to 'html/039wait.cc.html') diff --git a/html/039wait.cc.html b/html/039wait.cc.html index 34043e76..1e56cf9d 100644 --- a/html/039wait.cc.html +++ b/html/039wait.cc.html @@ -13,14 +13,14 @@ 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; } -.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } +.traceContains { color: #008000; } --> @@ -41,7 +41,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipe f1 [ 1:number <- copy 0:literal start-running f2:recipe - wait-for-location 1:number + wait-for-location 1:number # now wait for f2 to run and modify location 1 before using its value 2:number <- copy 1:number ] @@ -57,8 +57,8 @@ recipe f2 [ WAITING, :(before "End routine Fields") // only if state == WAITING -long long int waiting_on_location; -int old_value_of_waiting_location; +long long int waiting_on_location; +int old_value_of_waiting_location; :(before "End routine Constructor") waiting_on_location = old_value_of_waiting_location = 0; @@ -69,29 +69,23 @@ WAIT_FOR_LOCATION, :(before "End Primitive Recipe Numbers") Recipe_ordinal["wait-for-location"] = WAIT_FOR_LOCATION; :(before "End Primitive Recipe Implementations") -case WAIT_FOR_LOCATION: { +case WAIT_FOR_LOCATION: { reagent loc = canonize(current_instruction().ingredients.at(0)); Current_routine->state = WAITING; Current_routine->waiting_on_location = loc.value; Current_routine->old_value_of_waiting_location = Memory[loc.value]; - trace(Primitive_recipe_depth, "run") << "waiting for location " << loc.value << " to change from " << Memory[loc.value]; -//? trace("schedule") << Current_routine->id << ": waiting for location " << loc.value << " to change from " << Memory[loc.value]; //? 2 + trace(Primitive_recipe_depth, "run") << "waiting for location " << loc.value << " to change from " << Memory[loc.value] << end(); break; } //: scheduler tweak to get routines out of that state :(before "End Scheduler State Transitions") -for (long long int i = 0; i < SIZE(Routines); ++i) { -//? trace("schedule") << "wake up loop 1: routine " << Routines.at(i)->id << " has state " << Routines.at(i)->state; //? 1 - if (Routines.at(i)->state != WAITING) continue; -//? trace("schedule") << "waiting on location: " << Routines.at(i)->waiting_on_location; //? 1 -//? if (Routines.at(i)->waiting_on_location) //? 2 -//? trace("schedule") << "checking routine " << Routines.at(i)->id << " waiting on location " //? 2 -//? << Routines.at(i)->waiting_on_location << ": " << Memory[Routines.at(i)->waiting_on_location] << " vs " << Routines.at(i)->old_value_of_waiting_location; //? 2 - if (Routines.at(i)->waiting_on_location && +for (long long int i = 0; i < SIZE(Routines); ++i) { + if (Routines.at(i)->state != WAITING) continue; + if (Routines.at(i)->waiting_on_location && Memory[Routines.at(i)->waiting_on_location] != Routines.at(i)->old_value_of_waiting_location) { - trace("schedule") << "waking up routine\n"; + trace("schedule") << "waking up routine\n" << end(); Routines.at(i)->state = RUNNING; Routines.at(i)->waiting_on_location = Routines.at(i)->old_value_of_waiting_location = 0; } @@ -103,7 +97,7 @@ for (long long int i = 01:number <- copy 0:literal 12:number/routine <- start-running f2:recipe - wait-for-routine 12:number/routine + wait-for-routine 12:number/routine # now wait for f2 to run and modify location 1 before using its value 3:number <- copy 1:number ] @@ -120,7 +114,7 @@ recipe f2 [ :(before "End routine Fields") // only if state == WAITING -long long int waiting_on_routine; +long long int waiting_on_routine; :(before "End routine Constructor") waiting_on_routine = 0; @@ -129,11 +123,22 @@ WAIT_FOR_ROUTINE, :(before "End Primitive Recipe Numbers") Recipe_ordinal["wait-for-routine"] = WAIT_FOR_ROUTINE; :(before "End Primitive Recipe Implementations") -case WAIT_FOR_ROUTINE: { +case WAIT_FOR_ROUTINE: { + if (SIZE(ingredients) != 1) { + raise << current_recipe_name() << ": 'wait-for-routine' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); + break; + } + if (!scalar(ingredients.at(0))) { + raise << current_recipe_name() << ": first ingredient of 'wait-for-routine' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + break; + } + if (ingredients.at(0).at(0) == Current_routine->id) { + raise << current_recipe_name() << ": routine can't wait for itself! " << current_instruction().to_string() << '\n' << end(); + break; + } Current_routine->state = WAITING; - assert(scalar(ingredients.at(0))); Current_routine->waiting_on_routine = ingredients.at(0).at(0); - trace(Primitive_recipe_depth, "run") << "waiting for routine " << ingredients.at(0).at(0); + trace(Primitive_recipe_depth, "run") << "waiting for routine " << ingredients.at(0).at(0) << end(); break; } @@ -141,14 +146,14 @@ case WAIT_FOR_ROUTINE: { // Wake up any routines waiting for other routines to go to sleep. // Important: this must come after the scheduler loop above giving routines // waiting for locations to change a chance to wake up. -for (long long int i = 0; i < SIZE(Routines); ++i) { - if (Routines.at(i)->state != WAITING) continue; - if (!Routines.at(i)->waiting_on_routine) continue; - long long int id = Routines.at(i)->waiting_on_routine; - assert(id != Routines.at(i)->id); - for (long long int j = 0; j < SIZE(Routines); ++j) { - if (Routines.at(j)->id == id && Routines.at(j)->state != RUNNING) { - trace("schedule") << "waking up routine " << Routines.at(i)->id; +for (long long int i = 0; i < SIZE(Routines); ++i) { + if (Routines.at(i)->state != WAITING) continue; + if (!Routines.at(i)->waiting_on_routine) continue; + long long int id = Routines.at(i)->waiting_on_routine; + assert(id != Routines.at(i)->id); // routine can't wait on itself + for (long long int j = 0; j < SIZE(Routines); ++j) { + if (Routines.at(j)->id == id && Routines.at(j)->state != RUNNING) { + trace("schedule") << "waking up routine " << Routines.at(i)->id << end(); Routines.at(i)->state = RUNNING; Routines.at(i)->waiting_on_routine = 0; } @@ -160,11 +165,10 @@ SWITCH, :(before "End Primitive Recipe Numbers") Recipe_ordinal["switch"] = SWITCH; :(before "End Primitive Recipe Implementations") -case SWITCH: { - long long int id = some_other_running_routine(); - if (id) { +case SWITCH: { + long long int id = some_other_running_routine(); + if (id) { assert(id != Current_routine->id); -//? cerr << "waiting on " << id << " from " << Current_routine->id << '\n'; //? 1 Current_routine->state = WAITING; Current_routine->waiting_on_routine = id; } @@ -172,12 +176,12 @@ case SWITCH: { } :(code) -long long int some_other_running_routine() { - for (long long int i = 0; i < SIZE(Routines); ++i) { - if (i == Current_routine_index) continue; +long long int some_other_running_routine() { + for (long long int i = 0; i < SIZE(Routines); ++i) { + if (i == Current_routine_index) continue; assert(Routines.at(i) != Current_routine); assert(Routines.at(i)->id != Current_routine->id); - if (Routines.at(i)->state == RUNNING) + if (Routines.at(i)->state == RUNNING) return Routines.at(i)->id; } return 0; -- cgit 1.4.1-2-gfad0