about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-24 15:45:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-24 15:45:09 -0700
commit012d2ee18de5daa3c08efea9fc30c89d474e77c1 (patch)
treed025a7edbf6e815e0b72e371a459c185e8f9a235
parent8156110ea633b7375096ab98be85254f00f6b0b2 (diff)
downloadmu-012d2ee18de5daa3c08efea9fc30c89d474e77c1.tar.gz
1451 - share post-processing between all call instructions
-rw-r--r--035call.cc3
-rw-r--r--036call_ingredient.cc6
-rw-r--r--048call_variable.cc15
-rw-r--r--049continuation.cc13
4 files changed, 10 insertions, 27 deletions
diff --git a/035call.cc b/035call.cc
index 91609312..3b574cc2 100644
--- a/035call.cc
+++ b/035call.cc
@@ -84,9 +84,10 @@ default: {
     raise << "undefined operation " << current_instruction().operation << ": " << current_instruction().to_string() << '\n';
     break;
   }
+  Current_routine->calls.push_front(call(current_instruction().operation));
+complete_call:
   ++Callstack_depth;
   assert(Callstack_depth < 9000);  // 9998-101 plus cushion
-  Current_routine->calls.push_front(call(current_instruction().operation));
   continue;  // not done with caller; don't increment current_step_index()
 }
 
diff --git a/036call_ingredient.cc b/036call_ingredient.cc
index fd78ce94..33c85e4d 100644
--- a/036call_ingredient.cc
+++ b/036call_ingredient.cc
@@ -26,12 +26,10 @@ long long int next_ingredient_to_process;
 :(before "End call Constructor")
 next_ingredient_to_process = 0;
 
-:(replace "Current_routine->calls.push_front(call(current_instruction().operation))" following "End Primitive Recipe Implementations")
-call callee(current_instruction().operation);
+:(after "complete_call:")
 for (long long int i = 0; i < SIZE(ingredients); ++i) {
-  callee.ingredient_atoms.push_back(ingredients.at(i));
+  Current_routine->calls.front().ingredient_atoms.push_back(ingredients.at(i));
 }
-Current_routine->calls.push_front(callee);
 
 :(before "End Primitive Recipe Declarations")
 NEXT_INGREDIENT,
diff --git a/048call_variable.cc b/048call_variable.cc
index 0d4e3cc6..1ae98ddd 100644
--- a/048call_variable.cc
+++ b/048call_variable.cc
@@ -28,14 +28,9 @@ CALL,
 Recipe_number["call"] = CALL;
 :(before "End Primitive Recipe Implementations")
 case CALL: {
-  ++Callstack_depth;
-  assert(Callstack_depth < 9000);  // 9998-101 plus cushion
   recipe_number r = 0;
-//?   cerr << current_instruction().to_string() << '\n'; //? 1
-//?   cerr << current_instruction().ingredients.at(0).to_string() << '\n'; //? 1
   if (current_instruction().ingredients.at(0).initialized) {
     assert(scalar(ingredients.at(0)));
-//?     cerr << current_instruction().ingredients.at(0).value << '\n'; //? 1
     // 'call' received an integer recipe_number
     r = ingredients.at(0).at(0);
   }
@@ -43,11 +38,7 @@ case CALL: {
     // 'call' received a literal recipe name
     r = Recipe_number[current_instruction().ingredients.at(0).name];
   }
-  call callee(r);
-  for (long long int i = 1; i < SIZE(ingredients); ++i) {
-//?     cerr << ingredients.at(i).at(0) << '\n'; //? 1
-    callee.ingredient_atoms.push_back(ingredients.at(i));
-  }
-  Current_routine->calls.push_front(callee);
-  continue;  // not done with caller; don't increment current_step_index()
+  Current_routine->calls.push_front(call(r));
+  ingredients.erase(ingredients.begin());  // drop the function
+  goto complete_call;
 }
diff --git a/049continuation.cc b/049continuation.cc
index 5ab2c233..b06abb98 100644
--- a/049continuation.cc
+++ b/049continuation.cc
@@ -209,18 +209,11 @@ CALL_DELIMITED_CONTINUATION,
 Recipe_number["call-delimited-continuation"] = CALL_DELIMITED_CONTINUATION;
 :(before "End Primitive Recipe Implementations")
 case CALL_DELIMITED_CONTINUATION: {
-  ++Callstack_depth;
-  assert(Callstack_depth < 9000);  // 9998-101 plus cushion
   assert(scalar(ingredients.at(0)));
   assert(Delimited_continuation.find(ingredients.at(0).at(0)) != Delimited_continuation.end());
   const call_stack& new_calls = Delimited_continuation[ingredients.at(0).at(0)];
-  for (call_stack::const_reverse_iterator p = new_calls.rbegin(); p != new_calls.rend(); ++p) {
-//?     cerr << "copying back " << Recipe[p->running_recipe].name << '\n'; //? 1
+  for (call_stack::const_reverse_iterator p = new_calls.rbegin(); p != new_calls.rend(); ++p)
     Current_routine->calls.push_front(*p);
-  }
-  for (long long int i = /*skip continuation*/1; i < SIZE(ingredients); ++i) {
-//?     cerr << "copying ingredient " << i << ": " << ingredients.at(i).at(0) << '\n'; //? 1
-    Current_routine->calls.front().ingredient_atoms.push_back(ingredients.at(i));
-  }
-  continue;  // not done with caller; don't increment current_step_index()
+  ingredients.erase(ingredients.begin());  // drop the function
+  goto complete_call;
 }