about summary refs log tree commit diff stats
path: root/054static_dispatch.cc
diff options
context:
space:
mode:
Diffstat (limited to '054static_dispatch.cc')
-rw-r--r--054static_dispatch.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/054static_dispatch.cc b/054static_dispatch.cc
index 0eb66443..7fdfa391 100644
--- a/054static_dispatch.cc
+++ b/054static_dispatch.cc
@@ -321,8 +321,18 @@ const recipe& best_variant(const instruction& inst, vector<recipe_ordinal>& cand
   int min_index = 0;
   for (int i = 0;  i < SIZE(candidates);  ++i) {
     const recipe& candidate = get(Recipe, candidates.at(i));
+    // prefer functions without extra or missing ingredients or products
     int score = abs(SIZE(candidate.products)-SIZE(inst.products))
                           + abs(SIZE(candidate.ingredients)-SIZE(inst.ingredients));
+    // prefer functions with non-address ingredients or products
+    for (int i = 0;  i < SIZE(candidate.ingredients);  ++i) {
+      if (is_mu_address(candidate.ingredients.at(i)))
+        ++score;
+    }
+    for (int i = 0;  i < SIZE(candidate.products);  ++i) {
+      if (is_mu_address(candidate.products.at(i)))
+        ++score;
+    }
     assert(score < 999);
     if (score < min_score) {
       min_score = score;
@@ -460,6 +470,21 @@ def foo x:num -> y:num [
 ]
 +mem: storing 35 in location 1
 
+:(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses_2)
+def main [
+  1:num <- foo 0 0
+]
+# Both variants need to bind 0 to address in first ingredient.
+# We still want to prefer the variant with a number rather than address for
+# _subsequent_ ingredients.
+def foo x:&:num y:&:num -> z:num [  # put the bad match before the good one
+  return 34
+]
+def foo x:&:num y:num -> z:num [
+  return 35
+]
++mem: storing 35 in location 1
+
 :(scenario static_dispatch_on_non_literal_character_ignores_variant_with_numbers)
 % Hide_errors = true;
 def main [