From 6d007fda037331e7761d2a9ed3a2e435131daf7e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 11 Nov 2016 15:54:19 -0800 Subject: 3667 --- html/030container.cc.html | 150 +++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 108 deletions(-) (limited to 'html/030container.cc.html') diff --git a/html/030container.cc.html b/html/030container.cc.html index 81437ba6..6948c628 100644 --- a/html/030container.cc.html +++ b/html/030container.cc.html @@ -13,17 +13,18 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 12pt; font-size: 1em; } -.Constant { color: #00a0a0; } -.traceAbsent { color: #c00000; } -.cSpecial { color: #008000; } -.muRecipe { color: #ff8700; } .SalientComment { color: #00ffff; } -.Comment { color: #9090ff; } -.Delimiter { color: #800080; } -.Special { color: #c00000; } +.CommentedCode { color: #6c6c6c; } +.muRecipe { color: #ff8700; } +.muData { color: #ffff00; } .traceContains { color: #008000; } +.Delimiter { color: #800080; } .Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } -.muData { color: #ffff00; } +.cSpecial { color: #008000; } +.traceAbsent { color: #c00000; } +.Comment { color: #9090ff; } +.Constant { color: #00a0a0; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } --> @@ -182,33 +183,27 @@ atexit(clear_container_metadata//: do no work in size_of, simply lookup Container_metadata -:(before "End size_of(reagent r) Cases") +:(before "End size_of(reagent r) Special-cases") if (r.metadata.size) return r.metadata.size; -:(before "End size_of(type) Cases") -if (type->atom) { - if (type->value == -1) return 1; // error value, but we'll raise it elsewhere - if (type->value == 0) return 1; -} -const type_tree* root = root_type(type); -if (!contains_key(Type, root->value)) { - raise << "no such type " << root->value << '\n' << end(); +:(before "End size_of(type) Special-cases") +const type_tree* base_type = type; +// Update base_type in size_of(type) +if (!contains_key(Type, base_type->value)) { + raise << "no such type " << base_type->value << '\n' << end(); return 0; } -type_info t = get(Type, root->value); +type_info t = get(Type, base_type->value); if (t.kind == CONTAINER) { // Compute size_of Container - if (!contains_key(Container_metadata, type)) return 1; // error raised elsewhere + if (!contains_key(Container_metadata, type)) { + raise << "unknown size for container type '" << to_string(type) << "'\n" << end(); +//? DUMP(""); + return 0; + } return get(Container_metadata, type).size; } -:(code) -const type_tree* root_type(const type_tree* t) { - const type_tree* result = t->atom ? t : t->left; - assert(result->atom); - return result; -} - //: precompute Container_metadata before we need size_of //: also store a copy in each reagent in each instruction in each recipe @@ -246,27 +241,21 @@ Transform.push_back(if (contains_key(pending_metadata, *type)) return; pending_metadata.insert(*type); if (!type->atom) { - assert(type->left->atom); - if (type->left->name == "address") { - compute_container_sizes(type->right, pending_metadata, location_for_error_messages); - } - else if (type->left->name == "array") { - const type_tree* element_type = type->right; - // hack: support both array:num:3 and array:address:num - if (!element_type->atom && element_type->right && element_type->right->atom && is_integer(element_type->right->name)) - element_type = element_type->left; - compute_container_sizes(element_type, pending_metadata, location_for_error_messages); + if (!type->left->atom) { + raise << "invalid type " << to_string(type) << location_for_error_messages << '\n' << end(); + return; } - // End compute_container_sizes Non-atom Cases + if (type->left->name == "address") + compute_container_sizes(payload_type(type), pending_metadata, location_for_error_messages); + // End compute_container_sizes Non-atom Special-cases return; } assert(type->atom); if (!contains_key(Type, type->value)) return; // error raised elsewhere type_info& info = get(Type, type->value); - if (info.kind == CONTAINER) { + if (info.kind == CONTAINER) compute_container_sizes(info, type, pending_metadata, location_for_error_messages); - } - // End compute_container_sizes Atom Cases + // End compute_container_sizes Atom Special-cases } void compute_container_sizes(const type_info& container_info, const type_tree* full_type, set<type_tree>& pending_metadata, const string& location_for_error_messages) { @@ -285,6 +274,14 @@ Transform.push_back(.push_back(pair<type_tree*, container_metadata>(new type_tree(*full_type), metadata)); } +const type_tree* payload_type(const type_tree* type) { + assert(!type->atom); + const type_tree* result = type->right; + assert(!result->atom); + if (!result->right) return result->left; + return result; +} + container_metadata& get(vector<pair<type_tree*, container_metadata> >& all, const type_tree* key) { for (int i = 0; i < SIZE(all); ++i) { if (matches(all.at(i).first, key)) @@ -384,67 +381,6 @@ container_metadata& get(vector<pair<typ CHECK_EQ(get(Container_metadata, container.type).size, 2); } -void test_container_sizes_from_array() { - // a container we don't have the size for - reagent container("x:point"); - CHECK(!contains_key(Container_metadata, container.type)); - // scanning an array of the container precomputes the size of the container - reagent r("x:array:point"); - compute_container_sizes(r, ""); - CHECK(contains_key(Container_metadata, container.type)); - CHECK_EQ(get(Container_metadata, container.type).size, 2); -} - -void test_container_sizes_from_address_to_array() { - // a container we don't have the size for - reagent container("x:point"); - CHECK(!contains_key(Container_metadata, container.type)); - // scanning an address to an array of the container precomputes the size of the container - reagent r("x:address:array:point"); - compute_container_sizes(r, ""); - CHECK(contains_key(Container_metadata, container.type)); - CHECK_EQ(get(Container_metadata, container.type).size, 2); -} - -void test_container_sizes_from_static_array() { - // a container we don't have the size for - reagent container("x:point"); - int old_size = SIZE(Container_metadata); - // scanning an address to an array of the container precomputes the size of the container - reagent r("x:array:point:10"); - compute_container_sizes(r, ""); - CHECK(contains_key(Container_metadata, container.type)); - CHECK_EQ(get(Container_metadata, container.type).size, 2); - // no non-container types precomputed - CHECK_EQ(SIZE(Container_metadata)-old_size, 1); -} - -void test_container_sizes_from_address_to_static_array() { - // a container we don't have the size for - reagent container("x:point"); - int old_size = SIZE(Container_metadata); - // scanning an address to an array of the container precomputes the size of the container - reagent r("x:address:array:point:10"); - compute_container_sizes(r, ""); - CHECK(contains_key(Container_metadata, container.type)); - CHECK_EQ(get(Container_metadata, container.type).size, 2); - // no non-container types precomputed - CHECK_EQ(SIZE(Container_metadata)-old_size, 1); -} - -void test_container_sizes_from_repeated_address_and_array_types() { - // a container we don't have the size for - reagent container("x:point"); - int old_size = SIZE(Container_metadata); - // scanning repeated address and array types modifying the container precomputes the size of the container - reagent r("x:address:array:address:array:point:10"); - compute_container_sizes(r, ""); - CHECK(contains_key(Container_metadata, container.type)); - CHECK_EQ(get(Container_metadata, container.type).size, 2); - // no non-container types precomputed - CHECK_EQ(SIZE(Container_metadata)-old_size, 1); -} - //:: To access elements of a container, use 'get' //: 'get' takes a 'base' container and an 'offset' into it and returns the //: appropriate element of the container value. @@ -530,10 +466,11 @@ put(Recipe_ordinal,:(code) const reagent element_type(const type_tree* type, int offset_value) { assert(offset_value >= 0); - const type_tree* root = root_type(type); - assert(contains_key(Type, root->value)); - assert(!get(Type, root->value).name.empty()); - const type_info& info = get(Type, root->value); + const type_tree* base_type = type; + // Update base_type in element_type + 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(info.kind == CONTAINER); if (offset_value >= SIZE(info.elements)) return reagent(); // error handled elsewhere reagent/*copy*/ element = info.elements.at(offset_value); @@ -821,9 +758,6 @@ Num_calls_to_transform_all_at_first_definition = -1if (contains_key(Type_ordinal, type->name)) { type->value = get(Type_ordinal, type->name); } - else if (is_integer(type->name)) { // sometimes types will contain non-type tags, like numbers for the size of an array - type->value = 0; - } // End insert_container Special-cases else if (type->name != "->") { // used in recipe types put(Type_ordinal, type->name, Next_type_ordinal++); -- cgit 1.4.1-2-gfad0