Files
c3c/test/test_suite/compile_time/comptime_array_folding.c3t
Christoffer Lerno 5c77c9a754 - Change distinct -> typedef.
- Order of attribute declaration is changed for `alias`.
- Added `LANGUAGE_DEV_VERSION` env constant.
- Rename `anyfault` -> `fault`.
- Changed `fault` -> `faultdef`.
- Added `attrdef` instead of `alias` for attribute aliases.
2025-03-15 20:10:47 +01:00

67 lines
1.6 KiB
Plaintext

// #target: macos-x64
module test;
import std;
attrdef @TaggedAttr(value) = @tag("foo", (ValueHere[*]){ value });
const FOO_STR = "foo";
union TestUnion
{
int a;
}
struct ValueHere
{
int value;
String thing;
}
const ValueHere VALUE_STRUCT = { 32, "lol" };
struct ThisOtherStruct @TaggedAttr(VALUE_STRUCT)
{
int something;
}
enum Example : int (String str) @TaggedAttr(VALUE_STRUCT)
{
FOO = FOO_STR,
}
const int[2][1] BAR = { { 1, 2} };
const int[2] BAZ = BAR[0];
const int BAZ2 = BAZ[1];
const TestUnion[1] ABC = { { .a = 112 } };
const TestUnion BCD = ABC[0];
macro int get_tag_value($Type)
{
$if $Type.has_tagof("foo"):
return $Type.tagof("foo")[0].value;
$else
return -1;
$endif
}
const MY_VALUE_1 = get_tag_value(Example);
const MY_VALUE_2 = get_tag_value(ThisOtherStruct);
fn void main()
{
io::printn(MY_VALUE_2);
io::printn(BAZ);
}
/* #expect: test.ll
@.enum.FOO = internal constant [4 x i8] c"FOO\00", align 1
@test.FOO_STR = local_unnamed_addr constant %"char[]" { ptr @.str.9, i64 3 }, align 8
@test.VALUE_STRUCT = local_unnamed_addr constant %ValueHere { i32 32, %"char[]" { ptr @.str.10, i64 3 } }, align 8
@test.BAR = local_unnamed_addr constant [1 x [2 x i32]] [[2 x i32] [i32 1, i32 2]], align 4
@test.BAZ = local_unnamed_addr constant [2 x i32] [i32 1, i32 2], align 4
@test.BAZ2 = local_unnamed_addr constant i32 2, align 4
@test.ABC = local_unnamed_addr constant [1 x %TestUnion] [%TestUnion { i32 112 }], align 4
@test.BCD = local_unnamed_addr constant %TestUnion { i32 112 }, align 4
@test.MY_VALUE_1 = local_unnamed_addr constant i32 32, align 4
@test.MY_VALUE_2 = local_unnamed_addr constant i32 32, align 4