about summary refs log tree commit diff stats
path: root/056recipe_header.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-28 18:32:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-28 18:32:21 -0700
commit813b93b801dc3c7d36b63b7a3779529a854416a7 (patch)
tree0f588555c425473627ad23ac10589d9572c6cfcb /056recipe_header.cc
parent855a5b08579a829dd87a6b0755aa163d2801819a (diff)
downloadmu-813b93b801dc3c7d36b63b7a3779529a854416a7.tar.gz
2308 - auto-reply on fall-through
Diffstat (limited to '056recipe_header.cc')
-rw-r--r--056recipe_header.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/056recipe_header.cc b/056recipe_header.cc
index 37855908..d00b0a2e 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -109,3 +109,33 @@ if (curr.name == "reply" && curr.ingredients.empty()) {
     curr.ingredients.push_back(result.products.at(i));
   }
 }
+
+:(scenario reply_on_fallthrough_based_on_header)
+recipe main [
+  1:number/raw <- add2 3, 5
+]
+recipe add2 x:number, y:number -> z:number [
+  local-scope
+  load-ingredients
+  z:number <- add x, y
+]
++mem: storing 8 in location 1
+
+:(after "int main")
+  Transform.push_back(deduce_fallthrough_reply);
+
+:(code)
+void deduce_fallthrough_reply(const recipe_ordinal r) {
+  recipe& rr = Recipe[r];
+  if (rr.products.empty()) return;
+  if (rr.steps.empty()) return;
+  if (rr.steps.at(SIZE(rr.steps)-1).operation != REPLY) {
+    instruction inst;
+    inst.operation = REPLY;
+    inst.name = "reply";
+    for (long long int i = 0; i < SIZE(rr.products); ++i) {
+      inst.ingredients.push_back(rr.products.at(i));
+    }
+    rr.steps.push_back(inst);
+  }
+}