about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/.traces/calling_recipe2
-rw-r--r--cpp/.traces/next_ingredient2
-rw-r--r--cpp/.traces/reply30
-rw-r--r--cpp/012run1
-rw-r--r--cpp/020call40
5 files changed, 73 insertions, 2 deletions
diff --git a/cpp/.traces/calling_recipe b/cpp/.traces/calling_recipe
index ab7089e0..3c220e09 100644
--- a/cpp/.traces/calling_recipe
+++ b/cpp/.traces/calling_recipe
@@ -1,4 +1,4 @@
-parse/0: instruction: 24
+parse/0: instruction: 25
 parse/0: instruction: 2
 parse/0:   ingredient: {name: "2", type: 0}
 parse/0:   ingredient: {name: "2", type: 0}
diff --git a/cpp/.traces/next_ingredient b/cpp/.traces/next_ingredient
index 5dccf578..8ded3d51 100644
--- a/cpp/.traces/next_ingredient
+++ b/cpp/.traces/next_ingredient
@@ -1,4 +1,4 @@
-parse/0: instruction: 24
+parse/0: instruction: 25
 parse/0:   ingredient: {name: "2", type: 0}
 parse/0: instruction: 22
 parse/0:   product: {name: "12", type: 1}
diff --git a/cpp/.traces/reply b/cpp/.traces/reply
new file mode 100644
index 00000000..6b7b7417
--- /dev/null
+++ b/cpp/.traces/reply
@@ -0,0 +1,30 @@
+parse/0: instruction: 25
+parse/0:   ingredient: {name: "2", type: 0}
+parse/0:   product: {name: "3", type: 1}
+parse/0:   product: {name: "4", type: 1}
+parse/0: instruction: 22
+parse/0:   product: {name: "12", type: 1}
+parse/0: instruction: 2
+parse/0:   ingredient: {name: "1", type: 0}
+parse/0:   ingredient: {name: "12", type: 1}
+parse/0:   product: {name: "13", type: 1}
+parse/0: instruction: 23
+parse/0:   ingredient: {name: "12", type: 1}
+parse/0:   ingredient: {name: "13", type: 1}
+run/0: instruction main/0
+run/0: instruction f/0
+run/0: product 0 is 2
+mem/0: storing in location 12
+run/0: instruction f/1
+run/0: ingredient 0 is 1
+run/0: ingredient 1 is 12
+mem/0: location 12 is 2
+run/0: product 0 is 3
+mem/0: storing 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...]
+mem/0: storing in location 3
+run/0: result 1 is 1[3...]
+mem/0: storing in location 4
diff --git a/cpp/012run b/cpp/012run
index 70317745..1a95f408 100644
--- a/cpp/012run
+++ b/cpp/012run
@@ -86,6 +86,7 @@ void run(routine rr) {
         callee.incoming_atoms.push_back(read_memory(*p));
       }
       rr.calls.push(callee);
+      continue;  // not done with caller; don't increment pc
     }}
     ++pc;
   }
diff --git a/cpp/020call b/cpp/020call
index c0401cbe..18c54e63 100644
--- a/cpp/020call
+++ b/cpp/020call
@@ -36,3 +36,43 @@ case NEXT_INGREDIENT: {
   }
   break;
 }
+
+:(scenario "reply")
+recipe main [
+  3:integer, 4:integer <- f 2:literal
+]
+recipe f [
+  12:integer <- next_ingredient
+  13:integer <- add 1:literal, 12:integer
+  reply 12:integer, 13:integer
+]
++run: instruction main/0
++run: result 0 is 1[2...]
++mem: storing in location 3
++run: result 1 is 1[3...]
++mem: storing in location 4
+
+:(before "End Globals")
+const int REPLY = 23;
+:(before "End Primitive Recipe Numbers")
+Recipe_number["reply"] = REPLY;
+assert(Next_recipe_number == REPLY);
+Next_recipe_number++;
+:(before "End Primitive Recipe Implementations")
+case REPLY: {
+  vector<vector<int> > callee_results;
+  for (size_t i = 0; i < instructions[pc].ingredients.size(); ++i) {
+    callee_results.push_back(read_memory(instructions[pc].ingredients[i]));
+  }
+  rr.calls.pop();
+  size_t& new_pc = rr.calls.top().pc;
+//?   cout << new_pc << ": " << instructions[new_pc].products.size() << " <=> " << callee_results.size(); //? 2
+  assert(instructions[new_pc].products.size() <= callee_results.size());
+  for (size_t i = 0; i < instructions[new_pc].products.size(); ++i) {
+//?     cout << "AAA " << i << '\n'; //? 1
+    trace("run") << "result " << i << " is " << callee_results[i].size() << "[" << callee_results[i][0] << "...]";
+    write_memory(instructions[new_pc].products[i], callee_results[i]);
+  }
+  ++new_pc;
+  break;
+}