From db1f56c8449d2ea3d158753fe37bac5a750a2566 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 29 Nov 2015 14:18:52 -0800 Subject: 2611 --- html/032array.cc.html | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'html/032array.cc.html') diff --git a/html/032array.cc.html b/html/032array.cc.html index 8c0ce105..d2689076 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -119,7 +119,7 @@ recipe main [ 2:number <- copy 14 3:number <- copy 15 4:number <- copy 16 - 5:address:array:number <- copy 1/raw + 5:address:array:number <- copy 1/unsafe 6:array:number <- copy *5:address:array:number ] +mem: storing 3 in location 6 @@ -194,7 +194,7 @@ case INDEX: { canonize_type(product); reagent element; element.type = new type_tree(*array_element(base.type)); - if (!types_match(product, element)) { + if (!types_coercible(product, element)) { raise_error << maybe(get(Recipe, r).name) << "'index' on " << base.original_string << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << '\n' << end(); break; } @@ -238,7 +238,7 @@ recipe main [ 2:number <- copy 14 3:number <- copy 15 4:number <- copy 16 - 5:address:array:number <- copy 1/raw + 5:address:array:number <- copy 1/unsafe 6:number <- index *5:address:array:number, 1 ] +mem: storing 15 in location 6 @@ -268,7 +268,7 @@ recipe main [ 5:number <- copy 14 6:number <- copy 15 7:number <- copy 16 - 8:address:array:point <- copy 1/raw + 8:address:array:point <- copy 1/unsafe index *8:address:array:point, -1 ] +error: main: invalid index -1 @@ -283,11 +283,23 @@ recipe main [ 5:number <- copy 14 6:number <- copy 15 7:number <- copy 16 - 8:address:array:point <- copy 1/raw + 8:address:array:point <- copy 1/unsafe 9:number <- index *8:address:array:point, 0 ] +error: main: 'index' on *8:address:array:point can't be saved in 9:number; type should be point +//: we might want to call 'index' without saving the results, say in a sandbox + +:(scenario index_without_product) +recipe main [ + 1:array:number:3 <- create-array + 2:number <- copy 14 + 3:number <- copy 15 + 4:number <- copy 16 + index 1:array:number:3, 0 +] +# just don't die + //:: To write to elements of containers, you need their address. :(scenario index_address) @@ -322,7 +334,7 @@ case INDEX_ADDRESS: { reagent element; element.type = new type_tree(*array_element(base.type)); element.type = new type_tree(get(Type_ordinal, "address"), element.type); - if (!types_match(product, element)) { + if (!types_coercible(product, element)) { raise_error << maybe(get(Recipe, r).name) << "'index' on " << base.original_string << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << '\n' << end(); break; } @@ -376,7 +388,7 @@ recipe main [ 5:number <- copy 14 6:number <- copy 15 7:number <- copy 16 - 8:address:array:point <- copy 1/raw + 8:address:array:point <- copy 1/unsafe index-address *8:address:array:point, -1 ] +error: main: invalid index -1 @@ -391,7 +403,7 @@ recipe main [ 5:number <- copy 14 6:number <- copy 15 7:number <- copy 16 - 8:address:array:point <- copy 1/raw + 8:address:array:point <- copy 1/unsafe 9:address:number <- index-address *8:address:array:point, 0 ] +error: main: 'index' on *8:address:array:point can't be saved in 9:address:number; type should be <address : <point : <>>> @@ -445,6 +457,18 @@ case LENGTH: { recipe_ordinal r = current_instruction().operation; if (r == CREATE_ARRAY || r == INDEX || r == INDEX_ADDRESS || r == LENGTH) return false; + +//: a particularly common array type is the string, or address:array:character +:(code) +bool is_mu_string(const reagent& x) { + return x.type + && x.type->value == get(Type_ordinal, "address") + && x.type->right + && x.type->right->value == get(Type_ordinal, "array") + && x.type->right->right + && x.type->right->right->value == get(Type_ordinal, "character") + && x.type->right->right->right == NULL; +} -- cgit 1.4.1-2-gfad0