From dea902172dd62d14eebc5fed9e11542ebcdc88e6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 27 Apr 2016 15:40:46 -0700 Subject: 2875 --- html/028call_reply.cc.html | 92 ++++++---------------------------------------- 1 file changed, 11 insertions(+), 81 deletions(-) (limited to 'html/028call_reply.cc.html') diff --git a/html/028call_reply.cc.html b/html/028call_reply.cc.html index 39ecff7c..396e7332 100644 --- a/html/028call_reply.cc.html +++ b/html/028call_reply.cc.html @@ -34,7 +34,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 //: Calls can also generate products, using 'reply' or 'return'.
 
-:(scenario reply)
+:(scenario return)
 def main [
   1:number, 2:number <- f 34
 ]
@@ -47,16 +47,16 @@ def f [
 +mem: storing 35 in location 2
 
 :(before "End Primitive Recipe Declarations")
-REPLY,
+RETURN,
 :(before "End Primitive Recipe Numbers")
-put(Recipe_ordinal, "reply", REPLY);
-put(Recipe_ordinal, "return", REPLY);
+put(Recipe_ordinal, "return", RETURN);
+put(Recipe_ordinal, "reply", RETURN);  // synonym while teaching
 :(before "End Primitive Recipe Checks")
-case REPLY: {
+case RETURN: {
   break;  // checks will be performed by a transform below
 }
 :(before "End Primitive Recipe Implementations")
-case REPLY: {
+case RETURN: {
   // Starting Reply
   if (Trace_stream) {
     trace(9999, "trace") << "reply: decrementing callstack depth from " << Trace_stream->callstack_depth << end();
@@ -95,7 +95,7 @@ Transform.push_back(const recipe& callee = get(Recipe, caller_instruction.operation);
     for (int i = 0; i < SIZE(callee.steps); ++i) {
       const instruction& reply_inst = callee.steps.at(i);
-      if (reply_inst.operation != REPLY) continue;
+      if (reply_inst.operation != RETURN) continue;
       // check types with the caller
       if (SIZE(caller_instruction.products) > SIZE(reply_inst.ingredients)) {
         raise << maybe(caller.name) << "too few values replied from " << callee.name << '\n' << end();
@@ -104,7 +104,7 @@ Transform.push_back(for (int i = 0; i < SIZE(caller_instruction.products); ++i) {
         reagent lhs = reply_inst.ingredients.at(i);
         reagent rhs = caller_instruction.products.at(i);
-        // End Check REPLY Copy(lhs, rhs)
+        // End Check RETURN Copy(lhs, rhs)
         if (!types_coercible(rhs, lhs)) {
           raise << maybe(callee.name) << reply_inst.name << " ingredient " << lhs.original_string << " can't be saved in " << rhs.original_string << '\n' << end();
           raise << to_string(lhs.type) << " vs " << to_string(rhs.type) << '\n' << end();
@@ -135,7 +135,7 @@ Transform.push_back(}
 }
 
-:(scenario reply_type_mismatch)
+:(scenario return_type_mismatch)
 % Hide_errors = true;
 def main [
   3:number <- f 2
@@ -153,7 +153,7 @@ def f [
 //: the recipe's 'reply' will help catch accidental misuse of such
 //: 'ingredient-products' (sometimes called in-out parameters in other languages).
 
-:(scenario reply_same_as_ingredient)
+:(scenario return_same_as_ingredient)
 % Hide_errors = true;
 def main [
   1:number <- copy 0
@@ -165,7 +165,7 @@ def test1 [
 ]
 +error: main: '2:number <- test1 1:number' should write to 1:number rather than 2:number
 
-:(scenario reply_same_as_ingredient_dummy)
+:(scenario return_same_as_ingredient_dummy)
 def main [
   1:number <- copy 0
   _ <- test1 1:number  # call with different ingredient and product
@@ -192,76 +192,6 @@ string to_string(const"]";
   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<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 = 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<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 = 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