about summary refs log tree commit diff stats
path: root/cpp/020call
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/020call
parentf7051fadd90af17820df750d448dc35ea63690e3 (diff)
downloadmu-df8bb4c30d8ef534ddde50a4ac8ce9ecb411b72f.tar.gz
902: c++: calling recipes with ingredients
Diffstat (limited to 'cpp/020call')
-rw-r--r--cpp/020call30
1 files changed, 30 insertions, 0 deletions
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;
+}