wip
This commit is contained in:
parent
a6cd3bf713
commit
9bacb2df63
@ -339,7 +339,7 @@ fn String compile_file(Arena* arena, Compile options)
|
|||||||
library_names = { library_buffer, library_count };
|
library_names = { library_buffer, library_count };
|
||||||
library_paths = { &llvm_bindings_library, 1 };
|
library_paths = { &llvm_bindings_library, 1 };
|
||||||
}
|
}
|
||||||
else if (base_name.equal(string_literal("c_abi")))
|
else if (base_name.equal(string_literal("tests")))
|
||||||
{
|
{
|
||||||
library_paths = { &c_abi_library, 1 };
|
library_paths = { &c_abi_library, 1 };
|
||||||
}
|
}
|
||||||
|
280
tests/c_abi.bbb
280
tests/c_abi.bbb
@ -148,146 +148,6 @@ require = fn (ok: u1) void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[export] main = fn [cc(c)] () s32
|
|
||||||
{
|
|
||||||
run_c_tests();
|
|
||||||
c_u8(0xff);
|
|
||||||
c_u16(0xfffe);
|
|
||||||
c_u32(0xfffffffd);
|
|
||||||
c_u64(0xfffffffffffffffc);
|
|
||||||
|
|
||||||
//if (has_i128) {
|
|
||||||
// c_struct_u128({ .value = 0xfffffffffffffffc, });
|
|
||||||
//}
|
|
||||||
|
|
||||||
c_s8(-1);
|
|
||||||
c_s16(-2);
|
|
||||||
c_s32(-3);
|
|
||||||
c_s64(-4);
|
|
||||||
|
|
||||||
//if (has_i128) {
|
|
||||||
// c_struct_i128({ .value = -6, });
|
|
||||||
//}
|
|
||||||
|
|
||||||
c_bool(1);
|
|
||||||
|
|
||||||
c_five_integers(12, 34, 56, 78, 90);
|
|
||||||
|
|
||||||
>s = c_ret_struct_u64_u64();
|
|
||||||
require(s.a == 21);
|
|
||||||
require(s.b == 22);
|
|
||||||
c_struct_u64_u64_0({ .a = 23, .b = 24, });
|
|
||||||
c_struct_u64_u64_1(0, { .a = 25, .b = 26, });
|
|
||||||
c_struct_u64_u64_2(0, 1, { .a = 27, .b = 28, });
|
|
||||||
c_struct_u64_u64_3(0, 1, 2, { .a = 29, .b = 30, });
|
|
||||||
c_struct_u64_u64_4(0, 1, 2, 3, { .a = 31, .b = 32, });
|
|
||||||
c_struct_u64_u64_5(0, 1, 2, 3, 4, { .a = 33, .b = 34, });
|
|
||||||
c_struct_u64_u64_6(0, 1, 2, 3, 4, 5, { .a = 35, .b = 36, });
|
|
||||||
c_struct_u64_u64_7(0, 1, 2, 3, 4, 5, 6, { .a = 37, .b = 38, });
|
|
||||||
c_struct_u64_u64_8(0, 1, 2, 3, 4, 5, 6, 7, { .a = 39, .b = 40, });
|
|
||||||
|
|
||||||
>big_struct: BigStruct = {
|
|
||||||
.a = 1,
|
|
||||||
.b = 2,
|
|
||||||
.c = 3,
|
|
||||||
.d = 4,
|
|
||||||
.e = 5,
|
|
||||||
};
|
|
||||||
c_big_struct(big_struct);
|
|
||||||
|
|
||||||
>small: SmallStructInts = {
|
|
||||||
.a = 1,
|
|
||||||
.b = 2,
|
|
||||||
.c = 3,
|
|
||||||
.d = 4,
|
|
||||||
};
|
|
||||||
c_small_struct_ints(small);
|
|
||||||
>small2 = c_ret_small_struct_ints();
|
|
||||||
require(small2.a == 1);
|
|
||||||
require(small2.b == 2);
|
|
||||||
require(small2.c == 3);
|
|
||||||
require(small2.d == 4);
|
|
||||||
|
|
||||||
>med: MedStructInts = {
|
|
||||||
.x = 1,
|
|
||||||
.y = 2,
|
|
||||||
.z = 3,
|
|
||||||
};
|
|
||||||
c_med_struct_ints(med);
|
|
||||||
>med2 = c_ret_med_struct_ints();
|
|
||||||
require(med2.x == 1);
|
|
||||||
require(med2.y == 2);
|
|
||||||
require(med2.z == 3);
|
|
||||||
|
|
||||||
>p: SmallPackedStruct = { .a = 0, .b = 1, .c = 2, .d = 3, };
|
|
||||||
c_small_packed_struct(p);
|
|
||||||
>p2 = c_ret_small_packed_struct();
|
|
||||||
require(p2.a == 0);
|
|
||||||
require(p2.b == 1);
|
|
||||||
require(p2.c == 2);
|
|
||||||
require(p2.d == 3);
|
|
||||||
|
|
||||||
>split: SplitStructInt = {
|
|
||||||
.a = 1234,
|
|
||||||
.b = 100,
|
|
||||||
.c = 1337,
|
|
||||||
};
|
|
||||||
c_split_struct_ints(split);
|
|
||||||
|
|
||||||
> big: BigStruct = {
|
|
||||||
.a = 1,
|
|
||||||
.b = 2,
|
|
||||||
.c = 3,
|
|
||||||
.d = 4,
|
|
||||||
.e = 5,
|
|
||||||
};
|
|
||||||
>big2 = c_big_struct_both(big);
|
|
||||||
require(big2.a == 10);
|
|
||||||
require(big2.b == 11);
|
|
||||||
require(big2.c == 12);
|
|
||||||
require(big2.d == 13);
|
|
||||||
require(big2.e == 14);
|
|
||||||
|
|
||||||
>r1: Rect = {
|
|
||||||
.left = 1,
|
|
||||||
.right = 21,
|
|
||||||
.top = 16,
|
|
||||||
.bottom = 4,
|
|
||||||
};
|
|
||||||
>r2: Rect = {
|
|
||||||
.left = 178,
|
|
||||||
.right = 189,
|
|
||||||
.top = 21,
|
|
||||||
.bottom = 15,
|
|
||||||
};
|
|
||||||
c_multiple_struct_ints(r1, r2);
|
|
||||||
|
|
||||||
require(c_ret_bool() == 1);
|
|
||||||
|
|
||||||
require(c_ret_u8() == 0xff);
|
|
||||||
require(c_ret_u16() == 0xffff);
|
|
||||||
require(c_ret_u32() == 0xffffffff);
|
|
||||||
require(c_ret_u64() == 0xffffffffffffffff);
|
|
||||||
|
|
||||||
require(c_ret_s8() == -1);
|
|
||||||
require(c_ret_s16() == -1);
|
|
||||||
require(c_ret_s32() == -1);
|
|
||||||
require(c_ret_s64() == -1);
|
|
||||||
|
|
||||||
c_struct_with_array({ .a = 1, .padding = [0, 0, 0, 0], .b = 2, });
|
|
||||||
|
|
||||||
>x = c_ret_struct_with_array();
|
|
||||||
require(x.a == 4);
|
|
||||||
require(x.b == 155);
|
|
||||||
|
|
||||||
>res = c_modify_by_ref_param({ .val = 1, .arr = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] });
|
|
||||||
require(res.val == 42);
|
|
||||||
|
|
||||||
>function_pointer = &c_func_ptr_byval;
|
|
||||||
function_pointer(1, 2, { .origin = { .x = 9, .y = 10, .z = 11, }, .size = { .width = 12, .height = 13, .depth = 14, }, }, 3, 4, 5);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
[export] bb_u8 = fn [cc(c)] (x: u8) void
|
[export] bb_u8 = fn [cc(c)] (x: u8) void
|
||||||
{
|
{
|
||||||
require(x == 0xff);
|
require(x == 0xff);
|
||||||
@ -537,3 +397,143 @@ require = fn (ok: u1) void
|
|||||||
require(s.y == 2);
|
require(s.y == 2);
|
||||||
require(s.z == 3);
|
require(s.z == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[export] main = fn [cc(c)] () s32
|
||||||
|
{
|
||||||
|
run_c_tests();
|
||||||
|
c_u8(0xff);
|
||||||
|
c_u16(0xfffe);
|
||||||
|
c_u32(0xfffffffd);
|
||||||
|
c_u64(0xfffffffffffffffc);
|
||||||
|
|
||||||
|
//if (has_i128) {
|
||||||
|
// c_struct_u128({ .value = 0xfffffffffffffffc, });
|
||||||
|
//}
|
||||||
|
|
||||||
|
c_s8(-1);
|
||||||
|
c_s16(-2);
|
||||||
|
c_s32(-3);
|
||||||
|
c_s64(-4);
|
||||||
|
|
||||||
|
//if (has_i128) {
|
||||||
|
// c_struct_i128({ .value = -6, });
|
||||||
|
//}
|
||||||
|
|
||||||
|
c_bool(1);
|
||||||
|
|
||||||
|
c_five_integers(12, 34, 56, 78, 90);
|
||||||
|
|
||||||
|
>s = c_ret_struct_u64_u64();
|
||||||
|
require(s.a == 21);
|
||||||
|
require(s.b == 22);
|
||||||
|
c_struct_u64_u64_0({ .a = 23, .b = 24, });
|
||||||
|
c_struct_u64_u64_1(0, { .a = 25, .b = 26, });
|
||||||
|
c_struct_u64_u64_2(0, 1, { .a = 27, .b = 28, });
|
||||||
|
c_struct_u64_u64_3(0, 1, 2, { .a = 29, .b = 30, });
|
||||||
|
c_struct_u64_u64_4(0, 1, 2, 3, { .a = 31, .b = 32, });
|
||||||
|
c_struct_u64_u64_5(0, 1, 2, 3, 4, { .a = 33, .b = 34, });
|
||||||
|
c_struct_u64_u64_6(0, 1, 2, 3, 4, 5, { .a = 35, .b = 36, });
|
||||||
|
c_struct_u64_u64_7(0, 1, 2, 3, 4, 5, 6, { .a = 37, .b = 38, });
|
||||||
|
c_struct_u64_u64_8(0, 1, 2, 3, 4, 5, 6, 7, { .a = 39, .b = 40, });
|
||||||
|
|
||||||
|
>big_struct: BigStruct = {
|
||||||
|
.a = 1,
|
||||||
|
.b = 2,
|
||||||
|
.c = 3,
|
||||||
|
.d = 4,
|
||||||
|
.e = 5,
|
||||||
|
};
|
||||||
|
c_big_struct(big_struct);
|
||||||
|
|
||||||
|
>small: SmallStructInts = {
|
||||||
|
.a = 1,
|
||||||
|
.b = 2,
|
||||||
|
.c = 3,
|
||||||
|
.d = 4,
|
||||||
|
};
|
||||||
|
c_small_struct_ints(small);
|
||||||
|
>small2 = c_ret_small_struct_ints();
|
||||||
|
require(small2.a == 1);
|
||||||
|
require(small2.b == 2);
|
||||||
|
require(small2.c == 3);
|
||||||
|
require(small2.d == 4);
|
||||||
|
|
||||||
|
>med: MedStructInts = {
|
||||||
|
.x = 1,
|
||||||
|
.y = 2,
|
||||||
|
.z = 3,
|
||||||
|
};
|
||||||
|
c_med_struct_ints(med);
|
||||||
|
>med2 = c_ret_med_struct_ints();
|
||||||
|
require(med2.x == 1);
|
||||||
|
require(med2.y == 2);
|
||||||
|
require(med2.z == 3);
|
||||||
|
|
||||||
|
>p: SmallPackedStruct = { .a = 0, .b = 1, .c = 2, .d = 3, };
|
||||||
|
c_small_packed_struct(p);
|
||||||
|
>p2 = c_ret_small_packed_struct();
|
||||||
|
require(p2.a == 0);
|
||||||
|
require(p2.b == 1);
|
||||||
|
require(p2.c == 2);
|
||||||
|
require(p2.d == 3);
|
||||||
|
|
||||||
|
>split: SplitStructInt = {
|
||||||
|
.a = 1234,
|
||||||
|
.b = 100,
|
||||||
|
.c = 1337,
|
||||||
|
};
|
||||||
|
c_split_struct_ints(split);
|
||||||
|
|
||||||
|
> big: BigStruct = {
|
||||||
|
.a = 1,
|
||||||
|
.b = 2,
|
||||||
|
.c = 3,
|
||||||
|
.d = 4,
|
||||||
|
.e = 5,
|
||||||
|
};
|
||||||
|
>big2 = c_big_struct_both(big);
|
||||||
|
require(big2.a == 10);
|
||||||
|
require(big2.b == 11);
|
||||||
|
require(big2.c == 12);
|
||||||
|
require(big2.d == 13);
|
||||||
|
require(big2.e == 14);
|
||||||
|
|
||||||
|
>r1: Rect = {
|
||||||
|
.left = 1,
|
||||||
|
.right = 21,
|
||||||
|
.top = 16,
|
||||||
|
.bottom = 4,
|
||||||
|
};
|
||||||
|
>r2: Rect = {
|
||||||
|
.left = 178,
|
||||||
|
.right = 189,
|
||||||
|
.top = 21,
|
||||||
|
.bottom = 15,
|
||||||
|
};
|
||||||
|
c_multiple_struct_ints(r1, r2);
|
||||||
|
|
||||||
|
require(c_ret_bool() == 1);
|
||||||
|
|
||||||
|
require(c_ret_u8() == 0xff);
|
||||||
|
require(c_ret_u16() == 0xffff);
|
||||||
|
require(c_ret_u32() == 0xffffffff);
|
||||||
|
require(c_ret_u64() == 0xffffffffffffffff);
|
||||||
|
|
||||||
|
require(c_ret_s8() == -1);
|
||||||
|
require(c_ret_s16() == -1);
|
||||||
|
require(c_ret_s32() == -1);
|
||||||
|
require(c_ret_s64() == -1);
|
||||||
|
|
||||||
|
c_struct_with_array({ .a = 1, .padding = [0, 0, 0, 0], .b = 2, });
|
||||||
|
|
||||||
|
>x = c_ret_struct_with_array();
|
||||||
|
require(x.a == 4);
|
||||||
|
require(x.b == 155);
|
||||||
|
|
||||||
|
>res = c_modify_by_ref_param({ .val = 1, .arr = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] });
|
||||||
|
require(res.val == 42);
|
||||||
|
|
||||||
|
>function_pointer = &c_func_ptr_byval;
|
||||||
|
function_pointer(1, 2, { .origin = { .x = 9, .y = 10, .z = 11, }, .size = { .width = 12, .height = 13, .depth = 14, }, }, 3, 4, 5);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
result: s32 = 0;
|
result: s32 = 0;
|
||||||
|
|
||||||
[export] main = fn [cc(c)] () s32 {
|
[export] main = fn [cc(c)] () s32
|
||||||
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ foo = fn (slices: [][]u8) void
|
|||||||
#trap();
|
#trap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[export] main = fn [cc(c)] () s32
|
[export] main = fn [cc(c)] () s32
|
||||||
{
|
{
|
||||||
>some_bool: u1 = 0;
|
>some_bool: u1 = 0;
|
||||||
|
2328
tests/tests.bbb
Normal file
2328
tests/tests.bbb
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user