Semi-implemented foreach for vectors (#423)

Implement foreach for vectors
This commit is contained in:
Dmitry Atamanov
2022-04-09 23:09:35 +05:00
committed by GitHub
parent b99db4be24
commit 151cbfd706
2 changed files with 19 additions and 0 deletions

View File

@@ -2200,6 +2200,7 @@ void llvm_emit_len_for_expr(GenContext *c, BEValue *be_value, BEValue *expr_to_l
}
break;
case TYPE_ARRAY:
case TYPE_VECTOR:
llvm_value_set(be_value, llvm_const_int(c, type_usize, expr_to_len->type->array.len), type_usize);
break;
default:

View File

@@ -6,6 +6,7 @@ extern fn void printf(char*, ...);
fn void main()
{
float[3] foo = { 2, 4.5, 8 };
float[<3>] foo2 = { 2, 4.5, 8 };
foreach (a : foo)
{
printf("Value: %f\n", a);
@@ -31,6 +32,23 @@ fn void main()
{
printf("Value3: %f\n", a);
}
foreach (a : foo2)
{
printf("Value: %f\n", a);
}
foreach (i, a : foo2)
{
printf("Value[%d]: %f\n", i, a);
}
foreach (char i, double a : foo2)
{
printf("Value2[%d]: %f\n", i, a);
}
foreach (double a : foo2)
{
printf("Value3: %f\n", a);
}
}
/* #expect: test.ll