diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-06-15 22:12:03 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-06-15 22:12:03 -0700 |
commit | 0edd9b9fc60440213e4df926ea511419ee291f1e (patch) | |
tree | 84b22f7afdeb9110ad7105c5fc070dacff178502 /025compare.cc | |
parent | 3f34ac9369978b396d00a4fd02c9fb06b8eea621 (diff) | |
download | mu-0edd9b9fc60440213e4df926ea511419ee291f1e.tar.gz |
4257 - abortive attempt at safe fat pointers
I've been working on this slowly over several weeks, but it's too hard to support 0 as the null value for addresses. I constantly have to add exceptions for scalar value corresponding to an address type (now occupying 2 locations). The final straw is the test for 'reload': x:num <- reload text 'reload' returns an address. But there's no way to know that for arbitrary instructions. New plan: let's put this off for a bit and first create support for literals. Then use 'null' instead of '0' for addresses everywhere. Then it'll be easy to just change what 'null' means.
Diffstat (limited to '025compare.cc')
-rw-r--r-- | 025compare.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/025compare.cc b/025compare.cc index 92878208..c82f3578 100644 --- a/025compare.cc +++ b/025compare.cc @@ -29,6 +29,8 @@ case EQUAL: { } :(before "End Primitive Recipe Implementations") case EQUAL: { + // todo: keep the address exception from slowing down the common case + drop_alloc_ids_if_comparing_address_to_literal_0(ingredients); vector<double>& exemplar = ingredients.at(0); bool result = true; for (int i = /*skip exemplar*/1; i < SIZE(ingredients); ++i) { @@ -41,6 +43,23 @@ case EQUAL: { products.at(0).push_back(result); break; } +:(code) +void drop_alloc_ids_if_comparing_address_to_literal_0(vector<vector<double> >& ingredients) { + bool any_ingredient_is_null = false; + bool any_ingredient_is_address = false; + for (int i = 0; i < SIZE(current_instruction().ingredients); ++i) { + if (current_instruction().ingredients.at(i).name == "0") + any_ingredient_is_null = true; + if (is_mu_address(current_instruction().ingredients.at(i))) + any_ingredient_is_address = true; + } + if (any_ingredient_is_null && any_ingredient_is_address) { + for (int i = 0; i < SIZE(ingredients); ++i) { + if (is_mu_address(current_instruction().ingredients.at(i))) + ingredients.at(i).erase(ingredients.at(i).begin()); + } + } +} :(scenario equal) def main [ @@ -74,6 +93,42 @@ def main [ ] +mem: storing 0 in location 1 +:(scenario equal_address_null) +def main [ + 1:&:num <- copy 0 + 10:bool <- equal 1:&:num, 0 +] ++mem: storing 1 in location 10 + +:(scenario equal_address_null_2) +def main [ + 1:&:num <- copy 0 + 10:bool <- equal 0, 1:&:num +] ++mem: storing 1 in location 10 + +:(scenario equal_address_null_3) +def main [ + 1:&:num <- new num:type + 10:bool <- equal 1:&:num, 0 +] ++mem: storing 0 in location 10 + +:(scenario equal_address_null_multiple) +def main [ + 1:&:num <- copy 0 + 10:bool <- equal 0, 1:&:num, 0 +] ++mem: storing 1 in location 10 + +:(scenario equal_address_null_multiple_2) +def main [ + 1:&:num <- copy 0 + 3:&:num <- copy 0 + 10:bool <- equal 0, 1:&:num, 0, 3:&:num +] ++mem: storing 1 in location 10 + :(before "End Primitive Recipe Declarations") NOT_EQUAL, :(before "End Primitive Recipe Numbers") @@ -101,6 +156,8 @@ case NOT_EQUAL: { } :(before "End Primitive Recipe Implementations") case NOT_EQUAL: { + // todo: keep the address exception from slowing down the common case + drop_alloc_ids_if_comparing_address_to_literal_0(ingredients); vector<double>& exemplar = ingredients.at(0); products.resize(1); bool equal_ingredients = equal(ingredients.at(1).begin(), ingredients.at(1).end(), exemplar.begin()); |