about summary refs log tree commit diff stats
path: root/039wait.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-25 14:19:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-25 17:14:58 -0700
commite46306432ddb75a89f69d92ccc175a23f0b72072 (patch)
tree48ed3828064f29cefaf14e3fe61d7dc02cac0e80 /039wait.cc
parente83602d3917eba137cd8fb37605076fff5a746b1 (diff)
downloadmu-e46306432ddb75a89f69d92ccc175a23f0b72072.tar.gz
1848 - core instructions now check for ingredients
Also standardized warnings.
Diffstat (limited to '039wait.cc')
-rw-r--r--039wait.cc22
1 files changed, 13 insertions, 9 deletions
diff --git a/039wait.cc b/039wait.cc
index 8a40dc8a..5b589d6a 100644
--- a/039wait.cc
+++ b/039wait.cc
@@ -41,7 +41,6 @@ case WAIT_FOR_LOCATION: {
   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] << end();
-//?   trace("schedule") << Current_routine->id << ": waiting for location " << loc.value << " to change from " << Memory[loc.value] << end(); //? 2
   break;
 }
 
@@ -49,12 +48,7 @@ case WAIT_FOR_LOCATION: {
 
 :(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 << end(); //? 1
   if (Routines.at(i)->state != WAITING) continue;
-//?   trace("schedule") << "waiting on location: " << Routines.at(i)->waiting_on_location << end(); //? 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 &&
       Memory[Routines.at(i)->waiting_on_location] != Routines.at(i)->old_value_of_waiting_location) {
     trace("schedule") << "waking up routine\n" << end();
@@ -96,8 +90,19 @@ WAIT_FOR_ROUTINE,
 Recipe_ordinal["wait-for-routine"] = WAIT_FOR_ROUTINE;
 :(before "End Primitive Recipe Implementations")
 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) << end();
   break;
@@ -111,7 +116,7 @@ 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);
+  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();
@@ -130,7 +135,6 @@ 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;
   }