mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Rearchitecture contexts. Fixing macro resulution, hash arguments and defers.
This commit is contained in:
committed by
Christoffer Lerno
parent
439ae3e468
commit
1d5ff71b21
56
test/test_suite/macros/macro_defer_noscope.c3t
Normal file
56
test/test_suite/macros/macro_defer_noscope.c3t
Normal file
@@ -0,0 +1,56 @@
|
||||
// #target: x64-darwin
|
||||
module foo;
|
||||
extern fn void puts(char *);
|
||||
|
||||
fn void foo1()
|
||||
{
|
||||
puts("foo1");
|
||||
}
|
||||
|
||||
module foo2;
|
||||
import foo;
|
||||
fn void foo2()
|
||||
{
|
||||
foo::puts("foo2");
|
||||
}
|
||||
module bar;
|
||||
import foo2;
|
||||
macro bar1(#test) @noscope
|
||||
{
|
||||
defer foo2::foo2();
|
||||
#test;
|
||||
#test;
|
||||
}
|
||||
|
||||
module baz;
|
||||
import foo;
|
||||
import bar;
|
||||
extern fn void printf(char *, ...);
|
||||
fn void main()
|
||||
{
|
||||
var $foo = 1;
|
||||
@bar::bar1(foo::foo1());
|
||||
@bar::bar1($foo += 1);
|
||||
printf("End: %d\n", $foo);
|
||||
}
|
||||
|
||||
/* #expect: baz.ll
|
||||
|
||||
declare void @foo2.foo2()
|
||||
declare void @foo.foo1()
|
||||
|
||||
define void @baz.main() #0 {
|
||||
entry:
|
||||
call void @foo.foo1()
|
||||
call void @foo.foo1()
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i32 3)
|
||||
call void @foo2.foo2()
|
||||
br label %exit
|
||||
|
||||
exit: ; preds = %entry
|
||||
call void @foo2.foo2()
|
||||
br label %exit1
|
||||
|
||||
exit1: ; preds = %exit
|
||||
ret void
|
||||
}
|
||||
41
test/test_suite/macros/macro_defer_scope.c3t
Normal file
41
test/test_suite/macros/macro_defer_scope.c3t
Normal file
@@ -0,0 +1,41 @@
|
||||
// #target: x64-darwin
|
||||
module foo;
|
||||
macro int cofefe(#a)
|
||||
{
|
||||
int x = 0;
|
||||
defer printf("Was here\n");
|
||||
return #a + #a;
|
||||
}
|
||||
|
||||
extern fn int printf(char *, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
int x = 0;
|
||||
@cofefe(x += 1);
|
||||
printf("%d\n", x);
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
define void @foo.main() #0 {
|
||||
entry:
|
||||
%x = alloca i32, align 4
|
||||
%x1 = alloca i32, align 4
|
||||
store i32 0, i32* %x, align 4
|
||||
store i32 0, i32* %x1, align 4
|
||||
%0 = load i32, i32* %x, align 4
|
||||
%add = add i32 %0, 1
|
||||
store i32 %add, i32* %x, align 4
|
||||
%1 = load i32, i32* %x, align 4
|
||||
%add2 = add i32 %1, 1
|
||||
store i32 %add2, i32* %x, align 4
|
||||
%add3 = add i32 %add, %add2
|
||||
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0))
|
||||
br label %exit
|
||||
|
||||
exit: ; preds = %entry
|
||||
%3 = load i32, i32* %x, align 4
|
||||
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %3)
|
||||
ret void
|
||||
}
|
||||
24
test/test_suite/macros/macro_defer_with_body.c3t
Normal file
24
test/test_suite/macros/macro_defer_with_body.c3t
Normal file
@@ -0,0 +1,24 @@
|
||||
module foo;
|
||||
macro int cofefe(a; @body(x))
|
||||
{
|
||||
@body(a);
|
||||
@body(a);
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern fn int printf(char *, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
int x = 0;
|
||||
@cofefe(1; int y)
|
||||
{
|
||||
defer printf("defer: %d\n", x++);
|
||||
printf("%d\n", x++);
|
||||
};
|
||||
printf("Done!\n");
|
||||
}
|
||||
|
||||
/* expect: foo.ll
|
||||
|
||||
feokfef
|
||||
26
test/test_suite/macros/macro_import_res_private.c3t
Normal file
26
test/test_suite/macros/macro_import_res_private.c3t
Normal file
@@ -0,0 +1,26 @@
|
||||
// #target: x64-darwin
|
||||
module foo;
|
||||
private fn void foo1()
|
||||
{}
|
||||
|
||||
module bar;
|
||||
import private foo;
|
||||
macro bar1()
|
||||
{
|
||||
foo::foo1();
|
||||
}
|
||||
|
||||
module baz;
|
||||
import bar;
|
||||
fn void test()
|
||||
{
|
||||
@bar1();
|
||||
}
|
||||
|
||||
/* #expect: baz.ll
|
||||
|
||||
define void @baz.test() #0 {
|
||||
entry:
|
||||
call void @foo.foo1()
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user