ScummVM API documentation
as_callfunc.h
1 /*
2  AngelCode Scripting Library
3  Copyright (c) 2003-2021 Andreas Jonsson
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any
7  damages arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any
10  purpose, including commercial applications, and to alter it and
11  redistribute it freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you
14  must not claim that you wrote the original software. If you use
15  this software in a product, an acknowledgment in the product
16  documentation would be appreciated but is not required.
17 
18  2. Altered source versions must be plainly marked as such, and
19  must not be misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source
22  distribution.
23 
24  The original version of this library can be located at:
25  http://www.angelcode.com/angelscript/
26 
27  Andreas Jonsson
28  andreas@angelcode.com
29 */
30 
31 
32 //
33 // as_callfunc.h
34 //
35 // These functions handle the actual calling of system functions
36 //
37 
38 
39 #ifndef AS_CALLFUNC_H
40 #define AS_CALLFUNC_H
41 
42 #include "as_memory.h"
43 
44 BEGIN_AS_NAMESPACE
45 
46 class asCContext;
47 class asCScriptEngine;
48 class asCScriptFunction;
49 class asCObjectType;
51 
52 int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv, void *auxiliary, asSSystemFunctionInterface *internal);
53 
54 int PrepareSystemFunctionGeneric(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine *engine);
55 
56 int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine *engine);
57 
58 int CallSystemFunction(int id, asCContext *context);
59 
60 inline asPWORD FuncPtrToUInt(asFUNCTION_t func) {
61  // A little trickery as the C++ standard doesn't allow direct
62  // conversion between function pointer and data pointer
63  union {
64  asFUNCTION_t func;
65  asPWORD idx;
66  } u;
67  u.func = func;
68 
69  return u.idx;
70 }
71 
72 enum internalCallConv {
73  ICC_GENERIC_FUNC,
74  ICC_GENERIC_FUNC_RETURNINMEM, // never used
75  ICC_CDECL,
76  ICC_CDECL_RETURNINMEM,
77  ICC_STDCALL,
78  ICC_STDCALL_RETURNINMEM,
79  ICC_THISCALL,
80  ICC_THISCALL_RETURNINMEM,
81  ICC_VIRTUAL_THISCALL,
82  ICC_VIRTUAL_THISCALL_RETURNINMEM,
83  ICC_CDECL_OBJLAST,
84  ICC_CDECL_OBJLAST_RETURNINMEM,
85  ICC_CDECL_OBJFIRST,
86  ICC_CDECL_OBJFIRST_RETURNINMEM,
87  ICC_GENERIC_METHOD,
88  ICC_GENERIC_METHOD_RETURNINMEM, // never used
89  ICC_THISCALL_OBJLAST,
90  ICC_THISCALL_OBJLAST_RETURNINMEM,
91  ICC_VIRTUAL_THISCALL_OBJLAST,
92  ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM,
93  ICC_THISCALL_OBJFIRST,
94  ICC_THISCALL_OBJFIRST_RETURNINMEM,
95  ICC_VIRTUAL_THISCALL_OBJFIRST,
96  ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM
97 };
98 
100  asFUNCTION_t func;
101  int baseOffset;
102  internalCallConv callConv;
103  bool hostReturnInMemory;
104  bool hostReturnFloat;
105  int hostReturnSize;
106  int paramSize;
107  bool takesObjByVal;
108  asCArray<bool> paramAutoHandles; // TODO: Should be able to remove this array. Perhaps the flags can be stored together with the inOutFlags in asCScriptFunction?
109  bool returnAutoHandle;
110  int compositeOffset;
111  bool isCompositeIndirect;
112  void *auxiliary; // can be used for functors, e.g. by asCALL_THISCALL_ASGLOBAL or asCALL_THISCALL_OBJFIRST
113 
114  struct SClean {
115  asCObjectType *ot; // argument type for clean up
116  short op; // clean up operation: 0 = release, 1 = free, 2 = destruct then free
117  short off; // argument offset on the stack
118  };
119  asCArray<SClean> cleanArgs;
120 
122  Clear();
123  }
124 
126  *this = in;
127  }
128 
129  void Clear() {
130  func = 0;
131  baseOffset = 0;
132  callConv = ICC_GENERIC_FUNC;
133  hostReturnInMemory = false;
134  hostReturnFloat = false;
135  hostReturnSize = 0;
136  paramSize = 0;
137  takesObjByVal = false;
138  returnAutoHandle = false;
139  compositeOffset = 0;
140  isCompositeIndirect = false;
141  auxiliary = 0;
142 
143  paramAutoHandles.SetLength(0);
144  cleanArgs.SetLength(0);
145  }
146 
148  func = in.func;
149  baseOffset = in.baseOffset;
150  callConv = in.callConv;
151  hostReturnInMemory = in.hostReturnInMemory;
152  hostReturnFloat = in.hostReturnFloat;
153  hostReturnSize = in.hostReturnSize;
154  paramSize = in.paramSize;
155  takesObjByVal = in.takesObjByVal;
156  returnAutoHandle = in.returnAutoHandle;
157  compositeOffset = in.compositeOffset;
158  isCompositeIndirect = in.isCompositeIndirect;
159  auxiliary = in.auxiliary;
160 
161  cleanArgs = in.cleanArgs;
162  paramAutoHandles = in.paramAutoHandles;
163 
164  return *this;
165  }
166 };
167 
168 END_AS_NAMESPACE
169 
170 #endif
171 
Definition: as_callfunc.h:114
Definition: as_scriptfunction.h:146
Definition: as_objecttype.h:100
Definition: as_callfunc.h:99
Definition: angelscript.h:429
Definition: as_context.h:54
Definition: as_scriptengine.h:64