about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-05 19:39:20 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-05 19:39:20 -0700
commit5e14ce10db89a72a727c8dead0b27b036044099c (patch)
tree3bbf29499b5f62ed936ee5d46c459f89aef6a20a
parent363685b87d15307c91d1f330f44b57bf377361a8 (diff)
downloadmu-5e14ce10db89a72a727c8dead0b27b036044099c.tar.gz
1270 - we can now pass ingredients to routines as we start them
-rw-r--r--cpp/.traces/start_running_returns_routine_id2
-rw-r--r--cpp/.traces/start_running_takes_args32
-rw-r--r--cpp/036call_ingredient.cc4
-rw-r--r--cpp/038scheduler.cc14
4 files changed, 47 insertions, 5 deletions
diff --git a/cpp/.traces/start_running_returns_routine_id b/cpp/.traces/start_running_returns_routine_id
index 868b4ed2..dde9fca2 100644
--- a/cpp/.traces/start_running_returns_routine_id
+++ b/cpp/.traces/start_running_returns_routine_id
@@ -20,5 +20,3 @@ run/0: instruction f2/0
 run/0: {name: "12", value: 12, type: 1, properties: ["12": "integer"]} <- copy/1 {name: "44", value: 44, type: 0, properties: ["44": "literal"]}
 run/0: ingredient 0 is 44
 mem/0: storing 44 in location 12
-schedule/0: f1
-schedule/0: f2
diff --git a/cpp/.traces/start_running_takes_args b/cpp/.traces/start_running_takes_args
new file mode 100644
index 00000000..062c7371
--- /dev/null
+++ b/cpp/.traces/start_running_takes_args
@@ -0,0 +1,32 @@
+parse/0: instruction: start-running
+parse/0:   ingredient: {name: "f2", value: 0, type: 0, properties: ["f2": "recipe"]}
+parse/0:   ingredient: {name: "3", value: 0, type: 0, properties: ["3": "literal"]}
+parse/0: instruction: next-ingredient
+parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
+parse/0: instruction: add
+parse/0:   ingredient: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
+parse/0:   ingredient: {name: "1", value: 0, type: 0, properties: ["1": "literal"]}
+parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
+after-brace/0: recipe f1
+after-brace/0: start-running ...
+after-brace/0: recipe f2
+after-brace/0: next-ingredient ...
+after-brace/0: add ...
+new/0: routine allocated memory from 1000 to 101000
+schedule/0: f1
+run/0: instruction f1/0
+run/0: start-running/34 {name: "f2", value: 0, type: 0, properties: ["f2": "recipe"]}, {name: "3", value: 3, type: 0, properties: ["3": "literal"]}
+run/0: ingredient 0 is f2
+new/0: routine allocated memory from 101000 to 201000
+schedule/0: f2
+run/0: instruction f2/0
+run/0: {name: "1", value: 1, type: 1, properties: ["1": "integer"]} <- next-ingredient/30 
+run/0: product 0 is 3
+mem/0: storing 3 in location 1
+run/0: instruction f2/1
+run/0: {name: "2", value: 2, type: 1, properties: ["2": "integer"]} <- add/2 {name: "1", value: 1, type: 1, properties: ["1": "integer"]}, {name: "1", value: 1, type: 0, properties: ["1": "literal"]}
+run/0: ingredient 0 is 1
+mem/0: location 1 is 3
+run/0: ingredient 1 is 1
+run/0: product 0 is 4
+mem/0: storing 4 in location 2
diff --git a/cpp/036call_ingredient.cc b/cpp/036call_ingredient.cc
index bbbe3483..6224f8df 100644
--- a/cpp/036call_ingredient.cc
+++ b/cpp/036call_ingredient.cc
@@ -30,8 +30,8 @@ call(recipe_number r) :running_recipe(r), running_step_index(0), next_ingredient
 
 :(replace "Current_routine->calls.push(call(current_instruction().operation))" following "End Primitive Recipe Implementations")
 call callee(current_instruction().operation);
-for (vector<reagent>::const_iterator p = current_instruction().ingredients.begin(); p != current_instruction().ingredients.end(); ++p) {
-  callee.ingredient_atoms.push_back(read_memory(*p));
+for (size_t i = 0; i < current_instruction().ingredients.size(); ++i) {
+  callee.ingredient_atoms.push_back(read_memory(current_instruction().ingredients[i]));
 }
 Current_routine->calls.push(callee);
 
diff --git a/cpp/038scheduler.cc b/cpp/038scheduler.cc
index d387bae5..d5d6ca87 100644
--- a/cpp/038scheduler.cc
+++ b/cpp/038scheduler.cc
@@ -113,6 +113,9 @@ case START_RUNNING: {
   trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name;
   assert(!current_instruction().ingredients[0].initialized);
   routine* new_routine = new routine(Recipe_number[current_instruction().ingredients[0].name]);
+  // populate ingredients
+  for (index_t i = 1; i < current_instruction().ingredients.size(); ++i)
+    new_routine->calls.top().ingredient_atoms.push_back(read_memory(current_instruction().ingredients[i]));
   Routines.push_back(new_routine);
   if (!current_instruction().products.empty()) {
     vector<long long int> result;
@@ -155,8 +158,17 @@ recipe f2 [
 +schedule: f1
 +run: instruction f1/2
 
+:(scenario start_running_takes_args)
+recipe f1 [
+  start-running f2:recipe, 3:literal
+]
+recipe f2 [
+  1:integer <- next-ingredient
+  2:integer <- add 1:integer, 1:literal
+]
++mem: storing 4 in location 2
+
 :(scenario start_running_returns_routine_id)
-% Scheduling_interval = 1;
 recipe f1 [
   1:integer <- start-running f2:recipe
 ]