aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-06 02:27:01 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-03-06 02:27:01 -0500
commit211af053819ccfabcf97b0e2a372e7e7deb8495d (patch)
treea8cfe818c1171cb128895704cd7c2cdd36d51b3b /compile.c
parent4968d45f5a54d6a8e4a1ff8b060342d81f619200 (diff)
Fix up some array literal stuff with TCC
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/compile.c b/compile.c
index 0a878e3b..04397691 100644
--- a/compile.c
+++ b/compile.c
@@ -549,17 +549,19 @@ CORD compile(env_t *env, ast_t *ast)
comparison, " ? $ternary$lhs : $ternary$rhs;\n"
"})");
}
- // Min, Max,
case Array: {
auto array = Match(ast, Array);
if (!array->items)
return "(array_t){.length=0}";
-
- CORD code = "$Array(";
- for (ast_list_t *item = array->items; item; item = item->next) {
- code = CORD_cat(code, compile(env, item->ast));
- if (item->next) code = CORD_cat(code, ", ");
- }
+
+ int64_t n = 0;
+ for (ast_list_t *item = array->items; item; item = item->next)
+ ++n;
+
+ type_t *item_type = Match(get_type(env, ast), ArrayType)->item_type;
+ CORD code = CORD_all("$TypedArrayN(", compile_type(item_type), CORD_asprintf(", %ld", n));
+ for (ast_list_t *item = array->items; item; item = item->next)
+ code = CORD_all(code, ", ", compile(env, item->ast));
return CORD_cat(code, ")");
}
case Table: {