annotate test/callf/main.c @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents 7608e34098b0
children d9558c1555df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/callf/main.c
379
7d9f526dc2ad cosmetics
Tassilo Philipp
parents: 371
diff changeset
6 Description:
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 /* test dcCallF API */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 #include "../../dyncall/dyncall_callf.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 #include "../common/platformInit.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
34 #include <stdarg.h>
387
11483966a3ee - excluding syscall stuff from callf test for beos/haiku
Tassilo Philipp
parents: 379
diff changeset
35 #if defined(DC_UNIX) && !defined(DC__OS_BeOS)
379
7d9f526dc2ad cosmetics
Tassilo Philipp
parents: 371
diff changeset
36 #include <sys/syscall.h>
362
78dfa2f9783a - added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents: 358
diff changeset
37 #endif
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
38
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 /* sample void function */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
42 int i_iii(int x,int y,int z)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 int r = (x == 1 && y == 2 && z == 3);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 printf("%d %d %d: %d", x, y, z, r);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 return r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
49 int i_ffiffiffi(float a, float b, int c, float d, float e, int f, float g, float h, int i)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 int r = (a == 1.f && b == 2.f && c == 3 && d == 4.f && e == 5.f && f == 6 && g == 7.f && h == 8.f && i == 9);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 return r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
56 int i_ffiV(float a, float b, int c, ...)
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
57 {
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
58 va_list ap;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
59 double d, e, g, h;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
60 int f, i;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
61 int r;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
62
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
63 va_start(ap, c);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
64 d = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
65 e = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
66 f = va_arg(ap, int);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
67 g = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
68 h = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
69 i = va_arg(ap, int);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
70 va_end(ap);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
71
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
72 r = (a == 1.f && b == 2.f && c == 3 && d == 4. && e == 5. && f == 6 && g == 7. && h == 8. && i == 9);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
73 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
74 return r;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
75 }
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
76
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
77
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
78 #if defined(DC__Feature_AggrByVal)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
79 struct A { int i; char x[7]; long long dummy_too_big_for_regs[50]; }; /* returned via hidden ptr arg on x64/sysv */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
80 struct A A_cc(char a, char b)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
81 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
82 int i;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
83 struct A r = { (int)a-(int)b, { 3, a|b } };
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
84 for(i=2; i<7; ++i)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
85 r.x[i] = r.x[i-2]+r.x[i-1];
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
86 printf("%d %d: ", a, b);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
87 return r;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
88 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
89
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
90 struct B { int i; unsigned char x[7]; }; /* returned via regs on x64/sysv */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
91 struct B A_CC(unsigned char a, unsigned char b)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
92 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
93 int i;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
94 struct B r = { (int)a-(int)b, { 3, a|b } };
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
95 for(i=2; i<7; ++i)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
96 r.x[i] = r.x[i-2]+r.x[i-1];
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
97 printf("%d %d: ", a, b);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
98 return r;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
99 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
100 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
101
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
102
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 /* main */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 int main(int argc, char* argv[])
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 DCCallVM* vm;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 DCValue ret;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 int r = 1;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 dcTest_initPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 /* allocate call vm */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 vm = dcNewCallVM(4096);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117 /* calls using 'formatted' API */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119 printf("callf iii)i: ");
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
120 dcCallF(vm, &ret, (void*)&i_iii, "iii)i", 1, 2, 3);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121 r = ret.i && r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
122
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
123 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124 printf("\ncallf ffiffiffi)i: ");
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
125 dcCallF(vm, &ret, (void*)&i_ffiffiffi, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
126 r = ret.i && r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
127
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
128 /* same but with calling convention prefix */
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
129 dcReset(vm);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
130 printf("\ncallf _:ffiffiffi)i: ");
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
131 dcCallF(vm, &ret, (void*)&i_ffiffiffi, "_:ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
132 r = ret.i && r;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
133
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
134 /* vararg call */
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
135 dcReset(vm);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
136 printf("\ncallf _effi_.ddiddi)i: ");
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
137 dcCallF(vm, &ret, (void*)&i_ffiV, "_effi_.ddiddi)i", 1.f, 2.f, 3, 4., 5., 6, 7., 8., 9);
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
138 r = ret.i && r;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140 /* arg binding then call using 'formatted' API */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 dcReset(vm);
371
451299d50c1a - windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents: 363
diff changeset
142 /* reset calling convention too */
451299d50c1a - windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents: 363
diff changeset
143 dcMode(vm, DC_CALL_C_DEFAULT);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
144 printf("\nargf iii)i then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145 dcArgF(vm, "iii)i", 1, 2, 3);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
146 r = r && dcCallInt(vm, (void*)&i_iii);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149 printf("\nargf iii then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
150 dcArgF(vm, "iii", 1, 2, 3);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
151 r = r && dcCallInt(vm, (void*)&i_iii);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
152
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
153 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
154 printf("\nargf ffiffiffi)i then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
155 dcArgF(vm, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
156 r = r && dcCallInt(vm, (void*)&i_ffiffiffi);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
157
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
159 printf("\nargf ffiffiffi then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
160 dcArgF(vm, "ffiffiffi", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
161 r = r && dcCallInt(vm, (void*)&i_ffiffiffi);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
162
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
163 #if defined(DC__Feature_Syscall)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
164 # if defined(DC_UNIX)
362
78dfa2f9783a - added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents: 358
diff changeset
165 /* testing syscall using calling convention prefix - not available on all platforms */
78dfa2f9783a - added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents: 358
diff changeset
166 dcReset(vm);
363
3ff4a4ba7f0e - changelog addition
Tassilo Philipp
parents: 362
diff changeset
167 printf("\ncallf _$iZi)i");
362
78dfa2f9783a - added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents: 358
diff changeset
168 fflush(NULL); /* needed before syscall write as it's immediate, or order might be incorrect */
363
3ff4a4ba7f0e - changelog addition
Tassilo Philipp
parents: 362
diff changeset
169 dcCallF(vm, &ret, (DCpointer)(ptrdiff_t)SYS_write, "_$iZi)i", 1/*stdout*/, " = syscall: 1", 13);
362
78dfa2f9783a - added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents: 358
diff changeset
170 r = ret.i == 13 && r;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
171 # else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
172 /*@@@*/
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
173 # endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
174 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
175
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
176 #if defined(DC__Feature_AggrByVal)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
177 /* aggregate return value test */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
178 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
179 int r_;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
180 struct A a;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
181 DCaggr *s = dcNewAggr(1, sizeof(struct A));
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
182 dcAggrField(s, DC_SIGCHAR_INT, offsetof(struct A, i), 1);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
183 dcAggrField(s, DC_SIGCHAR_CHAR, offsetof(struct A, x), 7);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
184 dcCloseAggr(s);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
185
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
186 dcReset(vm);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
187 printf("\ncallf _:cc)A (A={ic[7]l[50]}): ");
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
188 dcCallF(vm, &ret, (void*)&A_cc, "_:cc)A", 3, 16, s, &a);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
189 r_ = ret.p == &a && a.i == -13 && a.x[0] == 3 && a.x[1] == 19 && a.x[2] == 22 && a.x[3] == 41 && a.x[4] == 63 && a.x[5] == 104 && a.x[6] == -89;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
190 printf("%d %d %d %d %d %d %d %d: %d", a.i, a.x[0], a.x[1], a.x[2], a.x[3], a.x[4], a.x[5], a.x[6], r_);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
191
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
192 dcFreeAggr(s);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
193
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
194 r = r_ && r;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
195 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
196 /* aggregate return value test */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
197 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
198 int r_;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
199 struct B b;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
200 DCaggr *s = dcNewAggr(1, sizeof(struct B));
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
201 dcAggrField(s, DC_SIGCHAR_INT, offsetof(struct B, i), 1);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
202 dcAggrField(s, DC_SIGCHAR_UCHAR, offsetof(struct B, x), 7);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
203 dcCloseAggr(s);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
204
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
205 dcReset(vm);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
206 printf("\ncallf _:cc)A (A={iC[7]}): ");
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
207 dcCallF(vm, &ret, (void*)&A_CC, "_:CC)A", 3, 16, s, &b);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
208 r_ = ret.p == &b && b.i == -13 && b.x[0] == 3 && b.x[1] == 19 && b.x[2] == 22 && b.x[3] == 41 && b.x[4] == 63 && b.x[5] == 104 && b.x[6] == 167;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
209 printf("%d %d %d %d %d %d %d %d: %d", b.i, b.x[0], b.x[1], b.x[2], b.x[3], b.x[4], b.x[5], b.x[6], r_);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
210
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
211 dcFreeAggr(s);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
212
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
213 r = r_ && r;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 410
diff changeset
214 }
362
78dfa2f9783a - added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents: 358
diff changeset
215 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
216
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
217 /* free vm */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
218 dcFree(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
219
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
220 printf("\nresult: callf: %d\n", r);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
221
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
222 dcTest_deInitPlatform();
379
7d9f526dc2ad cosmetics
Tassilo Philipp
parents: 371
diff changeset
223
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 387
diff changeset
224 return !r;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
225 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
226