comparison test/ellipsis/ellipsis.cc @ 0:3e629dc19168

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:24:28 +0100
parents
children 9bd3c5219505
comparison
equal deleted inserted replaced
-1:000000000000 0:3e629dc19168
1 /*
2
3 Package: dyncall
4 Library: test
5 File: test/ellipsis/ellipsis.cc
6 Description:
7 License:
8
9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>,
10 Tassilo Philipp <tphilipp@potion-studios.com>
11
12 Permission to use, copy, modify, and distribute this software for any
13 purpose with or without fee is hereby granted, provided that the above
14 copyright notice and this permission notice appear in all copies.
15
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
24 */
25
26
27
28 #include "config.h"
29 #include "../../dyncall/dyncall.h"
30 #include "../../dyncall/dyncall_value.h"
31
32
33 #if defined(__SUNPRO_CC) || defined(__ANDROID__)
34 #include <stdarg.h>
35 #else
36 #include <cstdarg>
37 #endif
38
39 DCValue mValue[NARGS];
40
41 void clearValues() { for(int i = 0;i<NARGS;++i) mValue[i].L = 0xCAFEBABEDEADC0DEULL; }
42
43 template<typename T> void g(T value, int pos);
44
45 template<> void g(DCchar value, int pos) { mValue[pos].c = value; }
46 template<> void g(DCshort value, int pos) { mValue[pos].s = value; }
47 template<> void g(DCint value, int pos) { mValue[pos].i = value; }
48 template<> void g(DClong value, int pos) { mValue[pos].l = value; }
49 template<> void g(DClonglong value, int pos) { mValue[pos].L = value; }
50 template<> void g(DCfloat value, int pos) { mValue[pos].f = value; }
51 template<> void g(DCdouble value, int pos) { mValue[pos].d = value; }
52 template<> void g(DCpointer value, int pos) { mValue[pos].p = value; }
53
54 DCValue* getArg(int pos) { return &mValue[pos]; }
55
56 int gID;
57 int getId() { return gID; }
58
59 extern "C" {
60
61 #define VF0(id,S) void S () {gID=id;}
62 #define VF1(id,A1,S) void S (A1 a1) {gID=id;g<A1>(a1,0);}
63 #define VF2(id,A1,A2,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);va_end(l);}
64 #define VF3(id,A1,A2,A3,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(va_arg(l,A3),2);va_end(l);}
65 #define VF4(id,A1,A2,A3,A4,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(va_arg(l,A3),2);g<A4>(va_arg(l,A4),3);va_end(l);}
66 #define VF5(id,A1,A2,A3,A4,A5,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(va_arg(l,A3),2);g<A4>(va_arg(l,A4),3);g<A5>(va_arg(l,A5),4);va_end(l);}
67 #define VF6(id,A1,A2,A3,A4,A5,A6,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(va_arg(l,A3),2);g<A4>(va_arg(l,A4),3);g<A5>(va_arg(l,A5),4);g<A6>(va_arg(l,A6),5);va_end(l);}
68 #define VF7(id,A1,A2,A3,A4,A5,A6,A7,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(va_arg(l,A3),2);g<A4>(va_arg(l,A4),3);g<A5>(va_arg(l,A5),4);g<A6>(va_arg(l,A6),5);g<A7>(va_arg(l,A7),6);va_end(l);}
69 #define VF8(id,A1,A2,A3,A4,A5,A6,A7,A8,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(a3,2);g<A4>(a4,3);g<A5>(a5,4);g<A6>(a6,5);g<A7>(a7,6);g<A8>(a8,7);va_end(l);}
70 #define VF9(id,A1,A2,A3,A4,A5,A6,A7,A8,A9,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(a3,2);g<A4>(a4,3);g<A5>(a5,4);g<A6>(a6,5);g<A7>(a7,6);g<A8>(a8,7);g<A9>(a9,8);va_end(l);}
71 #define VF10(id,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,S) void S (A1 a1, ...) {va_list l;va_start(l,a1);gID=id;g<A1>(a1,0);g<A2>(va_arg(l,A2),1);g<A3>(a3,2);g<A4>(a4,3);g<A5>(a5,4);g<A6>(a6,5);g<A7>(a7,6);g<A8>(a8,7);g<A9>(a9,8);g<A10>(a10,9);va_end(l);}
72
73 #include "case.h"
74
75 }
76
77 #undef VF0
78 #undef VF1
79 #undef VF2
80 #undef VF3
81 #undef VF4
82 #undef VF5
83 #undef VF6
84 #undef VF7
85 #undef VF8
86 #undef VF9
87 #undef VF10
88
89 #define VF0(id,S) (void*)S,
90 #define VF1(id,A1,S) (void*)S,
91 #define VF2(id,A1,A2,S) (void*)S,
92 #define VF3(id,A1,A2,A3,S) (void*)S,
93 #define VF4(id,A1,A2,A3,A4,S) (void*)S,
94 #define VF5(id,A1,A2,A3,A4,A5,S) (void*)S,
95 #define VF6(id,A1,A2,A3,A4,A5,A6,S) (void*)S,
96 #define VF7(id,A1,A2,A3,A4,A5,A6,A7,S) (void*)S,
97 #define VF8(id,A1,A2,A3,A4,A5,A6,A7,A8,S) (void*)S,
98 #define VF9(id,A1,A2,A3,A4,A5,A6,A7,A8,A9,S) (void*)S,
99 #define VF10(id,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,S) (void*)S,
100
101 DCpointer gFuncTable[] = {
102 #include "case.h"
103 };
104
105 DCpointer getFunc(int x) {
106 return gFuncTable[x];
107 }