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_ingredient18
-rw-r--r--cpp/012run20
-rw-r--r--cpp/020call30
4 files changed, 62 insertions, 8 deletions
diff --git a/cpp/.traces/calling_recipe b/cpp/.traces/calling_recipe
index c0538ca8..ab7089e0 100644
--- a/cpp/.traces/calling_recipe
+++ b/cpp/.traces/calling_recipe
@@ -1,4 +1,4 @@
-parse/0: instruction: 23
+parse/0: instruction: 24
 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
new file mode 100644
index 00000000..5dccf578
--- /dev/null
+++ b/cpp/.traces/next_ingredient
@@ -0,0 +1,18 @@
+parse/0: instruction: 24
+parse/0:   ingredient: {name: "2", type: 0}
+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}
+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
diff --git a/cpp/012run b/cpp/012run
index 1a17c6d2..12e5696e 100644
--- a/cpp/012run
+++ b/cpp/012run
@@ -23,9 +23,10 @@ recipe main [
 struct call {
   recipe_number running_recipe;
   size_t pc;
-  vector<int> incoming_atoms;
-  vector<int> outgoing_atoms;
-  call(recipe_number r) :running_recipe(r), pc(0) {}
+  vector<vector<int> > incoming_atoms;
+  size_t next_ingredient_to_process;
+  vector<vector<int> > outgoing_atoms;
+  call(recipe_number r) :running_recipe(r), pc(0), next_ingredient_to_process(0) {}
 };
 typedef stack<call> call_stack;
 
@@ -59,7 +60,7 @@ void run(routine rr) {
       ++rr.calls.top().pc;
     }
     size_t& pc = rr.calls.top().pc;
-//?     cout << "instruction " << TOP_RECIPE.name << '/' << pc << '\n'; //? 1
+//?     cout << "instruction " << TOP_RECIPE.name << '/' << pc << '\n'; //? 2
     trace("run") << "instruction " << TOP_RECIPE.name << '/' << pc;
     switch (instructions[pc].operation) {
     // Primitive Recipe Implementations.
@@ -71,13 +72,18 @@ void run(routine rr) {
     }
     // End Primitive Recipe Implementations.
     default: {
+//?       cout << "non primitive op: " << instructions[pc].operation << '\n'; //? 1
       if (Recipe.find(instructions[pc].operation) == Recipe.end()) {
         raise << "undefined operation " << instructions[pc].operation << '\n';
         break;
       }
-//?       cout << "calling " << instructions[pc].operation << '\n'; //? 1
-      rr.calls.push(call(instructions[pc].operation));
-      // todo: push incoming atoms
+//?       cout << "calling " << instructions[pc].operation << '\n'; //? 2
+      call callee(instructions[pc].operation);
+      for (vector<reagent>::iterator p = instructions[pc].ingredients.begin(); p != instructions[pc].ingredients.end(); ++p) {
+//?         cout << "push back: " << p->to_string() << '\n'; //? 1
+        callee.incoming_atoms.push_back(read_memory(*p));
+      }
+      rr.calls.push(callee);
     }}
     ++pc;
   }
diff --git a/cpp/020call b/cpp/020call
index bcc29b3d..c0401cbe 100644
--- a/cpp/020call
+++ b/cpp/020call
@@ -6,3 +6,33 @@ recipe f [
   3:integer <- add 2:literal, 2:literal
 ]
 +mem: storing in location 3
+
+:(scenario "next_ingredient")
+recipe main [
+  f 2:literal
+]
+recipe f [
+  12:integer <- next_ingredient
+  13:integer <- add 1:literal, 12:integer
+]
++run: instruction f/1
++mem: location 12 is 2
++mem: storing in location 13
+
+:(before "End Globals")
+const int NEXT_INGREDIENT = 22;
+:(before "End Primitive Recipe Numbers")
+Recipe_number["next_ingredient"] = NEXT_INGREDIENT;
+assert(Next_recipe_number == NEXT_INGREDIENT);
+Next_recipe_number++;
+:(before "End Primitive Recipe Implementations")
+case NEXT_INGREDIENT: {
+  if (rr.calls.top().next_ingredient_to_process < rr.calls.top().incoming_atoms.size()) {
+    trace("run") << "product 0 is "
+        << rr.calls.top().incoming_atoms[rr.calls.top().next_ingredient_to_process][0];
+    write_memory(instructions[pc].products[0],
+        rr.calls.top().incoming_atoms[rr.calls.top().next_ingredient_to_process]);
+    ++rr.calls.top().next_ingredient_to_process;
+  }
+  break;
+}