Mercurial > pub > dyncall > dyncall
comparison test/callf/main.c @ 358:30aae7371373
- extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
- made formatted call (dcV?{Call,Arg}F) interface use those calling convention mode signature specifications to begin with
- extended callf testcode with one standard and one vararg call to test those cc mode switches
author | Tassilo Philipp |
---|---|
date | Mon, 13 Apr 2020 15:12:01 +0200 |
parents | f5577f6bf97a |
children | 78dfa2f9783a |
comparison
equal
deleted
inserted
replaced
357:d982a00c2177 | 358:30aae7371373 |
---|---|
29 | 29 |
30 #include "../../dyncall/dyncall_callf.h" | 30 #include "../../dyncall/dyncall_callf.h" |
31 #include "../common/platformInit.h" | 31 #include "../common/platformInit.h" |
32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | 32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ |
33 | 33 |
34 #include <stdarg.h> | |
35 | |
34 | 36 |
35 /* sample void function */ | 37 /* sample void function */ |
36 | 38 |
37 int vf_iii(int x,int y,int z) | 39 int vf_iii(int x,int y,int z) |
38 { | 40 { |
42 } | 44 } |
43 | 45 |
44 int vf_ffiffiffi(float a, float b, int c, float d, float e, int f, float g, float h, int i) | 46 int vf_ffiffiffi(float a, float b, int c, float d, float e, int f, float g, float h, int i) |
45 { | 47 { |
46 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); | 48 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); |
49 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r); | |
50 return r; | |
51 } | |
52 | |
53 int vf_ffiV(float a, float b, int c, ...) | |
54 { | |
55 va_list ap; | |
56 double d, e, g, h; | |
57 int f, i; | |
58 int r; | |
59 | |
60 va_start(ap, c); | |
61 d = va_arg(ap, double); | |
62 e = va_arg(ap, double); | |
63 f = va_arg(ap, int); | |
64 g = va_arg(ap, double); | |
65 h = va_arg(ap, double); | |
66 i = va_arg(ap, int); | |
67 va_end(ap); | |
68 | |
69 r = (a == 1.f && b == 2.f && c == 3 && d == 4. && e == 5. && f == 6 && g == 7. && h == 8. && i == 9); | |
47 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r); | 70 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r); |
48 return r; | 71 return r; |
49 } | 72 } |
50 | 73 |
51 /* main */ | 74 /* main */ |
71 dcReset(vm); | 94 dcReset(vm); |
72 printf("\ncallf ffiffiffi)i: "); | 95 printf("\ncallf ffiffiffi)i: "); |
73 dcCallF(vm, &ret, (void*)&vf_ffiffiffi, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9); | 96 dcCallF(vm, &ret, (void*)&vf_ffiffiffi, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9); |
74 r = ret.i && r; | 97 r = ret.i && r; |
75 | 98 |
99 /* same but with calling convention prefix */ | |
100 dcReset(vm); | |
101 printf("\ncallf _:ffiffiffi)i: "); | |
102 dcCallF(vm, &ret, (void*)&vf_ffiffiffi, "_:ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9); | |
103 r = ret.i && r; | |
104 | |
105 /* vararg call */ | |
106 dcReset(vm); | |
107 printf("\ncallf _effi_.ddiddi)i: "); | |
108 dcCallF(vm, &ret, (void*)&vf_ffiV, "_effi_.ddiddi)i", 1.f, 2.f, 3, 4., 5., 6, 7., 8., 9); | |
109 r = ret.i && r; | |
76 | 110 |
77 /* arg binding then call using 'formatted' API */ | 111 /* arg binding then call using 'formatted' API */ |
78 dcReset(vm); | 112 dcReset(vm); |
79 printf("\nargf iii)i then call: "); | 113 printf("\nargf iii)i then call: "); |
80 dcArgF(vm, "iii)i", 1, 2, 3); | 114 dcArgF(vm, "iii)i", 1, 2, 3); |