mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Update tests to (Foo) { ... } syntax.
This commit is contained in:
@@ -95,7 +95,7 @@ fn ulong! elf_module_image_base(String path) @local
|
||||
defer (void)file.close();
|
||||
char[4] buffer;
|
||||
io::read_all(&file, &buffer)!;
|
||||
if (buffer != char[4]{ 0x7f, 'E', 'L', 'F'}) return BacktraceFault.IMAGE_NOT_FOUND?;
|
||||
if (buffer != { 0x7f, 'E', 'L', 'F'}) return BacktraceFault.IMAGE_NOT_FOUND?;
|
||||
bool is_64 = file.read_byte()! == 2;
|
||||
bool is_little_endian = file.read_byte()! == 1;
|
||||
// Actually, not supported.
|
||||
|
||||
@@ -1843,7 +1843,7 @@ static inline Decl *parse_interface_declaration(ParseContext *c)
|
||||
{
|
||||
do
|
||||
{
|
||||
ASSIGN_TYPE_OR_RET(TypeInfo *type, parse_type(c), poisoned_decl);
|
||||
ASSIGN_TYPE_OR_RET(TypeInfo *type, parse_optional_type_no_generic(c), poisoned_decl);
|
||||
vec_add(parents, type);
|
||||
} while (try_consume(c, TOKEN_COMMA));
|
||||
}
|
||||
|
||||
@@ -394,9 +394,12 @@ INLINE bool sema_resolve_generic_type(SemaContext *context, TypeInfo *type_info)
|
||||
{
|
||||
RETURN_SEMA_ERROR(inner, "Parameterization required a concrete type name here.");
|
||||
}
|
||||
if (inner->resolve_status != RESOLVE_NOT_DONE)
|
||||
if (inner->resolve_status == RESOLVE_DONE)
|
||||
{
|
||||
puts("feokf");
|
||||
if (!type_is_user_defined(inner->type))
|
||||
{
|
||||
RETURN_SEMA_ERROR(inner, "A user defined type was expected here, not %s.", type_quoted_error_string(inner->type));
|
||||
}
|
||||
}
|
||||
ASSERT_SPAN(inner, inner->resolve_status == RESOLVE_NOT_DONE);
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
module test;
|
||||
|
||||
def Mm256 = float[<8>];
|
||||
struct St256 {
|
||||
Mm256 m;
|
||||
struct St256
|
||||
{
|
||||
Mm256 m;
|
||||
}
|
||||
|
||||
St256 x38;
|
||||
@@ -20,18 +21,21 @@ fn void f39() { f38(x38); f37(x37); }
|
||||
// CHECK: declare void @func40(%struct.t128* byval(%struct.t128) align 16)
|
||||
|
||||
def Mm128 = float[<4>];
|
||||
struct Two128 {
|
||||
Mm128 m;
|
||||
Mm128 n;
|
||||
struct Two128
|
||||
{
|
||||
Mm128 m;
|
||||
Mm128 n;
|
||||
}
|
||||
|
||||
extern fn void func40(Two128 s);
|
||||
fn void func41(Two128 s) {
|
||||
func40(s);
|
||||
fn void func41(Two128 s)
|
||||
{
|
||||
func40(s);
|
||||
}
|
||||
|
||||
struct Atwo128 {
|
||||
Mm128[2] array;
|
||||
struct Atwo128
|
||||
{
|
||||
Mm128[2] array;
|
||||
}
|
||||
|
||||
struct Sa {
|
||||
@@ -59,14 +63,14 @@ struct Complex { double i; double c; }
|
||||
extern fn void test52_helper(int, ...);
|
||||
Mm256 x52;
|
||||
fn void test52() {
|
||||
test52_helper(0, x52, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Complex { 0, 1.0 });
|
||||
test52_helper(0, x52, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, (Complex) { 0, 1.0 });
|
||||
}
|
||||
|
||||
extern fn void test54_helper(Mm256, ...);
|
||||
Mm256 x54;
|
||||
fn void test54() {
|
||||
test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, Complex { 0, 1.0 });
|
||||
test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Complex { 0, 1.0 });
|
||||
test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, (Complex) { 0, 1.0 });
|
||||
test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, (Complex) { 0, 1.0 });
|
||||
}
|
||||
|
||||
def Mm512 = float[<16>];
|
||||
|
||||
@@ -45,14 +45,14 @@ struct Complex { double i; double c; }
|
||||
extern fn void f62_helper(int, ...);
|
||||
Mm512 x62;
|
||||
fn void f62() {
|
||||
f62_helper(0, x62, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Complex { 1.0, 1.0 });
|
||||
f62_helper(0, x62, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, (Complex) { 1.0, 1.0 });
|
||||
}
|
||||
|
||||
extern fn void f64_helper(Mm512, ...);
|
||||
Mm512 x64;
|
||||
fn void f64() {
|
||||
f64_helper(x64, x64, 1.0, 1.0, 1.0, 1.0, 1.0, Complex { 1.0, 1.0 });
|
||||
f64_helper(x64, x64, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Complex { 1.0, 1.0 });
|
||||
f64_helper(x64, x64, 1.0, 1.0, 1.0, 1.0, 1.0, (Complex) { 1.0, 1.0 });
|
||||
f64_helper(x64, x64, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, (Complex) { 1.0, 1.0 });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
|
||||
fn char f0() {
|
||||
fn char f0()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn short f1() {
|
||||
fn short f1()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn int f2() {
|
||||
fn int f2()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -32,7 +35,7 @@ struct Struct8
|
||||
int b;
|
||||
}
|
||||
|
||||
fn Struct8 f8_1() { while (0) {} return Struct8 {}; }
|
||||
fn Struct8 f8_1() { while (0) {} return (Struct8) {}; }
|
||||
fn void f8_2(Struct8 a0) {}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@@ -11,8 +11,8 @@ extern fn void blorg(Test t);
|
||||
|
||||
fn Test creator()
|
||||
{
|
||||
blorg(Test{});
|
||||
return Test{};
|
||||
blorg((Test){});
|
||||
return (Test){};
|
||||
}
|
||||
|
||||
/* #expect: literal_load.ll
|
||||
|
||||
@@ -12,8 +12,8 @@ extern fn void blorg(Test t);
|
||||
|
||||
fn Test creator()
|
||||
{
|
||||
blorg(Test{});
|
||||
return Test{};
|
||||
blorg((Test){});
|
||||
return (Test){};
|
||||
}
|
||||
|
||||
/* #expect: literal_load.ll
|
||||
|
||||
@@ -12,8 +12,8 @@ extern fn void blorg(Test t);
|
||||
|
||||
fn Test creator()
|
||||
{
|
||||
blorg(Test{});
|
||||
return Test{};
|
||||
blorg((Test){});
|
||||
return (Test){};
|
||||
}
|
||||
|
||||
/* #expect: literal_load.ll
|
||||
|
||||
@@ -171,9 +171,9 @@ fn void f_agg_stack(double a, long b, double c, long d, Tiny e,
|
||||
extern fn int f_va_callee(int, ...);
|
||||
|
||||
fn void f_va_caller() {
|
||||
f_va_callee(1, 2, 3, 4.0, 5.0, Tiny{6, 7, 8, 9},
|
||||
Small{10, null}, Small_aligned{11},
|
||||
Large{12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3, 4.0, 5.0, (Tiny){6, 7, 8, 9},
|
||||
(Small){10, null}, (Small_aligned){11},
|
||||
(Large){12, 13, 14, 15});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -172,9 +172,9 @@ fn void f_agg_stack(double a, long b, double c, long d, Tiny e,
|
||||
extern fn int f_va_callee(int, ...);
|
||||
|
||||
fn void f_va_caller() {
|
||||
f_va_callee(1, 2, 3, 4.0, 5.0, Tiny{6, 7, 8, 9},
|
||||
Small{10, null}, Small_aligned{11},
|
||||
Large{12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3, 4.0, 5.0, (Tiny){6, 7, 8, 9},
|
||||
(Small){10, null}, (Small_aligned){11},
|
||||
(Large){12, 13, 14, 15});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -172,9 +172,9 @@ fn void f_agg_stack(double a, long b, double c, long d, Tiny e,
|
||||
extern fn int f_va_callee(int, ...);
|
||||
|
||||
fn void f_va_caller() {
|
||||
f_va_callee(1, 2, 3, 4.0, 5.0, Tiny{6, 7, 8, 9},
|
||||
Small{10, null}, Small_aligned{11},
|
||||
Large{12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3, 4.0, 5.0, (Tiny){6, 7, 8, 9},
|
||||
(Small){10, null}, (Small_aligned){11},
|
||||
(Large){12, 13, 14, 15});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fn int f_scalar_stack_1(int a, int128 b, float c, float128 d, V32i8 e,
|
||||
|
||||
fn Large f_scalar_stack_2(double a, int128 b, float128 c, V32i8 d,
|
||||
char e, ichar f, char g) {
|
||||
return Large {(long)(a), e, f, g};
|
||||
return (Large) {(long)(a), e, f, g};
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@@ -145,18 +145,18 @@ extern fn int f_va_callee(int, ...);
|
||||
|
||||
fn void f_va_caller() {
|
||||
float128 fq;
|
||||
f_va_callee(1, 2, 3i64, 4.0f, 5.0, Tiny{6, 7, 8, 9},
|
||||
Small{10, null}, Small_aligned{11},
|
||||
Large{12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3i64, 4.0f, 5.0, (Tiny){6, 7, 8, 9},
|
||||
(Small){10, null}, (Small_aligned){11},
|
||||
(Large){12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3, 4, fq, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, Small_aligned{5}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, Small{5,null}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, (Small_aligned){5}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, (Small){5,null}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, fq, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, Small_aligned{6}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, Small{6, null}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, (Small_aligned){6}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, (Small){6, null}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, fq, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, Small_aligned{7}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, Small{7, null}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, (Small_aligned){7}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, (Small){7, null}, 8, 9);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -146,18 +146,18 @@ extern fn int f_va_callee(int, ...);
|
||||
|
||||
fn void f_va_caller() {
|
||||
float128 fq;
|
||||
f_va_callee(1, 2, 3i64, 4.0f, 5.0, Tiny{6, 7, 8, 9},
|
||||
Small{10, null}, Small_aligned{11},
|
||||
Large{12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3i64, 4.0f, 5.0, (Tiny){6, 7, 8, 9},
|
||||
(Small){10, null}, (Small_aligned){11},
|
||||
(Large){12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3, 4, fq, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, Small_aligned{5}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, Small{5,null}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, (Small_aligned){5}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, (Small){5,null}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, fq, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, Small_aligned{6}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, Small{6, null}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, (Small_aligned){6}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, (Small){6, null}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, fq, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, Small_aligned{7}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, Small{7, null}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, (Small_aligned){7}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, (Small){7, null}, 8, 9);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -146,18 +146,18 @@ extern fn int f_va_callee(int, ...);
|
||||
|
||||
fn void f_va_caller() {
|
||||
float128 fq;
|
||||
f_va_callee(1, 2, 3i64, 4.0f, 5.0, Tiny{6, 7, 8, 9},
|
||||
Small{10, null}, Small_aligned{11},
|
||||
Large{12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3i64, 4.0f, 5.0, (Tiny){6, 7, 8, 9},
|
||||
(Small){10, null}, (Small_aligned){11},
|
||||
(Large){12, 13, 14, 15});
|
||||
f_va_callee(1, 2, 3, 4, fq, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, Small_aligned{5}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, Small{5,null}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, (Small_aligned){5}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, (Small){5,null}, 6, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, fq, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, Small_aligned{6}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, Small{6, null}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, (Small_aligned){6}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, (Small){6, null}, 7, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, fq, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, Small_aligned{7}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, Small{7, null}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, (Small_aligned){7}, 8, 9);
|
||||
f_va_callee(1, 2, 3, 4, 5, 6, (Small){7, null}, 8, 9);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ struct Foo
|
||||
|
||||
fn int testing()
|
||||
{
|
||||
Foo y = getFoo(Foo { 4, 5, 6 });
|
||||
Foo y = getFoo((Foo) { 4, 5, 6 });
|
||||
return y.a + y.c;
|
||||
}
|
||||
|
||||
fn Foo getFoo(Foo f)
|
||||
{
|
||||
return Foo { 1, 2, 3 };
|
||||
return (Foo) { 1, 2, 3 };
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@@ -11,7 +11,7 @@ struct Rectangle
|
||||
|
||||
fn void test(Rectangle r)
|
||||
{
|
||||
test(Rectangle { 1, 2, 3, 4 });
|
||||
test((Rectangle) { 1, 2, 3, 4 });
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
}
|
||||
fn Vector2 vector2_zero() @extern("vector2_zero") { return Vector2 {}; }
|
||||
fn Vector2 vector2_one() @extern("vector2_one") { return Vector2 {}; }
|
||||
fn Vector2 vector2_add(Vector2 v1, Vector2 v2) @extern("vector2_add") { return Vector2 {}; }
|
||||
fn Vector2 vector2_add_value(Vector2 v, float add) @extern("vector2_add_value") { return Vector2 {}; }
|
||||
fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) @extern("vector2_subtract") { return Vector2 {}; }
|
||||
fn Vector2 vector2_subtract_value(Vector2 v, float sub) @extern("vector2_subtract_value") { return Vector2 {}; }
|
||||
fn Vector2 vector2_zero() @extern("vector2_zero") { return {}; }
|
||||
fn Vector2 vector2_one() @extern("vector2_one") { return {}; }
|
||||
fn Vector2 vector2_add(Vector2 v1, Vector2 v2) @extern("vector2_add") { return {}; }
|
||||
fn Vector2 vector2_add_value(Vector2 v, float add) @extern("vector2_add_value") { return {}; }
|
||||
fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) @extern("vector2_subtract") { return {}; }
|
||||
fn Vector2 vector2_subtract_value(Vector2 v, float sub) @extern("vector2_subtract_value") { return {}; }
|
||||
|
||||
|
||||
/* #expect: abi.ll
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
}
|
||||
fn Vector2 vector2_zero() @extern("vector2_zero") { return Vector2 {}; }
|
||||
fn Vector2 vector2_one() @extern("vector2_one") { return Vector2 {}; }
|
||||
fn Vector2 vector2_add(Vector2 v1, Vector2 v2) @extern("vector2_add") { return Vector2 {}; }
|
||||
fn Vector2 vector2_add_value(Vector2 v, float add) @extern("vector2_add_value") { return Vector2 {}; }
|
||||
fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) @extern("vector2_subtract") { return Vector2 {}; }
|
||||
fn Vector2 vector2_subtract_value(Vector2 v, float sub) @extern("vector2_subtract_value") { return Vector2 {}; }
|
||||
fn Vector2 vector2_zero() @extern("vector2_zero") { return {}; }
|
||||
fn Vector2 vector2_one() @extern("vector2_one") { return {}; }
|
||||
fn Vector2 vector2_add(Vector2 v1, Vector2 v2) @extern("vector2_add") { return {}; }
|
||||
fn Vector2 vector2_add_value(Vector2 v, float add) @extern("vector2_add_value") { return {}; }
|
||||
fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) @extern("vector2_subtract") { return {}; }
|
||||
fn Vector2 vector2_subtract_value(Vector2 v, float sub) @extern("vector2_subtract_value") { return {}; }
|
||||
|
||||
/* #expect: abi.ll
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
}
|
||||
fn Vector2 vector2_zero() @extern("vector2_zero") { return Vector2 {}; }
|
||||
fn Vector2 vector2_one() @extern("vector2_one") { return Vector2 {}; }
|
||||
fn Vector2 vector2_add(Vector2 v1, Vector2 v2) @extern("vector2_add") { return Vector2 {}; }
|
||||
fn Vector2 vector2_add_value(Vector2 v, float add) @extern("vector2_add_value") { return Vector2 {}; }
|
||||
fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) @extern("vector2_subtract") { return Vector2 {}; }
|
||||
fn Vector2 vector2_subtract_value(Vector2 v, float sub) @extern("vector2_subtract_value") { return Vector2 {}; }
|
||||
fn Vector2 vector2_zero() @extern("vector2_zero") { return {}; }
|
||||
fn Vector2 vector2_one() @extern("vector2_one") { return {}; }
|
||||
fn Vector2 vector2_add(Vector2 v1, Vector2 v2) @extern("vector2_add") { return {}; }
|
||||
fn Vector2 vector2_add_value(Vector2 v, float add) @extern("vector2_add_value") { return {}; }
|
||||
fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) @extern("vector2_subtract") { return {}; }
|
||||
fn Vector2 vector2_subtract_value(Vector2 v, float sub) @extern("vector2_subtract_value") { return {}; }
|
||||
|
||||
/* #expect: abi.ll
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module testing;
|
||||
import std::io;
|
||||
|
||||
const FOO = Foo[2]{ {11}, {22} };
|
||||
const FOO = (Foo[2]){ {11}, {22} };
|
||||
|
||||
struct Foo
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fn void main()
|
||||
{
|
||||
int[?][?][] x = int[2][1][] { { { 1, 2 } } };
|
||||
int[?][?][?] y = int[2][1][] { { { 1, 2 } } };
|
||||
int[?][?][] x = (int[2][1][]) { { { 1, 2 } } };
|
||||
int[?][?][?] y = (int[2][1][]) { { { 1, 2 } } };
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ bitstruct Foo : int
|
||||
fn void main()
|
||||
{
|
||||
Foo f;
|
||||
int z = (int) Foo { .abc = 2, .defg = 1 };
|
||||
int z = (int) (Foo) { .abc = 2, .defg = 1 };
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@@ -23,7 +23,7 @@ fn void main()
|
||||
io::printfn("%s %s", f3.a, f3.b);
|
||||
Foo f4 = (f1 | ~f2) ^ f3;
|
||||
io::printfn("%s %s", f4.a, f4.b);
|
||||
Foo f5 = Foo { true, false } | Foo { false, true };
|
||||
Foo f5 = (Foo) { true, false } | (Foo) { false, true };
|
||||
io::printfn("%s %s", f5.a, f5.b);
|
||||
|
||||
f5 &= f2;
|
||||
@@ -36,7 +36,7 @@ fn void main()
|
||||
io::printfn("%s %s %s", b3.z, b3.w, b3.gh);
|
||||
b3 = ~b3;
|
||||
io::printfn("%s %s %s", b3.z, b3.w, b3.gh);
|
||||
b3 ^= Bar { true, true, false };
|
||||
b3 ^= (Bar) { true, true, false };
|
||||
io::printfn("%s %s %s", b3.z, b3.w, b3.gh);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ struct Foo4
|
||||
fn void main()
|
||||
{
|
||||
void* foo;
|
||||
Foo *f = &&Foo { .expand = 2, .widget = &f };
|
||||
Foo2 *f2 = &&Foo2 { .expand = 2, .widget = &f };
|
||||
Foo3 *f3 = &&Foo3 { .expand = 2, .a = true, .b = true, .widget = &f };
|
||||
Foo4 *f4 = &&Foo4 { .expand = 2, .a = true, .b = true, .widget = &f };
|
||||
Foo *f = &&(Foo) { .expand = 2, .widget = &f };
|
||||
Foo2 *f2 = &&(Foo2) { .expand = 2, .widget = &f };
|
||||
Foo3 *f3 = &&(Foo3) { .expand = 2, .a = true, .b = true, .widget = &f };
|
||||
Foo4 *f4 = &&(Foo4) { .expand = 2, .a = true, .b = true, .widget = &f };
|
||||
}
|
||||
|
||||
/* #expect: testing.ll
|
||||
|
||||
@@ -5,21 +5,21 @@ import std::io;
|
||||
fn void main()
|
||||
{
|
||||
int a;
|
||||
io::printfn("%s", $$pow_int(double[<2>] { 23.3, 2.1 }, 3));
|
||||
io::printfn("%s", $$reduce_add(int[<2>] { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_fadd(double[<2>] { 3, 10 }, -0.0));
|
||||
io::printfn("%s", $$reduce_fadd(double[<2>] { 3, 10 }, 3.2));
|
||||
io::printfn("%s", $$reduce_mul(int[<2>] { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_fmul(double[<2>] { 3, 10 }, 3.4));
|
||||
io::printfn("%s", $$reduce_and(int[<2>] { 3, 11 }));
|
||||
io::printfn("%s", $$reduce_or(int[<2>] { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_xor(int[<2>] { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_max(double[<2>] { 23.2, 23.3 }));
|
||||
io::printfn("%s", $$reduce_max(int[<2>] { -23, 32 }));
|
||||
io::printfn("%s", $$reduce_max(char[<2>] { 4, 253 }));
|
||||
io::printfn("%s", $$reduce_min(double[<2>] { 23.2, 23.3 }));
|
||||
io::printfn("%s", $$reduce_min(int[<2>] { -23, 32 }));
|
||||
io::printfn("%s", $$reduce_min(char[<2>] { 4, 253 }));
|
||||
io::printfn("%s", $$pow_int((double[<2>]) { 23.3, 2.1 }, 3));
|
||||
io::printfn("%s", $$reduce_add((int[<2>]) { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_fadd((double[<2>]) { 3, 10 }, -0.0));
|
||||
io::printfn("%s", $$reduce_fadd((double[<2>]) { 3, 10 }, 3.2));
|
||||
io::printfn("%s", $$reduce_mul((int[<2>]) { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_fmul((double[<2>]) { 3, 10 }, 3.4));
|
||||
io::printfn("%s", $$reduce_and((int[<2>]) { 3, 11 }));
|
||||
io::printfn("%s", $$reduce_or((int[<2>]) { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_xor((int[<2>]) { 3, 10 }));
|
||||
io::printfn("%s", $$reduce_max((double[<2>]) { 23.2, 23.3 }));
|
||||
io::printfn("%s", $$reduce_max((int[<2>]) { -23, 32 }));
|
||||
io::printfn("%s", $$reduce_max((char[<2>]) { 4, 253 }));
|
||||
io::printfn("%s", $$reduce_min((double[<2>]) { 23.2, 23.3 }));
|
||||
io::printfn("%s", $$reduce_min((int[<2>]) { -23, 32 }));
|
||||
io::printfn("%s", $$reduce_min((char[<2>]) { 4, 253 }));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ fn void main()
|
||||
ichar[<2>] w = { -44, 30 };
|
||||
io::printfn("%s %s", $$sat_add(x, y), $$sat_add(z, z));
|
||||
io::printfn("%s %s", $$sat_sub(x, y), $$sat_sub(w, z));
|
||||
io::printfn("%s %s", $$sat_shl(x, char[<2>] { 1, 1 }), $$sat_shl(z, ichar[<2>] { 1, 1 }));
|
||||
io::printfn("%s %s", $$sat_shl(x, (char[<2>]) { 1, 1 }), $$sat_shl(z, (ichar[<2>]) { 1, 1 }));
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@@ -23,7 +23,7 @@ struct Matrix2x2
|
||||
|
||||
fn float[<2>] apply1(Matrix2x2* mat, float[<2>] vec)
|
||||
{
|
||||
return float[<2>] {
|
||||
return (float[<2>]) {
|
||||
mat.m00 * vec[0] + mat.m01 * vec[1],
|
||||
mat.m10 * vec[0] + mat.m11 * vec[1],
|
||||
};
|
||||
@@ -31,7 +31,7 @@ fn float[<2>] apply1(Matrix2x2* mat, float[<2>] vec)
|
||||
|
||||
fn float[<2>] apply2(Matrix2x2* mat, float[<2>] vec)
|
||||
{
|
||||
return float[<2>] {
|
||||
return (float[<2>]) {
|
||||
mat.m0[0] * vec[0] + mat.m0[1] * vec[1],
|
||||
mat.m1[0] * vec[0] + mat.m1[1] * vec[1],
|
||||
};
|
||||
@@ -49,9 +49,9 @@ fn float[<2>] apply3(Matrix2x2* mat, float[<2>] vec)
|
||||
fn void main()
|
||||
{
|
||||
Matrix2x2 a = { 1, -3, 5, -7 };
|
||||
io::printfn("1: %s", apply1(&a, float[<2>] { 11, 13 }));
|
||||
io::printfn("2: %s", apply2(&a, float[<2>] { 11, 13 }));
|
||||
io::printfn("3: %s", apply3(&a, float[<2>] { 11, 13 }));
|
||||
io::printfn("1: %s", apply1(&a, (float[<2>]) { 11, 13 }));
|
||||
io::printfn("2: %s", apply2(&a, (float[<2>]) { 11, 13 }));
|
||||
io::printfn("3: %s", apply3(&a, (float[<2>]) { 11, 13 }));
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@@ -4,8 +4,8 @@ module test;
|
||||
fn void main()
|
||||
{
|
||||
Enum e = ENUM1;
|
||||
ushort x = (ushort)Foo{ .x = e };
|
||||
Foo z = (Foo)(ushort)Foo { .x = e };
|
||||
ushort x = (ushort)(Foo){ .x = e };
|
||||
Foo z = (Foo)(ushort)(Foo) { .x = e };
|
||||
}
|
||||
|
||||
enum Enum : char
|
||||
|
||||
@@ -7,5 +7,5 @@ fn void test4()
|
||||
|
||||
fn void test5()
|
||||
{
|
||||
Foo x = (Foo)(Foo{32});
|
||||
Foo x = (Foo)((Foo){32});
|
||||
}
|
||||
@@ -2,7 +2,7 @@ struct Foo { int a; }
|
||||
|
||||
fn void test2()
|
||||
{
|
||||
int x = int{ 32 }; // #error: 'int' with a non-empty initializer list
|
||||
int x = (int){ 32 }; // #error: 'int' with a non-empty initializer list
|
||||
}
|
||||
|
||||
fn void test3()
|
||||
|
||||
@@ -9,7 +9,7 @@ bitstruct Image_Tag : uint
|
||||
}
|
||||
|
||||
distinct Glyph_Format = CInt;
|
||||
const Glyph_Format GLYPH_FORMAT_BITMAP = (Glyph_Format)Image_Tag {'b', 'i', 't', 's'};
|
||||
const Glyph_Format GLYPH_FORMAT_BITMAP = (Glyph_Format)(Image_Tag) {'b', 'i', 't', 's'};
|
||||
|
||||
fn void main() {
|
||||
// Error: Implicitly casting 'Image_Tag' to 'Glyph_Format' is not permitted
|
||||
|
||||
@@ -6,16 +6,16 @@ struct Abc
|
||||
float m00, m01, m10, m11;
|
||||
}
|
||||
|
||||
Abc a = flip(Abc { 1, 2, 3, 4 });
|
||||
Abc a = flip((Abc) { 1, 2, 3, 4 });
|
||||
|
||||
macro flip($init)
|
||||
{
|
||||
return Abc { $init.m01, $init.m10, $init.m11, $init.m00 };
|
||||
return (Abc) { $init.m01, $init.m10, $init.m11, $init.m00 };
|
||||
}
|
||||
|
||||
macro check_type($Type)
|
||||
{
|
||||
var $b = $Type[4][4] {};
|
||||
var $b = ($Type[4][4]) {};
|
||||
$Type z = $b[2][2];
|
||||
return z;
|
||||
}
|
||||
@@ -25,9 +25,9 @@ enum Blurb { FOO }
|
||||
distinct Bdd = Abc;
|
||||
fn void main()
|
||||
{
|
||||
var $i = int[4] { 1, 2, 3, 4 };
|
||||
var $b = Abc[2] { Abc {}, Abc { 11, 22, 33, 44 }};
|
||||
var $c = any[4] {};
|
||||
var $i = (int[4]) { 1, 2, 3, 4 };
|
||||
var $b = (Abc[2]) { (Abc) {}, (Abc) { 11, 22, 33, 44 }};
|
||||
var $c = (any[4]) {};
|
||||
check_type(int);
|
||||
check_type(Abc);
|
||||
check_type(anyfault);
|
||||
|
||||
@@ -3,26 +3,30 @@ module test;
|
||||
import std;
|
||||
|
||||
def @TaggedAttr(value) = {
|
||||
@tag("foo", ValueHere[?]{ value })
|
||||
@tag("foo", (ValueHere[?]){ value })
|
||||
};
|
||||
|
||||
const FOO_STR = "foo";
|
||||
|
||||
union TestUnion {
|
||||
union TestUnion
|
||||
{
|
||||
int a;
|
||||
}
|
||||
struct ValueHere {
|
||||
struct ValueHere
|
||||
{
|
||||
int value;
|
||||
String thing;
|
||||
}
|
||||
|
||||
const ValueHere VALUE_STRUCT = { 32, "lol" };
|
||||
|
||||
struct ThisOtherStruct @TaggedAttr(VALUE_STRUCT) {
|
||||
struct ThisOtherStruct @TaggedAttr(VALUE_STRUCT)
|
||||
{
|
||||
int something;
|
||||
}
|
||||
|
||||
enum Example : int (String str) @TaggedAttr(VALUE_STRUCT) {
|
||||
enum Example : int (String str) @TaggedAttr(VALUE_STRUCT)
|
||||
{
|
||||
FOO = FOO_STR,
|
||||
}
|
||||
|
||||
@@ -32,7 +36,8 @@ const int BAZ2 = BAZ[1];
|
||||
const TestUnion[1] ABC = { { .a = 112 } };
|
||||
const TestUnion BCD = ABC[0];
|
||||
|
||||
macro int get_tag_value($Type) {
|
||||
macro int get_tag_value($Type)
|
||||
{
|
||||
$if $Type.has_tagof("foo"):
|
||||
return $Type.tagof("foo")[0].value;
|
||||
$else
|
||||
|
||||
@@ -3,13 +3,13 @@ module test;
|
||||
macro foo()
|
||||
{
|
||||
var c = "hello" +++ " world";
|
||||
String[?] a = String[1] { "hello" } +++ String[1] { " world" };
|
||||
String[?] a = (String[1]) { "hello" } +++ (String[1]) { " world" };
|
||||
int[2] $a = { 1, 2 };
|
||||
$a = $a +++ 100;
|
||||
int z = $typeof($a).len;
|
||||
var b = $a;
|
||||
var d = int[]{} +++ 1 +++ 2 +++ 3;
|
||||
var e = String[1] { "hello... " } +++ " there!";
|
||||
var d = (int[]){} +++ 1 +++ 2 +++ 3;
|
||||
var e = (String[1]) { "hello... " } +++ " there!";
|
||||
var f = "" +++ "";
|
||||
var g = "bye";
|
||||
var h = $$str_hash("helloworld");
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
fn void main(String[] args)
|
||||
{
|
||||
var $x = int[2]{ 1, 2 } +++ int[2]{ 4, 5 };
|
||||
var $x = (int[2]){ 1, 2 } +++ (int[2]){ 4, 5 };
|
||||
var $v = "foo" +++ "baz" +++ '!' +++ '?';
|
||||
var $b = x'403322' +++ "baz";
|
||||
var $b2 = x'40334a' +++ 55 +++ 55;
|
||||
var $b3 = x'403322' +++ char[2] { 1, 2 };
|
||||
var $b4 = x'403322' +++ char[2] { 1, 2 };
|
||||
var $b3 = x'403322' +++ (char[2]) { 1, 2 };
|
||||
var $b4 = x'403322' +++ (char[2]) { 1, 2 };
|
||||
var $b5 = "foo" +++ { 55, 57 };
|
||||
var $b6 = ((ichar[3])x'403322') +++ ichar[2] { 1, 2 };
|
||||
var $b7 = char[2] { 1, 2 } +++ "foo";
|
||||
var $b6 = ((ichar[3])x'403322') +++ (ichar[2]) { 1, 2 };
|
||||
var $b7 = (char[2]) { 1, 2 } +++ "foo";
|
||||
assert($b7 == { 1, 2, 102, 111, 111});
|
||||
assert($b5 == "foo79");
|
||||
assert($b3 == $b4);
|
||||
assert($b6 == { 0x40, 0x33, 0x22, 1, 2 });
|
||||
int[4] $x2 = int[2]{ 1, 2 }+++ int[2]{ 4, 5 };
|
||||
int[4] $x2 = (int[2]){ 1, 2 }+++ (int[2]){ 4, 5 };
|
||||
int[4] $y = { 1, 2 } +++ { 4, 5 };
|
||||
assert($x == {1, 2, 4, 5});
|
||||
assert($x2 == {1, 2, 4, 5});
|
||||
|
||||
@@ -17,7 +17,7 @@ macro @printVecs(Vector3... vectors)
|
||||
|
||||
fn void main()
|
||||
{
|
||||
@printVecs(Vector3{10, 5, 3}, Vector3{9, 6, 4}, Vector3{5, 4, 3});
|
||||
@printVecs({10, 5, 3}, {9, 6, 4}, {5, 4, 3});
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
@@ -37,7 +37,7 @@ macro @patch(IFoo *x, $Type) {
|
||||
}
|
||||
|
||||
fn void main() {
|
||||
IFoo foo = @clone(Ba{});
|
||||
IFoo foo = @clone((Ba){});
|
||||
|
||||
io::printfn("Aa.typeid: %p, Ba.typeid: %p", (usz) Aa.typeid, (usz) Ba.typeid);
|
||||
io::printfn("foo.type: %p", (usz) foo.type);
|
||||
|
||||
@@ -55,19 +55,19 @@ fn Doc! readDoc(char[] url)
|
||||
{
|
||||
if (contains(url, "fail")) return ReadError.BAD_READ?;
|
||||
if (contains(url, "head-missing")) return { .head = null };
|
||||
if (contains(url, "title-missing")) return { dupe(Head { .title = null })! };
|
||||
if (contains(url, "title-empty")) return { dupe(Head { .title = dupe((char[])"")! })! };
|
||||
if (contains(url, "title-missing")) return { dupe((Head) { .title = null })! };
|
||||
if (contains(url, "title-empty")) return { dupe((Head) { .title = dupe((char[])"")! })! };
|
||||
// Not particularly elegant due to missing string functions.
|
||||
isz len = libc::snprintf(null, 0, "Title of %.*s", (int)url.len, url.ptr);
|
||||
char* str = malloc(len + 1);
|
||||
if (!str) return ReadError.OUT_OF_MEMORY?;
|
||||
libc::snprintf(str, len + 1, "Title of %.*s", (int)url.len, url.ptr);
|
||||
return { dupe(Head { .title = dupe(str[..len - 1])! })! };
|
||||
return { dupe((Head) { .title = dupe(str[..len - 1])! })! };
|
||||
}
|
||||
|
||||
fn Summary buildSummary(Doc doc)
|
||||
{
|
||||
return Summary {
|
||||
return {
|
||||
.title = doc.head ? doc.head.title : null,
|
||||
.ok = true,
|
||||
};
|
||||
@@ -75,7 +75,7 @@ fn Summary buildSummary(Doc doc)
|
||||
|
||||
fn Summary readAndBuildSummary(char[] url)
|
||||
{
|
||||
return buildSummary(readDoc(url)) ?? Summary { .title = null, .ok = false };
|
||||
return buildSummary(readDoc(url)) ?? (Summary) { .title = null, .ok = false };
|
||||
/*
|
||||
// or
|
||||
Summary summary = buildSummary(readDoc(url));
|
||||
|
||||
@@ -4,7 +4,7 @@ struct Foo { int a; }
|
||||
struct Bar { int b; Foo f; }
|
||||
fn void main()
|
||||
{
|
||||
Bar { .f = Foo { foo() } }; // #error: not be discarded
|
||||
(Bar) { .f = (Foo) { foo() } }; // #error: not be discarded
|
||||
}
|
||||
|
||||
fn int! foo() => 1;
|
||||
@@ -16,10 +16,10 @@ extern fn int printf(char *c, ...);
|
||||
fn void main()
|
||||
{
|
||||
int! z = 2;
|
||||
Foo*! w = &&Foo{ z, 0 };
|
||||
Foo*! w = &&(Foo){ z, 0 };
|
||||
(void)printf("%d\n", w.x);
|
||||
z = MyErr.FOO?;
|
||||
w = &&Foo{ z, 0 };
|
||||
w = &&(Foo){ z, 0 };
|
||||
(void)printf("Not visible: %d\n", w.x);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,13 +68,13 @@ fn void! TextTemplate.init(&self, String template, String tag_start = "{{", Stri
|
||||
{
|
||||
$switch ($m.typeid)
|
||||
$case String.typeid:
|
||||
return TextTag{
|
||||
return (TextTag){
|
||||
.kind = STRING,
|
||||
.data = (String*)(data + $m.offsetof),
|
||||
};
|
||||
$default:
|
||||
$if $defined($m.get(self.data).as_stream):
|
||||
return TextTag{
|
||||
return (TextTag){
|
||||
.kind = TEMPLATE,
|
||||
.template = self.data.$eval($m.nameof).as_stream(),
|
||||
};
|
||||
|
||||
@@ -3,6 +3,6 @@ import std::collections::maybe;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
maybe::Maybe(<float>) f = Maybe {.value=6.6, .has_value=true}; // #error: Did you mean the struct
|
||||
maybe::Maybe(<int>)g = Maybe {.value=8, .has_value=true};
|
||||
Maybe(<float>) f = (Maybe) {.value=6.6, .has_value=true}; // #error: Did you mean the struct
|
||||
Maybe(<int>)g = (Maybe) {.value=8, .has_value=true};
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import std::collections::maybe;
|
||||
|
||||
fn void test()
|
||||
{
|
||||
maybe::Maybe(<float>) f = Maybe {.value=6.6, .has_value=true}; // #error: Did you mean the struct
|
||||
maybe::Maybe(<float>) f = (Maybe) {.value=6.6, .has_value=true}; // #error: Did you mean the struct
|
||||
Maybe x; // #error: Did you mean the struct
|
||||
}
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@ import std::collections::maybe;
|
||||
|
||||
fn void test()
|
||||
{
|
||||
maybe::Maybe(<float>) f = Maybe {.value=6.6, .has_value=true}; // #error: Did you mean the struct
|
||||
maybe::Maybe(<float>) f = (Maybe) {.value=6.6, .has_value=true}; // #error: Did you mean the struct
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
const IS_ARCH_LITTLE_ENDIAN = (uint)(UIntLE{(uint)1}.val) == 1; // #error: This expression cannot be evaluated at compile time
|
||||
const IS_ARCH_LITTLE_ENDIAN = (uint)((UIntLE){(uint)1}.val) == 1; // #error: This expression cannot be evaluated at compile time
|
||||
|
||||
@@ -20,7 +20,7 @@ fn int test()
|
||||
int foo2 = $foo[2];
|
||||
var $foos = { "Hello!" };
|
||||
char* str = $foos[0];
|
||||
bool x = ! int[] { 1, 2, 3 };
|
||||
bool x = ! (int[]) { 1, 2, 3 };
|
||||
Bar b = {};
|
||||
Baz z = {};
|
||||
int[] sub = {};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// #target: windows-x64
|
||||
module test;
|
||||
const int[?] X = int[?] { 1, 2, 3 };
|
||||
int[?] y = int[?] { 1, 2, 3 };
|
||||
const int[?] X = (int[?]) { 1, 2, 3 };
|
||||
int[?] y = (int[?]) { 1, 2, 3 };
|
||||
|
||||
fn void main()
|
||||
{
|
||||
int x = $typeof(int[?] { 1, 2, 3}).len;
|
||||
int x = $typeof((int[?]) { 1, 2, 3}).len;
|
||||
int z = X.len;
|
||||
int w = y.len;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ struct Bar (Foo)
|
||||
fn int main() {
|
||||
Test(<Foo>) a = {{}};
|
||||
Test(<any>) b = {{}};
|
||||
Test(<Foo>) a2 = {Bar{}}; // #error: It is not possible to cast
|
||||
Test(<Foo>) a2 = {(Bar){}}; // #error: It is not possible to cast
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ macro test(foo)
|
||||
|
||||
fn void main()
|
||||
{
|
||||
test(int[] { 1, 2 });
|
||||
test((int[]) { 1, 2 });
|
||||
test({ 1, 2 }); // #error: It is only possible to use an untyped list as a
|
||||
}
|
||||
@@ -17,14 +17,14 @@ struct Bar
|
||||
|
||||
Bar[] arrbar = { { 3, 4 }, { 8, 9 }};
|
||||
int[] xd = { 1, 2 };
|
||||
int* fofeo = &&(int[2]{ 3, 4 });
|
||||
int* fofeo = &&((int[2]){ 3, 4 });
|
||||
|
||||
fn int main()
|
||||
{
|
||||
Bar w = arrbar[1];
|
||||
libc::printf("%d\n", arrbar[1].x);
|
||||
int[] x = { 1, 2, 3 };
|
||||
int* y = &&(int[3]{ 123, 234, 567 });
|
||||
int* y = &&((int[3]){ 123, 234, 567 });
|
||||
io::printn("Start:");
|
||||
libc::printf("X len: %d mid element %d\n", (int)(x.len), x[1]);
|
||||
libc::printf("Y mid element %d\n", y[1]);
|
||||
@@ -33,7 +33,7 @@ fn int main()
|
||||
int[1] azz = {};
|
||||
|
||||
//var $foo = { 1, 2, 3 };
|
||||
bool xy = ! int[] { 1, 2, 3 };
|
||||
bool xy = !(int[]){ 1, 2, 3 };
|
||||
if (!xy) io::printn("Ok");
|
||||
Bar b = {};
|
||||
Baz z = {};
|
||||
|
||||
@@ -7,7 +7,7 @@ macro int[2] test(#abc) @safemacro
|
||||
|
||||
fn void main()
|
||||
{
|
||||
int[2] x = int[2] { 1, 2 };
|
||||
int[2] x = (int[2]) { 1, 2 };
|
||||
int[2] y = test({ 2, 3 });
|
||||
int[2] z = test({ [0] = 1 });
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ fn bool Foo[].is_empty(Foo[] array) {
|
||||
def foo_arr_is_empty = Foo[].is_empty;
|
||||
|
||||
fn void main() {
|
||||
Foo[] foos = { Foo { .i = 0 } };
|
||||
Foo[] foos = { (Foo) { .i = 0 } };
|
||||
void* foo = &Foo[].is_empty;
|
||||
io::printfn("Is empty: %s", foos.is_empty());
|
||||
io::printfn("Is empty: %s", foo_arr_is_empty(foos));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
const int[?] X = int[?] { 1, 2, 3 };
|
||||
int[?] y = int[?] { 1, 2, 3 };
|
||||
const int[?] X = (int[?]) { 1, 2, 3 };
|
||||
int[?] y = (int[?]) { 1, 2, 3 };
|
||||
|
||||
fn int main()
|
||||
{
|
||||
|
||||
@@ -10,8 +10,8 @@ fn void main()
|
||||
io::printfn("%s %s", y, z);
|
||||
y[4..] = z[5..6];
|
||||
io::printfn("%s %s", y, z);
|
||||
int[][] a = { int[] { 1 } };
|
||||
int[][] b = { int[] { 2 } };
|
||||
int[][] a = { (int[]) { 1 } };
|
||||
int[][] b = { (int[]) { 2 } };
|
||||
io::printfn("%s", a);
|
||||
a[0..0] = b[0..0];
|
||||
io::printfn("%s", a);
|
||||
|
||||
@@ -10,8 +10,8 @@ fn void main()
|
||||
io::printfn("%s %s", y, z);
|
||||
y[4..] = z[5..6];
|
||||
io::printfn("%s %s", y, z);
|
||||
int[][] a = { int[] { 1 } };
|
||||
int[][] b = { int[] { 2 } };
|
||||
int[][] a = { (int[]) { 1 } };
|
||||
int[][] b = { (int[]) { 2 } };
|
||||
io::printfn("%s", a);
|
||||
a[0..0] = b[0..0];
|
||||
io::printfn("%s", a);
|
||||
|
||||
@@ -6,12 +6,12 @@ int[] y2 = FOO[1..2];
|
||||
|
||||
fn void test()
|
||||
{
|
||||
int[][] a = { int[] { 1 } };
|
||||
int[][] a = { (int[]) { 1 } };
|
||||
char[4] $a = x'aabbccdd';
|
||||
var $b = $a[1..2];
|
||||
char[2] y = $b;
|
||||
assert($b == char[] { 187, 204 });
|
||||
assert(y == char[2] { 187, 204 });
|
||||
assert($b == (char[]) { 187, 204 });
|
||||
assert(y == (char[2]) { 187, 204 });
|
||||
|
||||
}
|
||||
fn int main()
|
||||
|
||||
@@ -26,7 +26,7 @@ macro int Foo.@operator_element_at(Foo* &f, int a) @operator([])
|
||||
fn int[5] getFields()
|
||||
{
|
||||
printf("getFields\n");
|
||||
return int[5] { 3, 5, 2, 10, 111};
|
||||
return (int[5]) { 3, 5, 2, 10, 111};
|
||||
}
|
||||
fn Foo *call(Foo* f)
|
||||
{
|
||||
@@ -62,7 +62,7 @@ fn void main()
|
||||
i++;
|
||||
}
|
||||
|
||||
foreach(i, y : int[5] { 1, 2, 10, 111, 123 } )
|
||||
foreach(i, y : (int[5]) { 1, 2, 10, 111, 123 } )
|
||||
{
|
||||
printf("Adding %d: %d\n", i, y);
|
||||
i++;
|
||||
|
||||
@@ -23,14 +23,14 @@ fn void main()
|
||||
IntFooMap map;
|
||||
map.new_init();
|
||||
io::printfn("Map size: %d", map.count);
|
||||
map.set(1, Foo { 1, null });
|
||||
map.set(1, { 1, null });
|
||||
io::printfn("Map size: %d", map.count);
|
||||
map.set(1, Foo { 2, null });
|
||||
map.set(1, { 2, null });
|
||||
io::printfn("Map size: %d", map.count);
|
||||
(void)io::printfn("Val: %d", map.get(1).x);
|
||||
io::printfn("Has 1: %s", map.has_key(1));
|
||||
io::printfn("Has 2: %s", map.has_key(2));
|
||||
map.set(7, Foo { 4, null });
|
||||
map.set(7, { 4, null });
|
||||
io::printfn("Values: %s", map.value_new_list());
|
||||
IntDoubleMap map2;
|
||||
map2.new_init();
|
||||
|
||||
@@ -23,14 +23,14 @@ fn void main()
|
||||
IntFooMap map;
|
||||
map.new_init();
|
||||
io::printfn("Map size: %d", map.count);
|
||||
map.set(1, Foo { 1, null });
|
||||
map.set(1, { 1, null });
|
||||
io::printfn("Map size: %d", map.count);
|
||||
map.set(1, Foo { 2, null });
|
||||
map.set(1, { 2, null });
|
||||
io::printfn("Map size: %d", map.count);
|
||||
(void)io::printfn("Val: %d", map.get(1).x);
|
||||
io::printfn("Has 1: %s", map.has_key(1));
|
||||
io::printfn("Has 2: %s", map.has_key(2));
|
||||
map.set(7, Foo { 4, null });
|
||||
map.set(7, { 4, null });
|
||||
io::printfn("Values: %s", map.value_new_list());
|
||||
IntDoubleMap map2;
|
||||
map2.new_init();
|
||||
|
||||
@@ -10,9 +10,9 @@ fn void main()
|
||||
{
|
||||
|
||||
FooPriorityQueue agh;
|
||||
agh.push(Foo { 3 });
|
||||
agh.push(Foo { 101 });
|
||||
agh.push(Foo { 10 });
|
||||
agh.push((Foo) { 3 });
|
||||
agh.push((Foo) { 101 });
|
||||
agh.push({ 10 });
|
||||
while (try f = agh.pop()) io::printf("%s\n", f.x);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ struct Test
|
||||
char[2] id;
|
||||
}
|
||||
|
||||
Test t = Test{"id"};
|
||||
Test t = (Test){"id"};
|
||||
fn int main()
|
||||
{
|
||||
io::printn(t);
|
||||
Test y = Test { "id" };
|
||||
Test y = (Test) { "id" };
|
||||
io::printn();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ struct Matrix2x2
|
||||
union
|
||||
{
|
||||
float[4] m;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
float m00, m01, m10, m11;
|
||||
}
|
||||
}
|
||||
@@ -16,15 +17,19 @@ struct Matrix2x2_b
|
||||
{
|
||||
union
|
||||
{
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
float m00, m01, m10, m11;
|
||||
}
|
||||
float[4] m;
|
||||
}
|
||||
}
|
||||
struct Matrix4x4 {
|
||||
union {
|
||||
struct {
|
||||
struct Matrix4x4
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
float m00, m01, m02, m03;
|
||||
float m10, m11, m12, m13;
|
||||
float m20, m21, m22, m23;
|
||||
@@ -35,9 +40,12 @@ struct Matrix4x4 {
|
||||
}
|
||||
|
||||
|
||||
struct Matrix3x3 {
|
||||
union {
|
||||
struct {
|
||||
struct Matrix3x3
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
float m00, m01, m02, m10, m11, m12, m20, m21, m22;
|
||||
}
|
||||
float[9] m;
|
||||
@@ -46,7 +54,7 @@ struct Matrix3x3 {
|
||||
fn void main()
|
||||
{
|
||||
Matrix3x3 x = { 1, 2, 3, 4, 5, 6, 7,8 ,9};
|
||||
Matrix2x2 m = { float[4] { 1, 2, 3, 4 } };
|
||||
Matrix2x2 m = { (float[4]) { 1, 2, 3, 4 } };
|
||||
Matrix2x2_b m2 = { 1, 2, 3, 4 };
|
||||
libc::printf("%f %f %f %f\n", x.m00, x.m[1], x.m10, x.m[3]);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ fn void main()
|
||||
{
|
||||
Abc x = { 1, 4};
|
||||
print(&x) @noinline;
|
||||
x = Abc { x.b, x.a };
|
||||
x = (Abc) { x.b, x.a };
|
||||
print(&x) @noinline;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
<*
|
||||
@require Token.kindof == ENUM && $typefrom(Token.inner).kindof == UNSIGNED_INT
|
||||
@require $defined(Token{}.token)
|
||||
@require $defined(Comment{}.start) && $defined(Comment{}.end)
|
||||
@require $defined((Token){}.token)
|
||||
@require $defined((Comment){}.start) && $defined((Comment){}.end)
|
||||
*>
|
||||
module lexer(<Token, Comment>);
|
||||
import std::io;
|
||||
@@ -493,7 +493,7 @@ fn void Trie.init(&self, usz initial_capacity = 8, Allocator using = allocator::
|
||||
{
|
||||
*self = {};
|
||||
self.nodes.new_init(initial_capacity, allocator: using);
|
||||
self.nodes.push(TrieNode{});
|
||||
self.nodes.push((TrieNode){});
|
||||
}
|
||||
|
||||
<*
|
||||
@@ -585,7 +585,7 @@ fn void! TrieNode.set(&self, Trie *t, char[] key, Value value) @private
|
||||
if (new_idx > Index.max) return TrieError.TRIE_FULL?;
|
||||
idx = (Index)new_idx;
|
||||
self.children[c] = idx;
|
||||
t.nodes.push(TrieNode{});
|
||||
t.nodes.push((TrieNode){});
|
||||
}
|
||||
t.nodes[idx].set(t, key[1..], value)!;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ enum EnumWithErrorWithMissingName : (int) // #error: Expected a member name her
|
||||
}
|
||||
|
||||
enum EnumWithErrorData : ( int
|
||||
{ // #error: Expected a member name here
|
||||
,{ // #error: Expected a member name here
|
||||
TEST
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ fn void main()
|
||||
int[5] a = { 1, 2, 3, 4, 5 };
|
||||
void*[<2>] x = { &a[0], &a[4] };
|
||||
int*[<2>] y = x;
|
||||
int[<2>] result = mem::@gather_aligned(y, bool[<2>] { true, false }, int[<2>]{ 10, 20 }, 4);
|
||||
int[<2>] result = mem::@gather_aligned(y, (bool[<2>]) { true, false }, (int[<2>]){ 10, 20 }, 4);
|
||||
assert(result == { 1, 20});
|
||||
result = mem::gather(y, bool[<2>] { true, false }, int[<2>]{ 10, 20 });
|
||||
result = mem::gather(y, (bool[<2>]) { true, false }, (int[<2>]){ 10, 20 });
|
||||
assert(result == { 1, 20});
|
||||
mem::@scatter_aligned(y, int[<2>]{ 66, 77 }, bool[<2>] { false, true } , 4);
|
||||
assert(a == int[5]{ 1, 2, 3, 4, 77});
|
||||
mem::scatter(y, int[<2>]{ 88, 99 }, bool[<2>] { true, false });
|
||||
assert(a == int[5]{ 88, 2, 3, 4, 77});
|
||||
mem::@scatter_aligned(y, (int[<2>]){ 66, 77 }, (bool[<2>]) { false, true } , 4);
|
||||
assert(a == (int[5]){ 1, 2, 3, 4, 77});
|
||||
mem::scatter(y, (int[<2>]){ 88, 99 }, (bool[<2>]) { true, false });
|
||||
assert(a == (int[5]){ 88, 2, 3, 4, 77});
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
@@ -4,7 +4,7 @@ import std::math;
|
||||
fn int x(char[<8>] a, char[<8>] b)
|
||||
{
|
||||
bool[<8>] z = a.comp_eq(b);
|
||||
return (char[<8>] { [0..7] = 255 } & (char[<8>])z + ~(char[<8>])z & char[<8>] { 0, 1, 2, 3, 4, 5, 6, 7 }).min();
|
||||
return ((char[<8>]) { [0..7] = 255 } & (char[<8>])z + ~(char[<8>])z & (char[<8>]) { 0, 1, 2, 3, 4, 5, 6, 7 }).min();
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
@@ -5,7 +5,7 @@ import std;
|
||||
// issue 1954
|
||||
macro splat($Type, x)
|
||||
{
|
||||
return $Type {x,x,x,x};
|
||||
return ($Type) {x,x,x,x};
|
||||
}
|
||||
|
||||
fn void main()
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
module test;
|
||||
|
||||
int[<2>] b = (int[<2>])(int[2] { 1, 2 });
|
||||
int[2] c = (int[2])(int[<2>] { 1, 2 });
|
||||
int[<2>] b = (int[<2>])((int[2]) { 1, 2 });
|
||||
int[2] c = (int[2])((int[<2>]) { 1, 2 });
|
||||
|
||||
fn void tester()
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ fn void test_bitops() @test
|
||||
|
||||
Foo f4 = (f1 | ~f2) ^ f3;
|
||||
assert(f4.a == false && f4.b == true);
|
||||
Foo f5 = Foo { true, false } | Foo { false, true };
|
||||
Foo f5 = (Foo) { true, false } | (Foo) { false, true };
|
||||
assert(f5.a == true && f5.b == true);
|
||||
|
||||
f5 &= f2;
|
||||
@@ -38,7 +38,7 @@ fn void test_bitops() @test
|
||||
assert(b3.z == true && b3.w == false && b3.gh == false);
|
||||
b3 = ~b3;
|
||||
assert(b3.z == false && b3.w == true && b3.gh == true);
|
||||
b3 ^= Bar { true, true, false };
|
||||
b3 ^= (Bar) { true, true, false };
|
||||
assert(b3.z == true && b3.w == false && b3.gh == true);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ fn void test_bitops() @test
|
||||
|
||||
Foo f4 = (f1 | ~f2) ^ f3;
|
||||
assert(f4.a == false && f4.b == true);
|
||||
Foo f5 = Foo { true, false } | Foo { false, true };
|
||||
Foo f5 = (Foo) { true, false } | (Foo) { false, true };
|
||||
assert(f5.a == true && f5.b == true);
|
||||
|
||||
f5 &= f2;
|
||||
@@ -38,7 +38,7 @@ fn void test_bitops() @test
|
||||
assert(b3.z == true && b3.w == false && b3.gh == false);
|
||||
b3 = ~b3;
|
||||
assert(b3.z == false && b3.w == true && b3.gh == true);
|
||||
b3 ^= Bar { true, true, false };
|
||||
b3 ^= (Bar) { true, true, false };
|
||||
assert(b3.z == true && b3.w == false && b3.gh == true);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ fn void test_bitops_const() @test
|
||||
|
||||
const Foo F4 = (F1 | ~F2) ^ F3;
|
||||
assert(F4.a == false && F4.b == true);
|
||||
const Foo F5 = Foo { true, false } | Foo { false, true };
|
||||
const Foo F5 = (Foo) { true, false } | (Foo) { false, true };
|
||||
assert(F5.a == true && F5.b == true);
|
||||
|
||||
const Bar B1 = { true, true, true };
|
||||
|
||||
@@ -82,7 +82,7 @@ fn void negate()
|
||||
Flags flags;
|
||||
flags = ~flags;
|
||||
assert(~0 == (int)flags);
|
||||
flags = ~Flags {};
|
||||
flags = ~(Flags){};
|
||||
assert(3 == (int)flags);
|
||||
const Flags FLAGS = {.flag1 };
|
||||
flags = ~FLAGS;
|
||||
|
||||
@@ -5,7 +5,7 @@ fn void to_arr()
|
||||
int[] x = { 1, 2, 3, 4, 5 };
|
||||
int z = 2;
|
||||
int[2] y = x[z:2];
|
||||
assert(y == int[2]{ 3, 4 });
|
||||
assert(y == {3, 4});
|
||||
}
|
||||
|
||||
fn void to_vec()
|
||||
|
||||
@@ -5,8 +5,8 @@ fn void slice_bytes()
|
||||
char[4] $a = x'aabbccdd';
|
||||
var $b = $a[1..2];
|
||||
char[2] y = $b;
|
||||
assert($b == char[] { 187, 204 });
|
||||
assert(y == char[2] { 187, 204 });
|
||||
assert($b == (char[]){187, 204});
|
||||
assert(y == {187, 204 });
|
||||
}
|
||||
|
||||
fn void slice_string()
|
||||
@@ -28,11 +28,11 @@ fn void slice_untyped()
|
||||
{
|
||||
var $v = { 1, "hello", 3 };
|
||||
int[1] v = $v[0:1];
|
||||
assert(v == int[1] { 1 });
|
||||
assert(v == { 1 });
|
||||
int[1] v2 = $v[2:1];
|
||||
assert(v2 == int[1] { 3 });
|
||||
assert(v2 == { 3 });
|
||||
String[1] v3 = $v[1:1];
|
||||
assert(v3 == String[1] { "hello" });
|
||||
assert(v3 == { "hello" });
|
||||
int[] v4 = $v[0:1];
|
||||
assert(v4 == int[] { 1 });
|
||||
assert(v4 == { 1 });
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ fn void ordinals()
|
||||
assert(z.ordinal == 0);
|
||||
$assert Foo.ABC.ordinal == 1;
|
||||
$assert Foo.CDE.ordinal == 2;
|
||||
$assert (Foo{}).ordinal == 0;
|
||||
$assert (Foo){}.ordinal == 0;
|
||||
Foo x = Foo.CDE;
|
||||
assert(x.ordinal == 2);
|
||||
x = Foo.ABC;
|
||||
|
||||
@@ -5,12 +5,12 @@ fn void test_simple() @test
|
||||
int[5] a = { 1, 2, 3, 4, 5 };
|
||||
void*[<2>] x = { &a[0], &a[4] };
|
||||
int*[<2>] y = x;
|
||||
int[<2>] result = mem::@gather_aligned(y, bool[<2>] { true, false }, int[<2>]{ 10, 20 }, 4);
|
||||
int[<2>] result = mem::@gather_aligned(y, (bool[<2>]) { true, false }, (int[<2>]){ 10, 20 }, 4);
|
||||
assert(result == { 1, 20});
|
||||
result = mem::gather(y, bool[<2>] { true, false }, int[<2>]{ 10, 20 });
|
||||
result = mem::gather(y, (bool[<2>]) { true, false }, (int[<2>]){ 10, 20 });
|
||||
assert(result == { 1, 20});
|
||||
mem::@scatter_aligned(y, int[<2>]{ 66, 77 }, bool[<2>] { false, true } , 4);
|
||||
assert(a == int[5]{ 1, 2, 3, 4, 77});
|
||||
mem::scatter(y, int[<2>]{ 88, 99 }, bool[<2>] { true, false });
|
||||
assert(a == int[5]{ 88, 2, 3, 4, 77});
|
||||
mem::@scatter_aligned(y, (int[<2>]){ 66, 77 }, (bool[<2>]) { false, true } , 4);
|
||||
assert(a == (int[5]){ 1, 2, 3, 4, 77});
|
||||
mem::scatter(y, (int[<2>]){ 88, 99 }, (bool[<2>]) { true, false });
|
||||
assert(a == (int[5]){ 88, 2, 3, 4, 77});
|
||||
}
|
||||
|
||||
@@ -2,27 +2,27 @@ import std;
|
||||
fn void masked_load() @test
|
||||
{
|
||||
long[<4>] val = { 1, 3, 5, 8 };
|
||||
long[<4>] res = mem::masked_load(&val, { true, false, true, false }, long[<4>] { 100, 200, 300, 400 });
|
||||
long[<4>] res = mem::masked_load(&val, { true, false, true, false }, (long[<4>]){ 100, 200, 300, 400 });
|
||||
assert(res == { 1, 200, 5, 400 });
|
||||
}
|
||||
|
||||
fn void masked_load_aligned() @test
|
||||
{
|
||||
long[<4>] val = { 1, 3, 5, 8 };
|
||||
long[<4>] res = mem::@masked_load_aligned(&val, { true, false, true, false }, long[<4>] { 100, 200, 300, 400 }, 8);
|
||||
long[<4>] res = mem::@masked_load_aligned(&val, { true, false, true, false }, (long[<4>]) { 100, 200, 300, 400 }, 8);
|
||||
assert(res == { 1, 200, 5, 400 });
|
||||
}
|
||||
|
||||
fn void masked_store() @test
|
||||
{
|
||||
long[<4>] val = { 1, 3, 5, 8 };
|
||||
mem::masked_store(&val, long[<4>] { 11, 22, 33, 44 }, { true, false, false, true });
|
||||
mem::masked_store(&val, (long[<4>]){11, 22, 33, 44}, { true, false, false, true });
|
||||
assert(val == { 11, 3, 5, 44 });
|
||||
}
|
||||
|
||||
fn void masked_store_aligned() @test
|
||||
{
|
||||
long[<4>] val = { 1, 3, 5, 8 };
|
||||
mem::@masked_store_aligned(&val, long[<4>] { 11, 22, 33, 44 }, { true, false, false, true }, 8);
|
||||
mem::@masked_store_aligned(&val, (long[<4>]){11, 22, 33, 44}, { true, false, false, true }, 8);
|
||||
assert(val == { 11, 3, 5, 44 });
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ fn void assign_slice()
|
||||
int[8] a;
|
||||
a[2..3] = { 1, 2 };
|
||||
a[5..7] = 5;
|
||||
assert(a == int[8]{ 0, 0, 1, 2, 0, 5, 5, 5});
|
||||
assert(a == (int[8]){ 0, 0, 1, 2, 0, 5, 5, 5});
|
||||
}
|
||||
@@ -4,8 +4,8 @@ fn void test_swizzle()
|
||||
{
|
||||
int[<4>] a = { 1, 2, 3, 4 };
|
||||
int[<4>] b = { 100, 1000, 10000, 100000 };
|
||||
assert($$swizzle(a, 0, 1, 1, 3) == int[<4>] { 1, 2, 2, 4 });
|
||||
assert($$swizzle2(a, b, 0, 1, 4, 6, 2) == int[<5>] { 1, 2, 100, 10000, 3 });
|
||||
assert($$swizzle(a, 0, 1, 1, 3) == (int[<4>]) { 1, 2, 2, 4 });
|
||||
assert($$swizzle2(a, b, 0, 1, 4, 6, 2) == (int[<5>]) { 1, 2, 100, 10000, 3 });
|
||||
}
|
||||
|
||||
fn void swizzle_builtin()
|
||||
|
||||
@@ -30,6 +30,6 @@ fn void pointer_add_sub_diff()
|
||||
assert(w == { -1, 2 });
|
||||
int*[<2>] zz = y - (y - yy);
|
||||
assert(zz[0] == &a[1] && zz[1] == &a[2]);
|
||||
int[?]*[<2>] g = int[2]*[<2>] { null, null };
|
||||
int[?]*[<?>] g2 = int[2]*[<2>] { null, null };
|
||||
int[?]*[<2>] g = (int[2]*[<2>]) { null, null };
|
||||
int[?]*[<?>] g2 = (int[2]*[<2>]) { null, null };
|
||||
}
|
||||
@@ -9,11 +9,11 @@ fn void vector_array_inferred()
|
||||
int[<?>] z = x;
|
||||
int[<?>] w = y;
|
||||
double[<2>] ww = x;
|
||||
assert((int[<2>])y == int[<2>]{ 4, 7});
|
||||
assert((int[<2>])y1 == int[<2>] { 4, 7 });
|
||||
assert((int[<2>])y2 == int[<2>] { 4, 7 });
|
||||
assert(z == int[<2>] { 4, 7 });
|
||||
assert(w == int[<2>] { 4, 7 });
|
||||
assert((int[<2>])y == { 4, 7});
|
||||
assert((int[<2>])y1 == { 4, 7 });
|
||||
assert((int[<2>])y2 == { 4, 7 });
|
||||
assert(z == { 4, 7 });
|
||||
assert(w == { 4, 7 });
|
||||
}
|
||||
|
||||
fn void vector_convert_slice()
|
||||
@@ -26,6 +26,6 @@ fn void vector_convert_slice()
|
||||
fn void vector_convert_bool()
|
||||
{
|
||||
bool[<2>] a = { true, false };
|
||||
assert(int[<2>] { -1, 0 } == (int[<2>])a);
|
||||
assert(float[<2>] { 1.0, 0 } == (float[<2>])a);
|
||||
assert({ -1, 0 } == (int[<2>])a);
|
||||
assert({ 1.0, 0 } == (float[<2>])a);
|
||||
}
|
||||
@@ -6,8 +6,8 @@ fn void test_int_mod() @test
|
||||
int[<2>] z = { 3, 5 };
|
||||
assert(y % z == { 1, 4 });
|
||||
assert(y / z == { 3, 19 });
|
||||
assert(int[<2>]{ 10, 99 } % int[<2>]{ 3, 5 } == { 1, 4 });
|
||||
assert(int[<2>]{ 10, 99 } / int[<2>]{ 3, 5 } == { 3, 19 });
|
||||
assert((int[<2>]){ 10, 99 } % { 3, 5 } == { 1, 4 });
|
||||
assert((int[<2>]){ 10, 99 } / { 3, 5 } == { 3, 19 });
|
||||
}
|
||||
|
||||
fn void test_conv() @test
|
||||
@@ -26,7 +26,7 @@ fn void test_conv() @test
|
||||
bool[<2>] b = { true, false };
|
||||
int[<2>] gh = b;
|
||||
assert(gh == { -1, 0 });
|
||||
var $k = bool[<2>] { true, false };
|
||||
var $k = (bool[<2>]){ true, false };
|
||||
var $gh = (int[<2>])$k;
|
||||
$assert $gh[0] == -1;
|
||||
var $gh2 = (char[<2>])$gh;
|
||||
|
||||
@@ -37,7 +37,7 @@ fn void set_get()
|
||||
assert(!x);
|
||||
}
|
||||
}
|
||||
assert(found.array_view() == usz[]{0, 2000});
|
||||
assert(found.array_view() == (usz[]){0, 2000});
|
||||
|
||||
bs.unset(0);
|
||||
assert(!bs.get(0));
|
||||
@@ -81,7 +81,7 @@ fn void growable_set_get()
|
||||
assert(!x, "Should not get here");
|
||||
}
|
||||
}
|
||||
assert(found.array_view() == usz[]{0, 2000}, "Array view should hold 2");
|
||||
assert(found.array_view() == (usz[]){0, 2000}, "Array view should hold 2");
|
||||
|
||||
bs.unset(0);
|
||||
assert(!bs.get(0), "Get should be false");
|
||||
|
||||
@@ -12,25 +12,25 @@ fn void delete_contains_index()
|
||||
assert(test.contains(2));
|
||||
assert(!test.contains(0));
|
||||
assert(!test.contains(3));
|
||||
assert(test.array_view() == int[]{ 1, 2 });
|
||||
assert(test.array_view() == (int[]){ 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[]{ 1, 2, 3 });
|
||||
assert(test.array_view() == (int[]){ 1, 2, 3 });
|
||||
assert(test.contains(3));
|
||||
test[0] = 10;
|
||||
assert(test.contains(10));
|
||||
test.remove_item(10);
|
||||
assert(test.array_view() == int[]{ 2, 3 });
|
||||
assert(test.array_view() == (int[]){ 2, 3 });
|
||||
assert(!test.contains(1));
|
||||
assert(test.contains(2));
|
||||
assert(test.len() == 2);
|
||||
test.push(0);
|
||||
test.insert_at(0, 0);
|
||||
assert(test.array_view() == int[]{ 0, 2, 3, 0 });
|
||||
assert(test.array_view() == (int[]){ 0, 2, 3, 0 });
|
||||
assert(test.index_of(0)!! == 0);
|
||||
assert(test.rindex_of(0)!! == 3);
|
||||
test.remove_item(0);
|
||||
assert(test.len() == 2);
|
||||
assert(test.array_view() == int[]{ 2, 3 });
|
||||
assert(test.array_view() == (int[]){ 2, 3 });
|
||||
}
|
||||
|
||||
fn void compact()
|
||||
@@ -52,13 +52,13 @@ fn void reverse()
|
||||
test.reverse();
|
||||
test.add_array({ 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[] { 1, 2, 3});
|
||||
assert(test.array_view() == (int[]) { 1, 2, 3});
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 3, 2, 1 });
|
||||
assert(test.array_view() == (int[]) { 3, 2, 1 });
|
||||
test.push(10);
|
||||
assert(test.array_view() == int[] { 3, 2, 1, 10 });
|
||||
assert(test.array_view() == (int[]) { 3, 2, 1, 10 });
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 10, 1, 2, 3 });
|
||||
assert(test.array_view() == (int[]) { 10, 1, 2, 3 });
|
||||
}
|
||||
|
||||
fn void remove_if()
|
||||
@@ -69,13 +69,13 @@ fn void remove_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_if(&filter);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == (int[]){1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_if(&select);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
|
||||
@@ -87,13 +87,13 @@ fn void remove_using_test()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == (int[]){1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_if()
|
||||
@@ -104,13 +104,13 @@ fn void retain_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.retain_if(&select);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == (int[]){1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.retain_if(&filter);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_using_test()
|
||||
@@ -121,13 +121,13 @@ fn void retain_using_test()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == (int[]){1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
module elastic_array_test;
|
||||
|
||||
@@ -31,25 +31,25 @@ fn void delete_contains_index()
|
||||
assert(test.contains(2));
|
||||
assert(!test.contains(0));
|
||||
assert(!test.contains(3));
|
||||
assert(test.array_view() == int[]{ 1, 2 });
|
||||
assert(test.array_view() == { 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[]{ 1, 2, 3 });
|
||||
assert(test.array_view() == { 1, 2, 3 });
|
||||
assert(test.contains(3));
|
||||
test[0] = 10;
|
||||
assert(test.contains(10));
|
||||
test.remove_item(10);
|
||||
assert(test.array_view() == int[]{ 2, 3 });
|
||||
assert(test.array_view() == { 2, 3 });
|
||||
assert(!test.contains(1));
|
||||
assert(test.contains(2));
|
||||
assert(test.len() == 2);
|
||||
test.push(0);
|
||||
test.insert_at(0, 0);
|
||||
assert(test.array_view() == int[]{ 0, 2, 3, 0 });
|
||||
assert(test.array_view() == { 0, 2, 3, 0 });
|
||||
assert(test.index_of(0)!! == 0);
|
||||
assert(test.rindex_of(0)!! == 3);
|
||||
test.remove_item(0);
|
||||
assert(test.len() == 2);
|
||||
assert(test.array_view() == int[]{ 2, 3 });
|
||||
assert(test.array_view() == { 2, 3 });
|
||||
}
|
||||
|
||||
fn void compact()
|
||||
@@ -74,13 +74,13 @@ fn void reverse()
|
||||
test.reverse();
|
||||
test.add_array({ 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[] { 1, 2, 3});
|
||||
assert(test.array_view() == { 1, 2, 3});
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 3, 2, 1 });
|
||||
assert(test.array_view() == { 3, 2, 1 });
|
||||
test.push(10);
|
||||
assert(test.array_view() == int[] { 3, 2, 1, 10 });
|
||||
assert(test.array_view() == { 3, 2, 1, 10 });
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 10, 1, 2, 3 });
|
||||
assert(test.array_view() == { 10, 1, 2, 3 });
|
||||
}
|
||||
|
||||
fn void remove_if()
|
||||
@@ -92,13 +92,13 @@ fn void remove_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_if(&filter);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == {1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_if(&select);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
fn void init_with_array()
|
||||
@@ -127,13 +127,13 @@ fn void remove_using_test()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == {1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_if()
|
||||
@@ -145,13 +145,13 @@ fn void retain_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.retain_if(&select);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == {1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.retain_if(&filter);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_using_test()
|
||||
@@ -163,13 +163,13 @@ fn void retain_using_test()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == {1, 2});
|
||||
|
||||
test.clear();
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
|
||||
assert(removed == 2);
|
||||
assert(test.array_view() == int[]{11, 10, 20});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
module list_test;
|
||||
|
||||
@@ -24,9 +24,9 @@ fn void concat()
|
||||
free(array::concat_new(a, a));
|
||||
free(array::concat_new(a[..], a[..]));
|
||||
free(array::concat_new(a[:0], a[:0]));
|
||||
free(array::concat_new(int[2] { 1, 2 }, a[:0]));
|
||||
free(array::concat_new(a[:0], int[2] { 1, 2 }));
|
||||
free(array::concat_new((int[2]) { 1, 2 }, a[:0]));
|
||||
free(array::concat_new(a[:0], (int[2]) { 1, 2 }));
|
||||
int[] c = array::concat_new(a[1..2], a);
|
||||
defer free(c);
|
||||
assert (c == int[]{ 2, 3, 1, 2, 3 });
|
||||
assert (c == (int[]){ 2, 3, 1, 2, 3 });
|
||||
}
|
||||
|
||||
@@ -62,16 +62,16 @@ fn void test_prefetch()
|
||||
|
||||
fn void test_hash()
|
||||
{
|
||||
char{}.hash();
|
||||
ichar{}.hash();
|
||||
short{}.hash();
|
||||
ushort{}.hash();
|
||||
int{}.hash();
|
||||
uint{}.hash();
|
||||
long{}.hash();
|
||||
ulong{}.hash();
|
||||
int128{}.hash();
|
||||
uint128{}.hash();
|
||||
(char){}.hash();
|
||||
(ichar){}.hash();
|
||||
(short){}.hash();
|
||||
(ushort){}.hash();
|
||||
(int){}.hash();
|
||||
(uint){}.hash();
|
||||
(long){}.hash();
|
||||
(ulong){}.hash();
|
||||
(int128){}.hash();
|
||||
(uint128){}.hash();
|
||||
String x = "abc";
|
||||
char[] y = "abc";
|
||||
assert(x.hash() == y.hash());
|
||||
|
||||
@@ -10,7 +10,7 @@ fn usz! Foo.to_format(&self, Formatter *f) @dynamic
|
||||
|
||||
fn void test_ref() @test
|
||||
{
|
||||
Foo* f = &&Foo{ 8 };
|
||||
Foo* f = &&(Foo){ 8 };
|
||||
Foo* f0 = null;
|
||||
int* a = (void*)(uptr)0x40;
|
||||
int* b = null;
|
||||
|
||||
@@ -36,7 +36,7 @@ fn void csv_each_row()
|
||||
String[] want = t.want;
|
||||
|
||||
CsvReader r;
|
||||
r.init(ByteReader{}.init(t.input), t.sep);
|
||||
r.init((ByteReader){}.init(t.input), t.sep);
|
||||
r.@each_row(; String[] row) {
|
||||
foreach (i, s : row) {
|
||||
assert(want.len > 0,
|
||||
@@ -58,7 +58,7 @@ fn void csv_row()
|
||||
","
|
||||
};
|
||||
CsvReader r;
|
||||
r.init(ByteReader{}.init(t.input), t.sep);
|
||||
r.init((ByteReader){}.init(t.input), t.sep);
|
||||
CsvRow row = r.read_temp_row()!!;
|
||||
assert(row.list.len == t.want.len, "not enough records found");
|
||||
for (int i = 0; i < row.list.len; i++) {
|
||||
|
||||
@@ -8,7 +8,7 @@ fn void test_multiwriter()
|
||||
defer mw.free();
|
||||
|
||||
String want = "foobar";
|
||||
io::copy_to(ByteReader{}.init(want), &mw)!!;
|
||||
io::copy_to((ByteReader){}.init(want), &mw)!!;
|
||||
|
||||
assert(w1.str_view() == want,
|
||||
"invalid write; got: %s, want: %s", w1.str_view(), want);
|
||||
|
||||
@@ -5,7 +5,7 @@ fn void test_teereader()
|
||||
String want = "foobar";
|
||||
|
||||
ByteWriter w;
|
||||
TeeReader r = tee_reader(ByteReader{}.init(want), w.temp_init());
|
||||
TeeReader r = tee_reader((ByteReader){}.init(want), w.temp_init());
|
||||
|
||||
char[16] buf;
|
||||
usz n = r.read(buf[..])!!;
|
||||
|
||||
@@ -11,9 +11,9 @@ fn void test_abs() @test
|
||||
assert(math::abs(z) == 21.0f);
|
||||
$assert @typeis(math::abs(z), float);
|
||||
int[<3>] xx = { -1, -1000, 1000 };
|
||||
assert(math::abs(xx) == int[<3>] { 1, 1000, 1000 });
|
||||
assert(math::abs(xx) == (int[<3>]) { 1, 1000, 1000 });
|
||||
double[<3>] yy = { -1, -0.5, 1000 };
|
||||
assert(math::abs(yy) == double[<3>] { 1, 0.5, 1000 });
|
||||
assert(math::abs(yy) == (double[<3>]) { 1, 0.5, 1000 });
|
||||
}
|
||||
|
||||
fn void test_acos() @test
|
||||
@@ -269,7 +269,7 @@ fn void test_ceil() @test
|
||||
assert(math::ceil(f) == 0.0f);
|
||||
$assert @typeis(math::ceil(f), float);
|
||||
double[<5>] vec = { -123.1, 123.1, 0.1, -0.9, 0 };
|
||||
assert(math::ceil(vec) == double[<5>] { -123, 124, 1, 0, 0 });
|
||||
assert(math::ceil(vec) == (double[<5>]) { -123, 124, 1, 0, 0 });
|
||||
}
|
||||
|
||||
fn void test_cos() @test
|
||||
@@ -351,7 +351,7 @@ fn void test_floor() @test
|
||||
assert(math::floor(f) == -1.0f);
|
||||
$assert @typeis(math::floor(f), float);
|
||||
double[<5>] vec = { -123.1, 123.1, 0.9, -0.1, 0 };
|
||||
assert(math::floor(vec) == double[<5>] { -124, 123, 0, -1, 0 });
|
||||
assert(math::floor(vec) == (double[<5>]) { -124, 123, 0, -1, 0 });
|
||||
}
|
||||
|
||||
fn void test_log() @test
|
||||
@@ -536,7 +536,7 @@ fn void test_trunc() @test
|
||||
assert(math::trunc(f) == -0.0f);
|
||||
$assert @typeis(math::trunc(f), float);
|
||||
double[<5>] vec = { -123.9, 123.9, 0.9, -0.9, 0 };
|
||||
assert(math::trunc(vec) == double[<5>] { -123, 123, 0, 0, 0 });
|
||||
assert(math::trunc(vec) == (double[<5>]) { -123, 123, 0, 0, 0 });
|
||||
}
|
||||
|
||||
fn void test_round_decimals() @test
|
||||
@@ -579,14 +579,14 @@ fn void test_muldiv()
|
||||
assert(h.muldiv(2_000_000_000_000u64, 1_000_000_000u64) == 2_000_000_000_000_000u64);
|
||||
|
||||
char[<4>] i = {20, 30, 40, 50};
|
||||
assert(i.muldiv(12,10) == char[<4>] {24, 36, 48, 60});
|
||||
assert(i.muldiv(char[<4>]{11, 12, 13, 14}, char[<4>]{10,10,10,10}) == char[<4>]{22, 36, 52, 70});
|
||||
assert(i.muldiv(12,10) == (char[<4>]) {24, 36, 48, 60});
|
||||
assert(i.muldiv((char[<4>]){11, 12, 13, 14}, (char[<4>]){10,10,10,10}) == (char[<4>]){22, 36, 52, 70});
|
||||
|
||||
long[<4>] j = {1_000_000_000_000i64, 2_000_000_000_000i64, 3_000_000_000_000i64, 4_000_000_000_000i64};
|
||||
assert(j.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == long[<4>]{2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64});
|
||||
assert(j.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == (long[<4>]){2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64});
|
||||
|
||||
ichar[<4>] k = {20, 30, 40, 50};
|
||||
assert(k.muldiv(20,-10) == ichar[<4>]{-40,-60,-80,-100});
|
||||
assert(k.muldiv(20,-10) == (ichar[<4>]){-40,-60,-80,-100});
|
||||
}
|
||||
|
||||
fn void test_gcd() @test
|
||||
|
||||
@@ -12,36 +12,36 @@ def ComplexType = Complex(<ElementType>);
|
||||
fn void complex_mul_imaginary()
|
||||
{
|
||||
ComplexType i = complex::IMAGINARY(<ElementType>);
|
||||
assert(i.mul(i).equals(ComplexType{-1, 0}));
|
||||
assert(i.mul(i).mul(i).equals(ComplexType{0, -1}));
|
||||
assert(i.mul(i).equals((ComplexType){-1, 0}));
|
||||
assert(i.mul(i).mul(i).equals((ComplexType){0, -1}));
|
||||
}
|
||||
|
||||
fn void complex_add()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
ComplexType b = {1, 2};
|
||||
assert(a.add(b).equals(ComplexType{4, 6}));
|
||||
assert(a.add_each(1).equals(ComplexType{4, 5}));
|
||||
assert(a.add(b).equals((ComplexType){4, 6}));
|
||||
assert(a.add_each(1).equals((ComplexType){4, 5}));
|
||||
}
|
||||
|
||||
fn void complex_sub()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
ComplexType b = {1, 2};
|
||||
assert(a.sub(b).equals(ComplexType{2, 2}));
|
||||
assert(a.sub_each(1).equals(ComplexType{2, 3}));
|
||||
assert(a.sub(b).equals((ComplexType){2, 2}));
|
||||
assert(a.sub_each(1).equals((ComplexType){2, 3}));
|
||||
}
|
||||
|
||||
fn void complex_scale()
|
||||
{
|
||||
ComplexType a = {2, 1};
|
||||
assert(a.scale(2).equals(ComplexType{4, 2}));
|
||||
assert(a.scale(2).equals((ComplexType){4, 2}));
|
||||
}
|
||||
|
||||
fn void complex_conjugate()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
assert(a.conjugate().equals(ComplexType{3, -4}));
|
||||
assert(a.conjugate().equals((ComplexType){3, -4}));
|
||||
}
|
||||
|
||||
fn void complex_inverse() @if(types::is_float(ElementType))
|
||||
@@ -54,6 +54,6 @@ fn void complex_div() @if(types::is_float(ElementType))
|
||||
{
|
||||
ComplexType a = {2, 5};
|
||||
ComplexType b = {4, -1};
|
||||
assert(a.div(b).equals(ComplexType{3.0/17.0, 22.0/17.0}));
|
||||
assert(a.div(b).equals((ComplexType){3.0/17.0, 22.0/17.0}));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ fn void test_mat4()
|
||||
Matrix4 calc = mat.mul(mat2);
|
||||
assert(calc.m == mat.m);
|
||||
|
||||
Matrix4 translated = mat.translate(Vec3{0.0, 0.0, 0.0});
|
||||
Matrix4 translated = mat.translate({0.0, 0.0, 0.0});
|
||||
assert(translated.m == mat.m);
|
||||
};
|
||||
|
||||
@@ -117,6 +117,6 @@ fn void test_mat2_inverse()
|
||||
|
||||
fn void test_vec3()
|
||||
{
|
||||
Vec3 cross = Vec3{2,3,4}.cross(Vec3{5,6,7});
|
||||
assert(cross == Vec3{-3,6,-3});
|
||||
Vec3 cross = (Vec3){2,3,4}.cross({5,6,7});
|
||||
assert(cross == {-3,6,-3});
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ fn void test()
|
||||
0.000000, 0.000000, 0.000000, 1.000000
|
||||
};
|
||||
|
||||
Matrix4 rotation = Quaternion {0.5, 0.5, 0.5, 1}.to_matrix();
|
||||
Matrix4f rotation_f = Quaternionf {0.5, 0.5, 0.5, 1}.to_matrixf();
|
||||
Matrix4 rotation = (Quaternion) {0.5, 0.5, 0.5, 1}.to_matrix();
|
||||
Matrix4f rotation_f = (Quaternionf) {0.5, 0.5, 0.5, 1}.to_matrixf();
|
||||
|
||||
assert(math::round_to_decimals((double[<16>])result.m, 2) == math::round_to_decimals((double[<16>])rotation.m, 2));
|
||||
assert(math::round_to_decimals((float[<16>])result.m, 2) == math::round_to_decimals((float[<16>])rotation_f.m, 2));
|
||||
|
||||
@@ -12,190 +12,66 @@ struct EncodeTest
|
||||
}
|
||||
|
||||
EncodeTest[?] decode_with_error_tests @local = {
|
||||
{
|
||||
"",
|
||||
"",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"1%41",
|
||||
"1A",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"1%41%42%43",
|
||||
"1ABC",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%4a",
|
||||
"J",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%6F",
|
||||
"o",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%a",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%1",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"123%45%6",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%zzzzz",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"a+b",
|
||||
"a b",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"a%20b",
|
||||
"a b",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{ "", "", {}, QUERY, },
|
||||
{ "abc", "abc", {}, QUERY, },
|
||||
{ "1%41", "1A", {}, QUERY, },
|
||||
{ "1%41%42%43", "1ABC", {}, QUERY, },
|
||||
{ "%4a", "J", {}, QUERY, },
|
||||
{ "%6F", "o", {}, QUERY, },
|
||||
{ "%", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "%a", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "%1", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "123%45%6", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "%zzzzz", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "a+b", "a b", {}, QUERY, },
|
||||
{ "a%20b", "a b", {}, QUERY, },
|
||||
};
|
||||
|
||||
fn void test_decoding_with_error()
|
||||
fn void test_decoding_with_error() => @pool()
|
||||
{
|
||||
String! actual;
|
||||
@pool() {
|
||||
foreach (test: decode_with_error_tests)
|
||||
foreach (test: decode_with_error_tests)
|
||||
{
|
||||
String! actual = url::temp_decode(test.in, test.mode);
|
||||
if (catch excuse = actual)
|
||||
{
|
||||
actual = url::temp_decode(test.in, test.mode);
|
||||
if (catch excuse = actual)
|
||||
{
|
||||
assert(excuse == test.err, "unescape(%s, %s); "
|
||||
assert(excuse == test.err, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, excuse, test.err);
|
||||
continue;
|
||||
}
|
||||
assert(actual == test.out, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
assert(actual == test.out, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
}
|
||||
}
|
||||
|
||||
EncodeTest[?] encode_tests @local = {
|
||||
{
|
||||
"",
|
||||
"",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
{ "", "", {}, PATH, },
|
||||
{ "abc", "abc", {}, PATH, },
|
||||
{ "abc+def", "abc+def", {}, PATH, },
|
||||
{ "a/b", "a/b", {}, PATH, },
|
||||
{ "one two", "one%20two", {}, PATH, },
|
||||
{ "10%", "10%25", {}, PATH, },
|
||||
{ "", "", {}, QUERY, },
|
||||
{ "abc", "abc", {}, QUERY, },
|
||||
{ "one two", "one+two", {}, QUERY, },
|
||||
{ "10%", "10%25", {}, QUERY, },
|
||||
{ " ?&=#+%!<>#\"{}|\\^[]`☺\t:/@$'()*,;",
|
||||
"+%3F%26%3D%23%2B%25%21%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%E2%98%BA%09%3A%2F%40%24%27%28%29%2A%2C%3B",
|
||||
{}, QUERY,
|
||||
},
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"abc+def",
|
||||
"abc+def",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"a/b",
|
||||
"a/b",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"one two",
|
||||
"one%20two",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"10%",
|
||||
"10%25",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"",
|
||||
"",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"one two",
|
||||
"one+two",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"10%",
|
||||
"10%25",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
" ?&=#+%!<>#\"{}|\\^[]`☺\t:/@$'()*,;",
|
||||
"+%3F%26%3D%23%2B%25%21%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%E2%98%BA%09%3A%2F%40%24%27%28%29%2A%2C%3B",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
fn void test_percent_encode_and_decode()
|
||||
fn void test_percent_encode_and_decode() => @pool()
|
||||
{
|
||||
String actual;
|
||||
@pool() {
|
||||
foreach (test: encode_tests)
|
||||
{
|
||||
actual = url::temp_encode(test.in, test.mode);
|
||||
assert(actual == test.out, "escape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
foreach (test: encode_tests)
|
||||
{
|
||||
String actual = url::temp_encode(test.in, test.mode);
|
||||
assert(actual == test.out, "escape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
|
||||
actual = url::temp_decode(test.out, test.mode)!!;
|
||||
assert(actual == test.in, "unescape(%s, %s); "
|
||||
actual = url::temp_decode(test.out, test.mode)!!;
|
||||
assert(actual == test.in, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.out, test.mode, actual, test.in);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
struct ShouldEncodeTest
|
||||
@@ -206,60 +82,59 @@ struct ShouldEncodeTest
|
||||
}
|
||||
|
||||
ShouldEncodeTest[?] should_encode_tests = {
|
||||
{'a', UrlEncodingMode.PATH, false},
|
||||
{'a', UrlEncodingMode.USERPASS, false},
|
||||
{'a', UrlEncodingMode.QUERY, false},
|
||||
{'a', UrlEncodingMode.FRAGMENT, false},
|
||||
{'a', UrlEncodingMode.HOST, false},
|
||||
{'z', UrlEncodingMode.PATH, false},
|
||||
{'A', UrlEncodingMode.PATH, false},
|
||||
{'Z', UrlEncodingMode.PATH, false},
|
||||
{'0', UrlEncodingMode.PATH, false},
|
||||
{'9', UrlEncodingMode.PATH, false},
|
||||
{'-', UrlEncodingMode.PATH, false},
|
||||
{'-', UrlEncodingMode.USERPASS, false},
|
||||
{'-', UrlEncodingMode.QUERY, false},
|
||||
{'-', UrlEncodingMode.FRAGMENT, false},
|
||||
{'.', UrlEncodingMode.PATH, false},
|
||||
{'_', UrlEncodingMode.PATH, false},
|
||||
{'~', UrlEncodingMode.PATH, false},
|
||||
{'a', PATH, false},
|
||||
{'a', USERPASS, false},
|
||||
{'a', QUERY, false},
|
||||
{'a', FRAGMENT, false},
|
||||
{'a', HOST, false},
|
||||
{'z', PATH, false},
|
||||
{'A', PATH, false},
|
||||
{'Z', PATH, false},
|
||||
{'0', PATH, false},
|
||||
{'9', PATH, false},
|
||||
{'-', PATH, false},
|
||||
{'-', USERPASS, false},
|
||||
{'-', QUERY, false},
|
||||
{'-', FRAGMENT, false},
|
||||
{'.', PATH, false},
|
||||
{'_', PATH, false},
|
||||
{'~', PATH, false},
|
||||
|
||||
{'/', UrlEncodingMode.USERPASS, true},
|
||||
{'?', UrlEncodingMode.USERPASS, true},
|
||||
{'@', UrlEncodingMode.USERPASS, true},
|
||||
{'$', UrlEncodingMode.USERPASS, false},
|
||||
{'&', UrlEncodingMode.USERPASS, false},
|
||||
{'+', UrlEncodingMode.USERPASS, false},
|
||||
{',', UrlEncodingMode.USERPASS, false},
|
||||
{';', UrlEncodingMode.USERPASS, false},
|
||||
{'=', UrlEncodingMode.USERPASS, false},
|
||||
{'/', USERPASS, true},
|
||||
{'?', USERPASS, true},
|
||||
{'@', USERPASS, true},
|
||||
{'$', USERPASS, false},
|
||||
{'&', USERPASS, false},
|
||||
{'+', USERPASS, false},
|
||||
{',', USERPASS, false},
|
||||
{';', USERPASS, false},
|
||||
{'=', USERPASS, false},
|
||||
|
||||
{'!', UrlEncodingMode.HOST, false},
|
||||
{'$', UrlEncodingMode.HOST, false},
|
||||
{'&', UrlEncodingMode.HOST, false},
|
||||
{'\'', UrlEncodingMode.HOST, false},
|
||||
{'(', UrlEncodingMode.HOST, false},
|
||||
{')', UrlEncodingMode.HOST, false},
|
||||
{'*', UrlEncodingMode.HOST, false},
|
||||
{'+', UrlEncodingMode.HOST, false},
|
||||
{',', UrlEncodingMode.HOST, false},
|
||||
{';', UrlEncodingMode.HOST, false},
|
||||
{'=', UrlEncodingMode.HOST, false},
|
||||
{'0', UrlEncodingMode.HOST, false},
|
||||
{'9', UrlEncodingMode.HOST, false},
|
||||
{'A', UrlEncodingMode.HOST, false},
|
||||
{'z', UrlEncodingMode.HOST, false},
|
||||
{'_', UrlEncodingMode.HOST, false},
|
||||
{'-', UrlEncodingMode.HOST, false},
|
||||
{'.', UrlEncodingMode.HOST, false},
|
||||
{'!', HOST, false},
|
||||
{'$', HOST, false},
|
||||
{'&', HOST, false},
|
||||
{'\'',HOST, false},
|
||||
{'(', HOST, false},
|
||||
{')', HOST, false},
|
||||
{'*', HOST, false},
|
||||
{'+', HOST, false},
|
||||
{',', HOST, false},
|
||||
{';', HOST, false},
|
||||
{'=', HOST, false},
|
||||
{'0', HOST, false},
|
||||
{'9', HOST, false},
|
||||
{'A', HOST, false},
|
||||
{'z', HOST, false},
|
||||
{'_', HOST, false},
|
||||
{'-', HOST, false},
|
||||
{'.', HOST, false},
|
||||
};
|
||||
|
||||
fn void test_should_encode()
|
||||
{
|
||||
bool actual;
|
||||
foreach (test: should_encode_tests)
|
||||
foreach (test : should_encode_tests)
|
||||
{
|
||||
actual = url::should_encode(test.in, test.mode);
|
||||
bool actual = url::should_encode(test.in, test.mode);
|
||||
assert(actual == test.escape, "should_encode(%c, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.escape);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user