about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-27 22:01:23 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-27 22:03:58 -0800
commit016599f1d2f861a5c36e6f88c05c98ef88e0ee85 (patch)
tree2a6019bf69a4764a0c7204f5904c9ffd84dff77c
parentfca48e92d4e51eb7e5b1a811b65e5d69fadeb713 (diff)
downloadmu-016599f1d2f861a5c36e6f88c05c98ef88e0ee85.tar.gz
2484
Eliminate one of several hacky type-check helpers; they've been
proliferating lately.
-rw-r--r--021check_instruction.cc45
-rw-r--r--035call_ingredient.cc11
-rw-r--r--038scheduler.cc2
-rw-r--r--059shape_shifting_recipe.cc3
4 files changed, 23 insertions, 38 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc
index 76d3ddb2..e2fc08d6 100644
--- a/021check_instruction.cc
+++ b/021check_instruction.cc
@@ -82,8 +82,19 @@ recipe main [
 $error: 0
 
 :(code)
+// types_match with some special-cases
+bool types_coercible(const reagent& lhs, const reagent& rhs) {
+  if (types_match(lhs, rhs)) return true;
+  if (is_mu_address(rhs) && is_mu_number(lhs)) return true;
+  // End types_coercible Special-cases
+  return false;
+}
+
 bool types_match(const reagent& lhs, const reagent& rhs) {
-  if (!is_unsafe(rhs) && is_literal(rhs)) return valid_type_for_literal(lhs, rhs) && size_of(rhs) == size_of(lhs);
+  if (!is_unsafe(rhs)) {
+    if (is_mu_address(lhs) && is_literal(rhs)) return rhs.name == "0";
+    if (is_literal(rhs)) return valid_type_for_literal(lhs, rhs) && size_of(rhs) == size_of(lhs);
+  }
   return types_strictly_match(lhs, rhs);
 }
 
@@ -99,22 +110,6 @@ bool types_strictly_match(reagent lhs, reagent rhs) {
   return types_match(lhs.type, rhs.type);
 }
 
-// types_match with some special-cases
-bool types_coercible(const reagent& lhs, const reagent& rhs) {
-  if (types_match(lhs, rhs)) return true;
-  if (is_mu_address(rhs) && is_mu_number(lhs)) return true;
-  // End types_coercible Special-cases
-  return false;
-}
-
-bool valid_type_for_literal(const reagent& lhs, const reagent& literal_rhs) {
-  if (is_mu_array(lhs)) return false;
-  // End valid_type_for_literal Special-cases
-  // allow writing 0 to any address
-  if (is_mu_address(lhs)) return literal_rhs.name == "0";
-  return true;
-}
-
 // two types match if the second begins like the first
 // (trees perform the same check recursively on each subtree)
 bool types_match(type_tree* lhs, type_tree* rhs) {
@@ -130,16 +125,12 @@ bool types_match(type_tree* lhs, type_tree* rhs) {
   return types_match(lhs->left, rhs->left) && types_match(lhs->right, rhs->right);
 }
 
-// hacky version that allows 0 addresses
-bool types_match(const reagent lhs, const type_tree* rhs, const vector<double>& data) {
-  if (is_dummy(lhs)) return true;
-  if (rhs->value == 0) {
-    if (lhs.type->value == get(Type_ordinal, "array")) return false;
-    if (lhs.type->value == get(Type_ordinal, "address")) return scalar(data) && data.at(0) == 0;
-    return size_of(rhs) == size_of(lhs);
-  }
-  if (lhs.type->value != rhs->value) return false;
-  return types_match(lhs.type->left, rhs->left) && types_match(lhs.type->right, rhs->right);
+bool valid_type_for_literal(const reagent& lhs, const reagent& literal_rhs) {
+  if (is_mu_array(lhs)) return false;
+  // End valid_type_for_literal Special-cases
+  // allow writing 0 to any address
+  if (is_mu_address(lhs)) return literal_rhs.name == "0";
+  return true;
 }
 
 bool is_raw(const reagent& r) {
diff --git a/035call_ingredient.cc b/035call_ingredient.cc
index 919320ea..2f28c8f7 100644
--- a/035call_ingredient.cc
+++ b/035call_ingredient.cc
@@ -22,7 +22,7 @@ recipe f [
 
 :(before "End call Fields")
 vector<vector<double> > ingredient_atoms;
-vector<type_tree*> ingredient_types;
+vector<reagent> ingredients;
 long long int next_ingredient_to_process;
 :(before "End call Constructor")
 next_ingredient_to_process = 0;
@@ -32,13 +32,9 @@ for (long long int i = 0; i < SIZE(ingredients); ++i) {
   current_call().ingredient_atoms.push_back(ingredients.at(i));
   reagent ingredient = call_instruction.ingredients.at(i);
   canonize_type(ingredient);
-  current_call().ingredient_types.push_back(ingredient.type);
+  current_call().ingredients.push_back(ingredient);
   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")
 NEXT_INGREDIENT,
@@ -65,8 +61,7 @@ case NEXT_INGREDIENT: {
         raise_error << "main: wrong type for ingredient " << product.original_string << '\n' << end();
     }
     else 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))) {
+                          current_call().ingredients.at(current_call().next_ingredient_to_process))) {
       raise_error << maybe(current_recipe_name()) << "wrong type for ingredient " << product.original_string << '\n' << end();
     }
     products.push_back(
diff --git a/038scheduler.cc b/038scheduler.cc
index c6f903d9..cee4f8f8 100644
--- a/038scheduler.cc
+++ b/038scheduler.cc
@@ -165,7 +165,7 @@ case START_RUNNING: {
     new_routine->calls.front().ingredient_atoms.push_back(ingredients.at(i));
     reagent ingredient = current_instruction().ingredients.at(i);
     canonize_type(ingredient);
-    new_routine->calls.front().ingredient_types.push_back(ingredient.type);
+    new_routine->calls.front().ingredients.push_back(ingredient);
     ingredient.type = NULL;  // release long-lived pointer
   }
   Routines.push_back(new_routine);
diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc
index 3d003b42..019206f7 100644
--- a/059shape_shifting_recipe.cc
+++ b/059shape_shifting_recipe.cc
@@ -613,8 +613,7 @@ recipe foo x:address:_elem -> y:address:_elem [
   load-ingredients
   y <- copy x
 ]
-+error: foo: failed to map a type to x
-+error: foo: failed to map a type to y
++error: ran into unspecialized shape-shifting recipe foo
 
 :(scenario specialize_with_literal_5)
 recipe main [