about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-03 18:00:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-03 18:00:11 -0700
commit1066660e66fd08f608b24426abf7ad60b3a5b566 (patch)
tree49dd035198bdc59f2c489b57a0c36997c01b85c8
parentae496d70be94f8ffa363ae1612aa3cbfbaca11b8 (diff)
downloadmu-1066660e66fd08f608b24426abf7ad60b3a5b566.tar.gz
1523
Variable 'instruction_counter' was obfuscating more than it clarified.
-rw-r--r--020run.cc5
-rw-r--r--023jump.cc19
-rw-r--r--037call_reply.cc4
-rw-r--r--049continuation.cc11
4 files changed, 17 insertions, 22 deletions
diff --git a/020run.cc b/020run.cc
index 0c91b71d..ec9c1c2b 100644
--- a/020run.cc
+++ b/020run.cc
@@ -69,9 +69,8 @@ void run_current_routine()
     for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
       ingredients.push_back(read_memory(current_instruction().ingredients.at(i)));
     }
-    // Instructions below will write to 'products' or to 'instruction_counter'.
+    // Instructions below will write to 'products'.
     vector<vector<double> > products;
-    long long int instruction_counter = current_step_index();
 //?     cerr << "AAA 8: " << current_instruction().operation << " ^" << Recipe[current_instruction().operation].name << "$\n"; //? 1
     switch (current_instruction().operation) {
       // Primitive Recipe Implementations
@@ -89,7 +88,7 @@ void run_current_routine()
     for (long long int i = 0; i < SIZE(current_instruction().products); ++i) {
       write_memory(current_instruction().products.at(i), products.at(i));
     }
-    current_step_index() = instruction_counter+1;
+    ++current_step_index();
   }
 //?   cerr << "AAA 9\n"; //? 1
   stop_running_current_routine:;
diff --git a/023jump.cc b/023jump.cc
index a737bf82..daa5e5e0 100644
--- a/023jump.cc
+++ b/023jump.cc
@@ -1,6 +1,7 @@
 //: Jump primitives
 
 :(scenario jump_can_skip_instructions)
+#? % Trace_stream->dump_layer = "all"; #? 1
 recipe main [
   jump 1:offset
   1:number <- copy 1:literal
@@ -18,9 +19,9 @@ case JUMP: {
   assert(current_instruction().ingredients.at(0).initialized);
   assert(SIZE(ingredients) == 1);
   assert(scalar(ingredients.at(0)));
-  instruction_counter += ingredients.at(0).at(0);
-  trace(Primitive_recipe_depth, "run") << "jumping to instruction " << instruction_counter+1;
-  break;
+  current_step_index() += ingredients.at(0).at(0)+1;
+  trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index();
+  continue;  // skip rest of this instruction
 }
 
 //: special type to designate jump targets
@@ -52,9 +53,9 @@ case JUMP_IF: {
     break;
   }
   assert(scalar(ingredients.at(1)));
-  instruction_counter += ingredients.at(1).at(0);
-  trace(Primitive_recipe_depth, "run") << "jumping to instruction " << instruction_counter+1;
-  break;
+  current_step_index() += ingredients.at(1).at(0)+1;
+  trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index();
+  continue;  // skip rest of this instruction
 }
 
 :(scenario jump_if)
@@ -91,9 +92,9 @@ case JUMP_UNLESS: {
     break;
   }
   assert(scalar(ingredients.at(1)));
-  instruction_counter += ingredients.at(1).at(0);
-  trace(Primitive_recipe_depth, "run") << "jumping to instruction " << instruction_counter+1;
-  break;
+  current_step_index() += ingredients.at(1).at(0)+1;
+  trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index();
+  continue;  // skip rest of this instruction
 }
 
 :(scenario jump_unless)
diff --git a/037call_reply.cc b/037call_reply.cc
index 7e973ed3..951e6a6b 100644
--- a/037call_reply.cc
+++ b/037call_reply.cc
@@ -43,9 +43,7 @@ case REPLY: {
         raise << "'same-as-ingredient' result " << caller_instruction.products.at(i).value << " must be location " << caller_instruction.ingredients.at(ingredient_index).value << '\n';
     }
   }
-  // refresh instruction_counter to caller's step_index
-  instruction_counter = current_step_index();
-  break;
+  break;  // continue to process rest of *caller* instruction
 }
 
 //: Products can include containers and exclusive containers, addresses and arrays.
diff --git a/049continuation.cc b/049continuation.cc
index 7a92a377..4e0dd0e0 100644
--- a/049continuation.cc
+++ b/049continuation.cc
@@ -42,10 +42,8 @@ Recipe_number["continue-from"] = CONTINUE_FROM;
 case CONTINUE_FROM: {
   assert(scalar(ingredients.at(0)));
   long long int c = ingredients.at(0).at(0);
-  Current_routine->calls = Continuation[c];  // deep copy because calls have no pointers
-  // refresh instruction_counter to next instruction after current-continuation
-  instruction_counter = current_step_index()+1;
-  continue;  // not done with caller; don't increment current_step_index() further
+  Current_routine->calls = Continuation[c];  // deep copy; calls have no pointers
+  continue;  // skip rest of this instruction
 }
 
 :(scenario continuation)
@@ -69,6 +67,7 @@ recipe main [
 $current-continuation: 1
 
 :(scenario continuation_inside_caller)
+#? % Trace_stream->dump_layer = "all"; #? 1
 recipe main [
   1:number <- copy 0:literal
   2:continuation <- loop-body
@@ -208,9 +207,7 @@ case REPLY_DELIMITED_CONTINUATION: {
   products.resize(1);
   products.at(0).push_back(Next_delimited_continuation_id);
   ++Next_delimited_continuation_id;
-  // refresh instruction_counter to caller's step_index
-  instruction_counter = current_step_index();
-  break;
+  break;  // continue to process rest of 'reset' call
 }
 
 :(code)