Else if and empty if
All checks were successful
CI / ci (ReleaseFast, ubuntu-latest) (pull_request) Successful in 2m3s
CI / ci (ReleaseSmall, ubuntu-latest) (pull_request) Successful in 2m3s
CI / ci (ReleaseSafe, ubuntu-latest) (pull_request) Successful in 2m12s
CI / ci (Debug, ubuntu-latest) (pull_request) Successful in 3m13s
CI / ci (ReleaseFast, ubuntu-latest) (push) Successful in 2m3s
CI / ci (ReleaseSmall, ubuntu-latest) (push) Successful in 2m2s
CI / ci (ReleaseSafe, ubuntu-latest) (push) Successful in 2m7s
CI / ci (Debug, ubuntu-latest) (push) Successful in 3m10s

This commit is contained in:
David Gonzalez Martin 2025-04-17 14:07:55 -06:00
parent d2e488edb1
commit 4dedaf3006
6 changed files with 795 additions and 685 deletions

File diff suppressed because it is too large Load Diff

View File

@ -231,6 +231,18 @@ CompilerCommand = enum
test, test,
} }
BuildMode = enum
{
debug_none,
debug_fast,
debug_size,
soft_optimize,
optimize_for_speed,
optimize_for_size,
aggressively_optimize_for_speed,
aggressively_optimize_for_size,
}
[export] main = fn [cc(c)] (argument_count: u32, argv: &&u8) s32 [export] main = fn [cc(c)] (argument_count: u32, argv: &&u8) s32
{ {
global_state_initialize(); global_state_initialize();
@ -242,7 +254,7 @@ CompilerCommand = enum
>command_string = c_string_to_slice(argv[1]); >command_string = c_string_to_slice(argv[1]);
> command_string_to_enum = #string_to_enum(CompilerCommand, command_string); >command_string_to_enum = #string_to_enum(CompilerCommand, command_string);
if (!command_string_to_enum.is_valid) if (!command_string_to_enum.is_valid)
{ {
return 1; return 1;
@ -253,6 +265,41 @@ CompilerCommand = enum
{ {
.compile => .compile =>
{ {
if (argument_count < 3)
{
return 1;
}
>build_mode: BuildMode = .debug_none;
>has_debug_info: u1 = 1;
if (argument_count >= 4)
{
>build_mode_string_to_enum = #string_to_enum(BuildMode, c_string_to_slice(argv[3]));
if (!build_mode_string_to_enum.is_valid)
{
return 1;
}
build_mode = build_mode_string_to_enum.enum_value;
}
if (argument_count >= 5)
{
>has_debug_info_string = c_string_to_slice(argv[4]);
if (string_equal(has_debug_info_string, "true"))
{
has_debug_info = 1;
}
else if (string_equal(has_debug_info_string, "false"))
{
has_debug_info = 0;
}
else
{
return 1;
}
}
>relative_file_path_pointer = argv[2]; >relative_file_path_pointer = argv[2];
if (!relative_file_path_pointer) if (!relative_file_path_pointer)
{ {

View File

@ -311,4 +311,7 @@ const names = &[_][]const u8{
"c_abi", "c_abi",
"string_to_enum", "string_to_enum",
"abi_enum_bool", "abi_enum_bool",
"empty_if",
"else_if",
"else_if_complicated",
}; };

16
tests/else_if.bbb Normal file
View File

@ -0,0 +1,16 @@
[export] main = fn [cc(c)] () s32
{
>result: s32 = 0;
if (result == 1)
{
return 1;
}
else if (result == 0)
{
return 0;
}
else
{
return 5;
}
}

View File

@ -0,0 +1,37 @@
Foo = enum
{
a,b,c,
}
[export] main = fn [cc(c)] (argument_count: u32) s32
{
>result: s32 = 0;
>foo: Foo = .b;
switch (foo)
{
.b =>
{
if (argument_count != 0)
{
>a: s32 = 1;
if (result == 1)
{
}
else if (result == 0)
{
return 0;
}
else
{
return 5;
}
return a;
}
},
else =>
{
}
}
return 0;
}

12
tests/empty_if.bbb Normal file
View File

@ -0,0 +1,12 @@
[export] main = fn [cc(c)] (argument_count: u32) s32
{
>result: s32 = 0;
if (argument_count != 1)
{
result = 1;
}
else
{
}
return result;
}