about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/.traces/reply4
-rw-r--r--cpp/.traces/reply_record29
-rw-r--r--cpp/023call_reply38
3 files changed, 66 insertions, 5 deletions
diff --git a/cpp/.traces/reply b/cpp/.traces/reply
index 86ed6d2c..499a9441 100644
--- a/cpp/.traces/reply
+++ b/cpp/.traces/reply
@@ -30,7 +30,7 @@ mem/0: storing 3 in location 13
 run/0: instruction f/2
 mem/0: location 12 is 2
 mem/0: location 13 is 3
-run/0: result 0 is 1[2...]
+run/0: result 0 is 2
 mem/0: storing 2 in location 3
-run/0: result 1 is 1[3...]
+run/0: result 1 is 3
 mem/0: storing 3 in location 4
diff --git a/cpp/.traces/reply_record b/cpp/.traces/reply_record
new file mode 100644
index 00000000..ea2d38f0
--- /dev/null
+++ b/cpp/.traces/reply_record
@@ -0,0 +1,29 @@
+parse/0: instruction: 101
+parse/0:   ingredient: {name: "2", value: 0, type: 0, properties: ["2": "literal"]}
+parse/0:   product: {name: "3", value: 0, type: 5, properties: ["3": "point"]}
+parse/0: instruction: 22
+parse/0:   product: {name: "12", value: 0, type: 1, properties: ["12": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "35", value: 0, type: 0, properties: ["35": "literal"]}
+parse/0:   product: {name: "13", value: 0, type: 1, properties: ["13": "integer"]}
+parse/0: instruction: 23
+parse/0:   ingredient: {name: "12", value: 0, type: 5, properties: ["12": "point"]}
+after-brace/0: recipe main
+after-brace/0: f ...
+after-brace/0: recipe f
+after-brace/0: next-ingredient ...
+after-brace/0: copy ...
+after-brace/0: reply ...
+run/0: instruction main/0
+run/0: instruction f/0
+run/0: product 0 is 2
+mem/0: storing 2 in location 12
+run/0: instruction f/1
+run/0: ingredient 0 is 35
+mem/0: storing 35 in location 13
+run/0: instruction f/2
+mem/0: location 12 is 2
+mem/0: location 13 is 35
+run/0: result 0 is [2, 35]
+mem/0: storing 2 in location 3
+mem/0: storing 35 in location 4
diff --git a/cpp/023call_reply b/cpp/023call_reply
index 0fd09fc2..476875ab 100644
--- a/cpp/023call_reply
+++ b/cpp/023call_reply
@@ -9,9 +9,9 @@ recipe f [
   reply 12:integer, 13:integer
 ]
 +run: instruction main/0
-+run: result 0 is 1[2...]
++run: result 0 is 2
 +mem: storing 2 in location 3
-+run: result 1 is 1[3...]
++run: result 1 is 3
 +mem: storing 3 in location 4
 
 :(before "End Globals")
@@ -31,9 +31,41 @@ case REPLY: {
   instruction& caller_instruction = Recipe[rr.calls.top().running_recipe].steps[caller_pc];
   assert(caller_instruction.products.size() <= callee_results.size());
   for (size_t i = 0; i < caller_instruction.products.size(); ++i) {
-    trace("run") << "result " << i << " is " << callee_results[i].size() << "[" << callee_results[i][0] << "...]";
+    trace("run") << "result " << i << " is " << to_string(callee_results[i]);
     write_memory(caller_instruction.products[i], callee_results[i]);
   }
   ++caller_pc;
   break;
 }
+
+//: Results can include records and arrays.
+:(scenario "reply_record")
+recipe main [
+  3:point <- f 2:literal
+]
+recipe f [
+  12:integer <- next-ingredient
+  13:integer <- copy 35:literal
+  reply 12:point
+]
++run: instruction main/0
++run: result 0 is [2, 35]
++mem: storing 2 in location 3
++mem: storing 35 in location 4
+
+:(code)
+string to_string(const vector<int>& in) {
+  if (in.empty()) return "[]";
+  ostringstream out;
+  if (in.size() == 1) {
+    out << in[0];
+    return out.str();
+  }
+  out << "[";
+  for (size_t i = 0; i < in.size(); ++i) {
+    if (i > 0) out << ", ";
+    out << in[i];
+  }
+  out << "]";
+  return out.str();
+}