about summary refs log tree commit diff stats
path: root/037call_reply.cc
diff options
context:
space:
mode:
Diffstat (limited to '037call_reply.cc')
-rw-r--r--037call_reply.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/037call_reply.cc b/037call_reply.cc
index 0d277658..fa224216 100644
--- a/037call_reply.cc
+++ b/037call_reply.cc
@@ -135,3 +135,20 @@ if (curr.name == "reply-if") {
   curr.operation = Recipe_number["reply"];
   curr.ingredients.swap(results);
 }
+// rewrite `reply-unless a, b, c, ...` to
+//   ```
+//   jump-if a, 1:offset
+//   reply b, c, ...
+//   ```
+if (curr.name == "reply-unless") {
+  assert(curr.products.empty());
+  curr.operation = Recipe_number["jump-if"];
+  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);
+}