about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-27 22:14:05 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-27 22:14:05 -0800
commitdfdbcbab4299bbb4fc2725abf7fa26ac592e296e (patch)
tree551c977526bab1429caf8710f5077778a8ca89eb
parenta2ee95cb89d4cf8b6a3b03721ceaadd8bf31a964 (diff)
downloadmu-dfdbcbab4299bbb4fc2725abf7fa26ac592e296e.tar.gz
2486
More cleanup. Haven't bothered to figure out why the trace for
specialize_with_literal_4 is repeatedly perturbed.
-rw-r--r--021check_instruction.cc24
-rw-r--r--059shape_shifting_recipe.cc5
2 files changed, 14 insertions, 15 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc
index cb3117ec..ada4333d 100644
--- a/021check_instruction.cc
+++ b/021check_instruction.cc
@@ -91,9 +91,15 @@ bool types_coercible(const reagent& lhs, const reagent& rhs) {
 }
 
 bool types_match(const reagent& lhs, const reagent& rhs) {
-  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);
+  // to sidestep type-checking, use /unsafe in the source.
+  // this will be highlighted in red inside vim. just for setting up some tests.
+  if (is_unsafe(rhs)) return true;
+  if (is_literal(rhs)) {
+    if (is_mu_array(lhs)) return false;
+    // End Matching Types For Literal(lhs)
+    // allow writing 0 to any address
+    if (is_mu_address(lhs)) return rhs.name == "0";
+    return size_of(lhs) == 1;  // literals are always scalars
   }
   return types_strictly_match(lhs, rhs);
 }
@@ -101,11 +107,11 @@ bool types_match(const reagent& lhs, const reagent& rhs) {
 // copy arguments because later layers will want to make changes to them
 // without perturbing the caller
 bool types_strictly_match(reagent lhs, reagent rhs) {
-  // '_' never raises type error
-  if (is_dummy(lhs)) return true;
   // to sidestep type-checking, use /unsafe in the source.
   // this will be highlighted in red inside vim. just for setting up some tests.
   if (is_unsafe(rhs)) return true;
+  // '_' never raises type error
+  if (is_dummy(lhs)) return true;
   if (!lhs.type) return !rhs.type;
   return types_match(lhs.type, rhs.type);
 }
@@ -123,14 +129,6 @@ bool types_match(type_tree* lhs, type_tree* rhs) {
   return types_match(lhs->left, rhs->left) && types_match(lhs->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) {
   return has_property(r, "raw");
 }
diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc
index 019206f7..5c223e4d 100644
--- a/059shape_shifting_recipe.cc
+++ b/059shape_shifting_recipe.cc
@@ -37,7 +37,7 @@ if (Current_routine->calls.front().running_step_index == 0
 
 //: Make sure we don't match up literals with type ingredients without
 //: specialization.
-:(before "End valid_type_for_literal Special-cases")
+:(before "End Matching Types For Literal(lhs)")
 if (contains_type_ingredient_name(lhs)) return false;
 
 //: We'll be creating recipes without loading them from anywhere by
@@ -613,7 +613,8 @@ recipe foo x:address:_elem -> y:address:_elem [
   load-ingredients
   y <- copy x
 ]
-+error: ran into unspecialized shape-shifting recipe foo
++error: foo: failed to map a type to x
++error: foo: failed to map a type to y
 
 :(scenario specialize_with_literal_5)
 recipe main [