| author | |
| committer | |
| log | 27d5e1f36cf7f7bd9345aba57d092206dc9e249b |
| tree | 5a7d50843bf9276dbecbdab40678fb6300395892 |
| parent | c17b1635ca40488a0b0a804126d0bdd2212bdf6b |
2 files changed, 44 insertions(+), 0 deletions(-)
test/stage1/c_abi/cfuncs.c+20| ... | @@ -18,9 +18,11 @@ void zig_i8(int8_t); | ... | @@ -18,9 +18,11 @@ void zig_i8(int8_t); |
| 18 | void zig_i16(int16_t); | 18 | void zig_i16(int16_t); |
| 19 | void zig_i32(int32_t); | 19 | void zig_i32(int32_t); |
| 20 | void zig_i64(int64_t); | 20 | void zig_i64(int64_t); |
| 21 | void zig_five_integers(int32_t, int32_t, int32_t, int32_t, int32_t); | ||
| 21 | 22 | ||
| 22 | void zig_f32(float); | 23 | void zig_f32(float); |
| 23 | void zig_f64(double); | 24 | void zig_f64(double); |
| 25 | void zig_five_floats(float, float, float, float, float); | ||
| 24 | 26 | ||
| 25 | void zig_ptr(void *); | 27 | void zig_ptr(void *); |
| 26 | 28 | ||
| ... | @@ -71,9 +73,11 @@ void run_c_tests(void) { | ... | @@ -71,9 +73,11 @@ void run_c_tests(void) { |
| 71 | zig_i16(-2); | 73 | zig_i16(-2); |
| 72 | zig_i32(-3); | 74 | zig_i32(-3); |
| 73 | zig_i64(-4); | 75 | zig_i64(-4); |
| 76 | zig_five_integers(12, 34, 56, 78, 90); | ||
| 74 | 77 | ||
| 75 | zig_f32(12.34f); | 78 | zig_f32(12.34f); |
| 76 | zig_f64(56.78); | 79 | zig_f64(56.78); |
| 80 | zig_five_floats(1.0f, 2.0f, 3.0f, 4.0f, 5.0f); | ||
| 77 | 81 | ||
| 78 | zig_ptr((void*)0xdeadbeefL); | 82 | zig_ptr((void*)0xdeadbeefL); |
| 79 | 83 | ||
| ... | @@ -156,6 +160,22 @@ void c_bool(bool x) { | ... | @@ -156,6 +160,22 @@ void c_bool(bool x) { |
| 156 | assert_or_panic(x); | 160 | assert_or_panic(x); |
| 157 | } | 161 | } |
| 158 | 162 | ||
| 163 | void c_five_integers(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e) { | ||
| 164 | assert_or_panic(a == 12); | ||
| 165 | assert_or_panic(b == 34); | ||
| 166 | assert_or_panic(c == 56); | ||
| 167 | assert_or_panic(d == 78); | ||
| 168 | assert_or_panic(e == 90); | ||
| 169 | } | ||
| 170 | |||
| 171 | void c_five_floats(float a, float b, float c, float d, float e) { | ||
| 172 | assert_or_panic(a == 1.0); | ||
| 173 | assert_or_panic(b == 2.0); | ||
| 174 | assert_or_panic(c == 3.0); | ||
| 175 | assert_or_panic(d == 4.0); | ||
| 176 | assert_or_panic(e == 5.0); | ||
| 177 | } | ||
| 178 | |||
| 159 | void c_array(uint8_t x[10]) { | 179 | void c_array(uint8_t x[10]) { |
| 160 | assert_or_panic(x[0] == '1'); | 180 | assert_or_panic(x[0] == '1'); |
| 161 | assert_or_panic(x[1] == '2'); | 181 | assert_or_panic(x[1] == '2'); |
test/stage1/c_abi/main.zig+24| ... | @@ -20,6 +20,17 @@ extern fn c_i16(i16) void; | ... | @@ -20,6 +20,17 @@ extern fn c_i16(i16) void; |
| 20 | extern fn c_i32(i32) void; | 20 | extern fn c_i32(i32) void; |
| 21 | extern fn c_i64(i64) void; | 21 | extern fn c_i64(i64) void; |
| 22 | 22 | ||
| 23 | // On windows x64, the first 4 are passed via registers, others on the stack. | ||
| 24 | extern fn c_five_integers(i32, i32, i32, i32, i32) void; | ||
| 25 | |||
| 26 | export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void { | ||
| 27 | expect(a == 12); | ||
| 28 | expect(b == 34); | ||
| 29 | expect(c == 56); | ||
| 30 | expect(d == 78); | ||
| 31 | expect(e == 90); | ||
| 32 | } | ||
| 33 | |||
| 23 | test "C ABI integers" { | 34 | test "C ABI integers" { |
| 24 | c_u8(0xff); | 35 | c_u8(0xff); |
| 25 | c_u16(0xfffe); | 36 | c_u16(0xfffe); |
| ... | @@ -30,6 +41,7 @@ test "C ABI integers" { | ... | @@ -30,6 +41,7 @@ test "C ABI integers" { |
| 30 | c_i16(-2); | 41 | c_i16(-2); |
| 31 | c_i32(-3); | 42 | c_i32(-3); |
| 32 | c_i64(-4); | 43 | c_i64(-4); |
| 44 | c_five_integers(12, 34, 56, 78, 90); | ||
| 33 | } | 45 | } |
| 34 | 46 | ||
| 35 | export fn zig_u8(x: u8) void { | 47 | export fn zig_u8(x: u8) void { |
| ... | @@ -60,9 +72,21 @@ export fn zig_i64(x: i64) void { | ... | @@ -60,9 +72,21 @@ export fn zig_i64(x: i64) void { |
| 60 | extern fn c_f32(f32) void; | 72 | extern fn c_f32(f32) void; |
| 61 | extern fn c_f64(f64) void; | 73 | extern fn c_f64(f64) void; |
| 62 | 74 | ||
| 75 | // On windows x64, the first 4 are passed via registers, others on the stack. | ||
| 76 | extern fn c_five_floats(f32, f32, f32, f32, f32) void; | ||
| 77 | |||
| 78 | export fn zig_five_floats(a: f32, b: f32, c: f32, d: f32, e: f32) void { | ||
| 79 | expect(a == 1.0); | ||
| 80 | expect(b == 2.0); | ||
| 81 | expect(c == 3.0); | ||
| 82 | expect(d == 4.0); | ||
| 83 | expect(e == 5.0); | ||
| 84 | } | ||
| 85 | |||
| 63 | test "C ABI floats" { | 86 | test "C ABI floats" { |
| 64 | c_f32(12.34); | 87 | c_f32(12.34); |
| 65 | c_f64(56.78); | 88 | c_f64(56.78); |
| 89 | c_five_floats(1.0, 2.0, 3.0, 4.0, 5.0); | ||
| 66 | } | 90 | } |
| 67 | 91 | ||
| 68 | export fn zig_f32(x: f32) void { | 92 | export fn zig_f32(x: f32) void { |