diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-03-12 13:02:12 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-03-12 13:02:12 -0700 |
commit | 3b82206fd6143da6be50ff5f3c7e4c050039548a (patch) | |
tree | 9ea57c92a900b71b752a97c3c2a60493700f3fd5 /054static_dispatch.cc | |
parent | 280eaa56ec45f87f02b5bd2938dd6e00a55743be (diff) | |
download | mu-3b82206fd6143da6be50ff5f3c7e4c050039548a.tar.gz |
3792
Bugfix: make sure 'print 0, 0' always does the right thing, no matter how it's overloaded. Thanks Ella Couch for reporting this.
Diffstat (limited to '054static_dispatch.cc')
-rw-r--r-- | 054static_dispatch.cc | 25 |
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 [ |