Files
c3c/test/test_suite/lambda/nested_lambda_def.c3t
Christoffer Lerno fc849c1440 0.6.0: init_new/init_temp removed. LinkedList API rewritten. List "pop" and "remove" function now return Optionals. RingBuffer API rewritten. Allocator interface changed. Deprecated Allocator, DString and mem functions removed. "identity" functions are now constants for Matrix and Complex numbers. @default implementations for interfaces removed. any* => any, same for interfaces. Emit local/private globals as "private" in LLVM, following C "static". Updated enum syntax. Add support [rgba] properties in vectors. Improved checks of aliased "void". Subarray -> slice. Fix of llvm codegen enum check. Improved alignment handling. Add --output-dir #1155. Removed List/Object append. GenericList renamed AnyList. Remove unused "unwrap". Fixes to cond. Optimize output in dead branches. Better checking of operator methods. Disallow any from implementing dynamic methods. Check for operator mismatch. Remove unnecessary bitfield. Remove numbering in --list* commands Old style enum declaration for params/type, but now the type is optional. Add note on #1086. Allow making distinct types out of "void", "typeid", "anyfault" and faults. Remove system linker build options. "Try" expressions must be simple expressions. Add optimized build to Mac tests. Register int. assert(false) only allowed in unused branches or in tests. Compile time failed asserts is a compile time error. Remove current_block_is_target. Bug when assigning an optional from an optional. Remove unused emit_zstring. Simplify phi code. Remove unnecessary unreachable blocks and remove unnecessary current_block NULL assignments. Proper handling of '.' and Win32 '//server' paths. Unify expression and macro blocks in the middle end. Add "no discard" to expression blocks with a return value. Detect "unsigned >= 0" as errors. Fix issue with distinct void as a member #1147. Improve callstack debug information #1184. Fix issue with absolute output-dir paths. Lambdas were not type checked thoroughly #1185. Fix compilation warning #1187. Request jump table using @jump for switches. Path normalization - fix possible null terminator out of bounds. Improved error messages on inlined macros.
2024-05-22 18:22:04 +02:00

79 lines
1.5 KiB
C

// #target: macos-x64
module abc;
import bar;
import std::io;
fn int xy(Callback a) => a();
fn void main()
{
const Callback F = bar::get_callback();
int z = xy(F);
z = xy(F);
io::printfn("val: %d", z);
}
module foo;
import bar;
import std::io;
int xz @private = 0;
macro Callback get_callback()
{
return fn int() { return bar::get_callback2()(); };
}
macro Callback get_callback2()
{
return fn int() { io::printfn("Hello"); return ++xz; };
}
module bar;
import foo;
def Callback = fn int();
macro Callback get_callback()
{
return fn int() { return foo::get_callback()(); };
}
macro Callback get_callback2()
{
return fn int() { return foo::get_callback2()(); };
}
/* #expect: abc.ll
@main.F = internal unnamed_addr constant ptr @"bar.get_callback$lambda1", align 8
%0 = call i32 @abc.xy(ptr @"bar.get_callback$lambda1")
%1 = call i32 @abc.xy(ptr @"bar.get_callback$lambda1")
declare i32 @"bar.get_callback$lambda1"()
// #expect: foo.ll
define i32 @"foo.get_callback2$lambda2"() #0 {
%1 = load i32, ptr @foo.xz, align 4
define i32 @"foo.get_callback$lambda1"() #0 {
%0 = call i32 @"bar.get_callback2$lambda2"()
declare i32 @"bar.get_callback2$lambda2"()
// #expect: bar.ll
define i32 @"bar.get_callback2$lambda2"() #0 {
entry:
%0 = call i32 @"foo.get_callback2$lambda2"()
ret i32 %0
}
define i32 @"bar.get_callback$lambda1"() #0 {
entry:
%0 = call i32 @"foo.get_callback$lambda1"()
ret i32 %0
declare i32 @"foo.get_callback2$lambda2"() #0
declare i32 @"foo.get_callback$lambda1"() #0