Add compile time ternary $val ??? <expr> : <expr>.

This commit is contained in:
Christoffer Lerno
2025-08-28 01:56:05 +02:00
parent 90d3f429aa
commit 47316dac59
15 changed files with 86 additions and 26 deletions

View File

@@ -0,0 +1,25 @@
// #target: macos-x64
module test;
import std;
fn int main()
{
int aa = false ??? 1 + a : 2;
int x = 42;
int bb = true ??? x : 1 + a;
return 0;
}
/* #expect: test.ll
define i32 @main() #0 {
entry:
%aa = alloca i32, align 4
%x = alloca i32, align 4
%bb = alloca i32, align 4
store i32 2, ptr %aa, align 4
store i32 42, ptr %x, align 4
%0 = load i32, ptr %x, align 4
store i32 %0, ptr %bb, align 4
ret i32 0
}

View File

@@ -2,8 +2,8 @@ module std::core::values @test;
fn void test_select()
{
const int X = @select(true, 1, "Hello");
const String Y = @select(false, 1, "Hello");
const int X = true ??? 1 : "Hello";
const String Y = false ??? 1 : "Hello";
test::eq(X, 1);
test::eq(Y, "Hello");
}