Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_api.c @ 466:ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
for upcoming aggregate support (until now only x86 platforms allowed for
specifically selecting thiscall mode, given the different conventions on
the same platform); also added respective DC_SIGCHAR_CC_THISCALL ('*')
author | Tassilo Philipp |
---|---|
date | Wed, 02 Feb 2022 18:30:44 +0100 |
parents | 2fb084f98439 |
children | 71c884e610f0 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_api.c | |
6 Description: C interface to call vm | |
7 License: | |
8 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 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 "dyncall.h" | |
29 #include "dyncall_callvm.h" | |
30 | |
31 void dcReset(DCCallVM* vm) | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
32 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
33 vm->mVTpointer->reset(vm); |
0 | 34 } |
35 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
36 void dcFree(DCCallVM* vm) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
37 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
38 vm->mVTpointer->free(vm); |
0 | 39 } |
40 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
41 void dcMode(DCCallVM* vm,DCint mode) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
42 { |
0 | 43 vm->mVTpointer->mode(vm,mode); |
44 } | |
45 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
46 void dcArgBool(DCCallVM* vm,DCbool x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
47 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
48 vm->mVTpointer->argBool(vm, x); |
0 | 49 } |
50 | |
51 void dcArgChar(DCCallVM* vm,DCchar x) | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
52 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
53 vm->mVTpointer->argChar(vm, x); |
0 | 54 } |
55 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
56 void dcArgShort(DCCallVM* vm,DCshort x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
57 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
58 vm->mVTpointer->argShort(vm, x); |
0 | 59 } |
60 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
61 void dcArgInt(DCCallVM* vm,DCint x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
62 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
63 vm->mVTpointer->argInt(vm, x); |
0 | 64 } |
65 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
66 void dcArgLong(DCCallVM* vm,DClong x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
67 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
68 vm->mVTpointer->argLong(vm, x); |
0 | 69 } |
70 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
71 void dcArgLongLong(DCCallVM* vm, DClonglong x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
72 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
73 vm->mVTpointer->argLongLong(vm, x); |
0 | 74 } |
75 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
76 void dcArgFloat(DCCallVM* vm, DCfloat x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
77 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
78 vm->mVTpointer->argFloat(vm, x); |
0 | 79 } |
80 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
81 void dcArgDouble(DCCallVM* vm, DCdouble x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
82 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
83 vm->mVTpointer->argDouble(vm, x); |
0 | 84 } |
85 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
86 void dcArgPointer(DCCallVM* vm, DCpointer x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
87 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
88 vm->mVTpointer->argPointer(vm, x); |
0 | 89 } |
90 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
91 void dcArgStruct(DCCallVM* vm, DCstruct* s, DCpointer x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
92 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
93 vm->mVTpointer->argStruct(vm, s, x); |
0 | 94 } |
95 | |
96 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
97 void dcCallVoid(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
98 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
99 vm->mVTpointer->callVoid(vm, funcptr); |
0 | 100 } |
101 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
102 DCchar dcCallChar(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
103 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
104 return vm->mVTpointer->callChar(vm, funcptr); |
0 | 105 } |
106 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
107 DCbool dcCallBool(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
108 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
109 return vm->mVTpointer->callBool(vm, funcptr); |
0 | 110 } |
111 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
112 DCshort dcCallShort(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
113 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
114 return vm->mVTpointer->callShort(vm, funcptr); |
0 | 115 } |
116 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
117 DCint dcCallInt(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
118 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
119 return vm->mVTpointer->callInt(vm, funcptr); |
0 | 120 } |
121 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
122 DClong dcCallLong(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
123 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
124 return vm->mVTpointer->callLong(vm, funcptr); |
0 | 125 } |
126 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
127 DClonglong dcCallLongLong(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
128 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
129 return vm->mVTpointer->callLongLong(vm, funcptr); |
0 | 130 } |
131 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
132 DCfloat dcCallFloat(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
133 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
134 return vm->mVTpointer->callFloat(vm, funcptr); |
0 | 135 } |
136 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
137 DCdouble dcCallDouble(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
138 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
139 return vm->mVTpointer->callDouble(vm, funcptr); |
0 | 140 } |
141 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
142 DCpointer dcCallPointer(DCCallVM* vm, DCpointer funcptr) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
143 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
144 return vm->mVTpointer->callPointer(vm, funcptr); |
0 | 145 } |
146 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
147 void dcCallStruct(DCCallVM* vm, DCpointer funcptr, DCstruct* s, DCpointer x) |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
148 { |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
149 vm->mVTpointer->callStruct(vm, funcptr, s, x); |
0 | 150 } |
151 | |
152 DCint dcGetError(DCCallVM *vm) | |
153 { | |
154 return vm->mError; | |
155 } | |
156 | |
362
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
157 DCint dcGetModeFromCCSigChar(DCsigchar sig_char) |
171
011b5e3a8548
- compatibility for older platforms - use ANSI comments
cslag
parents:
84
diff
changeset
|
158 { |
362
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
159 switch(sig_char) |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
160 { |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
161 case DC_SIGCHAR_CC_DEFAULT: return DC_CALL_C_DEFAULT; |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
367
diff
changeset
|
162 case DC_SIGCHAR_CC_THISCALL: return DC_CALL_C_DEFAULT_THIS; |
362
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
163 case DC_SIGCHAR_CC_ELLIPSIS: return DC_CALL_C_ELLIPSIS; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
164 case DC_SIGCHAR_CC_ELLIPSIS_VARARGS: return DC_CALL_C_ELLIPSIS_VARARGS; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
165 case DC_SIGCHAR_CC_CDECL: return DC_CALL_C_X86_CDECL; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
166 case DC_SIGCHAR_CC_STDCALL: return DC_CALL_C_X86_WIN32_STD; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
167 case DC_SIGCHAR_CC_FASTCALL_MS: return DC_CALL_C_X86_WIN32_FAST_MS; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
168 case DC_SIGCHAR_CC_FASTCALL_GNU: return DC_CALL_C_X86_WIN32_FAST_GNU; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
169 case DC_SIGCHAR_CC_THISCALL_MS: return DC_CALL_C_X86_WIN32_THIS_MS; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
170 case DC_SIGCHAR_CC_THISCALL_GNU: return DC_CALL_C_X86_WIN32_THIS_GNU; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
171 case DC_SIGCHAR_CC_ARM_ARM: return DC_CALL_C_ARM_ARM; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
172 case DC_SIGCHAR_CC_ARM_THUMB: return DC_CALL_C_ARM_THUMB; |
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
173 case DC_SIGCHAR_CC_SYSCALL: return DC_CALL_SYS_DEFAULT; |
171
011b5e3a8548
- compatibility for older platforms - use ANSI comments
cslag
parents:
84
diff
changeset
|
174 } |
362
78dfa2f9783a
- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode
Tassilo Philipp
parents:
281
diff
changeset
|
175 return DC_ERROR_UNSUPPORTED_MODE; |
171
011b5e3a8548
- compatibility for older platforms - use ANSI comments
cslag
parents:
84
diff
changeset
|
176 } |
0 | 177 |