about summary refs log tree commit diff stats
path: root/032array.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-11-08 10:20:49 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-11-08 10:20:49 -0800
commitf4647409b5fa658e463424c0a8249a4d72405d59 (patch)
treeff024555e70a2cb8649dbf7f494129d670997676 /032array.cc
parent2789e86118e1f4da63e5b8883ffdb4ef31c98887 (diff)
downloadmu-f4647409b5fa658e463424c0a8249a4d72405d59.tar.gz
3652
size_of(type_tree*) is a mess; clean it up with an eye to the final
tangled version.
Diffstat (limited to '032array.cc')
-rw-r--r--032array.cc13
1 files changed, 13 insertions, 0 deletions
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")