mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Adding "require" precondition. Corrects inferred arrays and fixes so that it uses [*] everywhere. Distict type will now allow methods to be added to it. Added $alignof and $sizeof.
This commit is contained in:
committed by
Christoffer Lerno
parent
12ffeeaad7
commit
a5ce7c47ba
90
test/test_suite/compile_time_introspection/alignof.c3t
Normal file
90
test/test_suite/compile_time_introspection/alignof.c3t
Normal file
@@ -0,0 +1,90 @@
|
||||
// #target: x64_darwin
|
||||
module foo;
|
||||
|
||||
int[100] zfe;
|
||||
struct Bob
|
||||
{
|
||||
Bob[] x;
|
||||
char[100] y;
|
||||
struct w {
|
||||
int z;
|
||||
}
|
||||
}
|
||||
|
||||
union Ex
|
||||
{
|
||||
char[8] c;
|
||||
int[2] y;
|
||||
double z;
|
||||
}
|
||||
|
||||
union Br
|
||||
{
|
||||
int y;
|
||||
char x;
|
||||
}
|
||||
struct Ar
|
||||
{
|
||||
long z;
|
||||
Br[10] br;
|
||||
}
|
||||
|
||||
union Foob
|
||||
{
|
||||
long a;
|
||||
char[8] c;
|
||||
}
|
||||
Ar izzy;
|
||||
|
||||
|
||||
long x = $alignof(zfe);
|
||||
short y = $alignof("Bob.y");
|
||||
int z = $alignof("Bob.y");
|
||||
int w = $alignof(Bob, y);
|
||||
int v = $alignof(v);
|
||||
int x1 = $alignof("Ex.c");
|
||||
int x2 = $alignof("Ex", y);
|
||||
int x3 = $alignof(char[8]);
|
||||
int x4 = $alignof("Ar.br[1]");
|
||||
int x5 = $alignof("Ar", "br[1]");
|
||||
int x6 = $alignof(Ar, "br[1]");
|
||||
int x7 = $alignof("Ar", br[1]);
|
||||
int x8 = $alignof(Ar, br[2]);
|
||||
int x9 = $alignof("izzy.br[1]");
|
||||
int x10 = $alignof("izzy", "br[1]");
|
||||
int x11 = $alignof("izzy", br[1]);
|
||||
int z0 = $alignof("Foob.c");
|
||||
int z00 = $alignof("Foob.c[0]");
|
||||
int z01 = $alignof("Foob.c[1]");
|
||||
int z02 = $alignof("Foob.c[2]");
|
||||
int z03 = $alignof("Foob.c[3]");
|
||||
int z04 = $alignof("Foob.c[4]");
|
||||
int z05 = $alignof("Foob.c[5]");
|
||||
|
||||
|
||||
|
||||
// #expect: foo.ll
|
||||
|
||||
@foo.x = global i64 16, align 8
|
||||
@foo.y = global i16 8, align 2
|
||||
@foo.z = global i32 8, align 4
|
||||
@foo.w = global i32 8, align 4
|
||||
@foo.v = global i32 4, align 4
|
||||
@foo.x1 = global i32 8, align 4
|
||||
@foo.x2 = global i32 8, align 4
|
||||
@foo.x3 = global i32 1, align 4
|
||||
@foo.x4 = global i32 4, align 4
|
||||
@foo.x5 = global i32 4, align 4
|
||||
@foo.x6 = global i32 4, align 4
|
||||
@foo.x7 = global i32 4, align 4
|
||||
@foo.x8 = global i32 8, align 4
|
||||
@foo.x9 = global i32 4, align 4
|
||||
@foo.x10 = global i32 4, align 4
|
||||
@foo.x11 = global i32 4, align 4
|
||||
@foo.z0 = global i32 8, align 4
|
||||
@foo.z00 = global i32 8, align 4
|
||||
@foo.z01 = global i32 1, align 4
|
||||
@foo.z02 = global i32 2, align 4
|
||||
@foo.z03 = global i32 1, align 4
|
||||
@foo.z04 = global i32 4, align 4
|
||||
@foo.z05 = global i32 1, align 4
|
||||
66
test/test_suite/compile_time_introspection/sizeof.c3t
Normal file
66
test/test_suite/compile_time_introspection/sizeof.c3t
Normal file
@@ -0,0 +1,66 @@
|
||||
module foo;
|
||||
import bar;
|
||||
import bar::abc;
|
||||
|
||||
long x = $sizeof(Baz);
|
||||
short y = $sizeof("Baz");
|
||||
int z = $sizeof(bar::Baz);
|
||||
int w = $sizeof("bar::Baz");
|
||||
int v = $sizeof("bar::abc::Foo");
|
||||
int x1 = $sizeof(x);
|
||||
int y1 = $sizeof("y");
|
||||
int a = $sizeof("Baz.y");
|
||||
int b = $sizeof("Deep.a.b");
|
||||
int c = $sizeof("Deep.a.b.c");
|
||||
int d = $sizeof("Deep[][100]");
|
||||
int e = $sizeof("Deep[][100]**[100][]*");
|
||||
int a2 = $sizeof("Baz", "y");
|
||||
int a3 = $sizeof("Baz", y);
|
||||
int a4 = $sizeof(Baz, "y");
|
||||
int a5 = $sizeof(Baz, y);
|
||||
|
||||
module bar;
|
||||
|
||||
struct Deep
|
||||
{
|
||||
int x;
|
||||
struct a
|
||||
{
|
||||
struct b
|
||||
{
|
||||
char[5] c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Baz
|
||||
{
|
||||
int x;
|
||||
char[60] y;
|
||||
}
|
||||
|
||||
module bar::abc;
|
||||
|
||||
struct Foo
|
||||
{
|
||||
char x;
|
||||
}
|
||||
|
||||
// #expect: foo.ll
|
||||
|
||||
@foo.x = global i64 64, align 8
|
||||
@foo.y = global i16 64, align 2
|
||||
@foo.z = global i32 64, align 4
|
||||
@foo.w = global i32 64, align 4
|
||||
@foo.v = global i32 1, align 4
|
||||
@foo.x1 = global i32 8, align 4
|
||||
@foo.y1 = global i32 2, align 4
|
||||
@foo.a = global i32 60, align 4
|
||||
@foo.b = global i32 5, align 4
|
||||
@foo.c = global i32 5, align 4
|
||||
@foo.d = global i32 1600, align 4
|
||||
@foo.e = global i32 8, align 4
|
||||
@foo.a2 = global i32 60, align 4
|
||||
@foo.a3 = global i32 60, align 4
|
||||
@foo.a4 = global i32 60, align 4
|
||||
@foo.a5 = global i32 60, align 4
|
||||
84
test/test_suite/compile_time_introspection/sizeof_errors.c3
Normal file
84
test/test_suite/compile_time_introspection/sizeof_errors.c3
Normal file
@@ -0,0 +1,84 @@
|
||||
module foo;
|
||||
import bar;
|
||||
import bar::abc;
|
||||
|
||||
func void a()
|
||||
{
|
||||
int x = $sizeof(Bazy); // #error: 'Bazy' could not be found, did you spell it right
|
||||
}
|
||||
|
||||
func void b()
|
||||
{
|
||||
int x = $sizeof("Bazz"); // #error: 'Bazz' could not be found, did you misspell it
|
||||
}
|
||||
|
||||
func void c()
|
||||
{
|
||||
int x = $sizeof("Baz#"); // #error: A '.' was expected after 'Baz'
|
||||
}
|
||||
|
||||
func void c2()
|
||||
{
|
||||
int x = $sizeof("#Baz"); // #error: '#Baz' is not a known identifier, did you misspell it?
|
||||
}
|
||||
|
||||
func void d()
|
||||
{
|
||||
int x = $sizeof("Baz."); // #error: The path to an existing member was expected after 'Baz', did you make a mistake?
|
||||
}
|
||||
|
||||
func void e()
|
||||
{
|
||||
int x = $sizeof(bar::Baze); // #error: 'Baze' could not be found, did you spell it right
|
||||
}
|
||||
|
||||
func void f()
|
||||
{
|
||||
int x = $sizeof("bar::Bazy"); // #error: 'Bazy' could not be found, did you spell it right
|
||||
}
|
||||
|
||||
func void g()
|
||||
{
|
||||
int x = $sizeof("bar::"); // #error: 'bar::' is not a known identifier, did you misspell it?
|
||||
}
|
||||
|
||||
func void k()
|
||||
{
|
||||
int v = $sizeof("int.x"); // #error: 'int' has no members
|
||||
}
|
||||
|
||||
func void l()
|
||||
{
|
||||
int v = $sizeof("int[].len"); // #error: 'int[]' has no members
|
||||
}
|
||||
|
||||
func void m()
|
||||
{
|
||||
int v = $sizeof("int[4].len"); // #error: 'int[4]' has no members
|
||||
}
|
||||
|
||||
func void n()
|
||||
{
|
||||
int v = $sizeof("Baz.x1"); // #error: The path to an existing member was expected after
|
||||
}
|
||||
|
||||
func void o()
|
||||
{
|
||||
int v = $sizeof("Baz.x", x); // #error: You cannot combine a string with a member path with a separate path here
|
||||
}
|
||||
|
||||
module bar;
|
||||
|
||||
struct Baz
|
||||
{
|
||||
int x;
|
||||
char[60] y;
|
||||
}
|
||||
|
||||
module bar::abc;
|
||||
|
||||
struct Foo
|
||||
{
|
||||
char x;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ define StructArr = distinct Struct2[3];
|
||||
func void test(int x)
|
||||
{
|
||||
StructArr z = { { .x = 1 }, { .y = x }, { 1, 2 }};
|
||||
usize xr = z.sizeof;
|
||||
usize len = z.len;
|
||||
Foo zz = z[2].x;
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ func void test1()
|
||||
|
||||
int b = (Number)(a);
|
||||
|
||||
int c = (Foo)(a); // #error: type 'Foo' could not be found
|
||||
int c = (Foo)(a); // #error: 'Foo' could not be found
|
||||
}
|
||||
|
||||
func void test2()
|
||||
{
|
||||
int d = (Number)(bar);; // #error: identifier 'bar' could not be found
|
||||
int d = (Number)(bar);; // #error: 'bar' could not be found
|
||||
}
|
||||
|
||||
func void test3()
|
||||
{
|
||||
int e = (Bar)( // #error: type 'Bar' could not be found
|
||||
faa); // #error: identifier 'faa' could not be found
|
||||
int e = (Bar)( // #error: 'Bar' could not be found
|
||||
faa); // #error: 'faa' could not be found
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
func void test1()
|
||||
{
|
||||
int a = (i ? 1 : 1); // #error: identifier 'i' could not be found, did you spell it right
|
||||
int a = (i ? 1 : 1); // #error: 'i' could not be found, did you spell it right
|
||||
}
|
||||
|
||||
func void test2()
|
||||
{
|
||||
int a = (1 ? i : 2); // #error: identifier 'i' could not be found, did you spell it right
|
||||
int a = (1 ? i : 2); // #error: 'i' could not be found, did you spell it right
|
||||
}
|
||||
|
||||
func void test3()
|
||||
{
|
||||
int a = (1 ? 2 : i); // #error: identifier 'i' could not be found, did you spell it right
|
||||
int a = (1 ? 2 : i); // #error: 'i' could not be found, did you spell it right
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func void test2()
|
||||
func void test3()
|
||||
{
|
||||
An2 a;
|
||||
a.@helloWorld.b; // #error: No such member or function could be found.
|
||||
a.@helloWorld.b; // #error: There is no member or method 'b' on 'void'
|
||||
}
|
||||
|
||||
func void test4()
|
||||
|
||||
@@ -19,6 +19,6 @@ func void main()
|
||||
@cofefe(x += 1);
|
||||
@cofefe(xx());
|
||||
@cofefe($x += 1); // #error: Cannot modify '$x' inside of a runtime scope.
|
||||
@cofefe(y += 1); // #error: identifier 'y' could not be found
|
||||
@cofefe(y += 1); // #error: 'y' could not be found
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func void test2()
|
||||
|
||||
macro foo2(x)
|
||||
{
|
||||
@body(x); // #error: The identifier 'body' could not be found, did you spell it right?
|
||||
@body(x); // #error: 'body' could not be found, did you spell it right?
|
||||
}
|
||||
|
||||
func void test4()
|
||||
|
||||
@@ -43,7 +43,7 @@ func void test_scope(int i)
|
||||
int a = 0;
|
||||
break;
|
||||
case 2:
|
||||
test_scope(a + 1); // #error: identifier 'a' could not be found, did you spell it right
|
||||
test_scope(a + 1); // #error: 'a' could not be found, did you spell it right
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
enum EnumTestErrorType3 : int
|
||||
{
|
||||
A = FOO // #error: constant 'FOO' could not be found, did you spell it
|
||||
A = FOO // #error: 'FOO' could not be found, did you spell it
|
||||
}
|
||||
|
||||
func int foo()
|
||||
|
||||
@@ -23,9 +23,9 @@ entry:
|
||||
%b = alloca %UnionB, align 8
|
||||
%0 = bitcast %UnionB* %b to i32*
|
||||
%1 = call i32 @bar()
|
||||
store i32 %1, i32* %0, align 4
|
||||
store i32 %1, i32* %0, align 8
|
||||
%2 = bitcast %UnionB* %b to %b*
|
||||
%3 = bitcast %b* %2 to i8*
|
||||
call void @llvm.memset.p0i8.i64(i8* align 4 %3, i8 0, i64 4, i1 false)
|
||||
call void @llvm.memset.p0i8.i64(i8* align 8 %3, i8 0, i64 4, i1 false)
|
||||
ret void
|
||||
|
||||
|
||||
Reference in New Issue
Block a user