diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-04-30 10:09:38 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-04-30 10:09:38 -0700 |
commit | 471839dad7e953fdd88902e03ddb55c02377ad44 (patch) | |
tree | 14d6e855e0d6a16fa1e3f32af84fde61585c8023 | |
parent | 841387aea82a398e86871c54132bb5d6b19ddca4 (diff) | |
download | mu-471839dad7e953fdd88902e03ddb55c02377ad44.tar.gz |
2889
-rw-r--r-- | 030container.cc | 24 | ||||
-rw-r--r-- | 057shape_shifting_container.cc | 28 | ||||
-rw-r--r-- | 058shape_shifting_recipe.cc | 2 | ||||
-rw-r--r-- | 063wait.cc | 2 | ||||
-rw-r--r-- | 078hash.cc | 2 |
5 files changed, 28 insertions, 30 deletions
diff --git a/030container.cc b/030container.cc index 879688a9..8daddd2d 100644 --- a/030container.cc +++ b/030container.cc @@ -104,8 +104,6 @@ if (!contains_key(Type, type->value)) { } type_info t = get(Type, type->value); if (t.kind == CONTAINER) { - reagent reagent_containing_type; - reagent_containing_type.type = new type_tree(*type); // size of a container is the sum of the sizes of its elements int result = 0; for (int i = 0; i < SIZE(t.elements); ++i) { @@ -114,7 +112,7 @@ if (t.kind == CONTAINER) { raise << "container " << t.name << " can't include itself as a member\n" << end(); return 0; } - result += size_of(element_type(reagent_containing_type, i)); + result += size_of(element_type(type, i)); } return result; } @@ -171,7 +169,7 @@ case GET: { if (inst.products.empty()) break; reagent product = inst.products.at(0); // Update GET product in Check - const reagent element = element_type(base, offset_value); + const reagent element = element_type(base.type, offset_value); if (!types_coercible(product, element)) { raise << maybe(get(Recipe, r).name) << "'get " << base.original_string << ", " << offset.original_string << "' should write to " << names_to_string_without_quotes(element.type) << " but " << product.name << " has type " << names_to_string_without_quotes(product.type) << '\n' << end(); break; @@ -192,9 +190,9 @@ case GET: { if (offset < 0 || offset >= SIZE(get(Type, base_type).elements)) break; // copied from Check above int src = base_address; for (int i = 0; i < offset; ++i) - src += size_of(element_type(base, i)); + src += size_of(element_type(base.type, i)); trace(9998, "run") << "address to copy is " << src << end(); - reagent element = element_type(base, offset); + reagent element = element_type(base.type, offset); element.set_value(src); trace(9998, "run") << "its type is " << names_to_string(element.type) << end(); // Read element @@ -203,11 +201,11 @@ case GET: { } :(code) -const reagent element_type(const reagent& base, int offset_value) { +const reagent element_type(const type_tree* type, int offset_value) { assert(offset_value >= 0); - assert(contains_key(Type, base.type->value)); - assert(!get(Type, base.type->value).name.empty()); - const type_info& info = get(Type, base.type->value); + assert(contains_key(Type, type->value)); + assert(!get(Type, type->value).name.empty()); + const type_info& info = get(Type, type->value); assert(info.kind == CONTAINER); reagent element = info.elements.at(offset_value); // End element_type Special-cases @@ -310,7 +308,7 @@ case PUT: { offset_value = offset.value; } reagent& value = inst.ingredients.at(2); - reagent element = element_type(base, offset_value); + reagent element = element_type(base.type, offset_value); if (!types_coercible(element, value)) { raise << maybe(get(Recipe, r).name) << "'put " << base.original_string << ", " << offset.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(); break; @@ -331,7 +329,7 @@ case PUT: { if (offset < 0 || offset >= SIZE(get(Type, base_type).elements)) break; // copied from Check above int address = base_address; for (int i = 0; i < offset; ++i) - address += size_of(element_type(base, i)); + address += size_of(element_type(base.type, i)); trace(9998, "run") << "address to copy to is " << address << end(); // optimization: directly write the element rather than updating 'product' // and writing the entire container @@ -748,7 +746,7 @@ void check_merge_call(const vector<reagent>& ingredients, const reagent& product // degenerate case: merge with the same type always succeeds if (state.data.top().container_element_index == 0 && types_coercible(container, inst.ingredients.at(ingredient_index))) return; - reagent expected_ingredient = element_type(container, state.data.top().container_element_index); + reagent expected_ingredient = element_type(container.type, state.data.top().container_element_index); trace(9999, "transform") << "checking container " << to_string(container) << " || " << to_string(expected_ingredient) << " vs ingredient " << ingredient_index << end(); // if the current element is the ingredient we expect, move on to the next element/ingredient if (types_coercible(expected_ingredient, ingredients.at(ingredient_index))) { diff --git a/057shape_shifting_container.cc b/057shape_shifting_container.cc index 1b9d51b7..fa587595 100644 --- a/057shape_shifting_container.cc +++ b/057shape_shifting_container.cc @@ -247,9 +247,9 @@ def main [ :(before "End element_type Special-cases") if (contains_type_ingredient(element)) { - if (!base.type->right) - raise << "illegal type " << names_to_string(base.type) << " seems to be missing a type ingredient or three\n" << end(); - replace_type_ingredients(element.type, base.type->right, info); + if (!type->right) + raise << "illegal type " << names_to_string(type) << " seems to be missing a type ingredient or three\n" << end(); + replace_type_ingredients(element.type, type->right, info); } :(code) @@ -353,7 +353,7 @@ void test_replace_type_ingredients_entire() { " y:number\n" "]\n"); reagent callsite("x:foo:point"); - reagent element = element_type(callsite, 0); + reagent element = element_type(callsite.type, 0); CHECK_EQ(element.name, "x"); CHECK_EQ(element.type->name, "point"); CHECK(!element.type->right); @@ -367,7 +367,7 @@ void test_replace_type_ingredients_tail() { " x:foo:_elem\n" "]\n"); reagent callsite("x:bar:point"); - reagent element = element_type(callsite, 0); + reagent element = element_type(callsite.type, 0); CHECK_EQ(element.name, "x"); CHECK_EQ(element.type->name, "foo"); CHECK_EQ(element.type->right->name, "point"); @@ -382,7 +382,7 @@ void test_replace_type_ingredients_head_tail_multiple() { " x:foo:_elem\n" "]\n"); reagent callsite("x:bar:address:array:character"); - reagent element = element_type(callsite, 0); + reagent element = element_type(callsite.type, 0); CHECK_EQ(element.name, "x"); CHECK_EQ(element.type->name, "foo"); CHECK_EQ(element.type->right->name, "address"); @@ -399,7 +399,7 @@ void test_replace_type_ingredients_head_middle() { " x:foo:_elem:number\n" "]\n"); reagent callsite("x:bar:address"); - reagent element = element_type(callsite, 0); + reagent element = element_type(callsite.type, 0); CHECK_EQ(element.name, "x"); CHECK(element.type) CHECK_EQ(element.type->name, "foo"); @@ -416,11 +416,11 @@ void test_replace_last_type_ingredient_with_multiple() { " y:_b\n" "]\n"); reagent callsite("{f: (foo number (address array character))}"); - reagent element1 = element_type(callsite, 0); + reagent element1 = element_type(callsite.type, 0); CHECK_EQ(element1.name, "x"); CHECK_EQ(element1.type->name, "number"); CHECK(!element1.type->right); - reagent element2 = element_type(callsite, 1); + reagent element2 = element_type(callsite.type, 1); CHECK_EQ(element2.name, "y"); CHECK_EQ(element2.type->name, "address"); CHECK_EQ(element2.type->right->name, "array"); @@ -435,17 +435,17 @@ void test_replace_middle_type_ingredient_with_multiple() { " z:_c\n" "]\n"); reagent callsite("{f: (foo number (address array character) boolean)}"); - reagent element1 = element_type(callsite, 0); + reagent element1 = element_type(callsite.type, 0); CHECK_EQ(element1.name, "x"); CHECK_EQ(element1.type->name, "number"); CHECK(!element1.type->right); - reagent element2 = element_type(callsite, 1); + reagent element2 = element_type(callsite.type, 1); CHECK_EQ(element2.name, "y"); CHECK_EQ(element2.type->name, "address"); CHECK_EQ(element2.type->right->name, "array"); CHECK_EQ(element2.type->right->right->name, "character"); CHECK(!element2.type->right->right->right); - reagent element3 = element_type(callsite, 2); + reagent element3 = element_type(callsite.type, 2); CHECK_EQ(element3.name, "z"); CHECK_EQ(element3.type->name, "boolean"); CHECK(!element3.type->right); @@ -457,7 +457,7 @@ void test_replace_middle_type_ingredient_with_multiple2() { " value:_value\n" "]\n"); reagent callsite("{f: (foo (address array character) number)}"); - reagent element = element_type(callsite, 0); + reagent element = element_type(callsite.type, 0); CHECK_EQ(element.name, "key"); CHECK_EQ(element.type->name, "address"); CHECK_EQ(element.type->right->name, "array"); @@ -475,7 +475,7 @@ void test_replace_middle_type_ingredient_with_multiple3() { " value:_value\n" "]\n"); reagent callsite("{f: (foo_table (address array character) number)}"); - reagent element = element_type(callsite, 0); + reagent element = element_type(callsite.type, 0); CHECK_EQ(element.name, "data"); CHECK_EQ(element.type->name, "address"); CHECK_EQ(element.type->right->name, "array"); diff --git a/058shape_shifting_recipe.cc b/058shape_shifting_recipe.cc index 0384dd57..433147cd 100644 --- a/058shape_shifting_recipe.cc +++ b/058shape_shifting_recipe.cc @@ -678,7 +678,7 @@ void test_shape_shifting_new_ingredient_does_not_pollute_global_namespace() { "]\n"); // then it should work as usual reagent callsite("x:foo:point"); - reagent element = element_type(callsite, 0); + reagent element = element_type(callsite.type, 0); CHECK_EQ(element.name, "x"); CHECK_EQ(element.type->name, "point"); CHECK(!element.type->right); diff --git a/063wait.cc b/063wait.cc index d25c5467..4595d7c1 100644 --- a/063wait.cc +++ b/063wait.cc @@ -156,7 +156,7 @@ case GET_LOCATION: { if (offset < 0 || offset >= SIZE(get(Type, base_type).elements)) break; // copied from Check above int result = base_address; for (int i = 0; i < offset; ++i) - result += size_of(element_type(base, i)); + result += size_of(element_type(base.type, i)); trace(9998, "run") << "address to copy is " << result << end(); products.resize(1); products.at(0).push_back(result); diff --git a/078hash.cc b/078hash.cc index 59b3e222..91db00ba 100644 --- a/078hash.cc +++ b/078hash.cc @@ -100,7 +100,7 @@ size_t hash_mu_container(size_t h, const reagent& r) { int address = r.value; int offset = 0; for (int i = 0; i < SIZE(info.elements); ++i) { - reagent element = element_type(r, i); + reagent element = element_type(r.type, i); if (has_property(element, "ignore-for-hash")) continue; element.set_value(address+offset); h = hash(h, element); |