From bff0fa450814fcadc4b35e3e740e8d9ee6370d11 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 26 Feb 2016 13:27:23 -0800 Subject: 2713 - require booleans for boolean operations Thanks Ella Couch for finding this bug. It's helped me find errors in mu's code itself. --- 025compare.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to '025compare.cc') diff --git a/025compare.cc b/025compare.cc index 59eb55b1..509e27fe 100644 --- a/025compare.cc +++ b/025compare.cc @@ -10,6 +10,14 @@ case EQUAL: { raise << maybe(get(Recipe, r).name) << "'equal' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end(); break; } + if (SIZE(inst.products) > 1) { + raise << maybe(get(Recipe, r).name) << "'equal' yields exactly one product in '" << to_string(inst) << "'\n" << end(); + break; + } + if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "'equal' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -31,7 +39,7 @@ case EQUAL: { recipe main [ 1:number <- copy 34 2:number <- copy 33 - 3:number <- equal 1:number, 2:number + 3:boolean <- equal 1:number, 2:number ] +mem: location 1 is 34 +mem: location 2 is 33 @@ -41,7 +49,7 @@ recipe main [ recipe main [ 1:number <- copy 34 2:number <- copy 34 - 3:number <- equal 1:number, 2:number + 3:boolean <- equal 1:number, 2:number ] +mem: location 1 is 34 +mem: location 2 is 34 @@ -49,13 +57,13 @@ recipe main [ :(scenario equal_multiple) recipe main [ - 1:number <- equal 34, 34, 34 + 1:boolean <- equal 34, 34, 34 ] +mem: storing 1 in location 1 :(scenario equal_multiple_2) recipe main [ - 1:number <- equal 34, 34, 35 + 1:boolean <- equal 34, 34, 35 ] +mem: storing 0 in location 1 @@ -75,6 +83,14 @@ case GREATER_THAN: { goto finish_checking_instruction; } } + if (SIZE(inst.products) > 1) { + raise << maybe(get(Recipe, r).name) << "'greater-than' yields exactly one product in '" << to_string(inst) << "'\n" << end(); + break; + } + if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "'greater-than' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -134,6 +150,14 @@ case LESSER_THAN: { goto finish_checking_instruction; } } + if (SIZE(inst.products) > 1) { + raise << maybe(get(Recipe, r).name) << "'lesser-than' yields exactly one product in '" << to_string(inst) << "'\n" << end(); + break; + } + if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "'lesser-than' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -193,6 +217,14 @@ case GREATER_OR_EQUAL: { goto finish_checking_instruction; } } + if (SIZE(inst.products) > 1) { + raise << maybe(get(Recipe, r).name) << "'greater-or-equal' yields exactly one product in '" << to_string(inst) << "'\n" << end(); + break; + } + if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "'greater-or-equal' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -260,6 +292,14 @@ case LESSER_OR_EQUAL: { goto finish_checking_instruction; } } + if (SIZE(inst.products) > 1) { + raise << maybe(get(Recipe, r).name) << "'greater-or-equal' yields exactly one product in '" << to_string(inst) << "'\n" << end(); + break; + } + if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "'greater-or-equal' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") -- cgit 1.4.1-2-gfad0