From cd9bb850caeca88747a25436fc65c67c6d5cd89a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 27 Aug 2016 20:49:03 -0700 Subject: 3266 --- html/087file.cc.html | 54 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'html/087file.cc.html') diff --git a/html/087file.cc.html b/html/087file.cc.html index d8af7ae0..052774d9 100644 --- a/html/087file.cc.html +++ b/html/087file.cc.html @@ -52,11 +52,18 @@ put(Recipe_ordinal,(get(Recipe, r).name) << "'$open-file-for-reading' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); break; } - string filename; if (!is_mu_string(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of '$open-file-for-reading' should be a string, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; } + if (SIZE(inst.products) != 1) { + raise << maybe(get(Recipe, r).name) << "'$open-file-for-reading' requires exactly one product, but got '" << inst.original_string << "'\n" << end(); + break; + } + if (!is_mu_number(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "first product of '$open-file-for-reading' should be a number (file handle), but got '" << to_string(inst.products.at(0)) << "'\n" << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -80,11 +87,18 @@ put(Recipe_ordinal,(get(Recipe, r).name) << "'$open-file-for-writing' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); break; } - string filename; if (!is_mu_string(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of '$open-file-for-writing' should be a string, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; } + if (SIZE(inst.products) != 1) { + raise << maybe(get(Recipe, r).name) << "'$open-file-for-writing' requires exactly one product, but got '" << inst.original_string << "'\n" << end(); + break; + } + if (!is_mu_number(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "first product of '$open-file-for-writing' should be a number (file handle), but got '" << to_string(inst.products.at(0)) << "'\n" << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -107,11 +121,22 @@ put(Recipe_ordinal,(get(Recipe, r).name) << "'$read-from-file' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); break; } - string filename; if (!is_mu_number(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of '$read-from-file' should be a number, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; } + if (SIZE(inst.products) != 2) { + raise << maybe(get(Recipe, r).name) << "'$read-from-file' requires exactly two products, but got '" << inst.original_string << "'\n" << end(); + break; + } + if (!is_mu_character(inst.products.at(0))) { + raise << maybe(get(Recipe, r).name) << "first product of '$read-from-file' should be a character, but got '" << to_string(inst.products.at(0)) << "'\n" << end(); + break; + } + if (!is_mu_boolean(inst.products.at(1))) { + raise << maybe(get(Recipe, r).name) << "second product of '$read-from-file' should be a boolean, but got '" << to_string(inst.products.at(1)) << "'\n" << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -122,9 +147,10 @@ put(Recipe_ordinal,(current_recipe_name()) << "can't read from null file in '" << to_string(current_instruction()) << "'\n" << end(); break; } - products.resize(1); + products.resize(2); if (feof(f)) { products.at(0).push_back(0); + products.at(1).push_back(1); // eof break; } if (ferror(f)) { @@ -132,12 +158,18 @@ put(Recipe_ordinal,break; } char c = getc(f); // todo: unicode + if (c == EOF) { + products.at(0).push_back(0); + products.at(1).push_back(1); // eof + break; + } if (ferror(f)) { raise << maybe(current_recipe_name()) << "couldn't read from file in '" << to_string(current_instruction()) << "'\n" << end(); raise << " errno: " << errno << '\n' << end(); break; } products.at(0).push_back(c); + products.at(1).push_back(0); // not eof break; } :(before "End Includes") @@ -153,7 +185,6 @@ put(Recipe_ordinal,(get(Recipe, r).name) << "'$write-to-file' requires exactly two ingredients, but got '" << inst.original_string << "'\n" << end(); break; } - string filename; if (!is_mu_number(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of '$write-to-file' should be a number, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; @@ -162,6 +193,10 @@ put(Recipe_ordinal,(get(Recipe, r).name) << "second ingredient of '$write-to-file' should be a character, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; } + if (!inst.products.empty()) { + raise << maybe(get(Recipe, r).name) << "'$write-to-file' writes to no products, but got '" << inst.original_string << "'\n" << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") @@ -198,11 +233,18 @@ put(Recipe_ordinal,(get(Recipe, r).name) << "'$close-file' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); break; } - string filename; if (!is_mu_number(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of '$close-file' should be a number, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; } + if (SIZE(inst.products) != 1) { + raise << maybe(get(Recipe, r).name) << "'$close-file' requires exactly one product, but got '" << inst.original_string << "'\n" << end(); + break; + } + if (inst.products.at(0).name != inst.ingredients.at(0).name) { + raise << maybe(get(Recipe, r).name) << "'$close-file' requires its product to be the same as its ingredient, but got '" << inst.original_string << "'\n" << end(); + break; + } break; } :(before "End Primitive Recipe Implementations") -- cgit 1.4.1-2-gfad0