test_foreign.c
Go to the documentation of this file.
1 // for eus.h
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <string.h>
6 #include <setjmp.h>
7 #include <errno.h>
8 #include <sstream>
9 
10 #define class eus_class
11 #define throw eus_throw
12 #define export eus_export
13 #define vector eus_vector
14 #define string eus_string
15 #include <eus.h> // include eus.h just for eusfloat_t ...
16 #undef class
17 #undef throw
18 #undef export
19 #undef vector
20 #undef string
21 
22 extern "C" {
23 int int_test(int n, int i1, int i2, int i3, int i4) {
24  unsigned int ui;
25 
26  //printf("int_test in c\n");
27  ui = *((unsigned int *)(&i1));
28  printf("%d: %8d %X\n", n, i1, ui);
29  ui = *((unsigned int *)(&i2));
30  printf("%d: %8d %X\n", n, i2, ui);
31  ui = *((unsigned int *)(&i3));
32  printf("%d: %8d %X\n", n, i3, ui);
33  ui = *((unsigned int *)(&i4));
34  printf("%d: %8d %X\n", n, i4, ui);
35 
36  return -1;
37 }
38 
39 int long_test(long n, long d1, long d2, long d3, long d4) {
40  unsigned long ul;
41 
42  //printf("long_test in c\n");
43  ul = *((unsigned long *)(&d1));
44  printf("%d: %8d %X\n", n, d1, ul);
45  ul = *((unsigned long *)(&d2));
46  printf("%d: %8d %X\n", n, d2, ul);
47  ul = *((unsigned long *)(&d3));
48  printf("%d: %8d %X\n", n, d3, ul);
49  ul = *((unsigned long *)(&d4));
50  printf("%d: %8d %X\n", n, d4, ul);
51 
52  return -1;
53 }
54 
56  unsigned long ul;
57 
58  //printf("eusinteger_test in c\n");
59  ul = *((unsigned int *)(&i1));
60  printf("%d: %8d %X\n", n, i1, ul);
61  ul = *((unsigned int *)(&i2));
62  printf("%d: %8d %X\n", n, i2, ul);
63  ul = *((unsigned int *)(&i3));
64  printf("%d: %8d %X\n", n, i3, ul);
65  ul = *((unsigned int *)(&i4));
66  printf("%d: %8d %X\n", n, i4, ul);
67 
68  return -1;
69 }
70 
71 int float_test(int n, float f1, float f2, float f3, float f4) {
72  unsigned int ui;
73 
74  //printf("float_test in c\n");
75  ui = *((unsigned int *)(&f1));
76  printf("%d: %8.8e %X (%4.1f)\n", n, f1, ui, f1);
77  ui = *((unsigned int *)(&f2));
78  printf("%d: %8.8e %X (%4.1f)\n", n, f2, ui, f2);
79  ui = *((unsigned int *)(&f3));
80  printf("%d: %8.8e %X (%4.1f)\n", n, f3, ui, f3);
81  ui = *((unsigned int *)(&f4));
82  printf("%d: %8.8e %X (%4.1f)\n", n, f4, ui, f4);
83 
84  return -1;
85 }
86 
87 int double_test(long n, double d1, double d2, double d3, double d4) {
88  unsigned long ul;
89 
90  //printf("double_test in c\n");
91  ul = *((unsigned long *)(&d1));
92  printf("%ld: %16.16e %lX (%4.1f)\n", n, d1, ul, d1);
93  ul = *((unsigned long *)(&d2));
94  printf("%ld: %16.16e %lX (%4.1f)\n", n, d2, ul, d2);
95  ul = *((unsigned long *)(&d3));
96  printf("%ld: %16.16e %lX (%4.1f)\n", n, d3, ul, d3);
97  ul = *((unsigned long *)(&d4));
98  printf("%ld: %16.16e %lX (%4.1f)\n", n, d4, ul, d4);
99 
100  return -1;
101 }
102 
104  unsigned int ui;
105 
106  //printf("float_test in c\n");
107  ui = *((unsigned int *)(&f1));
108  printf("%d: %8.8e %X (%4.1f)\n", n, f1, ui, f1);
109  ui = *((unsigned int *)(&f2));
110  printf("%d: %8.8e %X (%4.1f)\n", n, f2, ui, f2);
111  ui = *((unsigned int *)(&f3));
112  printf("%d: %8.8e %X (%4.1f)\n", n, f3, ui, f3);
113  ui = *((unsigned int *)(&f4));
114  printf("%d: %8.8e %X (%4.1f)\n", n, f4, ui, f4);
115 
116  return -1;
117 }
118 
119 int iv_test(int n, int *src) {
120  int i;
121  unsigned int *ui;
122  printf("size = %d\n", n);
123  for(i=0;i<n ;i++){
124  ui = (unsigned int *)(&(src[i]));
125  printf("%d: %d %X\n", i, src[i], *ui);
126  }
127  return -1;
128 }
129 
130 int lv_test(int n, long *src) {
131  int i;
132  unsigned long *ul;
133  printf("size = %d\n", n);
134  for(i=0;i<n ;i++){
135  ul = (unsigned long *)(&(src[i]));
136  printf("%d: %ld %lX\n", i, src[i], *ul);
137  }
138  return -1;
139 }
140 
141 int eiv_test(int n, eusinteger_t *src) {
142  eusinteger_t i;
143  unsigned long *ul;
144  printf("size = %d\n", n);
145  for(i=0;i<n ;i++){
146  ul = (unsigned long *)(&(src[i]));
147  printf("%d: %ld %lX\n", i, src[i], *ul);
148  }
149  return -1;
150 }
151 
152 int fv_test(int n, float *src) {
153  int i;
154  unsigned int *ui;
155  printf("size = %d\n", n);
156  for(i=0;i<n ;i++){
157  ui = (unsigned int *)(&(src[i]));
158  printf("%d: %e %X\n", i, src[i], *ui);
159  }
160  return -1;
161 }
162 
163 int dv_test(int n, double *src) {
164  int i;
165  unsigned long *ul;
166  printf("size = %d\n", n);
167  for(i=0;i<n ;i++){
168  ul = (unsigned long *)(&(src[i]));
169  printf("%d: %e %lX\n", i, src[i], *ul);
170  }
171  return -1;
172 }
173 
174 int efv_test(int n, eusfloat_t *src) {
175  int i;
176  unsigned long *ul;
177  printf("size = %d\n", n);
178  for(i=0;i<n ;i++){
179  ul = (unsigned long *)(&(src[i]));
180  printf("%d: %e %lX\n", i, src[i], *ul);
181  }
182  return -1;
183 }
184 
185 int str_test(int n, char *src) {
186  int i;
187  printf("size = %d\n", n);
188  for(i=0;i<n ;i++){
189  printf("%d: %c %x\n", i, src[i], src[i]);
190  }
191  return -1;
192 }
193 
194 int int_long_short_test(long l, int i, short s) {
195  printf("long = %ld(%lX)\n",l,l);
196  printf("int = %d(%X)\n",i,i);
197  printf("short = %d(%X)\n",s,s);
198 
199  return l + i + s;
200 }
201 
202 float ret_float(float a, float b) {
203  float ret = (float) (a + b);
204  unsigned int *ui;
205  ui = (unsigned int *)&ret;
206  printf("// %f + %f -> %f\n", a, b, ret);
207  printf("// return %e, %X\n", ret, *ui);
208  return ret;
209 }
210 
211 double ret_double(double a, double b) {
212  double ret = (a + b);
213  unsigned long long *ul;
214  ul = (unsigned long long*)&ret;
215  printf("// %f + %f -> %f\n", a, b, ret);
216  printf("// return %e, %lX\n", ret, *ul);
217  return ret;
218 }
219 
221  eusfloat_t ret = (a + b);
222  unsigned long *ul;
223  ul = (unsigned long *)&ret;
224  printf("// %f + %f -> %f\n", a, b, ret);
225  printf("// return %e, %lX\n", ret, *ul);
226  return ret;
227 }
228 
229 int ret_int(int a, int b) {
230  int ret = a + b;
231  unsigned long *ul;
232  ul = (unsigned long *)&ret;
233  printf("// %d + %d -> %d\n", a, b, ret);
234  printf("// return %ld, %lX\n", ret, *ul);
235  return ret;
236 }
237 
238 long ret_long(long a, long b) {
239  long ret = a + b;
240  unsigned long *ul;
241  ul = (unsigned long *)&ret;
242  printf("// %d + %d -> %d\n", a, b, ret);
243  printf("// return %ld, %lX\n", ret, *ul);
244  return ret;
245 }
246 
248  eusinteger_t ret = a + b;
249  unsigned long *ul;
250  ul = (unsigned long *)&ret;
251  printf("// %d + %d -> %d\n", a, b, ret);
252  printf("// return %ld, %lX\n", ret, *ul);
253  return ret;
254 }
255 
256 double test_testd(long i0, long i1, long i2,
257  long i3, long i4, long i5,
258  double d0, double d1, double d2, double d3,
259  double d4, double d5, double d6, double d7,
260  double d8, double d9,
261  long i6, long i7) {
262  printf("%ld %ld %ld\n", i0, i1, i2);
263  printf("%ld %ld %ld\n", i3, i4, i5);
264  //printf("%ld %ld %ld %ld\n",
265  //(long)d0, (long)d1, (long)d2, (long)d3);
266  printf("%lf %lf %lf %lf\n", d0, d1, d2, d3);
267  printf("%lf %lf %lf %lf\n", d4, d5, d6, d7);
268  printf("%lf %lf\n", d8, d9);
269  printf("%ld %ld\n", i6, i7);
270 
271  //return 0x1234;
272  return 1.23456;
273 }
274 double test_testd2(long i0, long i1, long i2,
275  long i3, long i4, long i5,
276  double d0, double d1, double d2, double d3,
277  double d4, double d5, double d6, double d7,
278  double d8, double d9, double d10,
279  long i6, long i7) {
280  printf("%ld %ld %ld\n", i0, i1, i2);
281  printf("%ld %ld %ld\n", i3, i4, i5);
282  //printf("%ld %ld %ld %ld\n",
283  //(long)d0, (long)d1, (long)d2, (long)d3);
284  printf("%lf %lf %lf %lf\n", d0, d1, d2, d3);
285  printf("%lf %lf %lf %lf\n", d4, d5, d6, d7);
286  printf("%lf %lf %lf\n", d8, d9, d10);
287  printf("%ld %ld\n", i6, i7);
288 
289  //return 0x1234;
290  return 1.23456;
291 }
292 eusfloat_t test_testf(long i0, long i1, long i2,
293  long i3, long i4, long i5,
296  eusfloat_t d8, eusfloat_t d9,
297  long i6, long i7) {
298  printf("%ld %ld %ld\n", i0, i1, i2);
299  printf("%ld %ld %ld\n", i3, i4, i5);
300  //printf("%ld %ld %ld %ld\n",
301  //(long)d0, (long)d1, (long)d2, (long)d3);
302  printf("%lf %lf %lf %lf\n", d0, d1, d2, d3);
303  printf("%lf %lf %lf %lf\n", d4, d5, d6, d7);
304  printf("%lf %lf\n", d8, d9);
305  printf("%ld %ld\n", i6, i7);
306 
307  //return 0x1234;
308  return 1.23456;
309 }
310 int test_testfd(long i0, long i1, long i2,
311  long i3, long i4, long i5,
312  double d0, float d1, double d2, float d3,
313  float d4, double d5, double d6, float d7,
314  float d8, double d9, double d10, float d11,
315  long i6, long i7) {
316  printf("%ld %ld %ld\n", i0, i1, i2);
317  printf("%ld %ld %ld\n", i3, i4, i5);
318  //printf("%ld %ld %ld %ld\n",
319  //(long)d0, (long)d1, (long)d2, (long)d3);
320  printf("%lf %f %lf %f\n", d0, d1, d2, d3);
321  printf("%f %lf %lf %f\n", d4, d5, d6, d7);
322  printf("%f %lf %lf %f\n", d8, d9, d10, d11);
323  printf("%ld %ld\n", i6, i7);
324 
325  //return 0x1234;
326  return 123456;
327 }
328 static long (*g)();
329 static double (*gf) (long i0, long i1, long i2,
330  long i3, long i4, long i5,
331  double d0, double d1, double d2, double d3,
332  double d4, double d5, double d6, double d7,
333  double d8, double d9,
334  long i6, long i7);
335 
336 long set_ifunc(long (*f) ())
337 {
338  g = f;
339  printf("set_ifunc, g = %lX\n", g);
340 }
341 
342 long set_ffunc(double (*f) ())
343 {
344  gf = (double (*) (long i0, long i1, long i2,
345  long i3, long i4, long i5,
346  double d0, double d1, double d2, double d3,
347  double d4, double d5, double d6, double d7,
348  double d8, double d9,
349  long i6, long i7))f;
350  printf("set_ffunc, gf = %lX\n", gf);
351 }
352 
353 long call_ifunc() {
354  printf("call_ifunc, g = %lX\n", g);
355  return g();
356 }
357 
358 double call_ffunc() {
359  printf("call_ffunc, gf = %lX\n", gf);
360  return gf(100,101,102,
361  103,104,105,
362  1000.0, 1010.0, 1020.0, 1030.0,
363  1040.0, 1050.0, 1060.0, 1070.0,
364  2080.0, 2090.0,
365  206, 207);
366 }
367 
369  return (sizeof(void *));
370 }
371 
373  return (sizeof(float));
374 }
375 
377  return (sizeof(double));
378 }
379 
381  return (sizeof(long));
382 }
383 
385  return (sizeof(int));
386 }
387 
389  return (sizeof(eusinteger_t));
390 }
391 
393  return (sizeof(eusfloat_t));
394 }
395 
396 };
long ret_long(long a, long b)
Definition: test_foreign.c:238
int efv_test(int n, eusfloat_t *src)
Definition: test_foreign.c:174
f
long call_ifunc()
Definition: test_foreign.c:353
long get_size_of_long()
Definition: test_foreign.c:380
static long(* g)()
Definition: test_foreign.c:328
eusinteger_t ret_eusinteger(eusinteger_t a, eusinteger_t b)
Definition: test_foreign.c:247
int int_long_short_test(long l, int i, short s)
Definition: test_foreign.c:194
long get_size_of_pointer()
Definition: test_foreign.c:368
GLfloat n[6][3]
Definition: cube.c:15
int lv_test(int n, long *src)
Definition: test_foreign.c:130
long set_ifunc(long(*f)())
Definition: test_foreign.c:336
eusfloat_t ret_eusfloat(eusfloat_t a, eusfloat_t b)
Definition: test_foreign.c:220
long get_size_of_eusfloat()
Definition: test_foreign.c:392
eusfloat_t test_testf(long i0, long i1, long i2, long i3, long i4, long i5, eusfloat_t d0, eusfloat_t d1, eusfloat_t d2, eusfloat_t d3, eusfloat_t d4, eusfloat_t d5, eusfloat_t d6, eusfloat_t d7, eusfloat_t d8, eusfloat_t d9, long i6, long i7)
Definition: test_foreign.c:292
double test_testd(long i0, long i1, long i2, long i3, long i4, long i5, double d0, double d1, double d2, double d3, double d4, double d5, double d6, double d7, double d8, double d9, long i6, long i7)
Definition: test_foreign.c:256
long l
Definition: structsize.c:3
double call_ffunc()
Definition: test_foreign.c:358
short s
Definition: structsize.c:2
int str_test(int n, char *src)
Definition: test_foreign.c:185
int test_testfd(long i0, long i1, long i2, long i3, long i4, long i5, double d0, float d1, double d2, float d3, float d4, double d5, double d6, float d7, float d8, double d9, double d10, float d11, long i6, long i7)
Definition: test_foreign.c:310
int eiv_test(int n, eusinteger_t *src)
Definition: test_foreign.c:141
double ret_double(double a, double b)
Definition: test_foreign.c:211
int eusfloat_test(int n, eusfloat_t f1, eusfloat_t f2, eusfloat_t f3, eusfloat_t f4)
Definition: test_foreign.c:103
long eusinteger_t
Definition: eus.h:19
int float_test(int n, float f1, float f2, float f3, float f4)
Definition: test_foreign.c:71
long get_size_of_int()
Definition: test_foreign.c:384
int eusinteger_test(int n, eusinteger_t i1, eusinteger_t i2, eusinteger_t i3, eusinteger_t i4)
Definition: test_foreign.c:55
long get_size_of_float32()
Definition: test_foreign.c:372
float ret_float(float a, float b)
Definition: test_foreign.c:202
double test_testd2(long i0, long i1, long i2, long i3, long i4, long i5, double d0, double d1, double d2, double d3, double d4, double d5, double d6, double d7, double d8, double d9, double d10, long i6, long i7)
Definition: test_foreign.c:274
int double_test(long n, double d1, double d2, double d3, double d4)
Definition: test_foreign.c:87
int ret_int(int a, int b)
Definition: test_foreign.c:229
int long_test(long n, long d1, long d2, long d3, long d4)
Definition: test_foreign.c:39
int iv_test(int n, int *src)
Definition: test_foreign.c:119
long get_size_of_double()
Definition: test_foreign.c:376
long set_ffunc(double(*f)())
Definition: test_foreign.c:342
double eusfloat_t
Definition: eus.h:21
int int_test(int n, int i1, int i2, int i3, int i4)
Definition: test_foreign.c:23
static double(* gf)(long i0, long i1, long i2, long i3, long i4, long i5, double d0, double d1, double d2, double d3, double d4, double d5, double d6, double d7, double d8, double d9, long i6, long i7)
Definition: test_foreign.c:329
int dv_test(int n, double *src)
Definition: test_foreign.c:163
int fv_test(int n, float *src)
Definition: test_foreign.c:152
long get_size_of_eusinteger()
Definition: test_foreign.c:388
char a[26]
Definition: freq.c:4


euslisp
Author(s): Toshihiro Matsui
autogenerated on Mon Feb 28 2022 22:18:28