mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
44 lines
770 B
C
44 lines
770 B
C
// #target: macos-x64
|
|
module example;
|
|
import std::io;
|
|
|
|
macro foo(a, b)
|
|
{
|
|
return a(b);
|
|
}
|
|
|
|
fn int square(int x)
|
|
{
|
|
return x * x;
|
|
}
|
|
|
|
fn int test()
|
|
{
|
|
int a = 2;
|
|
int b = 3;
|
|
return foo(&square, 2) + a + b; // 9
|
|
// return foo(square, 2) + a + b;
|
|
// Error the symbol "square" cannot be used as an argument.
|
|
}
|
|
|
|
/* #expect: example.ll
|
|
|
|
define i32 @example.square(i32 %0) #0 {
|
|
entry:
|
|
%mul = mul i32 %0, %0
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i32 @example.test() #0 {
|
|
entry:
|
|
%a = alloca i32, align 4
|
|
%b = alloca i32, align 4
|
|
store i32 2, ptr %a, align 4
|
|
store i32 3, ptr %b, align 4
|
|
%0 = call i32 @example.square(i32 2)
|
|
%1 = load i32, ptr %a, align 4
|
|
%add = add i32 %0, %1
|
|
%2 = load i32, ptr %b, align 4
|
|
%add1 = add i32 %add, %2
|
|
ret i32 %add1
|
|
}
|