raw { #define MY_C_CONST 12345 int legacy_add(int a, int b) { return a + b + MY_C_CONST; } } extern fn legacy_add(a: int, b: int) -> int; fn process_arrays(n: int, a: restrict int*, b: restrict int*, out: restrict int*) { for (let i = 0; i < n; i = i + 1) { out[i] = a[i] + b[i]; } } fn counter() -> int { static let count = 0; count = count + 1; return count; } test "test_raw" { println "Testing Raw C Embedding..."; let res = legacy_add(10, 20); // Expected: 10 + 20 + 12345 = 12375 assert(res == 12375, "Raw C Code failed"); println " Raw C Code: Success (Result: {res})"; } test "test_restrict" { let a: int[10]; let b: int[10]; let c: int[10]; for (let i = 0; i < 10; i = i + 1) { a[i] = i; b[i] = i * 2; } process_arrays(10, a, b, c); for (let i = 0; i < 10; i = i + 1) { assert(c[i] == i * 3, "Restrict test failed"); } } test "test_static_local" { let a = counter(); // 1 let b = counter(); // 2 let c = counter(); // 3 assert a == 1; assert b == 2; assert c == 3; } struct CastFoo { val: int; } fn test_cast_precedence_helper(ptr: void*) -> int { return ((CastFoo*)ptr)->val; } test "test_cast_precedence" { let f = CastFoo{val: 42}; let ptr = (void*)&f; let val = test_cast_precedence_helper(ptr); assert(val == 42, "Cast precedence failed"); }