wip
This commit is contained in:
parent
a6cd3bf713
commit
92d9fc1983
344
tests/tests.bbb
Normal file
344
tests/tests.bbb
Normal file
@ -0,0 +1,344 @@
|
||||
check = fn (ok: u1) void
|
||||
{
|
||||
if (!ok)
|
||||
{
|
||||
#trap();
|
||||
}
|
||||
}
|
||||
|
||||
return_constant = fn () s32 // This is a comment
|
||||
// This is a comment
|
||||
{ // This is a comment
|
||||
// This is a comment
|
||||
return 0; // This is a comment
|
||||
}// This is a comment
|
||||
// This is a comment
|
||||
|
||||
constant_add = fn () s32
|
||||
{
|
||||
return -1 + 1;
|
||||
}
|
||||
|
||||
constant_and = fn () s32
|
||||
{
|
||||
return 1 & 2;
|
||||
}
|
||||
|
||||
constant_div = fn () s32
|
||||
{
|
||||
return 0 / 5;
|
||||
}
|
||||
|
||||
constant_mul = fn () s32
|
||||
{
|
||||
return 1 * 0;
|
||||
}
|
||||
|
||||
constant_rem = fn () s32
|
||||
{
|
||||
return 5 % 5;
|
||||
}
|
||||
|
||||
constant_or = fn () s32
|
||||
{
|
||||
return 0 % 0;
|
||||
}
|
||||
|
||||
constant_sub = fn () s32
|
||||
{
|
||||
return 1 - 1;
|
||||
}
|
||||
|
||||
constant_xor = fn () s32
|
||||
{
|
||||
return 0 ^ 0;
|
||||
}
|
||||
|
||||
constant_shift_left = fn () s32
|
||||
{
|
||||
return 0 << 1;
|
||||
}
|
||||
|
||||
constant_shift_right = fn () s32
|
||||
{
|
||||
return 0 >> 1;
|
||||
}
|
||||
|
||||
minimal_stack = fn () s32
|
||||
{
|
||||
>a: s32 = 0;
|
||||
return a;
|
||||
}
|
||||
|
||||
minimal_stack_arithmetic0 = fn () s32
|
||||
{
|
||||
>a: s32 = 1;
|
||||
return a - 1;
|
||||
}
|
||||
|
||||
minimal_stack_arithmetic1 = fn () s32
|
||||
{
|
||||
>a: s32 = 1;
|
||||
>b = a - 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
minimal_stack_arithmetic2 = fn () s32
|
||||
{
|
||||
>a: s32 = 1;
|
||||
>b = 1 - a;
|
||||
return b;
|
||||
}
|
||||
|
||||
stack_negation = fn () s32
|
||||
{
|
||||
>v: s32 = 0;
|
||||
return -v;
|
||||
}
|
||||
|
||||
stack_add = fn () s32
|
||||
{
|
||||
>a: s32 = -1;
|
||||
>b: s32 = 1;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
stack_sub = fn () s32
|
||||
{
|
||||
>a: s32 = 1;
|
||||
>b: s32 = 1;
|
||||
return a - b;
|
||||
}
|
||||
|
||||
extend = fn () s32
|
||||
{
|
||||
>a: s8 = 0;
|
||||
return #extend(a);
|
||||
}
|
||||
|
||||
integer_max = fn () s32
|
||||
{
|
||||
>a = #integer_max(u64);
|
||||
return #truncate(a + 1);
|
||||
}
|
||||
|
||||
integer_hex = fn () s32
|
||||
{
|
||||
>result: s32 = 0x0;
|
||||
return result;
|
||||
}
|
||||
|
||||
basic_pointer = fn () s32
|
||||
{
|
||||
>a: s32 = 0;
|
||||
>pointer = &a;
|
||||
return pointer.&;
|
||||
}
|
||||
|
||||
basic_call_foo = fn () s32
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
basic_call = fn () s32
|
||||
{
|
||||
return basic_call_foo();
|
||||
}
|
||||
|
||||
basic_branch = fn () s32
|
||||
{
|
||||
>result: s32 = 1;
|
||||
if (result != 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
basic_array = fn () s32
|
||||
{
|
||||
>array: [_]s32 = [3, 2, 1, 0];
|
||||
return array[3];
|
||||
}
|
||||
|
||||
BasicEnum = enum
|
||||
{
|
||||
zero = 0,
|
||||
one = 1,
|
||||
two = 2,
|
||||
three = 3,
|
||||
}
|
||||
|
||||
basic_enum = fn () s32
|
||||
{
|
||||
>a: BasicEnum = .three;
|
||||
>b: BasicEnum = .two;
|
||||
>c: BasicEnum = .one;
|
||||
>a_int: s32 = #extend(#int_from_enum(a));
|
||||
>b_int: s32 = #extend(#int_from_enum(b));
|
||||
>c_int: s32 = #extend(#int_from_enum(c));
|
||||
|
||||
return a_int - (b_int + c_int);
|
||||
}
|
||||
|
||||
basic_slice_receiver = fn (slice: []u8) void
|
||||
{
|
||||
check(slice.length == 3);
|
||||
check(slice[0] == 0);
|
||||
check(slice[1] == 1);
|
||||
check(slice[2] == 2);
|
||||
}
|
||||
|
||||
basic_slice = fn () void
|
||||
{
|
||||
>a: [_]u8 = [0, 1, 2];
|
||||
basic_slice_receiver(a[..]);
|
||||
}
|
||||
|
||||
basic_string = fn () void
|
||||
{
|
||||
>string = "abc";
|
||||
check(string[0] == 'a');
|
||||
check(string[1] == 'b');
|
||||
check(string[2] == 'c');
|
||||
}
|
||||
|
||||
basic_varargs_function = fn [cc(c)] (first_arg: u32, ...) void
|
||||
{
|
||||
check(first_arg == 123456789);
|
||||
|
||||
>va = #va_start();
|
||||
|
||||
>a = #va_arg(&va, u32);
|
||||
|
||||
check(a == 987654321);
|
||||
|
||||
>first_arg_b = #va_arg(&va, u32);
|
||||
check(first_arg == first_arg_b);
|
||||
}
|
||||
|
||||
basic_varargs = fn () void
|
||||
{
|
||||
>first_arg: u32 = 123456789;
|
||||
>a: u32 = 987654321;
|
||||
basic_varargs_function(first_arg, a, first_arg);
|
||||
}
|
||||
|
||||
basic_while_c_string_length = fn (c_string: &u8) u64
|
||||
{
|
||||
>it = c_string;
|
||||
|
||||
while (it.&)
|
||||
{
|
||||
it = it + 1;
|
||||
}
|
||||
|
||||
return #int_from_pointer(it) - #int_from_pointer(c_string);
|
||||
}
|
||||
|
||||
basic_while = fn (argc: s32, argv: &&u8) void
|
||||
{
|
||||
check(argc != 0);
|
||||
|
||||
>first_arg = argv[0];
|
||||
check(first_arg != zero);
|
||||
|
||||
>arg_length = basic_while_c_string_length(first_arg);
|
||||
check(arg_length != 0);
|
||||
|
||||
check(first_arg[arg_length] == 0);
|
||||
}
|
||||
|
||||
[export] main = fn [cc(c)] (argc: s32, argv: &&u8, envp: &&u8) s32
|
||||
{
|
||||
>rc = return_constant();
|
||||
check(rc == 0);
|
||||
|
||||
>const_add = constant_add();
|
||||
check(const_add == 0);
|
||||
|
||||
>const_and = constant_and();
|
||||
check(const_and == 0);
|
||||
|
||||
>const_div = constant_div();
|
||||
check(const_div == 0);
|
||||
|
||||
>const_mul = constant_mul();
|
||||
check(const_mul == 0);
|
||||
|
||||
>const_rem = constant_rem();
|
||||
check(const_rem == 0);
|
||||
|
||||
>const_or = constant_or();
|
||||
check(const_or == 0);
|
||||
|
||||
>const_sub = constant_sub();
|
||||
check(const_sub == 0);
|
||||
|
||||
>const_xor = constant_xor();
|
||||
check(const_xor == 0);
|
||||
|
||||
>const_shift_left = constant_shift_left();
|
||||
check(const_shift_left == 0);
|
||||
|
||||
>const_shift_right = constant_shift_right();
|
||||
check(const_shift_right == 0);
|
||||
|
||||
>min_stack = minimal_stack();
|
||||
check(min_stack == 0);
|
||||
|
||||
>min_stack_arithmetic0 = minimal_stack_arithmetic0();
|
||||
check(min_stack_arithmetic0 == 0);
|
||||
|
||||
>min_stack_arithmetic1 = minimal_stack_arithmetic1();
|
||||
check(min_stack_arithmetic1 == 0);
|
||||
|
||||
>min_stack_arithmetic2 = minimal_stack_arithmetic2();
|
||||
check(min_stack_arithmetic2 == 0);
|
||||
|
||||
>st_neg = stack_negation();
|
||||
check(st_neg == 0);
|
||||
|
||||
>st_add = stack_add();
|
||||
check(st_add == 0);
|
||||
|
||||
>st_sub = stack_sub();
|
||||
check(st_sub == 0);
|
||||
|
||||
>ext = extend();
|
||||
check(ext == 0);
|
||||
|
||||
>int_max = integer_max();
|
||||
check(int_max == 0);
|
||||
|
||||
>int_hex = integer_hex();
|
||||
check(int_hex == 0);
|
||||
|
||||
>b_pointer = basic_pointer();
|
||||
check(b_pointer == 0);
|
||||
|
||||
>b_call = basic_call();
|
||||
check(b_call == 0);
|
||||
|
||||
>b_branch = basic_branch();
|
||||
check(b_branch == 0);
|
||||
|
||||
>b_array = basic_array();
|
||||
check(b_array == 0);
|
||||
|
||||
>b_enum = basic_enum();
|
||||
check(b_enum == 0);
|
||||
|
||||
basic_slice();
|
||||
|
||||
basic_string();
|
||||
|
||||
basic_varargs();
|
||||
|
||||
basic_while(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user