From 805d58c6aeeeba3e4989c0eed6781b3861e8fae0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 25 Jan 2018 22:39:31 -0800 Subject: 4199 --- html/032array.cc.html | 177 +++++++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 89 deletions(-) (limited to 'html/032array.cc.html') diff --git a/html/032array.cc.html b/html/032array.cc.html index a1426054..c8e8ebac 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -15,20 +15,19 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } -.LineNr { color: #444444; } -.SalientComment { color: #00ffff; } -.muRecipe { color: #ff8700; } .cSpecial { color: #008000; } +.LineNr { color: #444444; } .muData { color: #ffff00; } -.Identifier { color: #c0a020; } +.Constant { color: #00a0a0; } +.muRecipe { color: #ff8700; } .Delimiter { color: #800080; } -.traceContains { color: #008000; } -.Conceal { color: #4e4e4e; } +.Special { color: #c00000; } +.Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.Constant { color: #00a0a0; } -.Special { color: #c00000; } +.SalientComment { color: #00ffff; } +.traceContains { color: #008000; } --> @@ -85,30 +84,30 @@ if ('onhashchange' in window) { 20 :(before "End Primitive Recipe Checks") 21 case CREATE_ARRAY: { 22 if (inst.products.empty()) { - 23 ¦ raise << maybe(get(Recipe, r).name) << "'create-array' needs one product and no ingredients but got '" << to_original_string(inst) << '\n' << end(); - 24 ¦ break; + 23 raise << maybe(get(Recipe, r).name) << "'create-array' needs one product and no ingredients but got '" << to_original_string(inst) << '\n' << end(); + 24 break; 25 } 26 reagent/*copy*/ product = inst.products.at(0); 27 // Update CREATE_ARRAY product in Check 28 if (!is_mu_array(product)) { - 29 ¦ raise << maybe(get(Recipe, r).name) << "'create-array' cannot create non-array '" << product.original_string << "'\n" << end(); - 30 ¦ break; + 29 raise << maybe(get(Recipe, r).name) << "'create-array' cannot create non-array '" << product.original_string << "'\n" << end(); + 30 break; 31 } 32 if (!product.type->right) { - 33 ¦ raise << maybe(get(Recipe, r).name) << "create array of what? '" << to_original_string(inst) << "'\n" << end(); - 34 ¦ break; + 33 raise << maybe(get(Recipe, r).name) << "create array of what? '" << to_original_string(inst) << "'\n" << end(); + 34 break; 35 } 36 // 'create-array' will need to check properties rather than types 37 type_tree* array_length_from_type = product.type->right->right; 38 if (!array_length_from_type) { - 39 ¦ raise << maybe(get(Recipe, r).name) << "create array of what size? '" << to_original_string(inst) << "'\n" << end(); - 40 ¦ break; + 39 raise << maybe(get(Recipe, r).name) << "create array of what size? '" << to_original_string(inst) << "'\n" << end(); + 40 break; 41 } 42 if (!product.type->right->right->atom) - 43 ¦ array_length_from_type = array_length_from_type->left; + 43 array_length_from_type = array_length_from_type->left; 44 if (!is_integer(array_length_from_type->name)) { - 45 ¦ raise << maybe(get(Recipe, r).name) << "'create-array' product should specify size of array after its element type, but got '" << product.type->right->right->name << "'\n" << end(); - 46 ¦ break; + 45 raise << maybe(get(Recipe, r).name) << "'create-array' product should specify size of array after its element type, but got '" << product.type->right->right->name << "'\n" << end(); + 46 break; 47 } 48 break; 49 } @@ -119,7 +118,7 @@ if ('onhashchange' in window) { 54 int base_address = product.value; 55 type_tree* array_length_from_type = product.type->right->right; 56 if (!product.type->right->right->atom) - 57 ¦ array_length_from_type = array_length_from_type->left; + 57 array_length_from_type = array_length_from_type->left; 58 int array_length = to_integer(array_length_from_type->name); 59 // initialize array length, so that size_of will work 60 trace("mem") << "storing " << array_length << " in location " << base_address << end(); @@ -128,7 +127,7 @@ if ('onhashchange' in window) { 63 trace(9998, "run") << "creating array of size " << size << end(); 64 // initialize array 65 for (int i = 1; i <= size_of(product); ++i) - 66 ¦ put(Memory, base_address+i, 0); + 66 put(Memory, base_address+i, 0); 67 // no need to update product 68 write_products = false; 69 break; @@ -170,8 +169,8 @@ if ('onhashchange' in window) { 105 :(before "End size_of(reagent r) Special-cases") 106 if (!r.type->atom && r.type->left->atom && r.type->left->value == get(Type_ordinal, "array")) { 107 if (!r.type->right) { -108 ¦ raise << maybe(current_recipe_name()) << "'" << r.original_string << "' is an array of what?\n" << end(); -109 ¦ return 1; +108 raise << maybe(current_recipe_name()) << "'" << r.original_string << "' is an array of what?\n" << end(); +109 return 1; 110 } 111 return /*space for length*/1 + array_length(r)*size_of(array_element(r.type)); 112 } @@ -181,9 +180,9 @@ if ('onhashchange' in window) { 116 :(code) 117 int static_array_length(const type_tree* type) { 118 if (!type->atom && type->right && !type->right->atom && type->right->right && !type->right->right->atom && !type->right->right->right // exactly 3 types -119 ¦ ¦ && type->right->right->left && type->right->right->left->atom && is_integer(type->right->right->left->name)) { // third 'type' is a number -120 ¦ // get size from type -121 ¦ return to_integer(type->right->right->left->name); +119 && type->right->right->left && type->right->right->left->atom && is_integer(type->right->right->left->name)) { // third 'type' is a number +120 // get size from type +121 return to_integer(type->right->right->left->name); 122 } 123 cerr << to_string(type) << '\n'; 124 assert(false); @@ -220,18 +219,18 @@ if ('onhashchange' in window) { 155 { 156 const type_tree* type = info.elements.back().type; 157 if (type && type->atom && type->name == "array") { -158 ¦ raise << "container '" << name << "' doesn't specify type of array elements for '" << info.elements.back().name << "'\n" << end(); -159 ¦ continue; +158 raise << "container '" << name << "' doesn't specify type of array elements for '" << info.elements.back().name << "'\n" << end(); +159 continue; 160 } 161 if (type && !type->atom && type->left->atom && type->left->name == "array") { -162 ¦ if (!type->right) { -163 ¦ ¦ raise << "container '" << name << "' doesn't specify type of array elements for '" << info.elements.back().name << "'\n" << end(); -164 ¦ ¦ continue; -165 ¦ } -166 ¦ if (!type->right->right || !is_integer(type->right->right->left->name)) { // array has no length -167 ¦ ¦ raise << "container '" << name << "' cannot determine size of element '" << info.elements.back().name << "'\n" << end(); -168 ¦ ¦ continue; -169 ¦ } +162 if (!type->right) { +163 raise << "container '" << name << "' doesn't specify type of array elements for '" << info.elements.back().name << "'\n" << end(); +164 continue; +165 } +166 if (!type->right->right || !is_integer(type->right->right->left->name)) { // array has no length +167 raise << "container '" << name << "' cannot determine size of element '" << info.elements.back().name << "'\n" << end(); +168 continue; +169 } 170 } 171 } 172 @@ -239,7 +238,7 @@ if ('onhashchange' in window) { 174 //: can contain arrays, and since we already do plenty of checking for them 175 :(before "End size_mismatch(x) Special-cases") 176 if (current_call().running_step_index < SIZE(get(Recipe, current_call().running_recipe).steps) -177 ¦ && current_instruction().operation == MERGE) { +177 && current_instruction().operation == MERGE) { 178 return false; 179 } 180 @@ -289,7 +288,7 @@ if ('onhashchange' in window) { 224 reagent container("x:point"); 225 CHECK(!contains_key(Container_metadata, container.type)); 226 // scanning an address to an array of the container precomputes the size of the container -227 reagent r("x:address:array:point"); +227 reagent r("x:address:array:point"); 228 compute_container_sizes(r, ""); 229 CHECK(contains_key(Container_metadata, container.type)); 230 CHECK_EQ(get(Container_metadata, container.type).size, 2); @@ -313,7 +312,7 @@ if ('onhashchange' in window) { 248 reagent container("x:point"); 249 int old_size = SIZE(Container_metadata); 250 // scanning an address to an array of the container precomputes the size of the container -251 reagent r("x:address:array:point:10"); +251 reagent r("x:address:array:point:10"); 252 compute_container_sizes(r, ""); 253 CHECK(contains_key(Container_metadata, container.type)); 254 CHECK_EQ(get(Container_metadata, container.type).size, 2); @@ -326,7 +325,7 @@ if ('onhashchange' in window) { 261 reagent container("x:point"); 262 int old_size = SIZE(Container_metadata); 263 // scanning repeated address and array types modifying the container precomputes the size of the container -264 reagent r("x:address:array:address:array:point:10"); +264 reagent r("x:address:array:address:array:point:10"); 265 compute_container_sizes(r, ""); 266 CHECK(contains_key(Container_metadata, container.type)); 267 CHECK_EQ(get(Container_metadata, container.type).size, 2); @@ -339,7 +338,7 @@ if ('onhashchange' in window) { 274 reagent container("x:point"); 275 int old_size = SIZE(Container_metadata); 276 // scanning address to array with a typo -277 reagent r("x:address:array:adress:number"); +277 reagent r("x:address:array:adress:number"); 278 compute_container_sizes(r, ""); // should not crash 279 // no non-container types precomputed 280 CHECK_EQ(SIZE(Container_metadata), old_size); @@ -359,11 +358,11 @@ if ('onhashchange' in window) { 294 295 :(scenario index_compound_element) 296 def main [ -297 {1: (array (address number) 3)} <- create-array +297 {1: (array (address number) 3)} <- create-array 298 2:num <- copy 14 299 3:num <- copy 15 300 4:num <- copy 16 -301 5:address:num <- index {1: (array (address number) 3)}, 0 +301 5:address:num <- index {1: (array (address number) 3)}, 0 302 ] 303 +mem: storing 14 in location 5 304 @@ -385,20 +384,20 @@ if ('onhashchange' in window) { 320 :(before "End Primitive Recipe Checks") 321 case INDEX: { 322 if (SIZE(inst.ingredients) != 2) { -323 ¦ raise << maybe(get(Recipe, r).name) << "'index' expects exactly 2 ingredients in '" << to_original_string(inst) << "'\n" << end(); -324 ¦ break; +323 raise << maybe(get(Recipe, r).name) << "'index' expects exactly 2 ingredients in '" << to_original_string(inst) << "'\n" << end(); +324 break; 325 } 326 reagent/*copy*/ base = inst.ingredients.at(0); 327 // Update INDEX base in Check 328 if (!is_mu_array(base)) { -329 ¦ raise << maybe(get(Recipe, r).name) << "'index' on a non-array '" << base.original_string << "'\n" << end(); -330 ¦ break; +329 raise << maybe(get(Recipe, r).name) << "'index' on a non-array '" << base.original_string << "'\n" << end(); +330 break; 331 } 332 reagent/*copy*/ index = inst.ingredients.at(1); 333 // Update INDEX index in Check 334 if (!is_mu_number(index)) { -335 ¦ raise << maybe(get(Recipe, r).name) << "second ingredient of 'index' should be a number, but got '" << index.original_string << "'\n" << end(); -336 ¦ break; +335 raise << maybe(get(Recipe, r).name) << "second ingredient of 'index' should be a number, but got '" << index.original_string << "'\n" << end(); +336 break; 337 } 338 if (inst.products.empty()) break; 339 reagent/*copy*/ product = inst.products.at(0); @@ -406,8 +405,8 @@ if ('onhashchange' in window) { 341 reagent/*local*/ element; 342 element.type = copy_array_element(base.type); 343 if (!types_coercible(product, element)) { -344 ¦ raise << maybe(get(Recipe, r).name) << "'index' on '" << base.original_string << "' can't be saved in '" << product.original_string << "'; type should be '" << names_to_string_without_quotes(element.type) << "'\n" << end(); -345 ¦ break; +344 raise << maybe(get(Recipe, r).name) << "'index' on '" << base.original_string << "' can't be saved in '" << product.original_string << "'; type should be '" << names_to_string_without_quotes(element.type) << "'\n" << end(); +345 break; 346 } 347 break; 348 } @@ -416,17 +415,17 @@ if ('onhashchange' in window) { 351 reagent/*copy*/ base = current_instruction().ingredients.at(0); 352 // Update INDEX base in Run 353 int base_address = base.value; -354 trace(9998, "run") << "base address is " << base_address << end(); +354 trace(9998, "run") << "base address is " << base_address << end(); 355 if (base_address == 0) { -356 ¦ raise << maybe(current_recipe_name()) << "tried to access location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); -357 ¦ break; +356 raise << maybe(current_recipe_name()) << "tried to access location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); +357 break; 358 } 359 reagent/*copy*/ index = current_instruction().ingredients.at(1); 360 // Update INDEX index in Run 361 vector<double> index_val(read_memory(index)); 362 if (index_val.at(0) < 0 || index_val.at(0) >= get_or_insert(Memory, base_address)) { -363 ¦ raise << maybe(current_recipe_name()) << "invalid index " << no_scientific(index_val.at(0)) << " in '" << to_original_string(current_instruction()) << "'\n" << end(); -364 ¦ break; +363 raise << maybe(current_recipe_name()) << "invalid index " << no_scientific(index_val.at(0)) << " in '" << to_original_string(current_instruction()) << "'\n" << end(); +364 break; 365 } 366 reagent/*local*/ element; 367 element.type = copy_array_element(base.type); @@ -446,15 +445,15 @@ if ('onhashchange' in window) { 381 type_tree* array_element(const type_tree* type) { 382 assert(type->right); 383 if (type->right->atom) { -384 ¦ return type->right; +384 return type->right; 385 } 386 else if (!type->right->right) { -387 ¦ return type->right->left; +387 return type->right->left; 388 } 389 // hack: support array:num:3 without requiring extra parens 390 else if (type->right->right->left && type->right->right->left->atom && is_integer(type->right->right->left->name)) { -391 ¦ assert(!type->right->right->right); -392 ¦ return type->right->left; +391 assert(!type->right->right->right); +392 return type->right->left; 393 } 394 return type->right; 395 } @@ -463,9 +462,9 @@ if ('onhashchange' in window) { 398 // x should already be canonized. 399 // hack: look for length in type 400 if (!x.type->atom && x.type->right && !x.type->right->atom && x.type->right->right && !x.type->right->right->atom && !x.type->right->right->right // exactly 3 types -401 ¦ ¦ && x.type->right->right->left && x.type->right->right->left->atom && is_integer(x.type->right->right->left->name)) { // third 'type' is a number -402 ¦ // get size from type -403 ¦ return to_integer(x.type->right->right->left->name); +401 && x.type->right->right->left && x.type->right->right->left->atom && is_integer(x.type->right->right->left->name)) { // third 'type' is a number +402 // get size from type +403 return to_integer(x.type->right->right->left->name); 404 } 405 // this should never happen at transform time 406 return get_or_insert(Memory, x.value); @@ -477,7 +476,7 @@ if ('onhashchange' in window) { 412 put(Memory, 2, 14); 413 put(Memory, 3, 15); 414 put(Memory, 4, 16); -415 reagent x("1:array:address:num"); // 3 types, but not a static array +415 reagent x("1:array:address:num"); // 3 types, but not a static array 416 populate_value(x); 417 CHECK_EQ(array_length(x), 3); 418 } @@ -493,7 +492,7 @@ if ('onhashchange' in window) { 428 2:num <- copy 14 429 3:num <- copy 15 430 4:num <- copy 16 -431 5:num <- index 1:array:num:3, 1.5 # non-whole number +431 5:num <- index 1:array:num:3, 1.5 # non-whole number 432 ] 433 # fraction is truncated away 434 +mem: storing 15 in location 5 @@ -571,33 +570,33 @@ if ('onhashchange' in window) { 506 :(before "End Primitive Recipe Checks") 507 case PUT_INDEX: { 508 if (SIZE(inst.ingredients) != 3) { -509 ¦ raise << maybe(get(Recipe, r).name) << "'put-index' expects exactly 3 ingredients in '" << to_original_string(inst) << "'\n" << end(); -510 ¦ break; +509 raise << maybe(get(Recipe, r).name) << "'put-index' expects exactly 3 ingredients in '" << to_original_string(inst) << "'\n" << end(); +510 break; 511 } 512 reagent/*copy*/ base = inst.ingredients.at(0); 513 // Update PUT_INDEX base in Check 514 if (!is_mu_array(base)) { -515 ¦ raise << maybe(get(Recipe, r).name) << "'put-index' on a non-array '" << base.original_string << "'\n" << end(); -516 ¦ break; +515 raise << maybe(get(Recipe, r).name) << "'put-index' on a non-array '" << base.original_string << "'\n" << end(); +516 break; 517 } 518 reagent/*copy*/ index = inst.ingredients.at(1); 519 // Update PUT_INDEX index in Check 520 if (!is_mu_number(index)) { -521 ¦ raise << maybe(get(Recipe, r).name) << "second ingredient of 'put-index' should have type 'number', but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); -522 ¦ break; +521 raise << maybe(get(Recipe, r).name) << "second ingredient of 'put-index' should have type 'number', but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); +522 break; 523 } 524 reagent/*copy*/ value = inst.ingredients.at(2); 525 // Update PUT_INDEX value in Check 526 reagent/*local*/ element; 527 element.type = copy_array_element(base.type); 528 if (!types_coercible(element, value)) { -529 ¦ raise << maybe(get(Recipe, r).name) << "'put-index " << base.original_string << ", " << inst.ingredients.at(1).original_string << "' should store " << names_to_string_without_quotes(element.type) << " but '" << value.name << "' has type " << names_to_string_without_quotes(value.type) << '\n' << end(); -530 ¦ break; +529 raise << maybe(get(Recipe, r).name) << "'put-index " << base.original_string << ", " << inst.ingredients.at(1).original_string << "' should store " << names_to_string_without_quotes(element.type) << " but '" << value.name << "' has type " << names_to_string_without_quotes(value.type) << '\n' << end(); +530 break; 531 } 532 if (inst.products.empty()) break; // no more checks necessary 533 if (inst.products.at(0).name != inst.ingredients.at(0).name) { -534 ¦ raise << maybe(get(Recipe, r).name) << "product of 'put-index' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end(); -535 ¦ break; +534 raise << maybe(get(Recipe, r).name) << "product of 'put-index' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end(); +535 break; 536 } 537 // End PUT_INDEX Product Checks 538 break; @@ -608,26 +607,26 @@ if ('onhashchange' in window) { 543 // Update PUT_INDEX base in Run 544 int base_address = base.value; 545 if (base_address == 0) { -546 ¦ raise << maybe(current_recipe_name()) << "tried to access location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); -547 ¦ break; +546 raise << maybe(current_recipe_name()) << "tried to access location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); +547 break; 548 } 549 reagent/*copy*/ index = current_instruction().ingredients.at(1); 550 // Update PUT_INDEX index in Run 551 vector<double> index_val(read_memory(index)); 552 if (index_val.at(0) < 0 || index_val.at(0) >= get_or_insert(Memory, base_address)) { -553 ¦ raise << maybe(current_recipe_name()) << "invalid index " << no_scientific(index_val.at(0)) << " in '" << to_original_string(current_instruction()) << "'\n" << end(); -554 ¦ break; +553 raise << maybe(current_recipe_name()) << "invalid index " << no_scientific(index_val.at(0)) << " in '" << to_original_string(current_instruction()) << "'\n" << end(); +554 break; 555 } -556 int address = base_address + /*skip length*/1 + index_val.at(0)*size_of(array_element(base.type)); -557 trace(9998, "run") << "address to copy to is " << address << end(); +556 int address = base_address + /*skip length*/1 + index_val.at(0)*size_of(array_element(base.type)); +557 trace(9998, "run") << "address to copy to is " << address << end(); 558 // optimization: directly write the element rather than updating 'product' 559 // and writing the entire array 560 write_products = false; 561 vector<double> value = read_memory(current_instruction().ingredients.at(2)); 562 // Write Memory in PUT_INDEX in Run 563 for (int i = 0; i < SIZE(value); ++i) { -564 ¦ trace("mem") << "storing " << no_scientific(value.at(i)) << " in location " << address+i << end(); -565 ¦ put(Memory, address+i, value.at(i)); +564 trace("mem") << "storing " << no_scientific(value.at(i)) << " in location " << address+i << end(); +565 put(Memory, address+i, value.at(i)); 566 } 567 break; 568 } @@ -691,14 +690,14 @@ if ('onhashchange' in window) { 626 :(before "End Primitive Recipe Checks") 627 case LENGTH: { 628 if (SIZE(inst.ingredients) != 1) { -629 ¦ raise << maybe(get(Recipe, r).name) << "'length' expects exactly 2 ingredients in '" << to_original_string(inst) << "'\n" << end(); -630 ¦ break; +629 raise << maybe(get(Recipe, r).name) << "'length' expects exactly 2 ingredients in '" << to_original_string(inst) << "'\n" << end(); +630 break; 631 } 632 reagent/*copy*/ array = inst.ingredients.at(0); 633 // Update LENGTH array in Check 634 if (!is_mu_array(array)) { -635 ¦ raise << "tried to calculate length of non-array '" << array.original_string << "'\n" << end(); -636 ¦ break; +635 raise << "tried to calculate length of non-array '" << array.original_string << "'\n" << end(); +636 break; 637 } 638 break; 639 } @@ -707,8 +706,8 @@ if ('onhashchange' in window) { 642 reagent/*copy*/ array = current_instruction().ingredients.at(0); 643 // Update LENGTH array in Run 644 if (array.value == 0) { -645 ¦ raise << maybe(current_recipe_name()) << "tried to access location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); -646 ¦ break; +645 raise << maybe(current_recipe_name()) << "tried to access location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); +646 break; 647 } 648 products.resize(1); 649 products.at(0).push_back(get_or_insert(Memory, array.value)); -- cgit 1.4.1-2-gfad0