bloat-buster/tests/tests.bbb
2025-06-22 22:04:02 -06:00

174 lines
2.7 KiB
Plaintext

error = fn () noreturn
{
#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);
}
[export] main = fn [cc(c)] () s32
{
>rc = return_constant();
if (rc != 0) error();
>const_add = constant_add();
if (const_add != 0) error();
>const_and = constant_and();
if (const_and != 0) error();
>const_div = constant_div();
if (const_div != 0) error();
>const_mul = constant_mul();
if (const_mul != 0) error();
>const_rem = constant_rem();
if (const_rem != 0) error();
>const_or = constant_or();
if (const_or != 0) error();
>const_sub = constant_sub();
if (const_sub != 0) error();
>const_xor = constant_xor();
if (const_xor != 0) error();
>const_shift_left = constant_shift_left();
if (const_shift_left != 0) error();
>const_shift_right = constant_shift_right();
if (const_shift_right != 0) error();
>min_stack = minimal_stack();
if (min_stack != 0) error();
>min_stack_arithmetic0 = minimal_stack_arithmetic0();
if (min_stack_arithmetic0 != 0) error();
>min_stack_arithmetic1 = minimal_stack_arithmetic1();
if (min_stack_arithmetic1 != 0) error();
>min_stack_arithmetic2 = minimal_stack_arithmetic2();
if (min_stack_arithmetic2 != 0) error();
>st_neg = stack_negation();
if (st_neg != 0) error();
>st_add = stack_add();
if (st_add != 0) error();
>st_sub = stack_sub();
if (st_sub != 0) error();
return 0;
}