about summary refs log tree commit diff stats
path: root/035call_ingredient.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-28 13:08:26 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-28 13:19:41 -0700
commit1fa530589eee7b668d936e77c1c430f18907a481 (patch)
tree95a506363d74231d1e85b402549b0ca6a466391e /035call_ingredient.cc
parent48086e1044a8c000eb7977621cde0813f7bb70cf (diff)
downloadmu-1fa530589eee7b668d936e77c1c430f18907a481.tar.gz
2299 - check types of ingredients in calls
Still very incomplete:

a) we perform the check at runtime

b) tests for edit and sandbox apps no longer work; we can't fix them
until we get type parameters in both containers and recipes (because
list and list operations need to become generic).
Diffstat (limited to '035call_ingredient.cc')
-rw-r--r--035call_ingredient.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/035call_ingredient.cc b/035call_ingredient.cc
index 41e7811b..eb899899 100644
--- a/035call_ingredient.cc
+++ b/035call_ingredient.cc
@@ -30,7 +30,14 @@ next_ingredient_to_process = 0;
 :(before "End Call Housekeeping")
 for (long long int i = 0; i < SIZE(ingredients); ++i) {
   current_call().ingredient_atoms.push_back(ingredients.at(i));
-  current_call().ingredient_types.push_back(call_instruction.ingredients.at(i).type);
+  reagent ingredient = call_instruction.ingredients.at(i);
+  canonize_type(ingredient);
+  current_call().ingredient_types.push_back(ingredient.type);
+  ingredient.type = NULL;  // release long-lived pointer
+}
+:(before "End call Destructor")
+for (long long int i = 0; i < SIZE(ingredient_types); ++i) {
+  delete ingredient_types.at(i);
 }
 
 :(before "End Primitive Recipe Declarations")
@@ -49,6 +56,14 @@ case NEXT_INGREDIENT: {
 case NEXT_INGREDIENT: {
   assert(!Current_routine->calls.empty());
   if (current_call().next_ingredient_to_process < SIZE(current_call().ingredient_atoms)) {
+    reagent product = current_instruction().products.at(0);
+    canonize_type(product);
+    if (!types_match(product,
+                     current_call().ingredient_types.at(current_call().next_ingredient_to_process),
+                     current_call().ingredient_atoms.at(current_call().next_ingredient_to_process)
+                     )) {
+      raise_error << maybe(current_recipe_name()) << "wrong type for ingredient " << current_instruction().products.at(0).original_string << '\n' << end();
+    }
     products.push_back(
         current_call().ingredient_atoms.at(current_call().next_ingredient_to_process));
     assert(SIZE(products) == 1);  products.resize(2);  // push a new vector