mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
59 lines
1.8 KiB
Plaintext
59 lines
1.8 KiB
Plaintext
// #target: macos-x64
|
|
module test;
|
|
import std::io;
|
|
import std::collections::list;
|
|
|
|
List{int[3]} x;
|
|
|
|
struct Map
|
|
{
|
|
char[20][] data;
|
|
int width;
|
|
}
|
|
fn int Map.len(self) @inline @operator(len) => self.width;
|
|
fn char[] Map.get(self, int i) @inline @operator([]) => self.data[i][:self.width];
|
|
|
|
fn void main ()
|
|
{
|
|
x.tinit();
|
|
int[3] y = { 1, 2, 3 };
|
|
x.push(y);
|
|
x[0][0] = 4;
|
|
char[20][20] z;
|
|
Map foo = { z[:10], 10 };
|
|
(*&&foo[3])[4] = 123;
|
|
}
|
|
|
|
/* #expect: test.ll
|
|
|
|
define void @test.main() #0 {
|
|
entry:
|
|
%y = alloca [3 x i32], align 4
|
|
%coerce = alloca [3 x i32], align 8
|
|
%z = alloca [20 x [20 x i8]], align 16
|
|
%foo = alloca %Map, align 8
|
|
%result = alloca %"char[]", align 8
|
|
%0 = call ptr @"std.collections.list.List$a3$int$.tinit"(ptr @test.x, i64 16)
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %y, ptr align 4 @.__const, i32 12, i1 false)
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 8 %coerce, ptr align 4 %y, i32 12, i1 false)
|
|
%lo = load i64, ptr %coerce, align 8
|
|
%ptradd = getelementptr inbounds i8, ptr %coerce, i64 8
|
|
%hi = load i32, ptr %ptradd, align 8
|
|
call void @"std.collections.list.List$a3$int$.push"(ptr @test.x, i64 %lo, i32 %hi) #3
|
|
%1 = call ptr @"std.collections.list.List$a3$int$.get_ref"(ptr @test.x, i64 0) #3
|
|
store i32 4, ptr %1, align 4
|
|
call void @llvm.memset.p0.i64(ptr align 16 %z, i8 0, i64 400, i1 false)
|
|
%2 = insertvalue %"char[20][]" undef, ptr %z, 0
|
|
%3 = insertvalue %"char[20][]" %2, i64 10, 1
|
|
store %"char[20][]" %3, ptr %foo, align 8
|
|
%ptradd1 = getelementptr inbounds i8, ptr %foo, i64 16
|
|
store i32 10, ptr %ptradd1, align 8
|
|
%4 = call { ptr, i64 } @test.Map.get(ptr byval(%Map) align 8 %foo, i32 3) #3
|
|
store { ptr, i64 } %4, ptr %result, align 8
|
|
%5 = load ptr, ptr %result, align 8
|
|
%ptradd2 = getelementptr inbounds i8, ptr %5, i64 4
|
|
store i8 123, ptr %ptradd2, align 1
|
|
ret void
|
|
}
|
|
|