diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-09 02:53:20 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-09 02:53:20 -0500 |
| commit | b33aa8c11f6a35428a91095d5e0a902174ce7cf5 (patch) | |
| tree | bfcaf629506a8d505205d039b32a9551f8b3736c | |
| parent | 18ef4c5b3ffe1fe85dd521fff98636e6c676c2ad (diff) | |
Back to using ARRAY_FOREACH
| -rw-r--r-- | compile.c | 13 |
1 files changed, 2 insertions, 11 deletions
@@ -892,17 +892,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 empty_handling = for_->empty ? CORD_all("if ($arr.length == 0) ", compile(env, for_->empty), "\nelse ") : CORD_EMPTY; - return CORD_all("{\n" - "array_t $arr = ", compile(env, for_->iter), ";\n", - // "$ARRAY_INCREF($arr);\n", - empty_handling, - "for (int64_t ", index, " = 1; ", index, " <= $arr.length; ", index, "++) {\n", - compile_type(item_t), " ", value, " = *(", compile_type(item_t), "*)($arr.data + (", index, "-1)*$arr.stride);\n", - compile(scope, for_->body), - "}\n" - // "$ARRAY_DECREF($arr);\n" - "}"); + return CORD_all("$ARRAY_FOREACH(", compile(env, for_->iter), ", ", index, ", ", compile_type(item_t), ", ", value, ", ", + compile(scope, for_->body), ", ", for_->empty ? compile(env, for_->empty) : "{}", ")"); } case TableType: { type_t *key_t = Match(iter_t, TableType)->key_type; |
