mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Single code path for kind/inner/len/sizeof on type and typeid. Fix of #493. Bump to 0.2.24. Remove ´func´ deprecated keyword. Unify builtin access. Enum and fault name reflection.
141 lines
3.1 KiB
C
141 lines
3.1 KiB
C
// #target: macos-x64
|
|
module foo;
|
|
import std::io;
|
|
import libc;
|
|
fault Foo
|
|
{
|
|
X,
|
|
Y,
|
|
Z,
|
|
W,
|
|
W1
|
|
|
|
|
|
}
|
|
|
|
fault Foob
|
|
{
|
|
X1,
|
|
Y2
|
|
}
|
|
|
|
define Bar = distinct int;
|
|
|
|
enum MyEnum
|
|
{
|
|
A,
|
|
B
|
|
}
|
|
|
|
fn void Foo.hello(Foo *f)
|
|
{
|
|
io::println("Hello from Foo");
|
|
}
|
|
|
|
fn void Bar.hello(Bar *b)
|
|
{
|
|
io::println("Hello from Bar");
|
|
}
|
|
|
|
fn void MyEnum.hello(MyEnum *myenum)
|
|
{
|
|
io::println("Hello from MyEnum");
|
|
}
|
|
fn void main()
|
|
{
|
|
Foo f = Foo.X;
|
|
Foo ef = Foo.Y;
|
|
anyerr x = f;
|
|
ulong z = (ulong)(x);
|
|
libc::printf("1: %p\n", z);
|
|
x = ef;
|
|
z = (ulong)(x);
|
|
libc::printf("2: %p\n", z);
|
|
x = Foo.W;
|
|
z = (ulong)(x);
|
|
libc::printf("21: %p\n", z);
|
|
x = Foo.W1;
|
|
z = (ulong)(x);
|
|
libc::printf("22: %p\n", z);
|
|
x = Foob.X1;
|
|
z = (ulong)(x);
|
|
libc::printf("3: %p\n", z);
|
|
x = Foob.Y2;
|
|
z = (ulong)(x);
|
|
libc::printf("4: %p\n", z);
|
|
Bar b;
|
|
MyEnum a = MyEnum.A;
|
|
f.hello();
|
|
b.hello();
|
|
a.hello();
|
|
}
|
|
|
|
/* #expect: foo.ll
|
|
|
|
define void @foo_Foo_hello(ptr %0) #0 {
|
|
entry:
|
|
%1 = call i32 @std_io_println(ptr @.str.12) #1
|
|
ret void
|
|
}
|
|
|
|
define void @foo_Bar_hello(ptr %0) #0 {
|
|
entry:
|
|
%1 = call i32 @std_io_println(ptr @.str.13) #1
|
|
ret void
|
|
}
|
|
|
|
define void @foo_MyEnum_hello(ptr %0) #0 {
|
|
entry:
|
|
%1 = call i32 @std_io_println(ptr @.str.14) #1
|
|
ret void
|
|
}
|
|
|
|
define void @foo_main() #0 {
|
|
entry:
|
|
%f = alloca i64, align 8
|
|
%ef = alloca i64, align 8
|
|
%x = alloca i64, align 8
|
|
%z = alloca i64, align 8
|
|
%b = alloca i32, align 4
|
|
%a = alloca i32, align 4
|
|
store i64 ptrtoint (ptr @"foo_Foo$X" to i64), ptr %f, align 8
|
|
store i64 ptrtoint (ptr @"foo_Foo$Y" to i64), ptr %ef, align 8
|
|
%0 = load i64, ptr %f, align 8
|
|
store i64 %0, ptr %x, align 8
|
|
%1 = load i64, ptr %x, align 8
|
|
store i64 %1, ptr %z, align 8
|
|
%2 = load i64, ptr %z, align 8
|
|
%3 = call i32 (ptr, ...) @printf(ptr @.str, i64 %2)
|
|
%4 = load i64, ptr %ef, align 8
|
|
store i64 %4, ptr %x, align 8
|
|
%5 = load i64, ptr %x, align 8
|
|
store i64 %5, ptr %z, align 8
|
|
%6 = load i64, ptr %z, align 8
|
|
%7 = call i32 (ptr, ...) @printf(ptr @.str.7, i64 %6)
|
|
store i64 ptrtoint (ptr @"foo_Foo$W" to i64), ptr %x, align 8
|
|
%8 = load i64, ptr %x, align 8
|
|
store i64 %8, ptr %z, align 8
|
|
%9 = load i64, ptr %z, align 8
|
|
%10 = call i32 (ptr, ...) @printf(ptr @.str.8, i64 %9)
|
|
store i64 ptrtoint (ptr @"foo_Foo$W1" to i64), ptr %x, align 8
|
|
%11 = load i64, ptr %x, align 8
|
|
store i64 %11, ptr %z, align 8
|
|
%12 = load i64, ptr %z, align 8
|
|
%13 = call i32 (ptr, ...) @printf(ptr @.str.9, i64 %12)
|
|
store i64 ptrtoint (ptr @"foo_Foob$X1" to i64), ptr %x, align 8
|
|
%14 = load i64, ptr %x, align 8
|
|
store i64 %14, ptr %z, align 8
|
|
%15 = load i64, ptr %z, align 8
|
|
%16 = call i32 (ptr, ...) @printf(ptr @.str.10, i64 %15)
|
|
store i64 ptrtoint (ptr @"foo_Foob$Y2" to i64), ptr %x, align 8
|
|
%17 = load i64, ptr %x, align 8
|
|
store i64 %17, ptr %z, align 8
|
|
%18 = load i64, ptr %z, align 8
|
|
%19 = call i32 (ptr, ...) @printf(ptr @.str.11, i64 %18)
|
|
store i32 0, ptr %b, align 4
|
|
store i32 0, ptr %a, align 4
|
|
call void @foo_Foo_hello(ptr %f)
|
|
call void @foo_Bar_hello(ptr %b)
|
|
call void @foo_MyEnum_hello(ptr %a)
|
|
ret void
|
|
}
|