Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / vm / ffi_test.c
blob1ec41ac2b937ea94e4d830dbdfd9a7766f5c1b88
1 /* This file is linked into the runtime for the sole purpose
2 * of testing FFI code. */
3 #include <stdio.h>
4 #include "master.h"
5 #include "ffi_test.h"
7 void ffi_test_0(void)
11 int ffi_test_1(void)
13 return 3;
16 int ffi_test_2(int x, int y)
18 return x + y;
21 int ffi_test_3(int x, int y, int z, int t)
23 return x + y + z * t;
26 float ffi_test_4(void)
28 return 1.5;
31 double ffi_test_5(void)
33 return 1.5;
36 double ffi_test_6(float x, float y)
38 return x * y;
41 double ffi_test_7(double x, double y)
43 return x * y;
46 double ffi_test_8(double x, float y, double z, float t, int w)
48 return x * y + z * t + w;
51 int ffi_test_9(int a, int b, int c, int d, int e, int f, int g)
53 return a + b + c + d + e + f + g;
56 int ffi_test_10(int a, int b, double c, int d, float e, int f, int g, int h)
58 return a - b - c - d - e - f - g - h;
61 int ffi_test_11(int a, struct foo b, int c)
63 return a * b.x + c * b.y;
66 int ffi_test_12(int a, int b, struct rect c, int d, int e, int f)
68 return a + b + c.x + c.y + c.w + c.h + d + e + f;
71 int ffi_test_13(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k)
73 return a + b + c + d + e + f + g + h + i + j + k;
76 struct foo ffi_test_14(int x, int y)
78 struct foo r;
79 r.x = x; r.y = y;
80 return r;
83 char *ffi_test_15(char *x, char *y)
85 if(strcmp(x,y))
86 return "foo";
87 else
88 return "bar";
91 struct bar ffi_test_16(long x, long y, long z)
93 struct bar r;
94 r.x = x; r.y = y; r.z = z;
95 return r;
98 struct tiny ffi_test_17(int x)
100 struct tiny r;
101 r.x = x;
102 return r;
105 F_STDCALL int ffi_test_18(int x, int y, int z, int t)
107 return x + y + z * t;
110 F_STDCALL struct bar ffi_test_19(long x, long y, long z)
112 struct bar r;
113 r.x = x; r.y = y; r.z = z;
114 return r;
117 void ffi_test_20(double x1, double x2, double x3,
118 double y1, double y2, double y3,
119 double z1, double z2, double z3)
123 long long ffi_test_21(long x, long y)
125 return (long long)x * (long long)y;
128 long ffi_test_22(long x, long long y, long long z)
130 return x + y / z;
133 float ffi_test_23(float x[3], float y[3])
135 return x[0] * y[0] + x[1] * y[1] + x[2] * y[2];
138 struct test_struct_1 ffi_test_24(void)
140 struct test_struct_1 s;
141 s.x = 1;
142 return s;
145 struct test_struct_2 ffi_test_25(void)
147 struct test_struct_2 s;
148 s.x = 1;
149 s.y = 2;
150 return s;
153 struct test_struct_3 ffi_test_26(void)
155 struct test_struct_3 s;
156 s.x = 1;
157 s.y = 2;
158 s.z = 3;
159 return s;
162 struct test_struct_4 ffi_test_27(void)
164 struct test_struct_4 s;
165 s.x = 1;
166 s.y = 2;
167 s.z = 3;
168 s.a = 4;
169 return s;
172 struct test_struct_5 ffi_test_28(void)
174 struct test_struct_5 s;
175 s.x = 1;
176 s.y = 2;
177 s.z = 3;
178 s.a = 4;
179 s.b = 5;
180 return s;
183 struct test_struct_6 ffi_test_29(void)
185 struct test_struct_6 s;
186 s.x = 1;
187 s.y = 2;
188 s.z = 3;
189 s.a = 4;
190 s.b = 5;
191 s.c = 6;
192 return s;
195 struct test_struct_7 ffi_test_30(void)
197 struct test_struct_7 s;
198 s.x = 1;
199 s.y = 2;
200 s.z = 3;
201 s.a = 4;
202 s.b = 5;
203 s.c = 6;
204 s.d = 7;
205 return s;
208 int ffi_test_31(int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20, int x21, int x22, int x23, int x24, int x25, int x26, int x27, int x28, int x29, int x30, int x31, int x32, int x33, int x34, int x35, int x36, int x37, int x38, int x39, int x40, int x41)
210 return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 + x23 + x24 + x25 + x26 + x27 + x28 + x29 + x30 + x31 + x32 + x33 + x34 + x35 + x36 + x37 + x38 + x39 + x40 + x41;
213 float ffi_test_31_point_5(float x0, float x1, float x2, float x3, float x4, float x5, float x6, float x7, float x8, float x9, float x10, float x11, float x12, float x13, float x14, float x15, float x16, float x17, float x18, float x19, float x20, float x21, float x22, float x23, float x24, float x25, float x26, float x27, float x28, float x29, float x30, float x31, float x32, float x33, float x34, float x35, float x36, float x37, float x38, float x39, float x40, float x41)
215 return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 + x23 + x24 + x25 + x26 + x27 + x28 + x29 + x30 + x31 + x32 + x33 + x34 + x35 + x36 + x37 + x38 + x39 + x40 + x41;
218 double ffi_test_32(struct test_struct_8 x, int y)
220 return (x.x + x.y) * y;
223 double ffi_test_33(struct test_struct_9 x, int y)
225 return (x.x + x.y) * y;
228 double ffi_test_34(struct test_struct_10 x, int y)
230 return (x.x + x.y) * y;
233 double ffi_test_35(struct test_struct_11 x, int y)
235 return (x.x + x.y) * y;
238 double ffi_test_36(struct test_struct_12 x)
240 return x.x;
243 static int global_var;
245 void ffi_test_36_point_5(void)
247 global_var = 0;
250 int ffi_test_37(int (*f)(int, int, int))
252 global_var = f(global_var,global_var * 2,global_var * 3);
253 return global_var;
256 unsigned long long ffi_test_38(unsigned long long x, unsigned long long y)
258 return x * y;
261 int ffi_test_39(long a, long b, struct test_struct_13 s)
263 if(a != b) abort();
264 return s.x1 + s.x2 + s.x3 + s.x4 + s.x5 + s.x6;
267 struct test_struct_14 ffi_test_40(double x1, double x2)
269 struct test_struct_14 retval;
270 retval.x1 = x1;
271 retval.x2 = x2;
272 return retval;
275 struct test_struct_12 ffi_test_41(int a, double x)
277 struct test_struct_12 retval;
278 retval.a = a;
279 retval.x = x;
280 return retval;
283 struct test_struct_15 ffi_test_42(float x, float y)
285 struct test_struct_15 retval;
286 retval.x = x;
287 retval.y = y;
288 return retval;
291 struct test_struct_16 ffi_test_43(float x, int a)
293 struct test_struct_16 retval;
294 retval.x = x;
295 retval.a = a;
296 return retval;
299 struct test_struct_14 ffi_test_44(void)
301 struct test_struct_14 retval;
302 retval.x1 = 1.0;
303 retval.x2 = 2.0;
304 return retval;