about summary refs log tree commit diff stats
path: root/cpp/012run
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-14 00:07:44 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-14 00:09:47 -0700
commitdf8bb4c30d8ef534ddde50a4ac8ce9ecb411b72f (patch)
tree1c85150627cff86ded3568a62a1f1a1cbed363c4 /cpp/012run
parentf7051fadd90af17820df750d448dc35ea63690e3 (diff)
downloadmu-df8bb4c30d8ef534ddde50a4ac8ce9ecb411b72f.tar.gz
902: c++: calling recipes with ingredients
Diffstat (limited to 'cpp/012run')
-rw-r--r--cpp/012run20
1 files changed, 13 insertions, 7 deletions
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;
   }