From 0d21947757a1e8ca4f5c94617fd94753f6d3de56 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 20 May 2016 23:45:03 -0700 Subject: 2992 Raise an error if a 'put' or 'put-index' doesn't match ingredient and product. That wouldn't do what you would expect. --- 030container.cc | 14 ++++++++++++++ 032array.cc | 14 ++++++++++++++ 035lookup.cc | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/030container.cc b/030container.cc index 6bf8bbdc..8c570498 100644 --- a/030container.cc +++ b/030container.cc @@ -435,6 +435,10 @@ 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) { + 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; + } break; } :(before "End Primitive Recipe Implementations") @@ -461,6 +465,16 @@ case PUT: { goto finish_instruction; } +:(scenario put_product_error) +% Hide_errors = true; +def main [ + local-scope + load-ingredients + 1:point <- merge 34, 35 + 3:point <- put 1:point, x:offset, 36 +] ++error: main: product of 'put' must be first ingredient '1:point', but got '3:point' + //:: Allow containers to be defined in mu code. :(scenarios load) diff --git a/032array.cc b/032array.cc index 016e9d19..8d08fdc2 100644 --- a/032array.cc +++ b/032array.cc @@ -355,6 +355,10 @@ 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) { + 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; + } break; } :(before "End Primitive Recipe Implementations") @@ -419,6 +423,16 @@ def main [ ] +error: main: invalid index -1 +:(scenario put_index_product_error) +% Hide_errors = true; +def main [ + local-scope + load-ingredients + 1:array:number:3 <- create-array + 4:array:number:3 <- put-index 1:array:number:3, 0, 34 +] ++error: main: product of 'put-index' must be first ingredient '1:array:number:3', but got '4:array:number:3' + //:: compute the length of an array :(scenario array_length) diff --git a/035lookup.cc b/035lookup.cc index 382d72aa..e56078bc 100644 --- a/035lookup.cc +++ b/035lookup.cc @@ -315,7 +315,7 @@ def main [ 5:address:number <- copy 10/unsafe # 10 reserved for refcount 11:number <- copy 1 - 5:address:array:number/lookup <- put-index 1:array:number:3, 5:address:number/lookup, 34 + 1:array:number:3 <- put-index 1:array:number:3, 5:address:number/lookup, 34 ] +mem: storing 34 in location 3 -- cgit 1.4.1-2-gfad0