diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-25 14:19:28 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-25 17:14:58 -0700 |
commit | e46306432ddb75a89f69d92ccc175a23f0b72072 (patch) | |
tree | 48ed3828064f29cefaf14e3fe61d7dc02cac0e80 /024compare.cc | |
parent | e83602d3917eba137cd8fb37605076fff5a746b1 (diff) | |
download | mu-e46306432ddb75a89f69d92ccc175a23f0b72072.tar.gz |
1848 - core instructions now check for ingredients
Also standardized warnings.
Diffstat (limited to '024compare.cc')
-rw-r--r-- | 024compare.cc | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/024compare.cc b/024compare.cc index c037c381..cd31065b 100644 --- a/024compare.cc +++ b/024compare.cc @@ -6,6 +6,10 @@ EQUAL, Recipe_ordinal["equal"] = EQUAL; :(before "End Primitive Recipe Implementations") case EQUAL: { + if (SIZE(ingredients) <= 1) { + raise << current_recipe_name() << ": 'equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end(); + break; + } vector<double>& exemplar = ingredients.at(0); bool result = true; for (long long int i = 1; i < SIZE(ingredients); ++i) { @@ -58,14 +62,22 @@ Recipe_ordinal["greater-than"] = GREATER_THAN; :(before "End Primitive Recipe Implementations") case GREATER_THAN: { bool result = true; + if (SIZE(ingredients) <= 1) { + raise << current_recipe_name() << ": 'greater-than' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end(); + break; + } for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'greater-than' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_greater_than; + } } for (long long int i = /**/1; i < SIZE(ingredients); ++i) { if (ingredients.at(i-1).at(0) <= ingredients.at(i).at(0)) { result = false; } } + finish_greater_than: products.resize(1); products.at(0).push_back(result); break; @@ -106,14 +118,22 @@ Recipe_ordinal["lesser-than"] = LESSER_THAN; :(before "End Primitive Recipe Implementations") case LESSER_THAN: { bool result = true; + if (SIZE(ingredients) <= 1) { + raise << current_recipe_name() << ": 'lesser-than' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end(); + break; + } for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'lesser-than' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_lesser_than; + } } for (long long int i = /**/1; i < SIZE(ingredients); ++i) { if (ingredients.at(i-1).at(0) >= ingredients.at(i).at(0)) { result = false; } } + finish_lesser_than: products.resize(1); products.at(0).push_back(result); break; @@ -154,14 +174,22 @@ Recipe_ordinal["greater-or-equal"] = GREATER_OR_EQUAL; :(before "End Primitive Recipe Implementations") case GREATER_OR_EQUAL: { bool result = true; + if (SIZE(ingredients) <= 1) { + raise << current_recipe_name() << ": 'greater-or-equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end(); + break; + } for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'greater-or-equal' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_greater_or_equal; + } } for (long long int i = /**/1; i < SIZE(ingredients); ++i) { if (ingredients.at(i-1).at(0) < ingredients.at(i).at(0)) { result = false; } } + finish_greater_or_equal: products.resize(1); products.at(0).push_back(result); break; @@ -210,14 +238,22 @@ Recipe_ordinal["lesser-or-equal"] = LESSER_OR_EQUAL; :(before "End Primitive Recipe Implementations") case LESSER_OR_EQUAL: { bool result = true; + if (SIZE(ingredients) <= 1) { + raise << current_recipe_name() << ": 'lesser-or-equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end(); + break; + } for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'lesser-or-equal' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_lesser_or_equal; + } } for (long long int i = /**/1; i < SIZE(ingredients); ++i) { if (ingredients.at(i-1).at(0) > ingredients.at(i).at(0)) { result = false; } } + finish_lesser_or_equal: products.resize(1); products.at(0).push_back(result); break; |