diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-07-21 11:56:27 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-07-21 12:04:55 -0700 |
commit | fc19980d91e306df87b308d0c2875a2dcaf4b5c7 (patch) | |
tree | cb0a172d6ccc356ef3a707b1b00c920621312cf9 | |
parent | 2c697d86791b0771e34b44d0b6864030595c6334 (diff) | |
download | mu-fc19980d91e306df87b308d0c2875a2dcaf4b5c7.tar.gz |
3119
Warn if 'put' or 'put-index' has a mismatch in the type of the product, not just the name. It won't do any harm, but could be misleading to a later reader. In both instructions, the product is just for documentation.
-rw-r--r-- | 030container.cc | 4 | ||||
-rw-r--r-- | 032array.cc | 4 | ||||
-rw-r--r-- | 035lookup.cc | 44 |
3 files changed, 50 insertions, 2 deletions
diff --git a/030container.cc b/030container.cc index 0c3da911..e22fe4be 100644 --- a/030container.cc +++ b/030container.cc @@ -434,10 +434,12 @@ case PUT: { raise << maybe(get(Recipe, r).name) << "'put " << base.original_string << ", " << offset.original_string << "' should write to " << names_to_string_without_quotes(element.type) << " but '" << value.name << "' has type " << names_to_string_without_quotes(value.type) << '\n' << end(); break; } - if (!inst.products.empty() && inst.products.at(0).name != inst.ingredients.at(0).name) { + if (inst.products.empty()) break; // no more checks necessary + if (inst.products.at(0).name != inst.ingredients.at(0).name) { raise << maybe(get(Recipe, r).name) << "product of 'put' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end(); break; } + // End PUT Product Checks break; } :(before "End Primitive Recipe Implementations") diff --git a/032array.cc b/032array.cc index 7f918870..56b487a6 100644 --- a/032array.cc +++ b/032array.cc @@ -385,10 +385,12 @@ case PUT_INDEX: { raise << maybe(get(Recipe, r).name) << "'put-index " << base.original_string << ", " << inst.ingredients.at(1).original_string << "' should store " << names_to_string_without_quotes(element.type) << " but '" << value.name << "' has type " << names_to_string_without_quotes(value.type) << '\n' << end(); break; } - if (!inst.products.empty() && inst.products.at(0).name != inst.ingredients.at(0).name) { + if (inst.products.empty()) break; // no more checks necessary + if (inst.products.at(0).name != inst.ingredients.at(0).name) { raise << maybe(get(Recipe, r).name) << "product of 'put-index' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end(); break; } + // End PUT_INDEX Product Checks break; } :(before "End Primitive Recipe Implementations") diff --git a/035lookup.cc b/035lookup.cc index bab280b6..6e43f66a 100644 --- a/035lookup.cc +++ b/035lookup.cc @@ -236,6 +236,27 @@ if (!canonize_type(offset)) break; :(after "Update PUT base in Run") canonize(base); +:(scenario put_product_error_with_lookup) +% Hide_errors = true; +def main [ + 1:address:point <- copy 10/unsafe + # 10 reserved for refcount + 11:number <- copy 34 + 12:number <- copy 35 + 1:address:point <- put 1:address:point/lookup, x:offset, 36 +] ++error: main: product of 'put' must be first ingredient '1:address:point/lookup', but got '1:address:point' + +:(before "End PUT Product Checks") +reagent/*copy*/ p = inst.products.at(0); +if (!canonize_type(p)) break; // error raised elsewhere +reagent/*copy*/ i = inst.ingredients.at(0); +if (!canonize_type(i)) break; // error raised elsewhere +if (!types_strictly_match(p, i)) { + raise << maybe(get(Recipe, r).name) << "product of 'put' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end(); + break; +} + :(scenario new_error) % Hide_errors = true; def main [ @@ -323,6 +344,29 @@ def main [ ] +mem: storing 34 in location 3 +:(scenario put_index_product_error_with_lookup) +% Hide_errors = true; +def main [ + # 10 reserved for refcount + 11:array:number:3 <- create-array + 12:number <- copy 14 + 13:number <- copy 15 + 14:number <- copy 16 + 1:address:array:number <- copy 10/unsafe + 1:address:array:number <- put-index 1:address:array:number/lookup, 1, 34 +] ++error: main: product of 'put-index' must be first ingredient '1:address:array:number/lookup', but got '1:address:array:number' + +:(before "End PUT_INDEX Product Checks") +reagent/*copy*/ p = inst.products.at(0); +if (!canonize_type(p)) break; // error raised elsewhere +reagent/*copy*/ i = inst.ingredients.at(0); +if (!canonize_type(i)) break; // error raised elsewhere +if (!types_strictly_match(p, i)) { + raise << maybe(get(Recipe, r).name) << "product of 'put-index' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end(); + break; +} + :(scenario dilated_reagent_in_static_array) def main [ {1: (array (address number) 3)} <- create-array |