mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
Add lambdas.
This commit is contained in:
committed by
Christoffer Lerno
parent
c9e1e2d763
commit
b508a43f8f
29
test/test_suite14/lambda/simple_lambda.c3t
Normal file
29
test/test_suite14/lambda/simple_lambda.c3t
Normal file
@@ -0,0 +1,29 @@
|
||||
// #target: macos-x64
|
||||
import std::io;
|
||||
import std::math::vector;
|
||||
import std::math;
|
||||
|
||||
define Callback = fn int();
|
||||
|
||||
fn int xy(Callback a) => a();
|
||||
|
||||
fn void main()
|
||||
{
|
||||
const Callback F = fn int() { io::printfn("Hello"); return 23; };
|
||||
int z = xy(F);
|
||||
io::printfn("%d", z);
|
||||
int y = xy(fn () { return 3; });
|
||||
}
|
||||
|
||||
/* #expect: simple_lambda.ll
|
||||
|
||||
define void @simple_lambda_main() #0 {
|
||||
entry:
|
||||
%F = alloca i32 ()*, align 8
|
||||
%z = alloca i32, align 4
|
||||
store i32 ()* @"simple_lambda_main$lambda1", i32 ()** %F, align 8
|
||||
%0 = call i32 @simple_lambda_xy(i32 ()* @"simple_lambda_main$lambda1")
|
||||
%12 = call i32 @simple_lambda_xy(i32 ()* @"simple_lambda_main$lambda2")
|
||||
|
||||
define internal i32 @"simple_lambda_main$lambda2"() #0
|
||||
define internal i32 @"simple_lambda_main$lambda1"() #0
|
||||
Reference in New Issue
Block a user