aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-09 02:53:20 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-03-09 02:53:20 -0500
commitb33aa8c11f6a35428a91095d5e0a902174ce7cf5 (patch)
treebfcaf629506a8d505205d039b32a9551f8b3736c
parent18ef4c5b3ffe1fe85dd521fff98636e6c676c2ad (diff)
Back to using ARRAY_FOREACH
-rw-r--r--compile.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/compile.c b/compile.c
index 61a345db..29feffac 100644
--- a/compile.c
+++ b/compile.c
@@ -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;