about summary refs log tree commit diff stats
path: root/037call_variable.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-03 18:07:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-03 18:11:25 -0700
commit608d5c9aa148801081d7dca80b6f3bfb5b285f08 (patch)
tree8f24ec8efb2c2b5081c068b90537913cef86973d /037call_variable.cc
parent7e867a045e29a37d66eedce03c95a2feb979411a (diff)
downloadmu-608d5c9aa148801081d7dca80b6f3bfb5b285f08.tar.gz
1698
Diffstat (limited to '037call_variable.cc')
-rw-r--r--037call_variable.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/037call_variable.cc b/037call_variable.cc
new file mode 100644
index 00000000..9514ed95
--- /dev/null
+++ b/037call_variable.cc
@@ -0,0 +1,44 @@
+//: push a variable recipe on the call stack
+
+:(scenario call_literal_recipe)
+recipe main [
+  1:number <- call f:recipe, 34:literal
+]
+recipe f [
+  2:number <- next-ingredient
+  reply 2:number
+]
++mem: storing 34 in location 1
+
+:(scenario call_variable)
+recipe main [
+  1:number/recipe <- copy 1001:literal/f  # hack: assumes tests start recipes at 1000
+  2:number <- call 1:number/recipe, 34:literal
+]
+recipe f [  # recipe 1001
+  3:number <- next-ingredient
+  reply 3:number
+]
++mem: storing 34 in location 2
+#? ?
+
+:(before "End Primitive Recipe Declarations")
+CALL,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["call"] = CALL;
+:(before "End Primitive Recipe Implementations")
+case CALL: {
+  recipe_number r = 0;
+  if (current_instruction().ingredients.at(0).initialized) {
+    assert(scalar(ingredients.at(0)));
+    // 'call' received an integer recipe_number
+    r = ingredients.at(0).at(0);
+  }
+  else {
+    // 'call' received a literal recipe name
+    r = Recipe_number[current_instruction().ingredients.at(0).name];
+  }
+  Current_routine->calls.push_front(call(r));
+  ingredients.erase(ingredients.begin());  // drop the callee
+  goto complete_call;
+}