diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-06 02:27:01 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-06 02:27:01 -0500 |
| commit | 211af053819ccfabcf97b0e2a372e7e7deb8495d (patch) | |
| tree | a8cfe818c1171cb128895704cd7c2cdd36d51b3b /compile.c | |
| parent | 4968d45f5a54d6a8e4a1ff8b060342d81f619200 (diff) | |
Fix up some array literal stuff with TCC
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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: { |
