diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-10-07 00:22:49 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-10-07 00:22:49 -0700 |
commit | 7afe09fbfeb88e3be98dfe4f0db43f66724d4abf (patch) | |
tree | 0592cc6cf3e98aa25ec9c35b638a56baeff1d5e3 /043new.cc | |
parent | 857adbc496dca7d41e46cbece815a24d32c735fe (diff) | |
download | mu-7afe09fbfeb88e3be98dfe4f0db43f66724d4abf.tar.gz |
2262 - strengthen some type checks
Diffstat (limited to '043new.cc')
-rw-r--r-- | 043new.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/043new.cc b/043new.cc index f821fad3..e28284ae 100644 --- a/043new.cc +++ b/043new.cc @@ -35,9 +35,7 @@ if (inst.operation == Recipe_ordinal["new"]) { // first arg must be of type 'type' if (inst.ingredients.empty()) raise_error << maybe(Recipe[r].name) << "'new' expects one or two ingredients\n" << end(); - if (inst.ingredients.at(0).properties.empty() - || inst.ingredients.at(0).properties.at(0).second.empty() - || inst.ingredients.at(0).properties.at(0).second.at(0) != "type") + if (!is_mu_type_literal(inst.ingredients.at(0))) raise_error << maybe(Recipe[r].name) << "first ingredient of 'new' should be a type, but got " << inst.ingredients.at(0).original_string << '\n' << end(); if (Type_ordinal.find(inst.ingredients.at(0).name) == Type_ordinal.end()) raise_error << maybe(Recipe[r].name) << "unknown type " << inst.ingredients.at(0).name << '\n' << end(); @@ -59,8 +57,9 @@ case NEW: { raise_error << maybe(Recipe[r].name) << "'new' requires one or two ingredients, but got " << inst.to_string() << '\n' << end(); break; } + // End NEW Checks reagent type = inst.ingredients.at(0); - if (!is_mu_scalar(type) && !is_literal(type)) { + if (!is_mu_type_literal(type)) { raise_error << maybe(Recipe[r].name) << "first ingredient of 'new' should be a type, but got " << type.original_string << '\n' << end(); break; } @@ -323,9 +322,10 @@ recipe main [ goto end_new_transform; } +:(before "End NEW Checks") +if (is_literal_string(inst.ingredients.at(0))) break; :(after "case NEW" following "Primitive Recipe Implementations") - if (is_literal(current_instruction().ingredients.at(0)) - && current_instruction().ingredients.at(0).properties.at(0).second.at(0) == "literal-string") { + if (is_literal_string(current_instruction().ingredients.at(0))) { products.resize(1); products.at(0).push_back(new_mu_string(current_instruction().ingredients.at(0).name)); break; @@ -428,3 +428,7 @@ string read_mu_string(long long int address) { } return tmp.str(); } + +bool is_mu_type_literal(reagent r) { + return is_literal(r) && !r.properties.empty() && !r.properties.at(0).second.empty() && r.properties.at(0).second.at(0) == "type"; +} |