]> gitweb.factorcode.org Git - factor.git/blob - vm/ffi_test.c
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / ffi_test.c
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"
6
7 void ffi_test_0(void)
8 {
9         printf("ffi_test_0()\n");
10 }
11
12 int ffi_test_1(void)
13 {
14         printf("ffi_test_1()\n");
15         return 3;
16 }
17
18 int ffi_test_2(int x, int y)
19 {
20         printf("ffi_test_2(%d,%d)\n",x,y);
21         return x + y;
22 }
23
24 int ffi_test_3(int x, int y, int z, int t)
25 {
26         printf("ffi_test_3(%d,%d,%d,%d)\n",x,y,z,t);
27         return x + y + z * t;
28 }
29
30 float ffi_test_4(void)
31 {
32         printf("ffi_test_4()\n");
33         return 1.5;
34 }
35
36 double ffi_test_5(void)
37 {
38         printf("ffi_test_5()\n");
39         return 1.5;
40 }
41
42 double ffi_test_6(float x, float y)
43 {
44         printf("ffi_test_6(%f,%f)\n",x,y);
45         return x * y;
46 }
47
48 double ffi_test_7(double x, double y)
49 {
50         printf("ffi_test_7(%f,%f)\n",x,y);
51         return x * y;
52 }
53
54 double ffi_test_8(double x, float y, double z, float t, int w)
55 {
56         printf("ffi_test_8(%f,%f,%f,%f,%d)\n",x,y,z,t,w);
57         return x * y + z * t + w;
58 }
59
60 int ffi_test_9(int a, int b, int c, int d, int e, int f, int g)
61 {
62         printf("ffi_test_9(%d,%d,%d,%d,%d,%d,%d)\n",a,b,c,d,e,f,g);
63         return a + b + c + d + e + f + g;
64 }
65
66 int ffi_test_10(int a, int b, double c, int d, float e, int f, int g, int h)
67 {
68         printf("ffi_test_10(%d,%d,%f,%d,%f,%d,%d,%d)\n",a,b,c,d,e,f,g,h);
69         return a - b - c - d - e - f - g - h;
70 }
71
72 int ffi_test_11(int a, struct foo b, int c)
73 {
74         printf("ffi_test_11(%d,{%d,%d},%d)\n",a,b.x,b.y,c);
75         return a * b.x + c * b.y;
76 }
77
78 int ffi_test_12(int a, int b, struct rect c, int d, int e, int f)
79 {
80         printf("ffi_test_12(%d,%d,{%f,%f,%f,%f},%d,%d,%d)\n",a,b,c.x,c.y,c.w,c.h,d,e,f);
81         return a + b + c.x + c.y + c.w + c.h + d + e + f;
82 }
83
84 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)
85 {
86         printf("ffi_test_13(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\n",a,b,c,d,e,f,g,h,i,j,k);
87         return a + b + c + d + e + f + g + h + i + j + k;
88 }
89
90 struct foo ffi_test_14(int x, int y)
91 {
92         struct foo r;
93         printf("ffi_test_14(%d,%d)\n",x,y);
94         r.x = x; r.y = y;
95         return r;
96 }
97
98 char *ffi_test_15(char *x, char *y)
99 {
100         if(strcmp(x,y))
101                 return "foo";
102         else
103                 return "bar";
104 }
105
106 struct bar ffi_test_16(long x, long y, long z)
107 {
108         struct bar r;
109         r.x = x; r.y = y; r.z = z;
110         return r;
111 }
112
113 struct tiny ffi_test_17(int x)
114 {
115         struct tiny r;
116         r.x = x;
117         return r;
118 }
119
120 F_STDCALL int ffi_test_18(int x, int y, int z, int t)
121 {
122         printf("ffi_test_18(%d,%d,%d,%d)\n",x,y,z,t);
123         return x + y + z * t;
124 }
125
126 F_STDCALL struct bar ffi_test_19(long x, long y, long z)
127 {
128         struct bar r;
129         r.x = x; r.y = y; r.z = z;
130         return r;
131 }
132
133 void ffi_test_20(double x1, double x2, double x3,
134         double y1, double y2, double y3,
135         double z1, double z2, double z3)
136 {
137         printf("ffi_test_20(%f,%f,%f,%f,%f,%f,%f,%f,%f)\n",
138                 x1, x2, x3, y1, y2, y3, z1, z2, z3);
139 }
140
141 long long ffi_test_21(long x, long y)
142 {
143         return (long long)x * (long long)y;
144 }
145
146 long ffi_test_22(long x, long long y, long long z)
147 {
148         printf("ffi_test_22(%ld,%lld,%lld)\n",x,y,z);
149         return x + y / z;
150 }
151
152 float ffi_test_23(float x[3], float y[3])
153 {
154         return x[0] * y[0] + x[1] * y[1] + x[2] * y[2];
155 }
156
157 struct test_struct_1 ffi_test_24(void)
158 {
159         struct test_struct_1 s;
160         s.x = 1;
161         return s;
162 }
163
164 struct test_struct_2 ffi_test_25(void)
165 {
166         struct test_struct_2 s;
167         s.x = 1;
168         s.y = 2;
169         return s;
170 }
171
172 struct test_struct_3 ffi_test_26(void)
173 {
174         struct test_struct_3 s;
175         s.x = 1;
176         s.y = 2;
177         s.z = 3;
178         return s;
179 }
180
181 struct test_struct_4 ffi_test_27(void)
182 {
183         struct test_struct_4 s;
184         s.x = 1;
185         s.y = 2;
186         s.z = 3;
187         s.a = 4;
188         return s;
189 }
190
191 struct test_struct_5 ffi_test_28(void)
192 {
193         struct test_struct_5 s;
194         s.x = 1;
195         s.y = 2;
196         s.z = 3;
197         s.a = 4;
198         s.b = 5;
199         return s;
200 }
201
202 struct test_struct_6 ffi_test_29(void)
203 {
204         struct test_struct_6 s;
205         s.x = 1;
206         s.y = 2;
207         s.z = 3;
208         s.a = 4;
209         s.b = 5;
210         s.c = 6;
211         return s;
212 }
213
214 struct test_struct_7 ffi_test_30(void)
215 {
216         struct test_struct_7 s;
217         s.x = 1;
218         s.y = 2;
219         s.z = 3;
220         s.a = 4;
221         s.b = 5;
222         s.c = 6;
223         s.d = 7;
224         return s;
225 }
226
227 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)
228 {
229         printf("ffi_test_31(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\n",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);
230         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;
231 }
232
233 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)
234 {
235         printf("ffi_test_31_point_5(%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f)\n",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);
236         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;
237 }
238
239 double ffi_test_32(struct test_struct_8 x, int y)
240 {
241         return (x.x + x.y) * y;
242 }
243
244 double ffi_test_33(struct test_struct_9 x, int y)
245 {
246         return (x.x + x.y) * y;
247 }
248
249 double ffi_test_34(struct test_struct_10 x, int y)
250 {
251         return (x.x + x.y) * y;
252 }
253
254 double ffi_test_35(struct test_struct_11 x, int y)
255 {
256         return (x.x + x.y) * y;
257 }
258
259 double ffi_test_36(struct test_struct_12 x)
260 {
261         return x.x;
262 }
263
264 static int global_var;
265
266 void ffi_test_36_point_5(void)
267 {
268         printf("ffi_test_36_point_5\n");
269         global_var = 0;
270 }
271
272 int ffi_test_37(int (*f)(int, int, int))
273 {
274         printf("ffi_test_37\n");
275         printf("global_var is %d\n",global_var);
276         global_var = f(global_var,global_var * 2,global_var * 3);
277         printf("global_var is %d\n",global_var);
278         fflush(stdout);
279         return global_var;
280 }
281
282 unsigned long long ffi_test_38(unsigned long long x, unsigned long long y)
283 {
284         return x * y;
285 }
286
287 int ffi_test_39(long a, long b, struct test_struct_13 s)
288 {
289         printf("ffi_test_39(%ld,%ld,%f,%f,%f,%f,%f,%f)\n",a,b,s.x1,s.x2,s.x3,s.x4,s.x5,s.x6);
290         if(a != b) abort();
291         return s.x1 + s.x2 + s.x3 + s.x4 + s.x5 + s.x6;
292 }
293
294 struct test_struct_14 ffi_test_40(double x1, double x2)
295 {
296         struct test_struct_14 retval;
297         retval.x1 = x1;
298         retval.x2 = x2;
299         printf("ffi_test_40(%f,%f)\n",x1,x2);
300         return retval;
301 }
302
303 struct test_struct_12 ffi_test_41(int a, double x)
304 {
305         struct test_struct_12 retval;
306         retval.a = a;
307         retval.x = x;
308         printf("ffi_test_41(%d,%f)\n",a,x);
309         return retval;
310 }
311
312 struct test_struct_15 ffi_test_42(float x, float y)
313 {
314         struct test_struct_15 retval;
315         retval.x = x;
316         retval.y = y;
317         printf("ffi_test_42(%f,%f)\n",x,y);
318         return retval;
319 }
320
321 struct test_struct_16 ffi_test_43(float x, int a)
322 {
323         struct test_struct_16 retval;
324         retval.x = x;
325         retval.a = a;
326         printf("ffi_test_43(%f,%d)\n",x,a);
327         return retval;
328 }
329
330 struct test_struct_14 ffi_test_44(void)
331 {
332         struct test_struct_14 retval;
333         retval.x1 = 1.0;
334         retval.x2 = 2.0;
335         //printf("ffi_test_44()\n");
336         return retval;
337 }