about summary refs log tree commit diff stats
path: root/049continuation.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 /049continuation.cc
parente83602d3917eba137cd8fb37605076fff5a746b1 (diff)
downloadmu-e46306432ddb75a89f69d92ccc175a23f0b72072.tar.gz
1848 - core instructions now check for ingredients
Also standardized warnings.
Diffstat (limited to '049continuation.cc')
-rw-r--r--049continuation.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/049continuation.cc b/049continuation.cc
index e625e7b7..c79db298 100644
--- a/049continuation.cc
+++ b/049continuation.cc
@@ -40,7 +40,10 @@ CONTINUE_FROM,
 Recipe_ordinal["continue-from"] = CONTINUE_FROM;
 :(before "End Primitive Recipe Implementations")
 case CONTINUE_FROM: {
-  assert(scalar(ingredients.at(0)));
+  if (!scalar(ingredients.at(0))) {
+    raise << current_recipe_name() << ": first ingredient of 'continue-from' should be a continuation id generated by 'current-continuation', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
+    break;
+  }
   long long int c = ingredients.at(0).at(0);
   Current_routine->calls = Continuation[c];  // deep copy; calls have no pointers
   continue;  // skip rest of this instruction
@@ -171,7 +174,7 @@ case CREATE_DELIMITED_CONTINUATION: {
   Current_routine->calls.front().is_reset = true;
   Current_routine->calls.push_front(call(Recipe_ordinal[current_instruction().ingredients.at(0).name]));
   ingredients.erase(ingredients.begin());  // drop the callee
-  goto complete_call;
+  goto call_housekeeping;
 }
 
 //: save the slice of current call stack until the 'create-delimited-continuation'
@@ -197,7 +200,10 @@ case REPLY_DELIMITED_CONTINUATION: {
   // copy the current call stack until the most recent 'reset' call
   call_stack::iterator find_reset(call_stack& c);  // manual prototype containing '::'
   call_stack::iterator reset = find_reset(Current_routine->calls);
-  assert(reset != Current_routine->calls.end());
+  if (reset == Current_routine->calls.end()) {
+    raise << current_recipe_name() << ": couldn't find a 'reset' call to jump out to\n" << end();
+    break;
+  }
   Delimited_continuation[Next_delimited_continuation_id] = call_stack(Current_routine->calls.begin(), reset);
   while (Current_routine->calls.begin() != reset) {
     --Callstack_depth;
@@ -218,15 +224,19 @@ call_stack::iterator find_reset(call_stack& c) {
 }
 
 //: overload 'call' for continuations
-:(after "case CALL:")
-  if (current_instruction().ingredients.at(0).properties.at(0).second.at(0) == "continuation") {
+:(after "Begin Call")
+  if (!current_instruction().ingredients.at(0).properties.empty()
+      && !current_instruction().ingredients.at(0).properties.at(0).second.empty()
+      && current_instruction().ingredients.at(0).properties.at(0).second.at(0) == "continuation") {
     // copy multiple calls on to current call stack
     assert(scalar(ingredients.at(0)));
-    assert(Delimited_continuation.find(ingredients.at(0).at(0)) != Delimited_continuation.end());
+    if (Delimited_continuation.find(ingredients.at(0).at(0)) == Delimited_continuation.end()) {
+      raise << current_recipe_name() << ": no such delimited continuation " << current_instruction().ingredients.at(0).original_string << '\n' << 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)
       Current_routine->calls.push_front(*p);
     ++current_step_index();  // skip past the reply-delimited-continuation
     ingredients.erase(ingredients.begin());  // drop the callee
-    goto complete_call;
+    goto call_housekeeping;
   }