Complete transition to fn. Introduce global/threadlocal

This commit is contained in:
Christoffer Lerno
2021-11-16 17:19:12 +01:00
committed by Christoffer Lerno
parent e2621617f1
commit b52b42d4da
331 changed files with 1279 additions and 1261 deletions

View File

@@ -7,9 +7,9 @@ struct Test
Test foo = {};
extern func void blorg(Test t);
extern fn void blorg(Test t);
func Test creator()
fn Test creator()
{
blorg(Test{});
return Test{};

View File

@@ -8,9 +8,9 @@ struct Test
Test foo = {};
extern func void blorg(Test t);
extern fn void blorg(Test t);
func Test creator()
fn Test creator()
{
blorg(Test{});
return Test{};

View File

@@ -8,9 +8,9 @@ struct Test
Test foo = {};
extern func void blorg(Test t);
extern fn void blorg(Test t);
func Test creator()
fn Test creator()
{
blorg(Test{});
return Test{};

View File

@@ -8,9 +8,9 @@ struct Large
void*[8] pointers;
}
extern func void pass_large(Large large);
extern fn void pass_large(Large large);
func void example()
fn void example()
{
Large l = {};
pass_large(l);

View File

@@ -8,10 +8,10 @@ struct Abc {
long e;
}
extern func Abc foo1();
extern func Abc foo2();
extern fn Abc foo1();
extern fn Abc foo2();
func void bar() {
fn void bar() {
Abc dummy1 = foo1();
Abc dummy2 = foo2();
}

View File

@@ -7,9 +7,9 @@ union Foo
long a;
char[12] b;
}
extern func void hello2(Foo f);
extern fn void hello2(Foo f);
func void hello(Foo f)
fn void hello(Foo f)
{
hello2(f);
}

View File

@@ -5,12 +5,12 @@ struct Vector2 {
float x;
float y;
}
extern func Vector2 vector2_zero() { return Vector2 {}; }
extern func Vector2 vector2_one() { return Vector2 {}; }
extern func Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern func Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
extern func Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern func Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
extern fn Vector2 vector2_zero() { return Vector2 {}; }
extern fn Vector2 vector2_one() { return Vector2 {}; }
extern fn Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern fn Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
extern fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern fn Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
// #expect: abi.ll
%Vector2 = type { float, float }

View File

@@ -5,12 +5,12 @@ struct Vector2 {
float x;
float y;
}
extern func Vector2 vector2_zero() { return Vector2 {}; }
extern func Vector2 vector2_one() { return Vector2 {}; }
extern func Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern func Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
extern func Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern func Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
extern fn Vector2 vector2_zero() { return Vector2 {}; }
extern fn Vector2 vector2_one() { return Vector2 {}; }
extern fn Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern fn Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
extern fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
extern fn Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
// #expect: abi.ll

View File

@@ -1,7 +1,7 @@
module array_casts;
func void test()
fn void test()
{
int[3] x;
int *y = &x;

View File

@@ -1,11 +1,11 @@
func void test()
fn void test()
{
int[3] x;
double *y = &x; // #error: 'int[3]*' to 'double*
}
func void test2()
fn void test2()
{
int[3] x;
double[] z = &x; // #error: 'int[3]*' into 'double[]'

View File

@@ -1,7 +1,7 @@
// #target: x64-darwin
module array_literal;
func double test(uint x)
fn double test(uint x)
{
double[30] student_t = { 0.0 , 12.706 , 4.303 , 3.182 , 2.776 , 2.571 ,
2.447 , 2.365 , 2.306 , 2.262 , 2.228 ,

View File

@@ -6,7 +6,7 @@ struct Foo
int x, y;
}
private Foo[10] array;
private global Foo[10] array;
// #expect: test.ll

View File

@@ -8,7 +8,7 @@ struct Connection
long length;
}
private Connection[3] link
private global Connection[3] link
= { {1, "link1", 10},
{2, "link2", 20},
{3, "link3", 30} };

View File

@@ -8,7 +8,7 @@ int[B] c2; // #error: Expected an integer size.
int non_constant = 10;
int[non_constant] b; // #error: Expected a constant value as
func int foo()
fn int foo()
{
return 10;
}

View File

@@ -1,4 +1,4 @@
func void test()
fn void test()
{
int[3] x = { 1, 2, 3 };
int[] z = &x;

View File

@@ -1,11 +1,11 @@
// #target: x64-windows
func int foo()
fn int foo()
{
return 1;
}
func void test()
fn void test()
{
int x = foo();
int y = foo();

View File

@@ -1,19 +1,19 @@
int x = 3;
func void test()
fn void test()
{
$assert(x == 3); // #error: Compile time evaluation requires a compile time constant value.
}
func void test2()
fn void test2()
{
int i = 0;
$assert(1);
$assert(i == 0); // #error: Compile time evaluation requires a compile time constant value.
}
func int foo();
func void test3()
fn int foo();
fn void test3()
{
int i = 0;
$assert(foo() == 0); // #error: Compile time evaluation requires a compile time constant value.

View File

@@ -1,7 +1,7 @@
const int FOO = 2;
func void test()
fn void test()
{
$assert(FOO == 2, "Bad");
$assert(FOO == 0, "Good"); // #error: Compile time assert - Good

View File

@@ -1,10 +1,10 @@
func int foo()
fn int foo()
{
return 1;
}
func void test()
fn void test()
{
int x = foo();
if (x > 0) return;

View File

@@ -1,6 +1,6 @@
module test;
func int foo()
fn int foo()
{
int x = 0;
int y;

View File

@@ -1,4 +1,4 @@
func void test()
fn void test()
{
for (int a @align(16) @align(16) = 0 ; a < 10; a++) // #error: Repeat of attribute 'align'
{

View File

@@ -1,11 +1,11 @@
struct Foo { int a; }
func void test4()
fn void test4()
{
int x = (int)(32);
}
func void test5()
fn void test5()
{
Foo x = (Foo)(Foo{32});
}

View File

@@ -1,11 +1,11 @@
struct Foo { int a; }
func void test2()
fn void test2()
{
int x = int{ 32 }; // #error: 'int' cannot use compound literal initialization, did you intend to use a cast
}
func void test3()
fn void test3()
{
int x = int(32); // #error: A type cannot be followed by (), if you intended a cast, use (type)(expression)
}

View File

@@ -1,7 +1,7 @@
struct Foo { int a; }
func void test1()
fn void test1()
{
Foo({ 32 });
(Foo)({ 32 }); // #error: Unexpected start of a block '{' here. If you intended a compound literal

View File

@@ -22,7 +22,7 @@ struct BazTwo
int e;
}
func void test()
fn void test()
{
Foo x;
Bar y = (Bar)(x);

View File

@@ -22,12 +22,12 @@ struct BazTwo
int e;
}
func void test1()
fn void test1()
{
Foo x;
Bar z = (Baz)(x); // #error: cast 'Foo' to 'Baz'
}
func void test2()
fn void test2()
{
Baz x;
BazTwo z = (BazTwo)(x); // #error: cast 'Baz' to 'BazTwo'

View File

@@ -3,7 +3,7 @@ errtype MyErr
FOO
}
func void test()
fn void test()
{
int! x;
int! d = ($typeof(MyErr.FOO!))(x); // #error: Casting to a failable type is not allowed

View File

@@ -7,7 +7,7 @@ module comments;
Multiline span style
*/
func void test()
fn void test()
{
return;
}

View File

@@ -2,12 +2,12 @@
module test;
int*[] blurp = { &ptr, &ptr, (&ptr + 1), &ptr - 1, (int*)((iptr)(&ptr) - 4) };
int* c = (int*)((iptr)(&ptr) - 4);
int* c2 = (int*)((iptr)(&ptr) + 4);
int* c3 = (int*)(4 + (iptr)(&ptr));
iptr ff = (iptr)(&ptr);
int ptr = 0;
global int*[] blurp = { &ptr, &ptr, (&ptr + 1), &ptr - 1, (int*)((iptr)(&ptr) - 4) };
global int* c = (int*)((iptr)(&ptr) - 4);
global int* c2 = (int*)((iptr)(&ptr) + 4);
global int* c3 = (int*)(4 + (iptr)(&ptr));
global iptr ff = (iptr)(&ptr);
global int ptr = 0;
// #expect: test.ll

View File

@@ -4,7 +4,7 @@ $else:
$elif (0):
$elif (0):
$else:
int x = 1;
global int x = 1;
$endif;
$endif;
@@ -18,7 +18,7 @@ $endif;
$if (1):
$assert(true);
int d = 5;
global int d = 5;
$elif (0):
$assert(false);
$else:
@@ -29,7 +29,7 @@ $if (0):
$assert(true);
$elif (1):
$assert(true);
int c = 5;
global int c = 5;
$else:
$assert(false);
$endif;
@@ -38,7 +38,7 @@ $if (0):
$assert(true);
$elif (1):
$assert(true);
int b = 4;
global int b = 4;
$elif (0):
$assert(false);
$else:
@@ -51,7 +51,7 @@ $elif (0):
$assert(false);
$elif (1):
$assert(true);
int a = 3;
global int a = 3;
$else:
$assert(false);
$endif;

View File

@@ -1,7 +1,7 @@
// #target: x64-darwin
module reassign;
func void test()
fn void test()
{
var $Foo = double;
$Foo = int;

View File

@@ -4,13 +4,13 @@ macro foo($Foo)
return a;
}
func void test1()
fn void test1()
{
var $Bar;
@foo($Bar); // #error: '$Bar' is not defined yet
}
func void test2()
fn void test2()
{
var $Bar;
$Bar z; // #error: '$Bar' is not defined yet

View File

@@ -1,15 +1,15 @@
// #target: x64-darwin
int foo = 2.2 ? 1 : 2;
double bar = false ? 1.0 : 2;
bool baz = 1 ? false : true;
global int foo = 2.2 ? 1 : 2;
global double bar = false ? 1.0 : 2;
global bool baz = 1 ? false : true;
func void test()
fn void test()
{
int x = 1 ? 0 : test2();
}
func int test2() { return 3; }
fn int test2() { return 3; }
// #expect: ternary_folding.ll

View File

@@ -1,4 +1,4 @@
extern func void printf(char *, ...);
extern fn void printf(char *, ...);
macro bitcast($Target, value)
{
@@ -7,7 +7,7 @@ macro bitcast($Target, value)
return *result;
}
func void main()
fn void main()
{
float f = 100;
int i = @bitcast(int, f);

View File

@@ -1,12 +1,12 @@
module foo;
func void a()
fn void a()
{
$typeof(9146744073709551615i64) ef;
int fffx = ef; // #error: 'long' to 'int'
}
func void b()
fn void b()
{
$typeof(9223372036854775809u64) ef;
int fffx = ef; // #error: 'ulong' to 'int'

View File

@@ -1,7 +1,7 @@
// #target: x64-darwin
module foo;
int[100] zfe;
global int[100] zfe;
struct Bob
{
Bob[] x;
@@ -37,29 +37,29 @@ union Foob
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]");
global long x = $alignof(zfe);
global short y = $alignof("Bob.y");
global int z = $alignof("Bob.y");
global int w = $alignof(Bob.y);
global int v = $alignof(v);
global int x1 = $alignof("Ex.c");
global int x2 = $alignof(Ex.y);
global int x3 = $alignof(char[8]);
global int x4 = $alignof("Ar.br[1]");
global int x5 = $alignof(Ar.br[1]);
global int x6 = $alignof(Ar.br[1]);
global int x7 = $alignof(Ar.br[1]);
global int x8 = $alignof(Ar.br[2]);
global int x9 = $alignof("izzy.br[1]");
global int x10 = $alignof("izzy.br[1]");
global int x11 = $alignof(izzy.br[1]);
global int z0 = $alignof("Foob.c");
global int z00 = $alignof("Foob.c[0]");
global int z01 = $alignof("Foob.c[1]");
global int z02 = $alignof("Foob.c[2]");
global int z03 = $alignof("Foob.c[3]");
global int z04 = $alignof("Foob.c[4]");
global int z05 = $alignof("Foob.c[5]");

View File

@@ -2,7 +2,7 @@
module mymodule;
extern func void printf(char *, ...);
extern fn void printf(char *, ...);
struct Foo
{
@@ -13,7 +13,7 @@ struct Foo
int j;
}
}
func void main()
fn void main()
{
int x = 0;
var $counter = 0;

View File

@@ -1,4 +1,4 @@
func void test1()
fn void test1()
{
bool x = $defined(1); // #error: constant string containing an identifier or type was expected
}
@@ -6,13 +6,13 @@ func void test1()
struct Foo
{}
func void test2()
fn void test2()
{
$assert($defined(int[1]));
bool x = $defined(int[y]); // #error: 'y' could not be found, did you spell it right?
}
func void test3()
fn void test3()
{
$assert($defined(Foo[1]));
$assert($defined(Foo*));

View File

@@ -1,13 +1,13 @@
// #target: x64-darwin
module mymodule;
extern func void printf(char *, ...);
extern fn void printf(char *, ...);
struct Foo { }
int b;
func void main()
fn void main()
{
printf("%s\n", $qnameof(Foo));
printf("%s\n", $qnameof("Foo"));

View File

@@ -1,15 +1,15 @@
func void main()
fn void main()
{
int a;
$extnameof(a); // #error: 'a' does not have an external name.
}
func void main2()
fn void main2()
{
int a;
$extnameof("a"); // #error: 'a' does not have an external name.
}
func void main3()
fn void main3()
{
$extnameof("int"); // #error: Only user defined types have an external name.
}

View File

@@ -1,7 +1,7 @@
// #target: x64-darwin
module foo;
int[100] zfe;
global int[100] zfe;
struct Bob
{
Bob[] x;
@@ -36,21 +36,21 @@ union Foob
}
short y = $offsetof("Bob.y");
int z = $offsetof("Bob.y");
int w = $offsetof(Bob.y);
int x1 = $offsetof("Ex.c[3]");
int x2 = $offsetof("Ex.y[1]");
int x4 = $offsetof("Ar.br[1]");
int x6 = $offsetof(Ar.br[1].x);
int x5 = $offsetof(Ar.br[1]);
int x7 = $offsetof("Ar.br[2].x");
int x8 = $offsetof(Ar.br[2]);
int z0 = $offsetof("Foob.c");
int z00 = $offsetof("Foob.c[0]");
int z01 = $offsetof("Foob.c[1]");
int z02 = $offsetof("Foob.c[5]");
int z03 = $offsetof("Foob.a");
global short y = $offsetof("Bob.y");
global int z = $offsetof("Bob.y");
global int w = $offsetof(Bob.y);
global int x1 = $offsetof("Ex.c[3]");
global int x2 = $offsetof("Ex.y[1]");
global int x4 = $offsetof("Ar.br[1]");
global int x6 = $offsetof(Ar.br[1].x);
global int x5 = $offsetof(Ar.br[1]);
global int x7 = $offsetof("Ar.br[2].x");
global int x8 = $offsetof(Ar.br[2]);
global int z0 = $offsetof("Foob.c");
global int z00 = $offsetof("Foob.c[0]");
global int z01 = $offsetof("Foob.c[1]");
global int z02 = $offsetof("Foob.c[5]");
global int z03 = $offsetof("Foob.a");
// #expect: foo.ll
@foo.y = global i16 16, align 2

View File

@@ -1,11 +1,11 @@
module qnametest;
extern func int printf(char *, ...);
extern fn int printf(char *, ...);
int x;
struct Blob { int z; int f; }
func void main()
fn void main()
{
int help;
printf("printf: %s\n", $nameof(printf));

View File

@@ -2,22 +2,22 @@ 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);
global long x = $sizeof(Baz);
global short y = $sizeof("Baz");
global int z = $sizeof(bar::Baz);
global int w = $sizeof("bar::Baz");
global int v = $sizeof("bar::abc::Foo");
global int x1 = $sizeof(x);
global int y1 = $sizeof("y");
global int a = $sizeof("Baz.y");
global int b = $sizeof("Deep.a.b");
global int c = $sizeof("Deep.a.b.c");
global int d = $sizeof("Deep[][100]");
global int e = $sizeof("Deep[][100]**[100][]*");
global int a2 = $sizeof("Baz.y");
global int a3 = $sizeof(Baz.y);
global int a4 = $sizeof(Baz.y);
global int a5 = $sizeof(Baz.y);
module bar;

View File

@@ -2,62 +2,62 @@ module foo;
import bar;
import bar::abc;
func void a()
fn void a()
{
int x = $sizeof(Bazy); // #error: 'Bazy' could not be found, did you spell it right
}
func void b()
fn void b()
{
int x = $sizeof("Bazz"); // #error: 'Bazz' could not be found, did you misspell it
}
func void c()
fn void c()
{
int x = $sizeof("Baz#"); // #error: The path to an existing member was expected after 'Baz', did you make a mistake?
}
func void c2()
fn void c2()
{
int x = $sizeof("#Baz"); // #error: '#Baz' is not a valid identifier, did you misspell it?
}
func void d()
fn 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()
fn void e()
{
int x = $sizeof(bar::Baze); // #error: 'Baze' could not be found, did you spell it right
}
func void f()
fn void f()
{
int x = $sizeof("bar::Bazy"); // #error: 'Bazy' could not be found, did you spell it right
}
func void g()
fn void g()
{
int x = $sizeof("bar::"); // #error: 'bar::' is not a valid identifier, did you misspell it?
}
func void k()
fn void k()
{
int v = $sizeof("int.x"); // #error: 'int' has no members
}
func void l()
fn void l()
{
int v = $sizeof("int[].len"); // #error: 'int[]' has no members
}
func void m()
fn void m()
{
int v = $sizeof("int[4].len"); // #error: 'int[4]' has no members
}
func void n()
fn void n()
{
int v = $sizeof("Baz.x1"); // #error: The path to an existing member was expected after
}

View File

@@ -1,8 +1,8 @@
char[*] foob = x"a0";
char[*] fooz = x"00aabbccddeeff";
char[*] fooy = x'dead beef';
char[*] foow = x"4549234d e d";
char[*] foo64 = b64"SGVsbG8gV29ybGQ=";
global char[*] foob = x"a0";
global char[*] fooz = x"00aabbccddeeff";
global char[*] fooy = x'dead beef';
global char[*] foow = x"4549234d e d";
global char[*] foo64 = b64"SGVsbG8gV29ybGQ=";
// #expect: byte_literals.ll

View File

@@ -1,15 +1,15 @@
// #file: file1.c3
module test;
char a = ' ';
char b = '\r';
char c = '\t';
char d = '\n';
char e = '\0';
char f = '\'';
char g = '"';
char h = '\\';
char i = '\e';
global char a = ' ';
global char b = '\r';
global char c = '\t';
global char d = '\n';
global char e = '\0';
global char f = '\'';
global char g = '"';
global char h = '\\';
global char i = '\e';
// #expect: test.ll

View File

@@ -5,13 +5,13 @@ private const uint DD = FOO;
private const FOO = ~(uint)(0);
private uint x = AA;
private uint z = CC;
private char w = (char)(FOO);
private ushort v = (ushort)(FOO);
private uint z2 = DD;
private global uint x = AA;
private global uint z = CC;
private global char w = (char)(FOO);
private global ushort v = (ushort)(FOO);
private global uint z2 = DD;
func void test()
fn void test()
{
int xx = FOO;
uint* yy = &&FOO;

View File

@@ -7,8 +7,8 @@ define FooInt = Foo<int>;
define A_CONST_INT = A_CONST<int>;
define standard_foo<int> = ofke; // #error: Expected '='
define func foo = fef; // #error: An identifier was expected here.
define feokfe = func void(int); // #error: Expected a function or variable name here
define fn foo = fef; // #error: An identifier was expected here.
define feokfe = fn void(int); // #error: Expected a function or variable name here
define AOFKE = ofek; // #error: Expected a constant name here
define okfoe = OFKEOK; // #error: Expected a function or variable name here
define Helo = helo; // #error: A type name was expected here

View File

@@ -18,7 +18,7 @@ struct Struct2
}
Foo f = { 1, 1.0 };
func void test(int x)
fn void test(int x)
{
Struct s = { 1, 2.0 };
Foo f2 = (Foo)(s);

View File

@@ -11,7 +11,7 @@ struct Struct
define Struct2 = distinct Struct;
define StructArr = distinct Struct2[3];
func void test(int x)
fn void test(int x)
{
StructArr z = { { .x = 1 }, { .y = x }, { 1, 2 }};
usize len = z.len;

View File

@@ -23,7 +23,7 @@ define Union3 = distinct Union2;
define UnionArr = distinct Union3[3];
func void test(int x)
fn void test(int x)
{
Union s = { .y = 2.0 };
Foo f2 = (Foo)(s);

View File

@@ -2,7 +2,7 @@ module test;
define Int2 = distinct int;
func void test()
fn void test()
{
Int2 a = 1;
a = a + 1;

View File

@@ -2,7 +2,7 @@ module test;
define Foo = distinct int;
func int test1()
fn int test1()
{
Foo x = 1;
x += 2;

View File

@@ -15,7 +15,7 @@ struct Struct2
}
Foo f = { 1, 1.0 };
func void test(int x)
fn void test(int x)
{
Struct s = { 1, 2.0 };
Foo f2 = (Foo)(s);

View File

@@ -5,11 +5,11 @@ enum MyEnum : short
BYE = -5
}
int myenum_max = MyEnum.max;
int myenum_min = MyEnum.min;
int myenum_elements = MyEnum.elements;
int myenum_alignof = $alignof(MyEnum);
int myenum_sizeof = $sizeof(MyEnum);
global int myenum_max = MyEnum.max;
global int myenum_min = MyEnum.min;
global int myenum_elements = MyEnum.elements;
global int myenum_alignof = $alignof(MyEnum);
global int myenum_sizeof = $sizeof(MyEnum);
// #expect: compile_time.ll

View File

@@ -6,7 +6,7 @@ enum HelloEnum
WORLD,
ELLOWORLD,
}
func void test()
fn void test()
{
HelloEnum h = WORLD;
h = ELLOWORLD;

View File

@@ -14,7 +14,7 @@ fn void! errorThing2()
}
extern fn void printf(char*, ...);
func void main()
fn void main()
{
anyerr z = errorThing();
printf("Z; %llx\n", (iptr)(z));

View File

@@ -1,4 +1,4 @@
func void test()
fn void test()
{
int! x = 0;
int! z = x << 100; // #error: shift exceeds bitsize of 'int'

View File

@@ -1,8 +1,8 @@
// #target: x64-darwin
extern func int! testError();
extern fn int! testError();
func void test()
fn void test()
{
double x = (testError() + testError()) ?? 100;

View File

@@ -5,7 +5,7 @@ errtype Blurg
Z
}
func void main()
fn void main()
{
int! i = Blurg.Z!;
int! j = Blurg.Z!;

View File

@@ -5,7 +5,7 @@ errtype Blurg
X, Y, Z
}
func void main()
fn void main()
{
anyerr foo;
}

View File

@@ -11,9 +11,9 @@ errtype MyErr
FOO
}
extern func int printf(char *c, ...);
extern fn int printf(char *c, ...);
func void main()
fn void main()
{
int! z = 2;
Foo*! w = &&Foo{ z, 0 };

View File

@@ -9,15 +9,15 @@ errtype MyErr
FOO
}
extern func int printf(char *c, ...);
extern fn int printf(char *c, ...);
func void main()
fn void main()
{
int! z = 2;
Foo*! w = &&{ z, 0 }; // #error: A failable 'int[2]*!' cannot be converted to 'Foo*'
}
func void test()
fn void test()
{
int! z = 2;
Foo*! w = &&Foo!{ z, 0 }; // #error: please remove the '!'

View File

@@ -26,21 +26,21 @@ enum MyEnum
B
}
func void Foo.hello(Foo *f)
fn void Foo.hello(Foo *f)
{
io::println("Hello from Foo");
}
func void Bar.hello(Bar *b)
fn void Bar.hello(Bar *b)
{
io::println("Hello from Bar");
}
func void MyEnum.hello(MyEnum *myenum)
fn void MyEnum.hello(MyEnum *myenum)
{
io::println("Hello from MyEnum");
}
func void main()
fn void main()
{
Foo f = Foo.X;
Foo ef = Foo.Y;

View File

@@ -1,4 +1,4 @@
func void syntaxErrors()
fn void syntaxErrors()
{
int! i = 0;
while (i + 1) {} // #error: 'int!' to 'bool'

View File

@@ -1,5 +1,5 @@
func void test()
fn void test()
{
int x = 3 ^ 5 & 6; // #error: You need to add explicit parentheses to clarify precedence
}

View File

@@ -1,6 +1,6 @@
// #target: x64-darwin
func void! test()
fn void! test()
{
int! i;
i?;

View File

@@ -2,7 +2,7 @@
module rethrow;
func void! test()
fn void! test()
{
int! i;
i?;

View File

@@ -1,5 +1,5 @@
func void test()
fn void test()
{
test()?; // #error: No failable to rethrow before '?' in the expression, please remove '?'
int i = 0;
@@ -9,7 +9,7 @@ func void test()
if ((j?)?) return; // #error: This expression implicitly returns with a failable result, but the function
}
func void! test2()
fn void! test2()
{
int! j = 0;
if (j?) return;

View File

@@ -7,7 +7,7 @@ errtype Blurg
Y
}
func void main()
fn void main()
{
static int! x = 120;
int! i = Blurg.Y!;

View File

@@ -1,10 +1,10 @@
// #target: x64-darwin
extern func int! err();
extern fn int! err();
errtype FooErr { QBERT }
extern func int printf(char* fmt, ...);
extern fn int printf(char* fmt, ...);
func void main()
fn void main()
{
int x = 123;
int! z = 234;

View File

@@ -1,13 +1,13 @@
// #target: x64-darwin
func int hello(int x)
fn int hello(int x)
{
return x + 1;
}
extern func int printf(char *c, ...);
extern fn int printf(char *c, ...);
func int! tester()
fn int! tester()
{
printf("In tester\n");
return 222;
@@ -17,7 +17,7 @@ errtype Foo
{
A
}
func void test1()
fn void test1()
{
int! a = 123;
if (catch err = (a, tester()))
@@ -29,7 +29,7 @@ func void test1()
printf("Noerr %d\n", a);
}
}
func void main()
fn void main()
{
test1();
}

View File

@@ -1,11 +1,11 @@
extern func int printf(char* fmt, ...);
extern fn int printf(char* fmt, ...);
extern func int! err();
extern fn int! err();
errtype FooErr
{
X
}
func void test1()
fn void test1()
{
int! z = 234;
if (try z)
@@ -17,7 +17,7 @@ func void test1()
}
func void test4()
fn void test4()
{
int! z = 234;
int! w = 123;
@@ -28,7 +28,7 @@ func void test4()
}
}
func void test5()
fn void test5()
{
int! z = 234;
int! w = 123;
@@ -37,7 +37,7 @@ func void test5()
int y = z;
}
}
func void test5b()
fn void test5b()
{
int! z = 234;
int! w = 123;
@@ -47,7 +47,7 @@ func void test5b()
}
}
func void test6()
fn void test6()
{
int! z = 234;
int! w = 123;
@@ -58,7 +58,7 @@ func void test6()
}
}
func void test7()
fn void test7()
{
int! z = 234;
int! w = 123;
@@ -71,7 +71,7 @@ func void test7()
}
}
func void test8()
fn void test8()
{
int! z = 234;
int! w = 123;
@@ -83,7 +83,7 @@ func void test8()
int y = z;
}
}
func void test9()
fn void test9()
{
int! z = 234;
int! w = 123;

View File

@@ -1,9 +1,9 @@
// #target: x64-darwin
module test;
extern func int! maybe();
extern fn int! maybe();
func int tester(int n)
fn int tester(int n)
{
int! num = maybe();
assert(try num, "Hello");

View File

@@ -1,4 +1,4 @@
func void test()
fn void test()
{
int! z;
int! w;

View File

@@ -1,11 +1,11 @@
// #target: x64-darwin
extern func char*! readLine();
extern func int! atoi(char*);
extern fn char*! readLine();
extern fn int! atoi(char*);
extern func int printf(char* fmt, ...);
extern fn int printf(char* fmt, ...);
func void main()
fn void main()
{
int val;
if (try val = atoi(readLine()))

View File

@@ -1,10 +1,10 @@
func void test()
fn void test()
{
int! a;
int b;
if (try int b = a) {} // #error: 'b' would shadow a previous declaration.
}
func void test2()
fn void test2()
{
int! a;
int b;
@@ -14,7 +14,7 @@ func void test2()
const int BAZ = 1;
func void test3()
fn void test3()
{
int! a;
@@ -23,7 +23,7 @@ func void test3()
}
func void test4()
fn void test4()
{
int! a;
@@ -31,7 +31,7 @@ func void test4()
if (try b = 1) {} // #error: Expected a failable expression to 'try' here. If it isn't a failable, remove 'try'
}
func void test5()
fn void test5()
{
int! a;
@@ -39,7 +39,7 @@ func void test5()
if (try a = a) {} // #error: This is a failable variable, you should only have non-failable variables on the left side unless you use 'try' without '='
}
func void test6()
fn void test6()
{
int! a;
@@ -49,7 +49,7 @@ func void test6()
}
func void test7()
fn void test7()
{
int! a;
int b;
@@ -57,7 +57,7 @@ func void test7()
if (try foo::z = a) {} // #error: The variable may not have a path.
}
func void test8()
fn void test8()
{
int! a;
int b;
@@ -66,7 +66,7 @@ func void test8()
if (try c = a && try c = a) { c++; }
}
func void test9()
fn void test9()
{
int! a = 11;
if (try z = a)
@@ -79,7 +79,7 @@ func void test9()
}
}
func void test10()
fn void test10()
{
int! a = 11;
if (try a)

View File

@@ -1,10 +1,10 @@
// #target: x64-darwin
extern func char*! readLine();
extern func int! atoi(char*);
extern fn char*! readLine();
extern fn int! atoi(char*);
extern func int printf(char* fmt, ...);
extern fn int printf(char* fmt, ...);
func void main()
fn void main()
{
char*! line = readLine();
if (try line)

View File

@@ -1,13 +1,13 @@
// #target: x64-darwin
func int hello(int x)
fn int hello(int x)
{
return x + 1;
}
extern func int printf(char *c, ...);
extern fn int printf(char *c, ...);
func int! tester()
fn int! tester()
{
printf("In tester\n");
return 222;
@@ -17,7 +17,7 @@ errtype Foo
{
A
}
func void test1()
fn void test1()
{
int! a = 11;
if (try int b = a && try int c = tester())
@@ -26,12 +26,12 @@ func void test1()
printf("%d\n", c);
}
}
func void main()
fn void main()
{
test1();
}
func void test2()
fn void test2()
{
int! a;
if (try int b = a && hello(b))

View File

@@ -1,4 +1,4 @@
func void test1()
fn void test1()
{
int! a;
@@ -7,7 +7,7 @@ func void test1()
if (try int &a = a) {} // #error: Expected a variable name after the type.
}
func void test2()
fn void test2()
{
int! a;
int b;

View File

@@ -1,12 +1,12 @@
module game_of_life;
extern func void printf(char *fmt, ...);
extern func int atoi(char *val);
extern fn void printf(char *fmt, ...);
extern fn int atoi(char *val);
extern void *__stdoutp;
extern func void fflush(void *std);
extern func int rand();
extern func void* malloc(usize size);
extern func void usleep(int time);
extern fn void fflush(void *std);
extern fn int rand();
extern fn void* malloc(usize size);
extern fn void usleep(int time);
struct GameBoard
@@ -17,7 +17,7 @@ struct GameBoard
char* temp;
}
func void GameBoard.show(GameBoard *board)
fn void GameBoard.show(GameBoard *board)
{
printf("\e[H");
@@ -34,7 +34,7 @@ func void GameBoard.show(GameBoard *board)
fflush(__stdoutp);
}
func void GameBoard.evolve(GameBoard *board)
fn void GameBoard.evolve(GameBoard *board)
{
for (int y = 0; y < board.h; y++)
{
@@ -61,7 +61,7 @@ func void GameBoard.evolve(GameBoard *board)
}
func int main(int c, char** v)
fn int main(int c, char** v)
{
int w = 0;
int h = 0;

View File

@@ -1,8 +1,8 @@
module fe;
import std::io;
extern func int printf(char *str, ...);
extern fn int printf(char *str, ...);
func int main()
fn int main()
{
while(true)
{

View File

@@ -2,16 +2,16 @@
module test;
extern func void printf(char*, ...);
extern fn void printf(char*, ...);
func void main()
fn void main()
{
test();
test2();
test3();
}
func void test()
fn void test()
{
int f = 3;
int* x = &(((f)));
@@ -21,7 +21,7 @@ func void test()
const int XX = 314;
func void test2()
fn void test2()
{
int* w = &XX;
printf("w = %d (314)\n", *w);
@@ -32,7 +32,7 @@ struct Foo
int x;
int y;
}
func void test3()
fn void test3()
{
Foo h = { 345, 555 };
int* zx = &h.x;

View File

@@ -1,4 +1,4 @@
func void test()
fn void test()
{
int f;
int* x = &(((f)));
@@ -7,7 +7,7 @@ func void test()
}
func void test2()
fn void test2()
{
int f;
var $foo;
@@ -20,24 +20,24 @@ macro int hello()
return he;
}
func void test3()
fn void test3()
{
int* x = &@hello(); // #error: To take the address of a temporary value, use '&&' instead of '&'
}
func void test3b()
fn void test3b()
{
int* x = &hello; // #error: It is not possible to take the address of a macro.
}
const X = 2;
const int XX = 3;
func void test4()
fn void test4()
{
int* w = &XX;
}
func void test5()
fn void test5()
{
int* z = &X; // #error: The constant is not typed, either type it or use && to take the reference to a temporary.
}
@@ -50,7 +50,7 @@ struct Foo
define heh = he;
func void test6()
fn void test6()
{
int* hee = &heh;
Foo h;
@@ -66,7 +66,7 @@ errtype Err { FOO }
union Un { int x; }
enum MyEnum { BAR }
func void test7()
fn void test7()
{
&Baz; // #error: It is not possible to take the address of a type.
&Bar; // #error: It is not possible to take the address of a type.

View File

@@ -1,40 +1,40 @@
module arithmetics;
func void testAdd(int a, int b)
fn void testAdd(int a, int b)
{
a = a + b;
a += b;
a += 1;
}
func void testSub(int a, int b)
fn void testSub(int a, int b)
{
a = a - b;
a -= b;
a -= 1;
}
func void testMult(int a, int b)
fn void testMult(int a, int b)
{
a = a * b;
a *= b;
a *= 1;
}
func void testDiv(int a, int b)
fn void testDiv(int a, int b)
{
a = a / b;
a /= b;
a /= 1;
}
func void testAssignment()
fn void testAssignment()
{
ichar x = -3 - 5;
ichar c = -128;
}
func char test22()
fn char test22()
{
return 100;
}

View File

@@ -1,51 +1,51 @@
func void test7()
fn void test7()
{
double x = 1.2 / 0; // This is ok! NaN
}
func void test8()
fn void test8()
{
int y = 0 / 0; // #error: division by zero is not allowed
}
func void test9()
fn void test9()
{
int y = 0;
int x = y / 0; // #error: division by zero is not allowed
}
func void test10()
fn void test10()
{
10 = 20; // #error: This expression is not assignable
}
func void test11()
fn void test11()
{
'10' = '20'; // #error: This expression is not assignable
}
func void test12()
fn void test12()
{
true = false; // #error: This expression is not assignable
}
func void test13()
fn void test13()
{
"a" = "b"; // #error: This expression is not assignable
}
func void test14()
fn void test14()
{
1.2 = 1.3; // #error: This expression is not assignable
}
func void test15()
fn void test15()
{
null = null; // #error: This expression is not assignable
}
func void test16()
fn void test16()
{
int a = 0;
uint b = 2;
@@ -54,24 +54,24 @@ func void test16()
int g = a + b;
}
func void test17()
fn void test17()
{
char a = 100 + 300; // #error: '400' is out of range for 'char'
}
func void test18()
fn void test18()
{
char b = 100 + 156; // #error: '256' is out of range for 'char'
}
func void test19()
fn void test19()
{
ichar b = (-40) - 126; // #error: '-166' is out of range for 'ichar'
}
func void test20()
fn void test20()
{
ichar d = ((-128 - 10) + 10) - 2; // #error: '-130' is out of range for 'ichar'
ichar c = 100 * 100; // #error: '10000' is out of range for 'ichar'
@@ -81,10 +81,10 @@ func void test20()
check(128); // #error: '128' is out of range for 'ichar'
}
func void check(ichar x) {}
fn void check(ichar x) {}
func char test22()
fn char test22()
{
return 300; // #error: '300' is out of range for 'char'
}

View File

@@ -1,4 +1,4 @@
func void test1()
fn void test1()
{
int* p;
*p = 10;

View File

@@ -1,38 +1,38 @@
define Number = int;
func void test1()
fn void test1()
{
10 = 20; // #error: This expression is not assignable
}
func void test2()
fn void test2()
{
"foo" = "bar"; // #error: This expression is not assignable
}
func void test3()
fn void test3()
{
true = false; // #error: This expression is not assignable
}
func void test4()
fn void test4()
{
'c' = 'd'; // #error: This expression is not assignable
}
func void test5()
fn void test5()
{
3.14 = 2.14; // #error: This expression is not assignable
}
func void test21()
fn void test21()
{
int a = 0;
int b = 2;
a++ = b++; // #error: This expression is not assignable
}
func void test22()
fn void test22()
{
$Type = int;
}

View File

@@ -1,6 +1,6 @@
module prec;
func void test()
fn void test()
{
int i = 1;
int j = 2;

View File

@@ -1,7 +1,7 @@
func void test2(ichar a)
fn void test2(ichar a)
{}
func void test1()
fn void test1()
{
test2(100);
ichar c = 1;

View File

@@ -1,22 +1,22 @@
module inlineme;
import std::io;
func void test1() @inline
fn void test1() @inline
{
io::println("Inline!");
}
func void test2() @noinline
fn void test2() @noinline
{
io::println("No inline!");
}
func void test3()
fn void test3()
{
io::println("Plain");
}
func void main()
fn void main()
{
test1() @inline;
test2() @inline;

View File

@@ -1,4 +1,4 @@
func void test1()
fn void test1()
{
ichar a = (ichar)(256 + 1);
ushort b = (ushort)(65536+1);

View File

@@ -16,9 +16,9 @@ enum EnumB : char
C, D
}
define Func = func void(Enum);
define Func = fn void(Enum);
func void test1(Enum e)
fn void test1(Enum e)
{
bool a = (bool)(e);
char b = (char)(e);
@@ -27,12 +27,12 @@ func void test1(Enum e)
uint* f = (uint*)(e); // #error: cast 'Enum' to 'uint*'
}
func void test2(Enum e)
fn void test2(Enum e)
{
Struct* g = (Struct*)(e); // #error: cast 'Enum' to 'Struct*'
}
func void test3(Enum e)
fn void test3(Enum e)
{
EnumB h = (EnumB)(e);
Func i = (Func)(e); // #error: cast 'Enum' to 'Func'

View File

@@ -1,6 +1,6 @@
module cast_expr;
func int main(int argc, char** argv)
fn int main(int argc, char** argv)
{
int a = 10;

View File

@@ -3,7 +3,7 @@ errtype MyErr
FOO
}
func void test()
fn void test()
{
int! x = (int!)(MyErr.FOO!); // #error: Casting to a failable type is not allowed
int! y = MyErr.FOO!;

View File

@@ -8,33 +8,33 @@ enum Enum : uptr
A, B
}
define Func = func void(int);
define FuncOther = func bool(char*);
define FuncSame = func void(int);
define Func = fn void(int);
define FuncOther = fn bool(char*);
define FuncSame = fn void(int);
func void test1(Func arg)
fn void test1(Func arg)
{
bool a = (bool)(arg);
bool b = arg;
}
func void test2(Func arg)
fn void test2(Func arg)
{
ichar b = (ichar)(arg); // #error: 'Func' (func void(int)) to 'ichar'
}
func void test3(Func arg)
fn void test3(Func arg)
{
uint c = (uint)(arg); // #error: 'Func' (func void(int)) to 'uint'
}
func void test4(Func arg)
fn void test4(Func arg)
{
float d = (float)(arg); // #error: 'Func' (func void(int)) to 'float'
}
func void test7(Func arg)
fn void test7(Func arg)
{
usize g = (usize)(arg);
FuncOther k = (FuncOther)(arg);

View File

@@ -3,7 +3,7 @@ struct Struct
int x;
}
func void test1()
fn void test1()
{
int a = (Struct)(200); // #error: 'int' to 'Struct'
}

View File

@@ -1,6 +1,6 @@
define Number = int;
func void test1()
fn void test1()
{
int a = 10;
@@ -9,12 +9,12 @@ func void test1()
int c = (Foo)(a); // #error: 'Foo' could not be found
}
func void test2()
fn void test2()
{
int d = (Number)(bar);; // #error: 'bar' could not be found
}
func void test3()
fn void test3()
{
int e = (Bar)( // #error: 'Bar' could not be found
faa); // #error: 'faa' could not be found

View File

@@ -1,7 +1,7 @@
define Number8 = char;
define Number32 = int;
func void test1()
fn void test1()
{
int a = (ichar)(10);
int b = (ichar)(200);
@@ -9,7 +9,7 @@ func void test1()
ichar d = (int)(200); // #error: 'int' to 'ichar'
}
func void test2()
fn void test2()
{
char e = (Number32)(200); // #error: 'Number32' (int) to 'char'
}

View File

@@ -1,11 +1,11 @@
module chained;
func int foo()
fn int foo()
{
return 1;
}
func void test()
fn void test()
{
int x = foo();
int y = foo();

Some files were not shown because too many files have changed in this diff Show More