diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-29 12:37:09 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-29 12:37:09 -0500 |
| commit | ec75208980f29628604aed45a4f64cfa3c62e0df (patch) | |
| tree | b1cf929cb2735f8ad258c60317410e111ad58462 /compile.c | |
| parent | a7bbbe9584f6e4cd35c9a78e8f83b458ddd8f914 (diff) | |
Fix up some import issues and improve arrays to use saturating refcounts
instead of .copy_on_write
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 14 |
1 files changed, 2 insertions, 12 deletions
@@ -711,18 +711,8 @@ CORD compile(env_t *env, ast_t *ast) set_binding(scope, CORD_to_const_char_star(index), new(binding_t, .type=Type(IntType, .bits=64))); CORD value = compile(env, for_->value); set_binding(scope, CORD_to_const_char_star(value), new(binding_t, .type=item_t)); - CORD loop = CORD_all( - "for (Int64_t ", index, " = 1; ", index, " <= $iter.length; ++", index, ") {\n" - "\t", compile_type(item_t), " ", value, " = *(", compile_type(item_t), "*)($iter.data + (", index, "-1)*$iter.stride);\n" - "\t", compile(scope, for_->body), "\n" - "}\n"); - if (for_->empty) - loop = CORD_all("if ($iter.length == 0)\n", compile(env, for_->empty), "\nelse\n", loop); - return CORD_all( - "{ // For loop:\n" - "array_t $iter = ", compile(env, for_->iter), ";\n", - loop, - "}\n"); + return CORD_all("$ARRAY_FOREACH(", compile(env, for_->iter), ", ", index, ", ", compile_type(item_t), ", ", value, + ", ", compile(scope, for_->body), ", ", for_->empty ? compile(scope, for_->empty) : "{}", ")"); } case TableType: { type_t *key_t = Match(iter_t, TableType)->key_type; |
