diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-08 10:20:49 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-08 10:20:49 -0800 |
commit | f4647409b5fa658e463424c0a8249a4d72405d59 (patch) | |
tree | ff024555e70a2cb8649dbf7f494129d670997676 | |
parent | 2789e86118e1f4da63e5b8883ffdb4ef31c98887 (diff) | |
download | mu-f4647409b5fa658e463424c0a8249a4d72405d59.tar.gz |
3652
size_of(type_tree*) is a mess; clean it up with an eye to the final tangled version.
-rw-r--r-- | 020run.cc | 10 | ||||
-rw-r--r-- | 030container.cc | 4 | ||||
-rw-r--r-- | 032array.cc | 13 | ||||
-rw-r--r-- | 036refcount.cc | 10 |
4 files changed, 23 insertions, 14 deletions
diff --git a/020run.cc b/020run.cc index 746bc9cd..de957dbb 100644 --- a/020run.cc +++ b/020run.cc @@ -329,6 +329,16 @@ int size_of(const reagent& r) { } int size_of(const type_tree* type) { if (!type) return 0; + if (type->atom) { + if (type->value == -1) return 1; // error value, but we'll raise it elsewhere + if (type->value == 0) return 1; + // End size_of(type) Atom Special-cases + } + else { + assert(type->left->atom); + if (type->left->name == "address") return 1; + // End size_of(type) Non-atom Special-cases + } // End size_of(type) Special-cases return 1; } diff --git a/030container.cc b/030container.cc index 626587f8..53efc857 100644 --- a/030container.cc +++ b/030container.cc @@ -148,10 +148,6 @@ void clear_container_metadata() { if (r.metadata.size) return r.metadata.size; :(before "End size_of(type) Special-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(); diff --git a/032array.cc b/032array.cc index 7d189749..4e233bff 100644 --- a/032array.cc +++ b/032array.cc @@ -107,6 +107,19 @@ if (!r.type->atom && r.type->left->atom && r.type->left->value == get(Type_ordin return /*space for length*/1 + array_length(r)*size_of(array_element(r.type)); } +:(before "End size_of(type) Non-atom Special-cases") +if (type->left->value == get(Type_ordinal, "array")) return static_array_length(type); +:(code) +int static_array_length(const type_tree* type) { + if (!type->atom && !type->right->atom && type->right->right->atom // exactly 3 types + && is_integer(type->right->right->name)) { // third 'type' is a number + // get size from type + return to_integer(type->right->right->name); + } + cerr << to_string(type) << '\n'; + assert(false); +} + //: disable the size mismatch check for arrays since the destination array //: need not be initialized :(before "End size_mismatch(x) Special-cases") diff --git a/036refcount.cc b/036refcount.cc index 765efba7..36aea6c0 100644 --- a/036refcount.cc +++ b/036refcount.cc @@ -402,16 +402,6 @@ void append_addresses(int base_offset, const type_tree* type, map<set<tag_condit } } -int static_array_length(const type_tree* type) { - if (!type->atom && !type->right->atom && type->right->right->atom // exactly 3 types - && is_integer(type->right->right->name)) { // third 'type' is a number - // get size from type - return to_integer(type->right->right->name); - } - cerr << to_string(type) << '\n'; - assert(false); -} - //: for the following unit tests we'll do the work of the transform by hand :(before "End Unit Tests") |