From 479e7a547adee04d3f9532eff58da79e28d28b91 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 30 Oct 2017 02:39:11 -0700 Subject: 4092 Some cleanup as I remind myself of how generic functions work in Mu. --- 054static_dispatch.cc | 9 +++++---- 056shape_shifting_recipe.cc | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/054static_dispatch.cc b/054static_dispatch.cc index e4e417d8..702e5331 100644 --- a/054static_dispatch.cc +++ b/054static_dispatch.cc @@ -180,7 +180,7 @@ void resolve_ambiguous_calls(const recipe_ordinal r) { } string best_variant(instruction& inst, const recipe& caller_recipe) { - vector& variants = get(Recipe_variants, inst.name); + const vector& variants = get(Recipe_variants, inst.name); vector candidates; // Static Dispatch Phase 1 @@ -234,7 +234,7 @@ string best_variant(instruction& inst, const recipe& caller_recipe) { } // phase 1 -vector strictly_matching_variants(const instruction& inst, vector& variants) { +vector strictly_matching_variants(const instruction& inst, const vector& variants) { vector result; for (int i = 0; i < SIZE(variants); ++i) { if (variants.at(i) == -1) continue; @@ -263,7 +263,7 @@ bool all_header_reagents_strictly_match(const instruction& inst, const recipe& v } // phase 2 -vector strictly_matching_variants_except_literal_against_address_or_boolean(const instruction& inst, vector& variants) { +vector strictly_matching_variants_except_literal_against_address_or_boolean(const instruction& inst, const vector& variants) { vector result; for (int i = 0; i < SIZE(variants); ++i) { if (variants.at(i) == -1) continue; @@ -302,7 +302,7 @@ bool types_strictly_match_except_literal_against_address_or_boolean(const reagen } // phase 4 -vector matching_variants(const instruction& inst, vector& variants) { +vector matching_variants(const instruction& inst, const vector& variants) { vector result; for (int i = 0; i < SIZE(variants); ++i) { if (variants.at(i) == -1) continue; @@ -333,6 +333,7 @@ bool all_header_reagents_match(const instruction& inst, const recipe& variant) { // tie-breaker for each phase const recipe& best_variant(const instruction& inst, vector& candidates) { assert(!candidates.empty()); + if (SIZE(candidates) == 1) return get(Recipe, candidates.at(0)); int min_score = 999; int min_index = 0; for (int i = 0; i < SIZE(candidates); ++i) { diff --git a/056shape_shifting_recipe.cc b/056shape_shifting_recipe.cc index 917fce5c..d28b5713 100644 --- a/056shape_shifting_recipe.cc +++ b/056shape_shifting_recipe.cc @@ -53,7 +53,7 @@ if (!candidates.empty()) { trace(9992, "transform") << "found variant to specialize: " << exemplar << ' ' << get(Recipe, exemplar).name << end(); recipe_ordinal new_recipe_ordinal = new_variant(exemplar, inst, caller_recipe); if (new_recipe_ordinal == 0) goto skip_shape_shifting_variants; - variants.push_back(new_recipe_ordinal); // side-effect + get(Recipe_variants, inst.name).push_back(new_recipe_ordinal); // side-effect recipe& variant = get(Recipe, new_recipe_ordinal); // perform all transforms on the new specialization if (!variant.steps.empty()) { @@ -87,7 +87,7 @@ if (is_literal(from) && is_mu_address(to)) :(code) // phase 3 of static dispatch -vector strictly_matching_shape_shifting_variants(const instruction& inst, vector& variants) { +vector strictly_matching_shape_shifting_variants(const instruction& inst, const vector& variants) { vector result; for (int i = 0; i < SIZE(variants); ++i) { if (variants.at(i) == -1) continue; @@ -118,6 +118,7 @@ bool all_concrete_header_reagents_strictly_match(const instruction& inst, const // tie-breaker for phase 3 recipe_ordinal best_shape_shifting_variant(const instruction& inst, vector& candidates) { assert(!candidates.empty()); + if (SIZE(candidates) == 1) return candidates.at(0); // primary score int max_score = -1; for (int i = 0; i < SIZE(candidates); ++i) { -- cgit 1.4.1-2-gfad0