From e765f9e74abc81b738e8670c6d77d363894107b1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 27 Apr 2016 15:23:44 -0700 Subject: 2873 - fix a bug in converting conditional returns This was an interaction between two transforms. The first turned: return-if ... into: jump-unless ..., 1:offset # skip next instruction return ... The second added an unconditional return at the end of the recipe if it didn't already exist (so that functions always end with a return). However, it was getting confused by the return instructions generated above, which look unconditional but sometimes get skipped. To fix this, conditional returns are now transformed into this: { break-unless ... return ... } Since the final instruction is now no longer a reply (but rather the '}' label), the second transform triggers and adds the unconditional return after it. This commit removes the final place marked 'BUG:' in the codebase yesterday (see commit 2870). --- 028call_reply.cc | 70 -------------------------------------------------------- 1 file changed, 70 deletions(-) (limited to '028call_reply.cc') diff --git a/028call_reply.cc b/028call_reply.cc index df5fa557..09360d25 100644 --- a/028call_reply.cc +++ b/028call_reply.cc @@ -158,73 +158,3 @@ string to_string(const vector& in) { out << "]"; return out.str(); } - -//: Conditional reply. - -:(scenario reply_if) -def main [ - 1:number <- test1 -] -def test1 [ - return-if 0, 34 - return 35 -] -+mem: storing 35 in location 1 - -:(scenario reply_if_2) -def main [ - 1:number <- test1 -] -def test1 [ - return-if 1, 34 - return 35 -] -+mem: storing 34 in location 1 - -:(before "End Rewrite Instruction(curr, recipe result)") -// rewrite `reply-if a, b, c, ...` to -// ``` -// jump-unless a, 1:offset -// reply b, c, ... -// ``` -if (curr.name == "reply-if" || curr.name == "return-if") { - if (curr.products.empty()) { - curr.operation = get(Recipe_ordinal, "jump-unless"); - curr.name = "jump-unless"; - vector 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 = get(Recipe_ordinal, "reply"); - curr.name = "reply"; - curr.ingredients.swap(results); - } - else { - raise << "'" << curr.name << "' never yields any products\n" << end(); - } -} -// rewrite `reply-unless a, b, c, ...` to -// ``` -// jump-if a, 1:offset -// reply b, c, ... -// ``` -if (curr.name == "reply-unless" || curr.name == "return-unless") { - if (curr.products.empty()) { - curr.operation = get(Recipe_ordinal, "jump-if"); - curr.name = "jump-if"; - vector 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 = get(Recipe_ordinal, "reply"); - curr.name = "reply"; - curr.ingredients.swap(results); - } - else { - raise << "'" << curr.name << "' never yields any products\n" << end(); - } -} -- cgit 1.4.1-2-gfad0