From 4690ce81e079fc58cae8d6d583e5e3eb3ed81a83 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 9 Mar 2016 02:56:27 -0800 Subject: 2743 Looks like "TOhtml | " doesn't work on Mac OS X for some reason.. --- html/063wait.cc.html | 100 ++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 54 deletions(-) (limited to 'html/063wait.cc.html') diff --git a/html/063wait.cc.html b/html/063wait.cc.html index 9115e7d6..bfb27103 100644 --- a/html/063wait.cc.html +++ b/html/063wait.cc.html @@ -3,48 +3,41 @@ Mu - 063wait.cc - - + + - - + - - -
+
 //: Routines can be put in a 'waiting' state, from which it will be ready to
 //: run again when a specific memory location changes its value. This is mu's
 //: basic technique for orchestrating the order in which different routines
 //: operate.
 
 :(scenario wait_for_location)
-recipe f1 [
+def f1 [
   1:number <- copy 0
   start-running f2
-  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
 ]
-recipe f2 [
+def f2 [
   1:number <- copy 34
 ]
 # if we got the synchronization wrong we'd be storing 0 in location 2
@@ -56,8 +49,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;
 
@@ -68,11 +61,11 @@ WAIT_FOR_LOCATION,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "wait-for-location", WAIT_FOR_LOCATION);
 :(before "End Primitive Recipe Checks")
-case WAIT_FOR_LOCATION: {
+case WAIT_FOR_LOCATION: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case WAIT_FOR_LOCATION: {
+case WAIT_FOR_LOCATION: {
   reagent loc = current_instruction().ingredients.at(0);
   canonize(loc);
   Current_routine->state = WAITING;
@@ -85,9 +78,9 @@ case WAIT_FOR_LOCATION: {
 //: scheduler tweak to get routines out of that state
 
 :(before "End Scheduler State Transitions")
-for (long long int i = 0; i < SIZE(Routines); ++i) {
-  if (Routines.at(i)->state != WAITING) continue;
-  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 &&
       get_or_insert(Memory, Routines.at(i)->waiting_on_location) != Routines.at(i)->old_value_of_waiting_location) {
     trace(9999, "schedule") << "waking up routine\n" << end();
     Routines.at(i)->state = RUNNING;
@@ -98,14 +91,14 @@ for (long long int i = 0//: also allow waiting on a routine to stop running
 
 :(scenario wait_for_routine)
-recipe f1 [
+def f1 [
   1:number <- copy 0
   12:number/routine <- start-running f2
-  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
 ]
-recipe f2 [
+def f2 [
   1:number <- copy 34
 ]
 +schedule: f1
@@ -118,7 +111,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;
 
@@ -127,21 +120,21 @@ WAIT_FOR_ROUTINE,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "wait-for-routine", WAIT_FOR_ROUTINE);
 :(before "End Primitive Recipe Checks")
-case WAIT_FOR_ROUTINE: {
-  if (SIZE(inst.ingredients) != 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'wait-for-routine' requires exactly one ingredient, but got " << to_string(inst) << '\n' << end();
+case WAIT_FOR_ROUTINE: {
+  if (SIZE(inst.ingredients) != 1) {
+    raise << maybe(get(Recipe, r).name) << "'wait-for-routine' requires exactly one ingredient, but got " << to_string(inst) << '\n' << end();
     break;
   }
-  if (!is_mu_number(inst.ingredients.at(0))) {
-    raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'wait-for-routine' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end();
+  if (!is_mu_number(inst.ingredients.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "first ingredient of 'wait-for-routine' 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 WAIT_FOR_ROUTINE: {
-  if (ingredients.at(0).at(0) == Current_routine->id) {
-    raise_error << maybe(current_recipe_name()) << "routine can't wait for itself! " << to_string(current_instruction()) << '\n' << end();
+case WAIT_FOR_ROUTINE: {
+  if (ingredients.at(0).at(0) == Current_routine->id) {
+    raise << maybe(current_recipe_name()) << "routine can't wait for itself! " << to_string(current_instruction()) << '\n' << end();
     break;
   }
   Current_routine->state = WAITING;
@@ -154,13 +147,13 @@ 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;
+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) {
+  for (long long int j = 0; j < SIZE(Routines); ++j) {
+    if (Routines.at(j)->id == id && Routines.at(j)->state != RUNNING) {
       trace(9999, "schedule") << "waking up routine " << Routines.at(i)->id << end();
       Routines.at(i)->state = RUNNING;
       Routines.at(i)->waiting_on_routine = 0;
@@ -173,13 +166,13 @@ SWITCH,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "switch", SWITCH);
 :(before "End Primitive Recipe Checks")
-case SWITCH: {
+case SWITCH: {
   break;
 }
 :(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);
     Current_routine->state = WAITING;
     Current_routine->waiting_on_routine = id;
@@ -188,12 +181,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;
@@ -201,4 +194,3 @@ long long int some_other_running_routine() 
 
 
-
-- 
cgit 1.4.1-2-gfad0