about summary refs log tree commit diff stats
path: root/037call_reply.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-10 11:38:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-10 11:40:33 -0700
commit4071055aeed22737366b3cb863b24a59f0625a28 (patch)
tree671bfd7bee9d5d75f5890bc78d1106719568fcde /037call_reply.cc
parent6b16a2ef6b12eedc14f2a7652bf8d977c8192b6e (diff)
downloadmu-4071055aeed22737366b3cb863b24a59f0625a28.tar.gz
1327 - better error handling in chessboard
Also a bugfix in break to label, because I noticed the screen wasn't
being cleaned up on quit.
Diffstat (limited to '037call_reply.cc')
-rw-r--r--037call_reply.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/037call_reply.cc b/037call_reply.cc
index 81f9c7c2..e44fe205 100644
--- a/037call_reply.cc
+++ b/037call_reply.cc
@@ -62,6 +62,7 @@ recipe f [
 //: ingredients unless they're also products. The /same-as-ingredient inside
 //: the recipe's 'reply' will help catch accidental misuse of such
 //: 'ingredient-results' (sometimes called in-out parameters in other languages).
+
 :(scenario reply_same_as_ingredient)
 % Hide_warnings = true;
 recipe main [
@@ -90,3 +91,44 @@ string to_string(const vector<long long int>& in) {
   out << "]";
   return out.str();
 }
+
+//: Conditional reply.
+
+:(scenario reply_if)
+recipe main [
+  1:integer <- test1
+]
+recipe test1 [
+  reply-if 0:literal, 34:literal
+  reply 35:literal
+]
++mem: storing 35 in location 1
+
+:(scenario reply_if2)
+recipe main [
+  1:integer <- test1
+]
+recipe test1 [
+  reply-if 1:literal, 34:literal
+  reply 35:literal
+]
++mem: storing 34 in location 1
+
+:(before "End Rewrite Instruction(curr)")
+// rewrite `reply-if a, b, c, ...` to
+//   ```
+//   jump-unless a, 1:offset
+//   reply b, c, ...
+//   ```
+if (curr.name == "reply-if") {
+  assert(curr.products.empty());
+  curr.operation = Recipe_number["jump-unless"];
+  vector<reagent> results;
+  copy(++curr.ingredients.begin(), curr.ingredients.end(), inserter(results, results.end()));
+  curr.ingredients.resize(1);
+  curr.ingredients.push_back(reagent("1:offset"));
+  result.steps.push_back(curr);
+  curr.clear();
+  curr.operation = Recipe_number["reply"];
+  curr.ingredients.swap(results);
+}