From c5ffb6e1cc9c5ff880d037c53b8ebc8562be0008 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 25 May 2015 22:27:19 -0700 Subject: 1459 --- html/048call_variable.cc.html | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 html/048call_variable.cc.html (limited to 'html/048call_variable.cc.html') diff --git a/html/048call_variable.cc.html b/html/048call_variable.cc.html new file mode 100644 index 00000000..e933bd0c --- /dev/null +++ b/html/048call_variable.cc.html @@ -0,0 +1,81 @@ + + + + +048call_variable.cc + + + + + + + + + + +
+//: 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;
+}
+
+ + + -- cgit 1.4.1-2-gfad0