From 211af053819ccfabcf97b0e2a372e7e7deb8495d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 6 Mar 2024 02:27:01 -0500 Subject: Fix up some array literal stuff with TCC --- compile.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'compile.c') 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: { -- cgit v1.2.3