about summary refs log tree commit diff stats
path: root/071recipe.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-22 04:44:07 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-22 04:44:07 -0700
commita542b5a9c58993c95332bc7f3f5289dac2d7a945 (patch)
tree8662f3f7241f49b36df874d10021a3a9980514d2 /071recipe.cc
parent70f4e9b60d4726d8c42560ec5cf209eb3a33f826 (diff)
downloadmu-a542b5a9c58993c95332bc7f3f5289dac2d7a945.tar.gz
3545
Type-check ingredients of 'start-running'
Diffstat (limited to '071recipe.cc')
-rw-r--r--071recipe.cc34
1 files changed, 24 insertions, 10 deletions
diff --git a/071recipe.cc b/071recipe.cc
index 9135feda..2acfa840 100644
--- a/071recipe.cc
+++ b/071recipe.cc
@@ -160,24 +160,38 @@ void check_indirect_calls_against_header(const recipe_ordinal r) {
   const recipe& caller = get(Recipe, r);
   for (int i = 0;  i < SIZE(caller.steps);  ++i) {
     const instruction& inst = caller.steps.at(i);
-    if (inst.operation != CALL) continue;
-    if (inst.ingredients.empty()) continue;  // error raised above
+    if (inst.ingredients.empty()) continue;  // if indirect call, error raised above
     const reagent& callee = inst.ingredients.at(0);
-    if (!is_mu_recipe(callee)) continue;  // error raised above
+    if (!is_mu_recipe(callee)) continue;  // if indirect call, error raised above
     const recipe callee_header = is_literal(callee) ? get(Recipe, callee.value) : from_reagent(inst.ingredients.at(0));
     if (!callee_header.has_header) continue;
-    for (long int i = /*skip callee*/1;  i < min(SIZE(inst.ingredients), SIZE(callee_header.ingredients)+/*skip callee*/1);  ++i) {
-      if (!types_coercible(callee_header.ingredients.at(i-/*skip callee*/1), inst.ingredients.at(i)))
-        raise << maybe(caller.name) << "ingredient " << i-/*skip callee*/1 << " has the wrong type at '" << inst.original_string << "'\n" << end();
+    if (is_indirect_call_with_ingredients(inst.operation)) {
+      for (long int i = /*skip callee*/1;  i < min(SIZE(inst.ingredients), SIZE(callee_header.ingredients)+/*skip callee*/1);  ++i) {
+        if (!types_coercible(callee_header.ingredients.at(i-/*skip callee*/1), inst.ingredients.at(i)))
+          raise << maybe(caller.name) << "ingredient " << i-/*skip callee*/1 << " has the wrong type at '" << inst.original_string << "'\n" << end();
+      }
     }
-    for (long int i = 0;  i < min(SIZE(inst.products), SIZE(callee_header.products));  ++i) {
-      if (is_dummy(inst.products.at(i))) continue;
-      if (!types_coercible(callee_header.products.at(i), inst.products.at(i)))
-        raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << inst.original_string << "'\n" << end();
+    if (is_indirect_call_with_products(inst.operation)) {
+      for (long int i = 0;  i < min(SIZE(inst.products), SIZE(callee_header.products));  ++i) {
+        if (is_dummy(inst.products.at(i))) continue;
+        if (!types_coercible(callee_header.products.at(i), inst.products.at(i)))
+          raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << inst.original_string << "'\n" << end();
+      }
     }
   }
 }
 
+bool is_indirect_call_with_ingredients(const recipe_ordinal r) {
+  if (r == CALL) return true;
+  // End is_indirect_call_with_ingredients Special-cases
+  return false;
+}
+bool is_indirect_call_with_products(const recipe_ordinal r) {
+  if (r == CALL) return true;
+  // End is_indirect_call_with_products Special-cases
+  return false;
+}
+
 recipe from_reagent(const reagent& r) {
   assert(r.type);
   recipe result_header;  // will contain only ingredients and products, nothing else