From 201458e3bd2f1d79a0ea0b853552e9df267e92b1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 26 Dec 2016 20:44:10 -0800 Subject: 3713 - cross-link calls with definitions in html --- html/053recipe_header.cc.html | 236 +++++++++++++++++++++--------------------- 1 file changed, 118 insertions(+), 118 deletions(-) (limited to 'html/053recipe_header.cc.html') diff --git a/html/053recipe_header.cc.html b/html/053recipe_header.cc.html index 50479877..07f94784 100644 --- a/html/053recipe_header.cc.html +++ b/html/053recipe_header.cc.html @@ -64,7 +64,7 @@ if ('onhashchange' in window) { 2 //: number of ingredients and yields some fixed number of products. 3 4 :(scenario recipe_with_header) - 5 def main [ + 5 def main [ 6 1:num/raw <- add2 3, 5 7 ] 8 def add2 x:num, y:num -> z:num [ @@ -77,52 +77,52 @@ if ('onhashchange' in window) { 15 16 //: When loading recipes save any header. 17 - 18 :(before "End recipe Fields") + 18 :(before "End recipe Fields") 19 bool has_header; 20 vector<reagent> ingredients; 21 vector<reagent> products; - 22 :(before "End recipe Constructor") + 22 :(before "End recipe Constructor") 23 has_header = false; 24 25 :(before "End Recipe Refinements") 26 if (in.peek() != '[') { - 27 trace(9999, "parse") << "recipe has a header; parsing" << end(); - 28 load_recipe_header(in, result); + 27 trace(9999, "parse") << "recipe has a header; parsing" << end(); + 28 load_recipe_header(in, result); 29 } 30 31 :(code) - 32 void load_recipe_header(istream& in, recipe& result) { + 32 void load_recipe_header(istream& in, recipe& result) { 33 result.has_header = true; - 34 while (has_data(in) && in.peek() != '[' && in.peek() != '\n') { - 35 string s = next_word(in); + 34 while (has_data(in) && in.peek() != '[' && in.peek() != '\n') { + 35 string s = next_word(in); 36 if (s.empty()) { 37 assert(!has_data(in)); - 38 raise << "incomplete recipe header at end of file (0)\n" << end(); + 38 raise << "incomplete recipe header at end of file (0)\n" << end(); 39 return; 40 } 41 if (s == "<-") - 42 raise << "recipe " << result.name << " should say '->' and not '<-'\n" << end(); + 42 raise << "recipe " << result.name << " should say '->' and not '<-'\n" << end(); 43 if (s == "->") break; 44 result.ingredients.push_back(reagent(s)); - 45 trace(9999, "parse") << "header ingredient: " << result.ingredients.back().original_string << end(); + 45 trace(9999, "parse") << "header ingredient: " << result.ingredients.back().original_string << end(); 46 skip_whitespace_but_not_newline(in); 47 } - 48 while (has_data(in) && in.peek() != '[' && in.peek() != '\n') { - 49 string s = next_word(in); + 48 while (has_data(in) && in.peek() != '[' && in.peek() != '\n') { + 49 string s = next_word(in); 50 if (s.empty()) { 51 assert(!has_data(in)); - 52 raise << "incomplete recipe header at end of file (1)\n" << end(); + 52 raise << "incomplete recipe header at end of file (1)\n" << end(); 53 return; 54 } 55 result.products.push_back(reagent(s)); - 56 trace(9999, "parse") << "header product: " << result.products.back().original_string << end(); + 56 trace(9999, "parse") << "header product: " << result.products.back().original_string << end(); 57 skip_whitespace_but_not_newline(in); 58 } 59 // End Load Recipe Header(result) 60 } 61 62 :(scenario recipe_handles_stray_comma) - 63 def main [ + 63 def main [ 64 1:num/raw <- add2 3, 5 65 ] 66 def add2 x:num, y:num -> z:num, [ @@ -134,7 +134,7 @@ if ('onhashchange' in window) { 72 +mem: storing 8 in location 1 73 74 :(scenario recipe_handles_stray_comma_2) - 75 def main [ + 75 def main [ 76 foo 77 ] 78 def foo, [ @@ -149,42 +149,42 @@ if ('onhashchange' in window) { 87 % Hide_errors = true; 88 def foo a:num <- b:num [ 89 ] - 90 +error: recipe foo should say '->' and not '<-' + 90 +error: recipe foo should say '->' and not '<-' 91 92 :(scenario recipe_handles_missing_bracket) 93 % Hide_errors = true; - 94 def main + 94 def main 95 ] - 96 +error: main: recipe body must begin with '[' + 96 +error: main: recipe body must begin with '[' 97 98 :(scenario recipe_handles_missing_bracket_2) 99 % Hide_errors = true; -100 def main +100 def main 101 local-scope 102 { 103 } 104 ] 105 # doesn't overflow line when reading header 106 -parse: header ingredient: local-scope -107 +error: main: recipe body must begin with '[' +107 +error: main: recipe body must begin with '[' 108 109 :(scenario recipe_handles_missing_bracket_3) 110 % Hide_errors = true; -111 def main # comment +111 def main # comment 112 local-scope 113 { 114 } 115 ] 116 # doesn't overflow line when reading header 117 -parse: header ingredient: local-scope -118 +error: main: recipe body must begin with '[' +118 +error: main: recipe body must begin with '[' 119 120 :(after "Begin debug_string(recipe x)") 121 out << "ingredients:\n"; -122 for (int i = 0; i < SIZE(x.ingredients); ++i) +122 for (int i = 0; i < SIZE(x.ingredients); ++i) 123 out << " " << debug_string(x.ingredients.at(i)) << '\n'; 124 out << "products:\n"; -125 for (int i = 0; i < SIZE(x.products); ++i) +125 for (int i = 0; i < SIZE(x.products); ++i) 126 out << " " << debug_string(x.products.at(i)) << '\n'; 127 128 //: If a recipe never mentions any ingredients or products, assume it has a header. @@ -193,12 +193,12 @@ if ('onhashchange' in window) { 131 def test [ 132 1:num <- copy 34 133 ] -134 +parse: recipe test has a header +134 +parse: recipe test has a header 135 136 :(before "End Recipe Body(result)") 137 if (!result.has_header) { 138 result.has_header = true; -139 for (int i = 0; i < SIZE(result.steps); ++i) { +139 for (int i = 0; i < SIZE(result.steps); ++i) { 140 const instruction& inst = result.steps.at(i); 141 if ((inst.name == "reply" && !inst.ingredients.empty()) 142 || (inst.name == "return" && !inst.ingredients.empty()) @@ -211,13 +211,13 @@ if ('onhashchange' in window) { 149 } 150 } 151 if (result.has_header) { -152 trace(9999, "parse") << "recipe " << result.name << " has a header" << end(); +152 trace(9999, "parse") << "recipe " << result.name << " has a header" << end(); 153 } 154 155 //: Support type abbreviations in headers. 156 157 :(scenario type_abbreviations_in_recipe_headers) -158 def main [ +158 def main [ 159 local-scope 160 a:text <- foo 161 1:char/raw <- index *a, 0 @@ -230,35 +230,35 @@ if ('onhashchange' in window) { 168 +mem: storing 97 in location 1 169 170 :(before "End Expand Type Abbreviations(caller)") -171 for (long int i = 0; i < SIZE(caller.ingredients); ++i) +171 for (long int i = 0; i < SIZE(caller.ingredients); ++i) 172 expand_type_abbreviations(caller.ingredients.at(i).type); -173 for (long int i = 0; i < SIZE(caller.products); ++i) +173 for (long int i = 0; i < SIZE(caller.products); ++i) 174 expand_type_abbreviations(caller.products.at(i).type); 175 176 //: Rewrite 'load-ingredients' to instructions to create all reagents in the header. 177 -178 :(before "End Rewrite Instruction(curr, recipe result)") +178 :(before "End Rewrite Instruction(curr, recipe result)") 179 if (curr.name == "load-ingredients") { -180 curr.clear(); -181 recipe_ordinal op = get(Recipe_ordinal, "next-ingredient-without-typechecking"); -182 for (int i = 0; i < SIZE(result.ingredients); ++i) { +180 curr.clear(); +181 recipe_ordinal op = get(Recipe_ordinal, "next-ingredient-without-typechecking"); +182 for (int i = 0; i < SIZE(result.ingredients); ++i) { 183 curr.operation = op; 184 curr.name = "next-ingredient-without-typechecking"; 185 curr.products.push_back(result.ingredients.at(i)); 186 result.steps.push_back(curr); -187 curr.clear(); +187 curr.clear(); 188 } 189 } 190 if (curr.name == "next-ingredient-without-typechecking") { -191 raise << maybe(result.name) << "never call 'next-ingredient-without-typechecking' directly\n" << end(); -192 curr.clear(); +191 raise << maybe(result.name) << "never call 'next-ingredient-without-typechecking' directly\n" << end(); +192 curr.clear(); 193 } 194 195 //: internal version of next-ingredient; don't call this directly 196 :(before "End Primitive Recipe Declarations") 197 NEXT_INGREDIENT_WITHOUT_TYPECHECKING, 198 :(before "End Primitive Recipe Numbers") -199 put(Recipe_ordinal, "next-ingredient-without-typechecking", NEXT_INGREDIENT_WITHOUT_TYPECHECKING); +199 put(Recipe_ordinal, "next-ingredient-without-typechecking", NEXT_INGREDIENT_WITHOUT_TYPECHECKING); 200 :(before "End Primitive Recipe Checks") 201 case NEXT_INGREDIENT_WITHOUT_TYPECHECKING: { 202 break; @@ -266,10 +266,10 @@ if ('onhashchange' in window) { 204 :(before "End Primitive Recipe Implementations") 205 case NEXT_INGREDIENT_WITHOUT_TYPECHECKING: { 206 assert(!Current_routine->calls.empty()); -207 if (current_call().next_ingredient_to_process < SIZE(current_call().ingredient_atoms)) { +207 if (current_call().next_ingredient_to_process < SIZE(current_call().ingredient_atoms)) { 208 products.push_back( 209 current_call().ingredient_atoms.at(current_call().next_ingredient_to_process)); -210 assert(SIZE(products) == 1); products.resize(2); // push a new vector +210 assert(SIZE(products) == 1); products.resize(2); // push a new vector 211 products.at(1).push_back(1); 212 ++current_call().next_ingredient_to_process; 213 } @@ -295,7 +295,7 @@ if ('onhashchange' in window) { 233 234 :(after "use-before-set Error") 235 if (is_present_in_ingredients(caller, ingredient.name)) -236 raise << " did you forget 'load-ingredients'?\n" << end(); +236 raise << " did you forget 'load-ingredients'?\n" << end(); 237 238 :(scenario load_ingredients_missing_error_2) 239 % Hide_errors = true; @@ -308,11 +308,11 @@ if ('onhashchange' in window) { 246 247 :(after "missing-type Error 1") 248 if (is_present_in_ingredients(get(Recipe, get(Recipe_ordinal, recipe_name)), x.name)) -249 raise << " did you forget 'load-ingredients'?\n" << end(); +249 raise << " did you forget 'load-ingredients'?\n" << end(); 250 251 :(code) 252 bool is_present_in_ingredients(const recipe& callee, const string& ingredient_name) { -253 for (int i = 0; i < SIZE(callee.ingredients); ++i) { +253 for (int i = 0; i < SIZE(callee.ingredients); ++i) { 254 if (callee.ingredients.at(i).name == ingredient_name) 255 return true; 256 } @@ -323,7 +323,7 @@ if ('onhashchange' in window) { 261 262 :(scenario show_clear_error_on_bad_call) 263 % Hide_errors = true; -264 def main [ +264 def main [ 265 1:num <- foo 34 266 ] 267 def foo x:point -> y:num [ @@ -331,11 +331,11 @@ if ('onhashchange' in window) { 269 load-ingredients 270 return 35 271 ] -272 +error: main: ingredient 0 has the wrong type at '1:num <- foo 34' +272 +error: main: ingredient 0 has the wrong type at '1:num <- foo 34' 273 274 :(scenario show_clear_error_on_bad_call_2) 275 % Hide_errors = true; -276 def main [ +276 def main [ 277 1:point <- foo 34 278 ] 279 def foo x:num -> y:num [ @@ -343,29 +343,29 @@ if ('onhashchange' in window) { 281 load-ingredients 282 return x 283 ] -284 +error: main: product 0 has the wrong type at '1:point <- foo 34' +284 +error: main: product 0 has the wrong type at '1:point <- foo 34' 285 286 :(after "Transform.push_back(check_instruction)") 287 Transform.push_back(check_calls_against_header); // idempotent 288 :(code) -289 void check_calls_against_header(const recipe_ordinal r) { +289 void check_calls_against_header(const recipe_ordinal r) { 290 const recipe& caller = get(Recipe, r); -291 trace(9991, "transform") << "--- type-check calls inside recipe " << caller.name << end(); -292 for (int i = 0; i < SIZE(caller.steps); ++i) { +291 trace(9991, "transform") << "--- type-check calls inside recipe " << caller.name << end(); +292 for (int i = 0; i < SIZE(caller.steps); ++i) { 293 const instruction& inst = caller.steps.at(i); -294 if (inst.operation < MAX_PRIMITIVE_RECIPES) continue; +294 if (inst.operation < MAX_PRIMITIVE_RECIPES) continue; 295 const recipe& callee = get(Recipe, inst.operation); 296 if (!callee.has_header) continue; -297 for (long int i = 0; i < min(SIZE(inst.ingredients), SIZE(callee.ingredients)); ++i) { +297 for (long int i = 0; i < min(SIZE(inst.ingredients), SIZE(callee.ingredients)); ++i) { 298 // ingredients coerced from call to callee 299 if (!types_coercible(callee.ingredients.at(i), inst.ingredients.at(i))) -300 raise << maybe(caller.name) << "ingredient " << i << " has the wrong type at '" << inst.original_string << "'\n" << end(); +300 raise << maybe(caller.name) << "ingredient " << i << " has the wrong type at '" << inst.original_string << "'\n" << end(); 301 } -302 for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee.products)); ++i) { +302 for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee.products)); ++i) { 303 if (is_dummy(inst.products.at(i))) continue; 304 // products coerced from callee to call 305 if (!types_coercible(inst.products.at(i), callee.products.at(i))) -306 raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << inst.original_string << "'\n" << end(); +306 raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << inst.original_string << "'\n" << end(); 307 } 308 } 309 } @@ -387,20 +387,20 @@ if ('onhashchange' in window) { 325 Transform.push_back(check_return_instructions_against_header); // idempotent 326 327 :(code) -328 void check_return_instructions_against_header(const recipe_ordinal r) { +328 void check_return_instructions_against_header(const recipe_ordinal r) { 329 const recipe& caller_recipe = get(Recipe, r); 330 if (!caller_recipe.has_header) return; -331 trace(9991, "transform") << "--- checking return instructions against header for " << caller_recipe.name << end(); -332 for (int i = 0; i < SIZE(caller_recipe.steps); ++i) { +331 trace(9991, "transform") << "--- checking return instructions against header for " << caller_recipe.name << end(); +332 for (int i = 0; i < SIZE(caller_recipe.steps); ++i) { 333 const instruction& inst = caller_recipe.steps.at(i); 334 if (inst.name != "reply" && inst.name != "return") continue; -335 if (SIZE(caller_recipe.products) != SIZE(inst.ingredients)) { -336 raise << maybe(caller_recipe.name) << "replied with the wrong number of products at '" << inst.original_string << "'\n" << end(); +335 if (SIZE(caller_recipe.products) != SIZE(inst.ingredients)) { +336 raise << maybe(caller_recipe.name) << "replied with the wrong number of products at '" << inst.original_string << "'\n" << end(); 337 continue; 338 } -339 for (int i = 0; i < SIZE(caller_recipe.products); ++i) { +339 for (int i = 0; i < SIZE(caller_recipe.products); ++i) { 340 if (!types_match(caller_recipe.products.at(i), inst.ingredients.at(i))) -341 raise << maybe(caller_recipe.name) << "replied with the wrong type at '" << inst.original_string << "'\n" << end(); +341 raise << maybe(caller_recipe.name) << "replied with the wrong type at '" << inst.original_string << "'\n" << end(); 342 } 343 } 344 } @@ -434,22 +434,22 @@ if ('onhashchange' in window) { 372 ] 373 +error: add2: 'x' can't repeat in the ingredients 374 -375 :(before "End recipe Fields") +375 :(before "End recipe Fields") 376 map<string, int> ingredient_index; 377 378 :(after "Begin Instruction Modifying Transforms") 379 Transform.push_back(check_header_ingredients); // idempotent 380 381 :(code) -382 void check_header_ingredients(const recipe_ordinal r) { +382 void check_header_ingredients(const recipe_ordinal r) { 383 recipe& caller_recipe = get(Recipe, r); 384 if (caller_recipe.products.empty()) return; -385 caller_recipe.ingredient_index.clear(); -386 trace(9991, "transform") << "--- checking return instructions against header for " << caller_recipe.name << end(); -387 for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) { +385 caller_recipe.ingredient_index.clear(); +386 trace(9991, "transform") << "--- checking return instructions against header for " << caller_recipe.name << end(); +387 for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) { 388 if (contains_key(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name)) -389 raise << maybe(caller_recipe.name) << "'" << caller_recipe.ingredients.at(i).name << "' can't repeat in the ingredients\n" << end(); -390 put(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name, i); +389 raise << maybe(caller_recipe.name) << "'" << caller_recipe.ingredients.at(i).name << "' can't repeat in the ingredients\n" << end(); +390 put(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name, i); 391 } 392 } 393 @@ -457,7 +457,7 @@ if ('onhashchange' in window) { 395 396 :(scenarios run) 397 :(scenario deduce_instruction_types_from_recipe_header) -398 def main [ +398 def main [ 399 1:num/raw <- add2 3, 5 400 ] 401 def add2 x:num, y:num -> z:num [ @@ -472,40 +472,40 @@ if ('onhashchange' in window) { 410 Transform.push_back(deduce_types_from_header); // idempotent 411 412 :(code) -413 void deduce_types_from_header(const recipe_ordinal r) { +413 void deduce_types_from_header(const recipe_ordinal r) { 414 recipe& caller_recipe = get(Recipe, r); 415 if (caller_recipe.products.empty()) return; -416 trace(9991, "transform") << "--- deduce types from header for " << caller_recipe.name << end(); +416 trace(9991, "transform") << "--- deduce types from header for " << caller_recipe.name << end(); 417 map<string, const type_tree*> header_type; -418 for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) { +418 for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) { 419 if (!caller_recipe.ingredients.at(i).type) continue; // error handled elsewhere -420 put(header_type, caller_recipe.ingredients.at(i).name, caller_recipe.ingredients.at(i).type); -421 trace(9993, "transform") << "type of " << caller_recipe.ingredients.at(i).name << " is " << names_to_string(caller_recipe.ingredients.at(i).type) << end(); +420 put(header_type, caller_recipe.ingredients.at(i).name, caller_recipe.ingredients.at(i).type); +421 trace(9993, "transform") << "type of " << caller_recipe.ingredients.at(i).name << " is " << names_to_string(caller_recipe.ingredients.at(i).type) << end(); 422 } -423 for (int i = 0; i < SIZE(caller_recipe.products); ++i) { +423 for (int i = 0; i < SIZE(caller_recipe.products); ++i) { 424 if (!caller_recipe.products.at(i).type) continue; // error handled elsewhere -425 put(header_type, caller_recipe.products.at(i).name, caller_recipe.products.at(i).type); -426 trace(9993, "transform") << "type of " << caller_recipe.products.at(i).name << " is " << names_to_string(caller_recipe.products.at(i).type) << end(); +425 put(header_type, caller_recipe.products.at(i).name, caller_recipe.products.at(i).type); +426 trace(9993, "transform") << "type of " << caller_recipe.products.at(i).name << " is " << names_to_string(caller_recipe.products.at(i).type) << end(); 427 } -428 for (int i = 0; i < SIZE(caller_recipe.steps); ++i) { +428 for (int i = 0; i < SIZE(caller_recipe.steps); ++i) { 429 instruction& inst = caller_recipe.steps.at(i); -430 trace(9992, "transform") << "instruction: " << to_string(inst) << end(); -431 for (int i = 0; i < SIZE(inst.ingredients); ++i) { +430 trace(9992, "transform") << "instruction: " << to_string(inst) << end(); +431 for (int i = 0; i < SIZE(inst.ingredients); ++i) { 432 if (inst.ingredients.at(i).type) continue; -433 if (header_type.find(inst.ingredients.at(i).name) == header_type.end()) +433 if (header_type.find(inst.ingredients.at(i).name) == header_type.end()) 434 continue; 435 if (!contains_key(header_type, inst.ingredients.at(i).name)) continue; // error handled elsewhere 436 inst.ingredients.at(i).type = new type_tree(*get(header_type, inst.ingredients.at(i).name)); -437 trace(9993, "transform") << "type of " << inst.ingredients.at(i).name << " is " << names_to_string(inst.ingredients.at(i).type) << end(); +437 trace(9993, "transform") << "type of " << inst.ingredients.at(i).name << " is " << names_to_string(inst.ingredients.at(i).type) << end(); 438 } -439 for (int i = 0; i < SIZE(inst.products); ++i) { -440 trace(9993, "transform") << " product: " << to_string(inst.products.at(i)) << end(); +439 for (int i = 0; i < SIZE(inst.products); ++i) { +440 trace(9993, "transform") << " product: " << to_string(inst.products.at(i)) << end(); 441 if (inst.products.at(i).type) continue; -442 if (header_type.find(inst.products.at(i).name) == header_type.end()) +442 if (header_type.find(inst.products.at(i).name) == header_type.end()) 443 continue; 444 if (!contains_key(header_type, inst.products.at(i).name)) continue; // error handled elsewhere 445 inst.products.at(i).type = new type_tree(*get(header_type, inst.products.at(i).name)); -446 trace(9993, "transform") << "type of " << inst.products.at(i).name << " is " << names_to_string(inst.products.at(i).type) << end(); +446 trace(9993, "transform") << "type of " << inst.products.at(i).name << " is " << names_to_string(inst.products.at(i).type) << end(); 447 } 448 } 449 } @@ -514,7 +514,7 @@ if ('onhashchange' in window) { 452 //: in the header. 453 454 :(scenario return_based_on_header) -455 def main [ +455 def main [ 456 1:num/raw <- add2 3, 5 457 ] 458 def add2 x:num, y:num -> z:num [ @@ -529,20 +529,20 @@ if ('onhashchange' in window) { 467 Transform.push_back(fill_in_return_ingredients); // idempotent 468 469 :(code) -470 void fill_in_return_ingredients(const recipe_ordinal r) { +470 void fill_in_return_ingredients(const recipe_ordinal r) { 471 recipe& caller_recipe = get(Recipe, r); 472 if (!caller_recipe.has_header) return; -473 trace(9991, "transform") << "--- fill in return ingredients from header for recipe " << caller_recipe.name << end(); -474 for (int i = 0; i < SIZE(caller_recipe.steps); ++i) { +473 trace(9991, "transform") << "--- fill in return ingredients from header for recipe " << caller_recipe.name << end(); +474 for (int i = 0; i < SIZE(caller_recipe.steps); ++i) { 475 instruction& inst = caller_recipe.steps.at(i); 476 if (inst.name == "reply" || inst.name == "return") 477 add_header_products(inst, caller_recipe); 478 } 479 // fall through return 480 if (caller_recipe.steps.empty()) return; // error will be raised elsewhere if there's a product in the header; just give up -481 const instruction& final_instruction = caller_recipe.steps.at(SIZE(caller_recipe.steps)-1); +481 const instruction& final_instruction = caller_recipe.steps.at(SIZE(caller_recipe.steps)-1); 482 if (final_instruction.name != "reply" && final_instruction.name != "return") { -483 instruction inst; +483 instruction inst; 484 inst.name = "return"; 485 add_header_products(inst, caller_recipe); 486 caller_recipe.steps.push_back(inst); @@ -552,9 +552,9 @@ if ('onhashchange' in window) { 490 void add_header_products(instruction& inst, const recipe& caller_recipe) { 491 assert(inst.name == "reply" || inst.name == "return"); 492 // collect any products with the same names as ingredients -493 for (int i = 0; i < SIZE(caller_recipe.products); ++i) { +493 for (int i = 0; i < SIZE(caller_recipe.products); ++i) { 494 // if the ingredient is missing, add it from the header -495 if (SIZE(inst.ingredients) == i) +495 if (SIZE(inst.ingredients) == i) 496 inst.ingredients.push_back(caller_recipe.products.at(i)); 497 // if it's missing /same_as_ingredient, try to fill it in 498 if (contains_key(caller_recipe.ingredient_index, caller_recipe.products.at(i).name) && !has_property(inst.ingredients.at(i), "same_as_ingredient")) { @@ -566,7 +566,7 @@ if ('onhashchange' in window) { 504 } 505 506 :(scenario explicit_return_ignores_header) -507 def main [ +507 def main [ 508 1:num/raw, 2:num/raw <- add2 3, 5 509 ] 510 def add2 a:num, b:num -> y:num, z:num [ @@ -580,7 +580,7 @@ if ('onhashchange' in window) { 518 +mem: storing -2 in location 2 519 520 :(scenario return_on_fallthrough_based_on_header) -521 def main [ +521 def main [ 522 1:num/raw <- add2 3, 5 523 ] 524 def add2 x:num, y:num -> z:num [ @@ -588,11 +588,11 @@ if ('onhashchange' in window) { 526 load-ingredients 527 z <- add x, y 528 ] -529 +transform: instruction: return {z: "number"} +529 +transform: instruction: return {z: "number"} 530 +mem: storing 8 in location 1 531 532 :(scenario return_on_fallthrough_already_exists) -533 def main [ +533 def main [ 534 1:num/raw <- add2 3, 5 535 ] 536 def add2 x:num, y:num -> z:num [ @@ -601,12 +601,12 @@ if ('onhashchange' in window) { 539 z <- add x, y # no type for z 540 return z 541 ] -542 +transform: instruction: return {z: ()} -543 -transform: instruction: return z:num +542 +transform: instruction: return {z: ()} +543 -transform: instruction: return z:num 544 +mem: storing 8 in location 1 545 546 :(scenario return_after_conditional_return_based_on_header) -547 def main [ +547 def main [ 548 1:num/raw <- add2 3, 5 549 ] 550 def add2 x:num, y:num -> z:num [ @@ -619,7 +619,7 @@ if ('onhashchange' in window) { 557 558 :(scenario recipe_headers_perform_same_ingredient_check) 559 % Hide_errors = true; -560 def main [ +560 def main [ 561 1:num <- copy 34 562 2:num <- copy 34 563 3:num <- add2 1:num, 2:num @@ -628,48 +628,48 @@ if ('onhashchange' in window) { 566 local-scope 567 load-ingredients 568 ] -569 +error: main: '3:num <- add2 1:num, 2:num' should write to '1:num' rather than '3:num' +569 +error: main: '3:num <- add2 1:num, 2:num' should write to '1:num' rather than '3:num' 570 571 //: One special-case is recipe 'main'. Make sure it's only ever taking in text 572 //: ingredients, and returning a single number. 573 574 :(scenario recipe_header_ingredients_constrained_for_main) 575 % Hide_errors = true; -576 def main x:num [ +576 def main x:num [ 577 ] -578 +error: ingredients of recipe 'main' must all be text (address:array:character) +578 +error: ingredients of recipe 'main' must all be text (address:array:character) 579 580 :(scenario recipe_header_products_constrained_for_main) 581 % Hide_errors = true; -582 def main -> x:text [ +582 def main -> x:text [ 583 ] -584 +error: recipe 'main' must return at most a single product, a number +584 +error: recipe 'main' must return at most a single product, a number 585 586 :(scenario recipe_header_products_constrained_for_main_2) 587 % Hide_errors = true; -588 def main -> x:num, y:num [ +588 def main -> x:num, y:num [ 589 ] -590 +error: recipe 'main' must return at most a single product, a number +590 +error: recipe 'main' must return at most a single product, a number 591 592 :(after "Transform.push_back(expand_type_abbreviations)") 593 Transform.push_back(check_recipe_header_constraints); 594 :(code) -595 void check_recipe_header_constraints(const recipe_ordinal r) { +595 void check_recipe_header_constraints(const recipe_ordinal r) { 596 const recipe& caller = get(Recipe, r); 597 if (caller.name != "main") return; 598 if (!caller.has_header) return; -599 reagent/*local*/ expected_ingredient("x:address:array:character"); -600 for (int i = 0; i < SIZE(caller.ingredients); ++i) { +599 reagent/*local*/ expected_ingredient("x:address:array:character"); +600 for (int i = 0; i < SIZE(caller.ingredients); ++i) { 601 if (!types_strictly_match(expected_ingredient, caller.ingredients.at(i))) { -602 raise << "ingredients of recipe 'main' must all be text (address:array:character)\n" << end(); +602 raise << "ingredients of recipe 'main' must all be text (address:array:character)\n" << end(); 603 break; 604 } 605 } -606 int nprod = SIZE(caller.products); +606 int nprod = SIZE(caller.products); 607 reagent/*local*/ expected_product("x:number"); 608 if (nprod > 1 609 || (nprod == 1 && !types_strictly_match(expected_product, caller.products.at(0)))) { -610 raise << "recipe 'main' must return at most a single product, a number\n" << end(); +610 raise << "recipe 'main' must return at most a single product, a number\n" << end(); 611 } 612 } 613 -- cgit 1.4.1-2-gfad0