From 5fe060d582d4a82444243a28b18085c971a85628 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 27 Jul 2018 17:07:52 -0700 Subject: 4447 --- html/072recipe.cc.html | 94 +++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'html/072recipe.cc.html') diff --git a/html/072recipe.cc.html b/html/072recipe.cc.html index 0aadddd3..2d8b05b2 100644 --- a/html/072recipe.cc.html +++ b/html/072recipe.cc.html @@ -79,7 +79,7 @@ if ('onhashchange' in window) { 16 :(before "End Mu Types Initialization") 17 put(Type_ordinal, "recipe-literal", 0); 18 // 'recipe' variables can store recipe-literal - 19 type_ordinal recipe = put(Type_ordinal, "recipe", Next_type_ordinal++); + 19 type_ordinal recipe = put(Type_ordinal, "recipe", Next_type_ordinal++); 20 get_or_insert(Type, recipe).name = "recipe"; 21 22 :(after "Deduce Missing Type(x, caller)") @@ -94,21 +94,21 @@ if ('onhashchange' in window) { 31 if (!contains_key(Recipe_ordinal, x.name)) return; 32 if (contains_reagent_with_non_recipe_literal_type(caller, x.name)) return; 33 x.type = new type_tree("recipe-literal"); - 34 x.set_value(get(Recipe_ordinal, x.name)); + 34 x.set_value(get(Recipe_ordinal, x.name)); 35 } 36 bool contains_reagent_with_non_recipe_literal_type(const recipe& caller, const string& name) { 37 for (int i = 0; i < SIZE(caller.steps); ++i) { 38 const instruction& inst = caller.steps.at(i); 39 for (int i = 0; i < SIZE(inst.ingredients); ++i) - 40 if (is_matching_non_recipe_literal(inst.ingredients.at(i), name)) return true; + 40 if (is_matching_non_recipe_literal(inst.ingredients.at(i), name)) return true; 41 for (int i = 0; i < SIZE(inst.products); ++i) - 42 if (is_matching_non_recipe_literal(inst.products.at(i), name)) return true; + 42 if (is_matching_non_recipe_literal(inst.products.at(i), name)) return true; 43 } - 44 return false; + 44 return false; 45 } 46 bool is_matching_non_recipe_literal(const reagent& x, const string& name) { - 47 if (x.name != name) return false; - 48 if (!x.type) return false; + 47 if (x.name != name) return false; + 48 if (!x.type) return false; 49 return !x.type->atom || x.type->name != "recipe-literal"; 50 } 51 @@ -130,11 +130,11 @@ if ('onhashchange' in window) { 67 :(before "End Primitive Recipe Checks") 68 case CALL: { 69 if (inst.ingredients.empty()) { - 70 raise << maybe(get(Recipe, r).name) << "'call' requires at least one ingredient (the recipe to call)\n" << end(); + 70 raise << maybe(get(Recipe, r).name) << "'call' requires at least one ingredient (the recipe to call)\n" << end(); 71 break; 72 } 73 if (!is_mu_recipe(inst.ingredients.at(0))) { - 74 raise << maybe(get(Recipe, r).name) << "first ingredient of 'call' should be a recipe, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + 74 raise << maybe(get(Recipe, r).name) << "first ingredient of 'call' should be a recipe, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); 75 break; 76 } 77 break; @@ -144,23 +144,23 @@ if ('onhashchange' in window) { 81 // Begin Call 82 if (Trace_stream) { 83 ++Trace_stream->callstack_depth; - 84 trace("trace") << "indirect 'call': incrementing callstack depth to " << Trace_stream->callstack_depth << end(); + 84 trace("trace") << "indirect 'call': incrementing callstack depth to " << Trace_stream->callstack_depth << end(); 85 assert(Trace_stream->callstack_depth < 9000); // 9998-101 plus cushion 86 } 87 if (!ingredients.at(0).at(0)) { - 88 raise << maybe(current_recipe_name()) << "tried to call empty recipe in '" << to_string(current_instruction()) << "'" << end(); + 88 raise << maybe(current_recipe_name()) << "tried to call empty recipe in '" << to_string(current_instruction()) << "'" << end(); 89 break; 90 } 91 const call& caller_frame = current_call(); - 92 instruction/*copy*/ call_instruction = to_instruction(caller_frame); + 92 instruction/*copy*/ call_instruction = to_instruction(caller_frame); 93 call_instruction.operation = ingredients.at(0).at(0); 94 call_instruction.ingredients.erase(call_instruction.ingredients.begin()); 95 Current_routine->calls.push_front(call(ingredients.at(0).at(0))); 96 ingredients.erase(ingredients.begin()); // drop the callee 97 finish_call_housekeeping(call_instruction, ingredients); 98 // not done with caller - 99 write_products = false; -100 fall_through_to_next_instruction = false; + 99 write_products = false; +100 fall_through_to_next_instruction = false; 101 break; 102 } 103 @@ -272,7 +272,7 @@ if ('onhashchange' in window) { 209 return x.type && x.type->atom && x.type->name == "recipe-literal"; 210 } 211 void resolve_indirect_ambiguous_call(const recipe_ordinal r, int index, instruction& inst, const recipe& caller_recipe) { -212 instruction inst2; +212 instruction inst2; 213 inst2.name = inst.ingredients.at(0).name; 214 for (int i = /*skip recipe*/1; i < SIZE(inst.ingredients); ++i) 215 inst2.ingredients.push_back(inst.ingredients.at(i)); @@ -280,14 +280,14 @@ if ('onhashchange' in window) { 217 inst2.products.push_back(inst.products.at(i)); 218 resolve_ambiguous_call(r, index, inst2, caller_recipe); 219 inst.ingredients.at(0).name = inst2.name; -220 inst.ingredients.at(0).set_value(get(Recipe_ordinal, inst2.name)); +220 inst.ingredients.at(0).set_value(get(Recipe_ordinal, inst2.name)); 221 } 222 223 :(after "Transform.push_back(check_instruction)") 224 Transform.push_back(check_indirect_calls_against_header); // idempotent 225 :(code) 226 void check_indirect_calls_against_header(const recipe_ordinal r) { -227 trace(9991, "transform") << "--- type-check 'call' instructions inside recipe " << get(Recipe, r).name << end(); +227 trace(9991, "transform") << "--- type-check 'call' instructions inside recipe " << get(Recipe, r).name << end(); 228 const recipe& caller = get(Recipe, r); 229 for (int i = 0; i < SIZE(caller.steps); ++i) { 230 const instruction& inst = caller.steps.at(i); @@ -300,14 +300,14 @@ if ('onhashchange' in window) { 237 if (is_indirect_call_with_ingredients(inst.operation)) { 238 for (long int i = /*skip callee*/1; i < min(SIZE(inst.ingredients), SIZE(callee_header.ingredients)+/*skip callee*/1); ++i) { 239 if (!types_coercible(callee_header.ingredients.at(i-/*skip callee*/1), inst.ingredients.at(i))) -240 raise << maybe(caller.name) << "ingredient " << i-/*skip callee*/1 << " has the wrong type at '" << to_original_string(inst) << "'\n" << end(); +240 raise << maybe(caller.name) << "ingredient " << i-/*skip callee*/1 << " has the wrong type at '" << to_original_string(inst) << "'\n" << end(); 241 } 242 } 243 if (is_indirect_call_with_products(inst.operation)) { 244 for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee_header.products)); ++i) { 245 if (is_dummy(inst.products.at(i))) continue; 246 if (!types_coercible(callee_header.products.at(i), inst.products.at(i))) -247 raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << to_original_string(inst) << "'\n" << end(); +247 raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << to_original_string(inst) << "'\n" << end(); 248 } 249 } 250 } @@ -318,20 +318,20 @@ if ('onhashchange' in window) { 255 } 256 257 bool is_indirect_call_with_ingredients(const recipe_ordinal r) { -258 if (r == CALL) return true; +258 if (r == CALL) return true; 259 // End is_indirect_call_with_ingredients Special-cases -260 return false; +260 return false; 261 } 262 bool is_indirect_call_with_products(const recipe_ordinal r) { -263 if (r == CALL) return true; +263 if (r == CALL) return true; 264 // End is_indirect_call_with_products Special-cases -265 return false; +265 return false; 266 } 267 268 recipe from_reagent(const reagent& r) { 269 assert(r.type); 270 recipe result_header; // will contain only ingredients and products, nothing else -271 result_header.has_header = true; +271 result_header.has_header = true; 272 // Begin Reagent->Recipe(r, recipe_header) 273 if (r.type->atom) { 274 assert(r.type->name == "recipe"); @@ -396,7 +396,7 @@ if ('onhashchange' in window) { 333 } 334 335 bool is_mu_recipe(const reagent& r) { -336 if (!r.type) return false; +336 if (!r.type) return false; 337 if (r.type->atom) { 338 // End is_mu_recipe Atom Cases(r) 339 return r.type->name == "recipe-literal"; @@ -433,32 +433,32 @@ if ('onhashchange' in window) { 370 :(before "End Matching Types For Literal(to)") 371 if (is_mu_recipe(to)) { 372 if (!contains_key(Recipe, from.value)) { -373 raise << "trying to store recipe " << from.name << " into " << to_string(to) << " but there's no such recipe\n" << end(); -374 return false; +373 raise << "trying to store recipe " << from.name << " into " << to_string(to) << " but there's no such recipe\n" << end(); +374 return false; 375 } 376 const recipe& rrhs = get(Recipe, from.value); 377 const recipe& rlhs = from_reagent(to); 378 for (long int i = 0; i < min(SIZE(rlhs.ingredients), SIZE(rrhs.ingredients)); ++i) { 379 if (!types_match(rlhs.ingredients.at(i), rrhs.ingredients.at(i))) -380 return false; +380 return false; 381 } 382 for (long int i = 0; i < min(SIZE(rlhs.products), SIZE(rrhs.products)); ++i) { 383 if (!types_match(rlhs.products.at(i), rrhs.products.at(i))) -384 return false; +384 return false; 385 } -386 return true; +386 return true; 387 } 388 389 :(scenario call_variable_compound_ingredient) 390 def main [ -391 {1: (recipe (address number) -> number)} <- copy f -392 2:&:num <- copy 0 -393 3:num <- call {1: (recipe (address number) -> number)}, 2:&:num +391 {1: (recipe (address number) -> number)} <- copy f +392 2:&:num <- copy null +393 3:num <- call {1: (recipe (address number) -> number)}, 2:&:num 394 ] 395 def f x:&:num -> y:num [ 396 local-scope 397 load-ingredients -398 y <- copy x +398 y <- deaddress x 399 ] 400 $error: 0 401 @@ -485,9 +485,9 @@ if ('onhashchange' in window) { 422 void check_for_recipe_literals(const instruction& inst, const recipe& caller) { 423 for (int i = 0; i < SIZE(inst.ingredients); ++i) { 424 if (is_mu_recipe(inst.ingredients.at(i))) { -425 raise << maybe(caller.name) << "missing type for '" << inst.ingredients.at(i).original_string << "' in '" << to_original_string(inst) << "'\n" << end(); +425 raise << maybe(caller.name) << "missing type for '" << inst.ingredients.at(i).original_string << "' in '" << to_original_string(inst) << "'\n" << end(); 426 if (is_present_in_ingredients(caller, inst.ingredients.at(i).name)) -427 raise << " did you forget 'load-ingredients'?\n" << end(); +427 raise << " did you forget 'load-ingredients'?\n" << end(); 428 } 429 } 430 } @@ -502,8 +502,8 @@ if ('onhashchange' in window) { 439 +error: did you forget 'load-ingredients'? 440 441 :(before "End Mu Types Initialization") -442 put(Type_abbreviations, "function", new_type_tree("recipe")); -443 put(Type_abbreviations, "fn", new_type_tree("recipe")); +442 put(Type_abbreviations, "function", new_type_tree("recipe")); +443 put(Type_abbreviations, "fn", new_type_tree("recipe")); 444 445 //: copying functions to variables 446 @@ -544,7 +544,7 @@ if ('onhashchange' in window) { 481 if (inst.name == "copy") { 482 for (int i = 0; i < SIZE(inst.ingredients); ++i) { 483 if (!is_recipe_literal(inst.ingredients.at(i))) continue; -484 if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue; +484 if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue; 485 // potentially overloaded recipe 486 string new_name = resolve_ambiguous_call(inst.ingredients.at(i).name, inst.products.at(i), r, index, caller_recipe); 487 if (new_name == "") continue; @@ -555,7 +555,7 @@ if ('onhashchange' in window) { 492 } 493 :(code) 494 string resolve_ambiguous_call(const string& recipe_name, const reagent& call_types, const recipe_ordinal r, int index, const recipe& caller_recipe) { -495 instruction inst; +495 instruction inst; 496 inst.name = recipe_name; 497 if (!is_mu_recipe(call_types)) return ""; // error raised elsewhere 498 if (is_recipe_literal(call_types)) return ""; // error raised elsewhere @@ -617,15 +617,15 @@ if ('onhashchange' in window) { 554 :(after "End resolve_ambiguous_call(r, index, inst, caller_recipe) Special-cases") 555 for (int i = 0; i < SIZE(inst.ingredients); ++i) { 556 if (!is_mu_recipe(inst.ingredients.at(i))) continue; -557 if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue; -558 if (get(Recipe_ordinal, inst.name) < MAX_PRIMITIVE_RECIPES) continue; -559 if (non_ghost_size(get_or_insert(Recipe_variants, inst.name)) > 1) { -560 raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to simultaneously guess which overloads you want for '" << inst.name << "' and '" << inst.ingredients.at(i).name << "'\n" << end(); +557 if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue; +558 if (get(Recipe_ordinal, inst.name) < MAX_PRIMITIVE_RECIPES) continue; +559 if (non_ghost_size(get_or_insert(Recipe_variants, inst.name)) > 1) { +560 raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to simultaneously guess which overloads you want for '" << inst.name << "' and '" << inst.ingredients.at(i).name << "'\n" << end(); 561 return; 562 } 563 const recipe& callee = get(Recipe, get(Recipe_ordinal, inst.name)); 564 if (!callee.has_header) { -565 raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to guess which variant of '" << inst.ingredients.at(i).name << "' you want, when the caller '" << inst.name << "' doesn't have a header\n" << end(); +565 raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to guess which variant of '" << inst.ingredients.at(i).name << "' you want, when the caller '" << inst.name << "' doesn't have a header\n" << end(); 566 return; 567 } 568 string new_name = resolve_ambiguous_call(inst.ingredients.at(i).name, callee.ingredients.at(i), r, index, caller_recipe); @@ -664,10 +664,10 @@ if ('onhashchange' in window) { 601 if (inst.name == "return" || inst.name == "reply") { 602 for (int i = 0; i < SIZE(inst.ingredients); ++i) { 603 if (!is_recipe_literal(inst.ingredients.at(i))) continue; -604 if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue; +604 if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue; 605 // potentially overloaded recipe 606 if (!caller_recipe.has_header) { -607 raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to guess which variant of '" << inst.ingredients.at(i).name << "' you want, without a recipe header\n" << end(); +607 raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to guess which variant of '" << inst.ingredients.at(i).name << "' you want, without a recipe header\n" << end(); 608 return; 609 } 610 string new_name = resolve_ambiguous_call(inst.ingredients.at(i).name, caller_recipe.products.at(i), r, index, caller_recipe); -- cgit 1.4.1-2-gfad0