Support #unroll(N) for for FCD arrays

This commit is contained in:
gingerBill
2026-03-16 12:28:18 +00:00
parent 38d5b234cb
commit 93852df29e
2 changed files with 28 additions and 2 deletions

View File

@@ -1018,15 +1018,28 @@ gb_internal void check_unroll_range_stmt(CheckerContext *ctx, Ast *node, u32 mod
inline_for_depth = exact_value_i64(unroll_count);
}
break;
case Type_FixedCapacityDynamicArray:
if (unroll_count > 0) {
val0 = t->FixedCapacityDynamicArray.elem;
val1 = t_int;
inline_for_depth = exact_value_i64(unroll_count);
}
break;
}
}
if (val0 == nullptr) {
ERROR_BLOCK();
gbString s = expr_to_string(operand.expr);
gbString t = type_to_string(operand.type);
defer (gb_string_free(s));
defer (gb_string_free(t));
error(operand.expr, "Cannot iterate over '%s' of type '%s' in an '#unroll for' statement", s, t);
gb_string_free(t);
gb_string_free(s);
if (is_type_slice(operand.type) || is_type_dynamic_array(operand.type) || is_type_fixed_capacity_dynamic_array(operand.type)) {
error_line("\tSuggestion: An unroll count `#unroll(N)` must be specified with an array of a runtime-known length\n");
}
} else if (operand.mode != Addressing_Constant && (
unroll_count <= 0 &&
compare_exact_values(Token_CmpEq, inline_for_depth, exact_value_i64(0)))) {

View File

@@ -1706,6 +1706,19 @@ gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *
break;
}
case Type_FixedCapacityDynamicArray: {
lbValue array = lb_build_expr(p, expr);
if (!is_type_pointer(array.type)) {
array = lb_address_from_load_or_generate_local(p, array);
}
GB_ASSERT(is_type_pointer(array.type));
count_ptr = lb_emit_struct_ep(p, array, 1);
data_ptr = lb_emit_conv(p, array, alloc_type_pointer(t->FixedCapacityDynamicArray.elem));
break;
}
case Type_Array: {
lbValue array = lb_build_expr(p, expr);
count_ptr = lb_add_local_generated(p, t_int, false).addr;