From e62aa7e305a0ea8ae2c79522588c3bbc80fa4dc3 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 4 Apr 2017 00:18:44 -0700 Subject: 3810 Stop naming 'jump' instructions in their errors since they're so often rewritten from 'break' or 'loop' instructions. Thanks Lakshman Swaminathan for running into this issue. --- 024jump.cc | 16 ++++++++-------- 040brace.cc | 10 +++++----- 041jump_target.cc | 8 ++++---- html/024jump.cc.html | 16 ++++++++-------- html/040brace.cc.html | 10 +++++----- html/041jump_target.cc.html | 8 ++++---- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/024jump.cc b/024jump.cc index 8b33a083..734cfc49 100644 --- a/024jump.cc +++ b/024jump.cc @@ -16,11 +16,11 @@ put(Recipe_ordinal, "jump", JUMP); :(before "End Primitive Recipe Checks") case JUMP: { if (SIZE(inst.ingredients) != 1) { - raise << maybe(get(Recipe, r).name) << "'jump' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' should get exactly one ingredient\n" << end(); break; } if (!is_literal(inst.ingredients.at(0))) { - raise << maybe(get(Recipe, r).name) << "first ingredient of 'jump' should be a label or offset, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "first ingredient of '" << inst.original_string << "' should be a label or offset, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); break; } break; @@ -55,15 +55,15 @@ put(Recipe_ordinal, "jump-if", JUMP_IF); :(before "End Primitive Recipe Checks") case JUMP_IF: { if (SIZE(inst.ingredients) != 2) { - raise << maybe(get(Recipe, r).name) << "'jump-if' requires exactly two ingredients, but got '" << inst.original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' should get exactly two ingredients\n" << end(); break; } if (!is_mu_scalar(inst.ingredients.at(0))) { - raise << maybe(get(Recipe, r).name) << "'jump-if' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a boolean for its first ingredient, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); break; } if (!is_literal(inst.ingredients.at(1))) { - raise << maybe(get(Recipe, r).name) << "'jump-if' requires a label or offset for its second ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a label or offset for its second ingredient, but '" << inst.ingredients.at(1).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(1).type) << "'\n" << end(); break; } // End JUMP_IF Checks @@ -108,15 +108,15 @@ put(Recipe_ordinal, "jump-unless", JUMP_UNLESS); :(before "End Primitive Recipe Checks") case JUMP_UNLESS: { if (SIZE(inst.ingredients) != 2) { - raise << maybe(get(Recipe, r).name) << "'jump-unless' requires exactly two ingredients, but got '" << inst.original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' should get exactly two ingredients\n" << end(); break; } if (!is_mu_scalar(inst.ingredients.at(0))) { - raise << maybe(get(Recipe, r).name) << "'jump-unless' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a boolean for its first ingredient, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); break; } if (!is_literal(inst.ingredients.at(1))) { - raise << maybe(get(Recipe, r).name) << "'jump-unless' requires a label or offset for its second ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a label or offset for its second ingredient, but '" << inst.ingredients.at(1).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(1).type) << "'\n" << end(); break; } // End JUMP_UNLESS Checks diff --git a/040brace.cc b/040brace.cc index cf9a401c..e6afce89 100644 --- a/040brace.cc +++ b/040brace.cc @@ -60,7 +60,7 @@ void transform_braces(const recipe_ordinal r) { } if (inst.label == "}") { if (open_braces.empty()) { - raise << "missing '{' in '" << get(Recipe, r).name << "'\n" << end(); + raise << maybe(get(Recipe, r).name) << "missing '{' in '" << get(Recipe, r).name << "'\n" << end(); return; } open_braces.pop(); @@ -79,7 +79,7 @@ void transform_braces(const recipe_ordinal r) { // check for errors if (inst.name.find("-if") != string::npos || inst.name.find("-unless") != string::npos) { if (inst.ingredients.empty()) { - raise << "'" << inst.name << "' expects 1 or 2 ingredients, but got none\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.name << "' expects 1 or 2 ingredients, but got none\n" << end(); continue; } } @@ -117,7 +117,7 @@ void transform_braces(const recipe_ordinal r) { target.type = new type_tree("offset"); target.set_value(0); if (open_braces.empty()) - raise << "'" << old_name << "' needs a '{' before\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << old_name << "' needs a '{' before\n" << end(); else if (old_name.find("loop") != string::npos) target.set_value(open_braces.top()-index); else // break instruction @@ -350,7 +350,7 @@ def test-factorial [ def main [ break ] -+error: 'break' needs a '{' before ++error: main: 'break' needs a '{' before :(scenario break_conditional_without_ingredient_fails) % Hide_errors = true; @@ -359,7 +359,7 @@ def main [ break-if } ] -+error: 'break-if' expects 1 or 2 ingredients, but got none ++error: main: 'break-if' expects 1 or 2 ingredients, but got none //: Using break we can now implement conditional returns. diff --git a/041jump_target.cc b/041jump_target.cc index 02d933fc..426ef2ad 100644 --- a/041jump_target.cc +++ b/041jump_target.cc @@ -49,14 +49,14 @@ void transform_labels(const recipe_ordinal r) { instruction& inst = get(Recipe, r).steps.at(i); if (inst.name == "jump") { if (inst.ingredients.empty()) { - raise << maybe(get(Recipe, r).name) << "'jump' expects an ingredient but got none\n" << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' expects an ingredient but got 0\n" << end(); return; } replace_offset(inst.ingredients.at(0), offset, i, r); } if (inst.name == "jump-if" || inst.name == "jump-unless") { if (SIZE(inst.ingredients) < 2) { - raise << maybe(get(Recipe, r).name) << "'" << inst.name << "' expects 2 ingredients but got " << SIZE(inst.ingredients) << '\n' << end(); + raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' expects 2 ingredients but got " << SIZE(inst.ingredients) << '\n' << end(); return; } replace_offset(inst.ingredients.at(1), offset, i, r); @@ -149,14 +149,14 @@ def main [ def main [ jump ] -+error: main: 'jump' expects an ingredient but got none ++error: main: 'jump' expects an ingredient but got 0 :(scenario jump_fails_without_target_2) % Hide_errors = true; def main [ jump-if 1/true ] -+error: main: 'jump-if' expects 2 ingredients but got 1 ++error: main: 'jump-if 1/true' expects 2 ingredients but got 1 :(scenario recipe_fails_on_duplicate_jump_target) % Hide_errors = true; diff --git a/html/024jump.cc.html b/html/024jump.cc.html index 52ac4c73..63f26819 100644 --- a/html/024jump.cc.html +++ b/html/024jump.cc.html @@ -80,11 +80,11 @@ if ('onhashchange' in window) { 16 :(before "End Primitive Recipe Checks") 17 case JUMP: { 18 if (SIZE(inst.ingredients) != 1) { - 19 ¦ raise << maybe(get(Recipe, r).name) << "'jump' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); + 19 ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' should get exactly one ingredient\n" << end(); 20 ¦ break; 21 } 22 if (!is_literal(inst.ingredients.at(0))) { - 23 ¦ raise << maybe(get(Recipe, r).name) << "first ingredient of 'jump' should be a label or offset, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + 23 ¦ raise << maybe(get(Recipe, r).name) << "first ingredient of '" << inst.original_string << "' should be a label or offset, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); 24 ¦ break; 25 } 26 break; @@ -119,15 +119,15 @@ if ('onhashchange' in window) { 55 :(before "End Primitive Recipe Checks") 56 case JUMP_IF: { 57 if (SIZE(inst.ingredients) != 2) { - 58 ¦ raise << maybe(get(Recipe, r).name) << "'jump-if' requires exactly two ingredients, but got '" << inst.original_string << "'\n" << end(); + 58 ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' should get exactly two ingredients\n" << end(); 59 ¦ break; 60 } 61 if (!is_mu_scalar(inst.ingredients.at(0))) { - 62 ¦ raise << maybe(get(Recipe, r).name) << "'jump-if' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + 62 ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a boolean for its first ingredient, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); 63 ¦ break; 64 } 65 if (!is_literal(inst.ingredients.at(1))) { - 66 ¦ raise << maybe(get(Recipe, r).name) << "'jump-if' requires a label or offset for its second ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + 66 ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a label or offset for its second ingredient, but '" << inst.ingredients.at(1).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(1).type) << "'\n" << end(); 67 ¦ break; 68 } 69 // End JUMP_IF Checks @@ -172,15 +172,15 @@ if ('onhashchange' in window) { 108 :(before "End Primitive Recipe Checks") 109 case JUMP_UNLESS: { 110 if (SIZE(inst.ingredients) != 2) { -111 ¦ raise << maybe(get(Recipe, r).name) << "'jump-unless' requires exactly two ingredients, but got '" << inst.original_string << "'\n" << end(); +111 ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' should get exactly two ingredients\n" << end(); 112 ¦ break; 113 } 114 if (!is_mu_scalar(inst.ingredients.at(0))) { -115 ¦ raise << maybe(get(Recipe, r).name) << "'jump-unless' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); +115 ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a boolean for its first ingredient, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); 116 ¦ break; 117 } 118 if (!is_literal(inst.ingredients.at(1))) { -119 ¦ raise << maybe(get(Recipe, r).name) << "'jump-unless' requires a label or offset for its second ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); +119 ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' requires a label or offset for its second ingredient, but '" << inst.ingredients.at(1).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(1).type) << "'\n" << end(); 120 ¦ break; 121 } 122 // End JUMP_UNLESS Checks diff --git a/html/040brace.cc.html b/html/040brace.cc.html index 762bf34f..5c868aaa 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -123,7 +123,7 @@ if ('onhashchange' in window) { 60 ¦ } 61 ¦ if (inst.label == "}") { 62 ¦ ¦ if (open_braces.empty()) { - 63 ¦ ¦ ¦ raise << "missing '{' in '" << get(Recipe, r).name << "'\n" << end(); + 63 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "missing '{' in '" << get(Recipe, r).name << "'\n" << end(); 64 ¦ ¦ ¦ return; 65 ¦ ¦ } 66 ¦ ¦ open_braces.pop(); @@ -142,7 +142,7 @@ if ('onhashchange' in window) { 79 ¦ // check for errors 80 ¦ if (inst.name.find("-if") != string::npos || inst.name.find("-unless") != string::npos) { 81 ¦ ¦ if (inst.ingredients.empty()) { - 82 ¦ ¦ ¦ raise << "'" << inst.name << "' expects 1 or 2 ingredients, but got none\n" << end(); + 82 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.name << "' expects 1 or 2 ingredients, but got none\n" << end(); 83 ¦ ¦ ¦ continue; 84 ¦ ¦ } 85 ¦ } @@ -180,7 +180,7 @@ if ('onhashchange' in window) { 117 ¦ target.type = new type_tree("offset"); 118 ¦ target.set_value(0); 119 ¦ if (open_braces.empty()) -120 ¦ ¦ raise << "'" << old_name << "' needs a '{' before\n" << end(); +120 ¦ ¦ raise << maybe(get(Recipe, r).name) << "'" << old_name << "' needs a '{' before\n" << end(); 121 ¦ else if (old_name.find("loop") != string::npos) 122 ¦ ¦ target.set_value(open_braces.top()-index); 123 ¦ else // break instruction @@ -413,7 +413,7 @@ if ('onhashchange' in window) { 350 def main [ 351 break 352 ] -353 +error: 'break' needs a '{' before +353 +error: main: 'break' needs a '{' before 354 355 :(scenario break_conditional_without_ingredient_fails) 356 % Hide_errors = true; @@ -422,7 +422,7 @@ if ('onhashchange' in window) { 359 ¦ break-if 360 } 361 ] -362 +error: 'break-if' expects 1 or 2 ingredients, but got none +362 +error: main: 'break-if' expects 1 or 2 ingredients, but got none 363 364 //: Using break we can now implement conditional returns. 365 diff --git a/html/041jump_target.cc.html b/html/041jump_target.cc.html index 2ca57608..3f9e3dd7 100644 --- a/html/041jump_target.cc.html +++ b/html/041jump_target.cc.html @@ -113,14 +113,14 @@ if ('onhashchange' in window) { 49 ¦ instruction& inst = get(Recipe, r).steps.at(i); 50 ¦ if (inst.name == "jump") { 51 ¦ ¦ if (inst.ingredients.empty()) { - 52 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "'jump' expects an ingredient but got none\n" << end(); + 52 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' expects an ingredient but got 0\n" << end(); 53 ¦ ¦ ¦ return; 54 ¦ ¦ } 55 ¦ ¦ replace_offset(inst.ingredients.at(0), offset, i, r); 56 ¦ } 57 ¦ if (inst.name == "jump-if" || inst.name == "jump-unless") { 58 ¦ ¦ if (SIZE(inst.ingredients) < 2) { - 59 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.name << "' expects 2 ingredients but got " << SIZE(inst.ingredients) << '\n' << end(); + 59 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "'" << inst.original_string << "' expects 2 ingredients but got " << SIZE(inst.ingredients) << '\n' << end(); 60 ¦ ¦ ¦ return; 61 ¦ ¦ } 62 ¦ ¦ replace_offset(inst.ingredients.at(1), offset, i, r); @@ -213,14 +213,14 @@ if ('onhashchange' in window) { 149 def main [ 150 jump 151 ] -152 +error: main: 'jump' expects an ingredient but got none +152 +error: main: 'jump' expects an ingredient but got 0 153 154 :(scenario jump_fails_without_target_2) 155 % Hide_errors = true; 156 def main [ 157 jump-if 1/true 158 ] -159 +error: main: 'jump-if' expects 2 ingredients but got 1 +159 +error: main: 'jump-if 1/true' expects 2 ingredients but got 1 160 161 :(scenario recipe_fails_on_duplicate_jump_target) 162 % Hide_errors = true; -- cgit 1.4.1-2-gfad0