diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-09-30 01:57:23 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-09-30 01:57:23 -0700 |
commit | 4e49b29e63b0d369b81318ac822dc06ce06786b5 (patch) | |
tree | d78b822660f33f40eea08c6747245fb729877073 /023boolean.cc | |
parent | a0d7a15594990974808cc613a4814d1f86471b5e (diff) | |
download | mu-4e49b29e63b0d369b81318ac822dc06ce06786b5.tar.gz |
2221
Diffstat (limited to '023boolean.cc')
-rw-r--r-- | 023boolean.cc | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/023boolean.cc b/023boolean.cc index ead678cf..b0debe6b 100644 --- a/023boolean.cc +++ b/023boolean.cc @@ -4,16 +4,21 @@ AND, :(before "End Primitive Recipe Numbers") Recipe_ordinal["and"] = AND; +:(before "End Primitive Recipe Type Checks") +case AND: { + for (long long int i = 0; i < SIZE(inst.ingredients); ++i) { + if (!is_mu_scalar(inst.ingredients.at(i))) { + raise << Recipe[r].name << ": 'and' requires boolean ingredients, but got " << inst.ingredients.at(i).original_string << '\n' << end(); + goto finish_checking_instruction; + } + } + break; +} :(before "End Primitive Recipe Implementations") case AND: { bool result = true; - for (long long int i = 0; i < SIZE(ingredients); ++i) { - if (!scalar(ingredients.at(i))) { - raise << current_recipe_name() << ": 'and' requires boolean ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); - goto finish_instruction; - } + for (long long int i = 0; i < SIZE(ingredients); ++i) result = result && ingredients.at(i).at(0); - } products.resize(1); products.at(0).push_back(result); break; @@ -49,16 +54,21 @@ recipe main [ OR, :(before "End Primitive Recipe Numbers") Recipe_ordinal["or"] = OR; +:(before "End Primitive Recipe Type Checks") +case OR: { + for (long long int i = 0; i < SIZE(inst.ingredients); ++i) { + if (!is_mu_scalar(inst.ingredients.at(i))) { + raise << Recipe[r].name << ": 'and' requires boolean ingredients, but got " << inst.ingredients.at(i).original_string << '\n' << end(); + goto finish_checking_instruction; + } + } + break; +} :(before "End Primitive Recipe Implementations") case OR: { bool result = false; - for (long long int i = 0; i < SIZE(ingredients); ++i) { - if (!scalar(ingredients.at(i))) { - raise << current_recipe_name() << ": 'or' requires boolean ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); - goto finish_instruction; - } + for (long long int i = 0; i < SIZE(ingredients); ++i) result = result || ingredients.at(i).at(0); - } products.resize(1); products.at(0).push_back(result); break; @@ -94,14 +104,24 @@ recipe main [ NOT, :(before "End Primitive Recipe Numbers") Recipe_ordinal["not"] = NOT; +:(before "End Primitive Recipe Type Checks") +case NOT: { + if (SIZE(inst.products) > SIZE(inst.ingredients)) { + raise << Recipe[r].name << ": 'not' cannot have fewer ingredients than products in '" << inst.to_string() << "'\n" << end(); + break; + } + for (long long int i = 0; i < SIZE(inst.ingredients); ++i) { + if (!is_mu_scalar(inst.ingredients.at(i))) { + raise << Recipe[r].name << ": 'not' requires boolean ingredients, but got " << inst.ingredients.at(i).original_string << '\n' << end(); + goto finish_checking_instruction; + } + } + break; +} :(before "End Primitive Recipe Implementations") case NOT: { products.resize(SIZE(ingredients)); for (long long int i = 0; i < SIZE(ingredients); ++i) { - if (!scalar(ingredients.at(i))) { - raise << current_recipe_name() << ": 'not' requires boolean ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); - goto finish_instruction; - } products.at(i).push_back(!ingredients.at(i).at(0)); } break; |