angelscript.h 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2017 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. [email protected]
  22. */
  23. // Modified by Lasse Oorni and Nathanial Lydick for Urho3D
  24. //
  25. // angelscript.h
  26. //
  27. // The script engine interface
  28. //
  29. #ifndef ANGELSCRIPT_H
  30. #define ANGELSCRIPT_H
  31. // Urho3D: Define AS_MAX_PORTABILITY for Web and 64-bit ARM platforms
  32. #if defined(__EMSCRIPTEN__) || defined(__aarch64__)
  33. #define AS_MAX_PORTABILITY
  34. #endif
  35. #include <stddef.h>
  36. #ifndef _MSC_VER
  37. #include <stdint.h>
  38. #endif
  39. #ifdef AS_USE_NAMESPACE
  40. #define BEGIN_AS_NAMESPACE namespace AngelScript {
  41. #define END_AS_NAMESPACE }
  42. #define AS_NAMESPACE_QUALIFIER AngelScript::
  43. #else
  44. #define BEGIN_AS_NAMESPACE
  45. #define END_AS_NAMESPACE
  46. #define AS_NAMESPACE_QUALIFIER ::
  47. #endif
  48. BEGIN_AS_NAMESPACE
  49. // AngelScript version
  50. #define ANGELSCRIPT_VERSION 23200
  51. #define ANGELSCRIPT_VERSION_STRING "2.32.0 WIP"
  52. // Data types
  53. class asIScriptEngine;
  54. class asIScriptModule;
  55. class asIScriptContext;
  56. class asIScriptGeneric;
  57. class asIScriptObject;
  58. class asITypeInfo;
  59. #ifdef AS_DEPRECATED
  60. // deprecated since 2.31.0 - 2015/11/18
  61. typedef asITypeInfo asIObjectType;
  62. #endif
  63. class asIScriptFunction;
  64. class asIBinaryStream;
  65. class asIJITCompiler;
  66. class asIThreadManager;
  67. class asILockableSharedBool;
  68. // Enumerations and constants
  69. // Return codes
  70. enum asERetCodes
  71. {
  72. asSUCCESS = 0,
  73. asERROR = -1,
  74. asCONTEXT_ACTIVE = -2,
  75. asCONTEXT_NOT_FINISHED = -3,
  76. asCONTEXT_NOT_PREPARED = -4,
  77. asINVALID_ARG = -5,
  78. asNO_FUNCTION = -6,
  79. asNOT_SUPPORTED = -7,
  80. asINVALID_NAME = -8,
  81. asNAME_TAKEN = -9,
  82. asINVALID_DECLARATION = -10,
  83. asINVALID_OBJECT = -11,
  84. asINVALID_TYPE = -12,
  85. asALREADY_REGISTERED = -13,
  86. asMULTIPLE_FUNCTIONS = -14,
  87. asNO_MODULE = -15,
  88. asNO_GLOBAL_VAR = -16,
  89. asINVALID_CONFIGURATION = -17,
  90. asINVALID_INTERFACE = -18,
  91. asCANT_BIND_ALL_FUNCTIONS = -19,
  92. asLOWER_ARRAY_DIMENSION_NOT_REGISTERED = -20,
  93. asWRONG_CONFIG_GROUP = -21,
  94. asCONFIG_GROUP_IS_IN_USE = -22,
  95. asILLEGAL_BEHAVIOUR_FOR_TYPE = -23,
  96. asWRONG_CALLING_CONV = -24,
  97. asBUILD_IN_PROGRESS = -25,
  98. asINIT_GLOBAL_VARS_FAILED = -26,
  99. asOUT_OF_MEMORY = -27,
  100. asMODULE_IS_IN_USE = -28
  101. };
  102. // Engine properties
  103. enum asEEngineProp
  104. {
  105. asEP_ALLOW_UNSAFE_REFERENCES = 1,
  106. asEP_OPTIMIZE_BYTECODE = 2,
  107. asEP_COPY_SCRIPT_SECTIONS = 3,
  108. asEP_MAX_STACK_SIZE = 4,
  109. asEP_USE_CHARACTER_LITERALS = 5,
  110. asEP_ALLOW_MULTILINE_STRINGS = 6,
  111. asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7,
  112. asEP_BUILD_WITHOUT_LINE_CUES = 8,
  113. asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9,
  114. asEP_REQUIRE_ENUM_SCOPE = 10,
  115. asEP_SCRIPT_SCANNER = 11,
  116. asEP_INCLUDE_JIT_INSTRUCTIONS = 12,
  117. asEP_STRING_ENCODING = 13,
  118. asEP_PROPERTY_ACCESSOR_MODE = 14,
  119. asEP_EXPAND_DEF_ARRAY_TO_TMPL = 15,
  120. asEP_AUTO_GARBAGE_COLLECT = 16,
  121. asEP_DISALLOW_GLOBAL_VARS = 17,
  122. asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT = 18,
  123. asEP_COMPILER_WARNINGS = 19,
  124. asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE = 20,
  125. asEP_ALTER_SYNTAX_NAMED_ARGS = 21,
  126. asEP_DISABLE_INTEGER_DIVISION = 22,
  127. asEP_DISALLOW_EMPTY_LIST_ELEMENTS = 23,
  128. asEP_PRIVATE_PROP_AS_PROTECTED = 24,
  129. asEP_ALLOW_UNICODE_IDENTIFIERS = 25,
  130. asEP_HEREDOC_TRIM_MODE = 26,
  131. asEP_MAX_NESTED_CALLS = 27,
  132. asEP_LAST_PROPERTY
  133. };
  134. // Calling conventions
  135. enum asECallConvTypes
  136. {
  137. asCALL_CDECL = 0,
  138. asCALL_STDCALL = 1,
  139. asCALL_THISCALL_ASGLOBAL = 2,
  140. asCALL_THISCALL = 3,
  141. asCALL_CDECL_OBJLAST = 4,
  142. asCALL_CDECL_OBJFIRST = 5,
  143. asCALL_GENERIC = 6,
  144. asCALL_THISCALL_OBJLAST = 7,
  145. asCALL_THISCALL_OBJFIRST = 8
  146. };
  147. // Object type flags
  148. enum asEObjTypeFlags
  149. {
  150. asOBJ_REF = (1<<0),
  151. asOBJ_VALUE = (1<<1),
  152. asOBJ_GC = (1<<2),
  153. asOBJ_POD = (1<<3),
  154. asOBJ_NOHANDLE = (1<<4),
  155. asOBJ_SCOPED = (1<<5),
  156. asOBJ_TEMPLATE = (1<<6),
  157. asOBJ_ASHANDLE = (1<<7),
  158. asOBJ_APP_CLASS = (1<<8),
  159. asOBJ_APP_CLASS_CONSTRUCTOR = (1<<9),
  160. asOBJ_APP_CLASS_DESTRUCTOR = (1<<10),
  161. asOBJ_APP_CLASS_ASSIGNMENT = (1<<11),
  162. asOBJ_APP_CLASS_COPY_CONSTRUCTOR = (1<<12),
  163. asOBJ_APP_CLASS_C = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR),
  164. asOBJ_APP_CLASS_CD = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR),
  165. asOBJ_APP_CLASS_CA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  166. asOBJ_APP_CLASS_CK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  167. asOBJ_APP_CLASS_CDA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  168. asOBJ_APP_CLASS_CDK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  169. asOBJ_APP_CLASS_CAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  170. asOBJ_APP_CLASS_CDAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  171. asOBJ_APP_CLASS_D = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR),
  172. asOBJ_APP_CLASS_DA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  173. asOBJ_APP_CLASS_DK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  174. asOBJ_APP_CLASS_DAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  175. asOBJ_APP_CLASS_A = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT),
  176. asOBJ_APP_CLASS_AK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  177. asOBJ_APP_CLASS_K = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  178. asOBJ_APP_PRIMITIVE = (1<<13),
  179. asOBJ_APP_FLOAT = (1<<14),
  180. asOBJ_APP_ARRAY = (1<<15),
  181. asOBJ_APP_CLASS_ALLINTS = (1<<16),
  182. asOBJ_APP_CLASS_ALLFLOATS = (1<<17),
  183. asOBJ_NOCOUNT = (1<<18),
  184. asOBJ_APP_CLASS_ALIGN8 = (1<<19),
  185. asOBJ_IMPLICIT_HANDLE = (1<<20),
  186. asOBJ_MASK_VALID_FLAGS = 0x1FFFFF,
  187. // Internal flags
  188. asOBJ_SCRIPT_OBJECT = (1<<21),
  189. asOBJ_SHARED = (1<<22),
  190. asOBJ_NOINHERIT = (1<<23),
  191. asOBJ_FUNCDEF = (1<<24),
  192. asOBJ_LIST_PATTERN = (1<<25),
  193. asOBJ_ENUM = (1<<26),
  194. asOBJ_TEMPLATE_SUBTYPE = (1<<27),
  195. asOBJ_TYPEDEF = (1<<28),
  196. asOBJ_ABSTRACT = (1<<29),
  197. asOBJ_APP_ALIGN16 = (1<<30)
  198. };
  199. // Behaviours
  200. enum asEBehaviours
  201. {
  202. // Value object memory management
  203. asBEHAVE_CONSTRUCT,
  204. asBEHAVE_LIST_CONSTRUCT,
  205. asBEHAVE_DESTRUCT,
  206. // Reference object memory management
  207. asBEHAVE_FACTORY,
  208. asBEHAVE_LIST_FACTORY,
  209. asBEHAVE_ADDREF,
  210. asBEHAVE_RELEASE,
  211. asBEHAVE_GET_WEAKREF_FLAG,
  212. // Object operators
  213. #ifdef AS_DEPRECATED
  214. // Deprecated since 2.30.0, 2014-10-24
  215. asBEHAVE_VALUE_CAST,
  216. asBEHAVE_IMPLICIT_VALUE_CAST,
  217. // Deprecated since 2.30.0, 2014-12-30
  218. asBEHAVE_REF_CAST,
  219. asBEHAVE_IMPLICIT_REF_CAST,
  220. #endif
  221. asBEHAVE_TEMPLATE_CALLBACK,
  222. // Garbage collection behaviours
  223. asBEHAVE_FIRST_GC,
  224. asBEHAVE_GETREFCOUNT = asBEHAVE_FIRST_GC,
  225. asBEHAVE_SETGCFLAG,
  226. asBEHAVE_GETGCFLAG,
  227. asBEHAVE_ENUMREFS,
  228. asBEHAVE_RELEASEREFS,
  229. asBEHAVE_LAST_GC = asBEHAVE_RELEASEREFS,
  230. asBEHAVE_MAX
  231. };
  232. // Context states
  233. enum asEContextState
  234. {
  235. asEXECUTION_FINISHED = 0,
  236. asEXECUTION_SUSPENDED = 1,
  237. asEXECUTION_ABORTED = 2,
  238. asEXECUTION_EXCEPTION = 3,
  239. asEXECUTION_PREPARED = 4,
  240. asEXECUTION_UNINITIALIZED = 5,
  241. asEXECUTION_ACTIVE = 6,
  242. asEXECUTION_ERROR = 7
  243. };
  244. // Message types
  245. enum asEMsgType
  246. {
  247. asMSGTYPE_ERROR = 0,
  248. asMSGTYPE_WARNING = 1,
  249. asMSGTYPE_INFORMATION = 2
  250. };
  251. // Garbage collector flags
  252. enum asEGCFlags
  253. {
  254. asGC_FULL_CYCLE = 1,
  255. asGC_ONE_STEP = 2,
  256. asGC_DESTROY_GARBAGE = 4,
  257. asGC_DETECT_GARBAGE = 8
  258. };
  259. // Token classes
  260. enum asETokenClass
  261. {
  262. asTC_UNKNOWN = 0,
  263. asTC_KEYWORD = 1,
  264. asTC_VALUE = 2,
  265. asTC_IDENTIFIER = 3,
  266. asTC_COMMENT = 4,
  267. asTC_WHITESPACE = 5
  268. };
  269. // Type id flags
  270. enum asETypeIdFlags
  271. {
  272. asTYPEID_VOID = 0,
  273. asTYPEID_BOOL = 1,
  274. asTYPEID_INT8 = 2,
  275. asTYPEID_INT16 = 3,
  276. asTYPEID_INT32 = 4,
  277. asTYPEID_INT64 = 5,
  278. asTYPEID_UINT8 = 6,
  279. asTYPEID_UINT16 = 7,
  280. asTYPEID_UINT32 = 8,
  281. asTYPEID_UINT64 = 9,
  282. asTYPEID_FLOAT = 10,
  283. asTYPEID_DOUBLE = 11,
  284. asTYPEID_OBJHANDLE = 0x40000000,
  285. asTYPEID_HANDLETOCONST = 0x20000000,
  286. asTYPEID_MASK_OBJECT = 0x1C000000,
  287. asTYPEID_APPOBJECT = 0x04000000,
  288. asTYPEID_SCRIPTOBJECT = 0x08000000,
  289. asTYPEID_TEMPLATE = 0x10000000,
  290. asTYPEID_MASK_SEQNBR = 0x03FFFFFF
  291. };
  292. // Type modifiers
  293. enum asETypeModifiers
  294. {
  295. asTM_NONE = 0,
  296. asTM_INREF = 1,
  297. asTM_OUTREF = 2,
  298. asTM_INOUTREF = 3,
  299. asTM_CONST = 4
  300. };
  301. // GetModule flags
  302. enum asEGMFlags
  303. {
  304. asGM_ONLY_IF_EXISTS = 0,
  305. asGM_CREATE_IF_NOT_EXISTS = 1,
  306. asGM_ALWAYS_CREATE = 2
  307. };
  308. // Compile flags
  309. enum asECompileFlags
  310. {
  311. asCOMP_ADD_TO_MODULE = 1
  312. };
  313. // Function types
  314. enum asEFuncType
  315. {
  316. asFUNC_DUMMY =-1,
  317. asFUNC_SYSTEM = 0,
  318. asFUNC_SCRIPT = 1,
  319. asFUNC_INTERFACE = 2,
  320. asFUNC_VIRTUAL = 3,
  321. asFUNC_FUNCDEF = 4,
  322. asFUNC_IMPORTED = 5,
  323. asFUNC_DELEGATE = 6
  324. };
  325. //
  326. // asBYTE = 8 bits
  327. // asWORD = 16 bits
  328. // asDWORD = 32 bits
  329. // asQWORD = 64 bits
  330. // asPWORD = size of pointer
  331. //
  332. typedef unsigned char asBYTE;
  333. typedef unsigned short asWORD;
  334. typedef unsigned int asUINT;
  335. #if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(__S3E__) || (defined(_MSC_VER) && defined(__clang__))
  336. // size_t is not really correct, since it only guaranteed to be large enough to hold the segment size.
  337. // For example, on 16bit systems the size_t may be 16bits only even if pointers are 32bit. But nobody
  338. // is likely to use MSVC6 to compile for 16bit systems anymore, so this should be ok.
  339. typedef size_t asPWORD;
  340. #else
  341. typedef uintptr_t asPWORD;
  342. #endif
  343. #ifdef __LP64__
  344. typedef unsigned int asDWORD;
  345. typedef unsigned long asQWORD;
  346. typedef long asINT64;
  347. #else
  348. typedef unsigned long asDWORD;
  349. #if !defined(_MSC_VER) && (defined(__GNUC__) || defined(__MWERKS__) || defined(__SUNPRO_CC) || defined(__psp2__))
  350. typedef uint64_t asQWORD;
  351. typedef int64_t asINT64;
  352. #else
  353. typedef unsigned __int64 asQWORD;
  354. typedef __int64 asINT64;
  355. #endif
  356. #endif
  357. // Is the target a 64bit system?
  358. #if defined(__LP64__) || defined(__amd64__) || defined(__x86_64__) || defined(_M_X64)
  359. #ifndef AS_64BIT_PTR
  360. #define AS_64BIT_PTR
  361. #endif
  362. #endif
  363. typedef void (*asFUNCTION_t)();
  364. typedef void (*asGENFUNC_t)(asIScriptGeneric *);
  365. typedef void *(*asALLOCFUNC_t)(size_t);
  366. typedef void (*asFREEFUNC_t)(void *);
  367. typedef void (*asCLEANENGINEFUNC_t)(asIScriptEngine *);
  368. typedef void (*asCLEANMODULEFUNC_t)(asIScriptModule *);
  369. typedef void (*asCLEANCONTEXTFUNC_t)(asIScriptContext *);
  370. typedef void (*asCLEANFUNCTIONFUNC_t)(asIScriptFunction *);
  371. typedef void (*asCLEANTYPEINFOFUNC_t)(asITypeInfo *);
  372. #ifdef AS_DEPRECATED
  373. // deprecated since 2.31.0 - 2015/11/18
  374. typedef asCLEANTYPEINFOFUNC_t asCLEANOBJECTTYPEFUNC_t;
  375. #endif
  376. typedef void (*asCLEANSCRIPTOBJECTFUNC_t)(asIScriptObject *);
  377. typedef asIScriptContext *(*asREQUESTCONTEXTFUNC_t)(asIScriptEngine *, void *);
  378. typedef void (*asRETURNCONTEXTFUNC_t)(asIScriptEngine *, asIScriptContext *, void *);
  379. // Check if the compiler can use C++11 features
  380. // Urho3D: restored earlier ifdef
  381. #if !defined(_MSC_VER) || _MSC_VER >= 1700 // MSVC 2012
  382. #if !defined(__GNUC__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) // gnuc 4.7
  383. #if !(defined(__GNUC__) && defined(__cplusplus) && __cplusplus < 201103L) // g++ -std=c++11
  384. #if !defined(__SUNPRO_CC)
  385. #define AS_CAN_USE_CPP11 1
  386. #endif
  387. #endif
  388. #endif
  389. #endif
  390. // This macro does basically the same thing as offsetof defined in stddef.h, but
  391. // GNUC should not complain about the usage as I'm not using 0 as the base pointer.
  392. #define asOFFSET(s,m) ((size_t)(&reinterpret_cast<s*>(100000)->m)-100000)
  393. #define asFUNCTION(f) asFunctionPtr(f)
  394. #if (defined(_MSC_VER) && _MSC_VER <= 1200) || (defined(__BORLANDC__) && __BORLANDC__ < 0x590)
  395. // MSVC 6 has a bug that prevents it from properly compiling using the correct asFUNCTIONPR with operator >
  396. // so we need to use ordinary C style cast instead of static_cast. The drawback is that the compiler can't
  397. // check that the cast is really valid.
  398. // BCC v5.8 (C++Builder 2006) and earlier have a similar bug which forces us to fall back to a C-style cast.
  399. #define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())((r (*)p)(f)))
  400. #elif (defined(_MSC_VER) && _MSC_VER >= 1900)
  401. // Urho3D: VS2015 does not compile the C-style cast of the function pointer
  402. #define asFUNCTIONPR(f,p,r) asFunctionPtr(reinterpret_cast<void (*)()>(static_cast<r (*)p>(f)))
  403. #else
  404. #define asFUNCTIONPR(f,p,r) asFunctionPtr(reinterpret_cast<void (*)()>(static_cast<r (*)p>(f)))
  405. #endif
  406. #ifndef AS_NO_CLASS_METHODS
  407. class asCUnknownClass;
  408. typedef void (asCUnknownClass::*asMETHOD_t)();
  409. struct asSFuncPtr
  410. {
  411. asSFuncPtr(asBYTE f = 0)
  412. {
  413. for( size_t n = 0; n < sizeof(ptr.dummy); n++ )
  414. ptr.dummy[n] = 0;
  415. flag = f;
  416. }
  417. void CopyMethodPtr(const void *mthdPtr, size_t size)
  418. {
  419. for( size_t n = 0; n < size; n++ )
  420. ptr.dummy[n] = reinterpret_cast<const char *>(mthdPtr)[n];
  421. }
  422. union
  423. {
  424. // The largest known method point is 20 bytes (MSVC 64bit),
  425. // but with 8byte alignment this becomes 24 bytes. So we need
  426. // to be able to store at least that much.
  427. char dummy[25];
  428. struct {asMETHOD_t mthd; char dummy[25-sizeof(asMETHOD_t)];} m;
  429. struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
  430. } ptr;
  431. asBYTE flag; // 1 = generic, 2 = global func, 3 = method
  432. };
  433. #if defined(__BORLANDC__)
  434. // A bug in BCC (QC #85374) makes it impossible to distinguish const/non-const method overloads
  435. // with static_cast<>. The workaround is to use an _implicit_cast instead.
  436. #if __BORLANDC__ < 0x590
  437. // BCC v5.8 (C++Builder 2006) and earlier have an even more annoying bug which causes
  438. // the "pretty" workaround below (with _implicit_cast<>) to fail. For these compilers
  439. // we need to use a traditional C-style cast.
  440. #define AS_METHOD_AMBIGUITY_CAST(t) (t)
  441. #else
  442. template <typename T>
  443. T _implicit_cast (T val)
  444. { return val; }
  445. #define AS_METHOD_AMBIGUITY_CAST(t) AS_NAMESPACE_QUALIFIER _implicit_cast<t >
  446. #endif
  447. #else
  448. #define AS_METHOD_AMBIGUITY_CAST(t) static_cast<t >
  449. #endif
  450. #define asMETHOD(c,m) asSMethodPtr<sizeof(void (c::*)())>::Convert((void (c::*)())(&c::m))
  451. #define asMETHODPR(c,m,p,r) asSMethodPtr<sizeof(void (c::*)())>::Convert(AS_METHOD_AMBIGUITY_CAST(r (c::*)p)(&c::m))
  452. #else // Class methods are disabled
  453. struct asSFuncPtr
  454. {
  455. asSFuncPtr(asBYTE f)
  456. {
  457. for( int n = 0; n < sizeof(ptr.dummy); n++ )
  458. ptr.dummy[n] = 0;
  459. flag = f;
  460. }
  461. union
  462. {
  463. char dummy[25]; // largest known class method pointer
  464. struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
  465. } ptr;
  466. asBYTE flag; // 1 = generic, 2 = global func
  467. };
  468. #endif
  469. struct asSMessageInfo
  470. {
  471. const char *section;
  472. int row;
  473. int col;
  474. asEMsgType type;
  475. const char *message;
  476. };
  477. // API functions
  478. // ANGELSCRIPT_EXPORT is defined when compiling the dll or lib
  479. // ANGELSCRIPT_DLL_LIBRARY_IMPORT is defined when dynamically linking to the
  480. // dll through the link lib automatically generated by MSVC++
  481. // ANGELSCRIPT_DLL_MANUAL_IMPORT is defined when manually loading the dll
  482. // Don't define anything when linking statically to the lib
  483. #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
  484. #if defined(ANGELSCRIPT_EXPORT)
  485. #define AS_API __declspec(dllexport)
  486. #elif defined(ANGELSCRIPT_DLL_LIBRARY_IMPORT)
  487. #define AS_API __declspec(dllimport)
  488. #else // statically linked library
  489. #define AS_API
  490. #endif
  491. #elif defined(__GNUC__)
  492. #if defined(ANGELSCRIPT_EXPORT)
  493. #define AS_API __attribute__((visibility ("default")))
  494. #else
  495. #define AS_API
  496. #endif
  497. #else
  498. #define AS_API
  499. #endif
  500. #ifndef ANGELSCRIPT_DLL_MANUAL_IMPORT
  501. extern "C"
  502. {
  503. // Engine
  504. AS_API asIScriptEngine *asCreateScriptEngine(asDWORD version = ANGELSCRIPT_VERSION);
  505. AS_API const char *asGetLibraryVersion();
  506. AS_API const char *asGetLibraryOptions();
  507. // Context
  508. AS_API asIScriptContext *asGetActiveContext();
  509. // Thread support
  510. AS_API int asPrepareMultithread(asIThreadManager *externalMgr = 0);
  511. AS_API void asUnprepareMultithread();
  512. AS_API asIThreadManager *asGetThreadManager();
  513. AS_API void asAcquireExclusiveLock();
  514. AS_API void asReleaseExclusiveLock();
  515. AS_API void asAcquireSharedLock();
  516. AS_API void asReleaseSharedLock();
  517. AS_API int asAtomicInc(int &value);
  518. AS_API int asAtomicDec(int &value);
  519. AS_API int asThreadCleanup();
  520. // Memory management
  521. AS_API int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);
  522. AS_API int asResetGlobalMemoryFunctions();
  523. AS_API void *asAllocMem(size_t size);
  524. AS_API void asFreeMem(void *mem);
  525. // Auxiliary
  526. AS_API asILockableSharedBool *asCreateLockableSharedBool();
  527. }
  528. #endif // ANGELSCRIPT_DLL_MANUAL_IMPORT
  529. // Determine traits of a type for registration of value types
  530. // Relies on C++11 features so it can not be used with non-compliant compilers
  531. #ifdef AS_CAN_USE_CPP11
  532. END_AS_NAMESPACE
  533. #include <type_traits>
  534. BEGIN_AS_NAMESPACE
  535. template<typename T>
  536. asUINT asGetTypeTraits()
  537. {
  538. // Urho3D: restore earlier ifdefs due to some Android CI builds breaking
  539. #if defined(_MSC_VER) || defined(_LIBCPP_TYPE_TRAITS) || (__GNUC__ >= 5)
  540. // MSVC, XCode/Clang, and gnuc 5+
  541. // C++11 compliant code
  542. bool hasConstructor = std::is_default_constructible<T>::value && !std::is_trivially_default_constructible<T>::value;
  543. bool hasDestructor = std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value;
  544. bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::is_trivially_copy_assignable<T>::value;
  545. bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::is_trivially_copy_constructible<T>::value;
  546. #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
  547. // gnuc 4.8 is using a mix of C++11 standard and pre-standard templates
  548. bool hasConstructor = std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
  549. bool hasDestructor = std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value;
  550. bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
  551. bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::has_trivial_copy_constructor<T>::value;
  552. #else
  553. // All other compilers and versions are assumed to use non C++11 compliant code until proven otherwise
  554. // Not fully C++11 compliant. The has_trivial checks were used while the standard was still
  555. // being elaborated, but were then removed in favor of the above is_trivially checks
  556. // http://stackoverflow.com/questions/12702103/writing-code-that-works-when-has-trivial-destructor-is-defined-instead-of-is
  557. // https://github.com/mozart/mozart2/issues/51
  558. bool hasConstructor = std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
  559. bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
  560. bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
  561. bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::has_trivial_copy_constructor<T>::value;
  562. #endif
  563. bool isFloat = std::is_floating_point<T>::value;
  564. bool isPrimitive = std::is_integral<T>::value || std::is_pointer<T>::value || std::is_enum<T>::value;
  565. bool isClass = std::is_class<T>::value;
  566. bool isArray = std::is_array<T>::value;
  567. if( isFloat )
  568. return asOBJ_APP_FLOAT;
  569. if( isPrimitive )
  570. return asOBJ_APP_PRIMITIVE;
  571. if( isClass )
  572. {
  573. asDWORD flags = asOBJ_APP_CLASS;
  574. if( hasConstructor )
  575. flags |= asOBJ_APP_CLASS_CONSTRUCTOR;
  576. if( hasDestructor )
  577. flags |= asOBJ_APP_CLASS_DESTRUCTOR;
  578. if( hasAssignmentOperator )
  579. flags |= asOBJ_APP_CLASS_ASSIGNMENT;
  580. if( hasCopyConstructor )
  581. flags |= asOBJ_APP_CLASS_COPY_CONSTRUCTOR;
  582. return flags;
  583. }
  584. if( isArray )
  585. return asOBJ_APP_ARRAY;
  586. // Unknown type traits
  587. return 0;
  588. }
  589. #endif // c++11
  590. // Interface declarations
  591. class asIScriptEngine
  592. {
  593. public:
  594. // Memory management
  595. virtual int AddRef() const = 0;
  596. virtual int Release() const = 0;
  597. virtual int ShutDownAndRelease() = 0;
  598. // Engine properties
  599. virtual int SetEngineProperty(asEEngineProp property, asPWORD value) = 0;
  600. virtual asPWORD GetEngineProperty(asEEngineProp property) const = 0;
  601. // Compiler messages
  602. virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv) = 0;
  603. virtual int ClearMessageCallback() = 0;
  604. virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message) = 0;
  605. // JIT Compiler
  606. virtual int SetJITCompiler(asIJITCompiler *compiler) = 0;
  607. virtual asIJITCompiler *GetJITCompiler() const = 0;
  608. // Global functions
  609. virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0) = 0;
  610. virtual asUINT GetGlobalFunctionCount() const = 0;
  611. virtual asIScriptFunction *GetGlobalFunctionByIndex(asUINT index) const = 0;
  612. virtual asIScriptFunction *GetGlobalFunctionByDecl(const char *declaration) const = 0;
  613. // Global properties
  614. virtual int RegisterGlobalProperty(const char *declaration, void *pointer) = 0;
  615. virtual asUINT GetGlobalPropertyCount() const = 0;
  616. virtual int GetGlobalPropertyByIndex(asUINT index, const char **name, const char **nameSpace = 0, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0, asDWORD *accessMask = 0) const = 0;
  617. virtual int GetGlobalPropertyIndexByName(const char *name) const = 0;
  618. virtual int GetGlobalPropertyIndexByDecl(const char *decl) const = 0;
  619. // Object types
  620. virtual int RegisterObjectType(const char *obj, int byteSize, asDWORD flags) = 0;
  621. virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset) = 0;
  622. virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0) = 0;
  623. virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0) = 0;
  624. virtual int RegisterInterface(const char *name) = 0;
  625. virtual int RegisterInterfaceMethod(const char *intf, const char *declaration) = 0;
  626. virtual asUINT GetObjectTypeCount() const = 0;
  627. virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const = 0;
  628. #ifdef AS_DEPRECATED
  629. // Deprecated since 2.31.0, 2015-12-06
  630. virtual asITypeInfo *GetObjectTypeByName(const char *name) const = 0;
  631. virtual asITypeInfo *GetObjectTypeByDecl(const char *decl) const = 0;
  632. #endif
  633. // String factory
  634. virtual int RegisterStringFactory(const char *datatype, const asSFuncPtr &factoryFunc, asDWORD callConv, void *auxiliary = 0) = 0;
  635. virtual int GetStringFactoryReturnTypeId(asDWORD *flags = 0) const = 0;
  636. // Default array type
  637. virtual int RegisterDefaultArrayType(const char *type) = 0;
  638. virtual int GetDefaultArrayTypeId() const = 0;
  639. // Enums
  640. virtual int RegisterEnum(const char *type) = 0;
  641. virtual int RegisterEnumValue(const char *type, const char *name, int value) = 0;
  642. virtual asUINT GetEnumCount() const = 0;
  643. virtual asITypeInfo *GetEnumByIndex(asUINT index) const = 0;
  644. // Urho3D: Removed deprecation for ScriptAPIDump
  645. // Deprecated since 2.31.0, 2015-12-06
  646. virtual int GetEnumValueCount(int enumTypeId) const = 0;
  647. virtual const char * GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
  648. // Funcdefs
  649. virtual int RegisterFuncdef(const char *decl) = 0;
  650. virtual asUINT GetFuncdefCount() const = 0;
  651. virtual asITypeInfo *GetFuncdefByIndex(asUINT index) const = 0;
  652. // Typedefs
  653. virtual int RegisterTypedef(const char *type, const char *decl) = 0;
  654. virtual asUINT GetTypedefCount() const = 0;
  655. virtual asITypeInfo *GetTypedefByIndex(asUINT index) const = 0;
  656. // Configuration groups
  657. virtual int BeginConfigGroup(const char *groupName) = 0;
  658. virtual int EndConfigGroup() = 0;
  659. virtual int RemoveConfigGroup(const char *groupName) = 0;
  660. virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask) = 0;
  661. virtual int SetDefaultNamespace(const char *nameSpace) = 0;
  662. virtual const char *GetDefaultNamespace() const = 0;
  663. // Script modules
  664. virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0;
  665. virtual int DiscardModule(const char *module) = 0;
  666. virtual asUINT GetModuleCount() const = 0;
  667. virtual asIScriptModule *GetModuleByIndex(asUINT index) const = 0;
  668. // Script functions
  669. virtual asIScriptFunction *GetFunctionById(int funcId) const = 0;
  670. #ifdef AS_DEPRECATED
  671. // deprecated since 2.31.0, 2016-01-01
  672. virtual asIScriptFunction *GetFuncdefFromTypeId(int typeId) const = 0;
  673. #endif
  674. // Type identification
  675. #ifdef AS_DEPRECATED
  676. // Deprecated since 2.31.0, 2015-12-06
  677. virtual asITypeInfo *GetObjectTypeById(int typeId) const = 0;
  678. #endif
  679. virtual int GetTypeIdByDecl(const char *decl) const = 0;
  680. virtual const char *GetTypeDeclaration(int typeId, bool includeNamespace = false) const = 0;
  681. virtual int GetSizeOfPrimitiveType(int typeId) const = 0;
  682. virtual asITypeInfo *GetTypeInfoById(int typeId) const = 0;
  683. virtual asITypeInfo *GetTypeInfoByName(const char *name) const = 0;
  684. virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const = 0;
  685. // Script execution
  686. virtual asIScriptContext *CreateContext() = 0;
  687. virtual void *CreateScriptObject(const asITypeInfo *type) = 0;
  688. virtual void *CreateScriptObjectCopy(void *obj, const asITypeInfo *type) = 0;
  689. virtual void *CreateUninitializedScriptObject(const asITypeInfo *type) = 0;
  690. virtual asIScriptFunction *CreateDelegate(asIScriptFunction *func, void *obj) = 0;
  691. virtual int AssignScriptObject(void *dstObj, void *srcObj, const asITypeInfo *type) = 0;
  692. virtual void ReleaseScriptObject(void *obj, const asITypeInfo *type) = 0;
  693. virtual void AddRefScriptObject(void *obj, const asITypeInfo *type) = 0;
  694. virtual int RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo *toType, void **newPtr, bool useOnlyImplicitCast = false) = 0;
  695. #ifdef AS_DEPRECATED
  696. // Deprecated since 2.30.0, 2014-11-04
  697. virtual bool IsHandleCompatibleWithObject(void *obj, int objTypeId, int handleTypeId) const = 0;
  698. #endif
  699. virtual asILockableSharedBool *GetWeakRefFlagOfScriptObject(void *obj, const asITypeInfo *type) const = 0;
  700. // Context pooling
  701. virtual asIScriptContext *RequestContext() = 0;
  702. virtual void ReturnContext(asIScriptContext *ctx) = 0;
  703. virtual int SetContextCallbacks(asREQUESTCONTEXTFUNC_t requestCtx, asRETURNCONTEXTFUNC_t returnCtx, void *param = 0) = 0;
  704. // String interpretation
  705. virtual asETokenClass ParseToken(const char *string, size_t stringLength = 0, asUINT *tokenLength = 0) const = 0;
  706. // Garbage collection
  707. virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE, asUINT numIterations = 1) = 0;
  708. virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed = 0, asUINT *totalDetected = 0, asUINT *newObjects = 0, asUINT *totalNewDestroyed = 0) const = 0;
  709. virtual int NotifyGarbageCollectorOfNewObject(void *obj, asITypeInfo *type) = 0;
  710. virtual int GetObjectInGC(asUINT idx, asUINT *seqNbr = 0, void **obj = 0, asITypeInfo **type = 0) = 0;
  711. virtual void GCEnumCallback(void *reference) = 0;
  712. // User data
  713. virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
  714. virtual void *GetUserData(asPWORD type = 0) const = 0;
  715. virtual void SetEngineUserDataCleanupCallback(asCLEANENGINEFUNC_t callback, asPWORD type = 0) = 0;
  716. virtual void SetModuleUserDataCleanupCallback(asCLEANMODULEFUNC_t callback, asPWORD type = 0) = 0;
  717. virtual void SetContextUserDataCleanupCallback(asCLEANCONTEXTFUNC_t callback, asPWORD type = 0) = 0;
  718. virtual void SetFunctionUserDataCleanupCallback(asCLEANFUNCTIONFUNC_t callback, asPWORD type = 0) = 0;
  719. #ifdef AS_DEPRECATED
  720. // Deprecated since 2.31.0, 2015-12-06
  721. virtual void SetObjectTypeUserDataCleanupCallback(asCLEANTYPEINFOFUNC_t callback, asPWORD type = 0) = 0;
  722. #endif
  723. virtual void SetTypeInfoUserDataCleanupCallback(asCLEANTYPEINFOFUNC_t callback, asPWORD type = 0) = 0;
  724. virtual void SetScriptObjectUserDataCleanupCallback(asCLEANSCRIPTOBJECTFUNC_t callback, asPWORD type = 0) = 0;
  725. protected:
  726. virtual ~asIScriptEngine() {}
  727. };
  728. class asIThreadManager
  729. {
  730. protected:
  731. virtual ~asIThreadManager() {}
  732. };
  733. class asIScriptModule
  734. {
  735. public:
  736. virtual asIScriptEngine *GetEngine() const = 0;
  737. virtual void SetName(const char *name) = 0;
  738. virtual const char *GetName() const = 0;
  739. virtual void Discard() = 0;
  740. // Compilation
  741. virtual int AddScriptSection(const char *name, const char *code, size_t codeLength = 0, int lineOffset = 0) = 0;
  742. virtual int Build() = 0;
  743. virtual int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asIScriptFunction **outFunc) = 0;
  744. virtual int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset) = 0;
  745. virtual asDWORD SetAccessMask(asDWORD accessMask) = 0;
  746. virtual int SetDefaultNamespace(const char *nameSpace) = 0;
  747. virtual const char *GetDefaultNamespace() const = 0;
  748. // Functions
  749. virtual asUINT GetFunctionCount() const = 0;
  750. virtual asIScriptFunction *GetFunctionByIndex(asUINT index) const = 0;
  751. virtual asIScriptFunction *GetFunctionByDecl(const char *decl) const = 0;
  752. virtual asIScriptFunction *GetFunctionByName(const char *name) const = 0;
  753. virtual int RemoveFunction(asIScriptFunction *func) = 0;
  754. // Global variables
  755. virtual int ResetGlobalVars(asIScriptContext *ctx = 0) = 0;
  756. virtual asUINT GetGlobalVarCount() const = 0;
  757. virtual int GetGlobalVarIndexByName(const char *name) const = 0;
  758. virtual int GetGlobalVarIndexByDecl(const char *decl) const = 0;
  759. virtual const char *GetGlobalVarDeclaration(asUINT index, bool includeNamespace = false) const = 0;
  760. virtual int GetGlobalVar(asUINT index, const char **name, const char **nameSpace = 0, int *typeId = 0, bool *isConst = 0) const = 0;
  761. virtual void *GetAddressOfGlobalVar(asUINT index) = 0;
  762. virtual int RemoveGlobalVar(asUINT index) = 0;
  763. // Type identification
  764. virtual asUINT GetObjectTypeCount() const = 0;
  765. virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const = 0;
  766. #ifdef AS_DEPRECATED
  767. // Deprecated since 2.31.0, 2015-12-06
  768. virtual asITypeInfo *GetObjectTypeByName(const char *name) const = 0;
  769. virtual asITypeInfo *GetObjectTypeByDecl(const char *decl) const = 0;
  770. #endif
  771. virtual int GetTypeIdByDecl(const char *decl) const = 0;
  772. virtual asITypeInfo *GetTypeInfoByName(const char *name) const = 0;
  773. virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const = 0;
  774. // Enums
  775. virtual asUINT GetEnumCount() const = 0;
  776. virtual asITypeInfo *GetEnumByIndex(asUINT index) const = 0;
  777. #ifdef AS_DEPRECATED
  778. // Deprecated since 2.31.0, 2015-12-06
  779. virtual int GetEnumValueCount(int enumTypeId) const = 0;
  780. virtual const char * GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
  781. #endif
  782. // Typedefs
  783. virtual asUINT GetTypedefCount() const = 0;
  784. virtual asITypeInfo *GetTypedefByIndex(asUINT index) const = 0;
  785. // Dynamic binding between modules
  786. virtual asUINT GetImportedFunctionCount() const = 0;
  787. virtual int GetImportedFunctionIndexByDecl(const char *decl) const = 0;
  788. virtual const char *GetImportedFunctionDeclaration(asUINT importIndex) const = 0;
  789. virtual const char *GetImportedFunctionSourceModule(asUINT importIndex) const = 0;
  790. virtual int BindImportedFunction(asUINT importIndex, asIScriptFunction *func) = 0;
  791. virtual int UnbindImportedFunction(asUINT importIndex) = 0;
  792. virtual int BindAllImportedFunctions() = 0;
  793. virtual int UnbindAllImportedFunctions() = 0;
  794. // Byte code saving and loading
  795. virtual int SaveByteCode(asIBinaryStream *out, bool stripDebugInfo = false) const = 0;
  796. virtual int LoadByteCode(asIBinaryStream *in, bool *wasDebugInfoStripped = 0) = 0;
  797. // User data
  798. virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
  799. virtual void *GetUserData(asPWORD type = 0) const = 0;
  800. protected:
  801. virtual ~asIScriptModule() {}
  802. };
  803. class asIScriptContext
  804. {
  805. public:
  806. // Memory management
  807. virtual int AddRef() const = 0;
  808. virtual int Release() const = 0;
  809. // Miscellaneous
  810. virtual asIScriptEngine *GetEngine() const = 0;
  811. // Execution
  812. virtual int Prepare(asIScriptFunction *func) = 0;
  813. virtual int Unprepare() = 0;
  814. virtual int Execute() = 0;
  815. virtual int Abort() = 0;
  816. virtual int Suspend() = 0;
  817. virtual asEContextState GetState() const = 0;
  818. virtual int PushState() = 0;
  819. virtual int PopState() = 0;
  820. virtual bool IsNested(asUINT *nestCount = 0) const = 0;
  821. // Object pointer for calling class methods
  822. virtual int SetObject(void *obj) = 0;
  823. // Arguments
  824. virtual int SetArgByte(asUINT arg, asBYTE value) = 0;
  825. virtual int SetArgWord(asUINT arg, asWORD value) = 0;
  826. virtual int SetArgDWord(asUINT arg, asDWORD value) = 0;
  827. virtual int SetArgQWord(asUINT arg, asQWORD value) = 0;
  828. virtual int SetArgFloat(asUINT arg, float value) = 0;
  829. virtual int SetArgDouble(asUINT arg, double value) = 0;
  830. virtual int SetArgAddress(asUINT arg, void *addr) = 0;
  831. virtual int SetArgObject(asUINT arg, void *obj) = 0;
  832. virtual int SetArgVarType(asUINT arg, void *ptr, int typeId) = 0;
  833. virtual void *GetAddressOfArg(asUINT arg) = 0;
  834. // Return value
  835. virtual asBYTE GetReturnByte() = 0;
  836. virtual asWORD GetReturnWord() = 0;
  837. virtual asDWORD GetReturnDWord() = 0;
  838. virtual asQWORD GetReturnQWord() = 0;
  839. virtual float GetReturnFloat() = 0;
  840. virtual double GetReturnDouble() = 0;
  841. virtual void *GetReturnAddress() = 0;
  842. virtual void *GetReturnObject() = 0;
  843. virtual void *GetAddressOfReturnValue() = 0;
  844. // Exception handling
  845. virtual int SetException(const char *string) = 0;
  846. virtual int GetExceptionLineNumber(int *column = 0, const char **sectionName = 0) = 0;
  847. virtual asIScriptFunction *GetExceptionFunction() = 0;
  848. virtual const char * GetExceptionString() = 0;
  849. virtual int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
  850. virtual void ClearExceptionCallback() = 0;
  851. // Debugging
  852. virtual int SetLineCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
  853. virtual void ClearLineCallback() = 0;
  854. virtual asUINT GetCallstackSize() const = 0;
  855. virtual asIScriptFunction *GetFunction(asUINT stackLevel = 0) = 0;
  856. virtual int GetLineNumber(asUINT stackLevel = 0, int *column = 0, const char **sectionName = 0) = 0;
  857. virtual int GetVarCount(asUINT stackLevel = 0) = 0;
  858. virtual const char *GetVarName(asUINT varIndex, asUINT stackLevel = 0) = 0;
  859. virtual const char *GetVarDeclaration(asUINT varIndex, asUINT stackLevel = 0, bool includeNamespace = false) = 0;
  860. virtual int GetVarTypeId(asUINT varIndex, asUINT stackLevel = 0) = 0;
  861. virtual void *GetAddressOfVar(asUINT varIndex, asUINT stackLevel = 0) = 0;
  862. virtual bool IsVarInScope(asUINT varIndex, asUINT stackLevel = 0) = 0;
  863. virtual int GetThisTypeId(asUINT stackLevel = 0) = 0;
  864. virtual void *GetThisPointer(asUINT stackLevel = 0) = 0;
  865. virtual asIScriptFunction *GetSystemFunction() = 0;
  866. // User data
  867. virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
  868. virtual void *GetUserData(asPWORD type = 0) const = 0;
  869. protected:
  870. virtual ~asIScriptContext() {}
  871. };
  872. class asIScriptGeneric
  873. {
  874. public:
  875. // Miscellaneous
  876. virtual asIScriptEngine *GetEngine() const = 0;
  877. virtual asIScriptFunction *GetFunction() const = 0;
  878. virtual void *GetAuxiliary() const = 0;
  879. // Object
  880. virtual void *GetObject() = 0;
  881. virtual int GetObjectTypeId() const = 0;
  882. // Arguments
  883. virtual int GetArgCount() const = 0;
  884. virtual int GetArgTypeId(asUINT arg, asDWORD *flags = 0) const = 0;
  885. virtual asBYTE GetArgByte(asUINT arg) = 0;
  886. virtual asWORD GetArgWord(asUINT arg) = 0;
  887. virtual asDWORD GetArgDWord(asUINT arg) = 0;
  888. virtual asQWORD GetArgQWord(asUINT arg) = 0;
  889. virtual float GetArgFloat(asUINT arg) = 0;
  890. virtual double GetArgDouble(asUINT arg) = 0;
  891. virtual void *GetArgAddress(asUINT arg) = 0;
  892. virtual void *GetArgObject(asUINT arg) = 0;
  893. virtual void *GetAddressOfArg(asUINT arg) = 0;
  894. // Return value
  895. virtual int GetReturnTypeId(asDWORD *flags = 0) const = 0;
  896. virtual int SetReturnByte(asBYTE val) = 0;
  897. virtual int SetReturnWord(asWORD val) = 0;
  898. virtual int SetReturnDWord(asDWORD val) = 0;
  899. virtual int SetReturnQWord(asQWORD val) = 0;
  900. virtual int SetReturnFloat(float val) = 0;
  901. virtual int SetReturnDouble(double val) = 0;
  902. virtual int SetReturnAddress(void *addr) = 0;
  903. virtual int SetReturnObject(void *obj) = 0;
  904. virtual void *GetAddressOfReturnLocation() = 0;
  905. protected:
  906. virtual ~asIScriptGeneric() {}
  907. };
  908. class asIScriptObject
  909. {
  910. public:
  911. // Memory management
  912. virtual int AddRef() const = 0;
  913. virtual int Release() const = 0;
  914. virtual asILockableSharedBool *GetWeakRefFlag() const = 0;
  915. // Type info
  916. virtual int GetTypeId() const = 0;
  917. virtual asITypeInfo *GetObjectType() const = 0;
  918. // Class properties
  919. virtual asUINT GetPropertyCount() const = 0;
  920. virtual int GetPropertyTypeId(asUINT prop) const = 0;
  921. virtual const char *GetPropertyName(asUINT prop) const = 0;
  922. virtual void *GetAddressOfProperty(asUINT prop) = 0;
  923. // Miscellaneous
  924. virtual asIScriptEngine *GetEngine() const = 0;
  925. virtual int CopyFrom(asIScriptObject *other) = 0;
  926. // User data
  927. virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
  928. virtual void *GetUserData(asPWORD type = 0) const = 0;
  929. protected:
  930. virtual ~asIScriptObject() {}
  931. };
  932. class asITypeInfo
  933. {
  934. public:
  935. // Miscellaneous
  936. virtual asIScriptEngine *GetEngine() const = 0;
  937. virtual const char *GetConfigGroup() const = 0;
  938. virtual asDWORD GetAccessMask() const = 0;
  939. virtual asIScriptModule *GetModule() const = 0;
  940. // Memory management
  941. virtual int AddRef() const = 0;
  942. virtual int Release() const = 0;
  943. // Type info
  944. virtual const char *GetName() const = 0;
  945. virtual const char *GetNamespace() const = 0;
  946. virtual asITypeInfo *GetBaseType() const = 0;
  947. virtual bool DerivesFrom(const asITypeInfo *objType) const = 0;
  948. virtual asDWORD GetFlags() const = 0;
  949. virtual asUINT GetSize() const = 0;
  950. virtual int GetTypeId() const = 0;
  951. virtual int GetSubTypeId(asUINT subTypeIndex = 0) const = 0;
  952. virtual asITypeInfo *GetSubType(asUINT subTypeIndex = 0) const = 0;
  953. virtual asUINT GetSubTypeCount() const = 0;
  954. // Interfaces
  955. virtual asUINT GetInterfaceCount() const = 0;
  956. virtual asITypeInfo *GetInterface(asUINT index) const = 0;
  957. virtual bool Implements(const asITypeInfo *objType) const = 0;
  958. // Factories
  959. virtual asUINT GetFactoryCount() const = 0;
  960. virtual asIScriptFunction *GetFactoryByIndex(asUINT index) const = 0;
  961. virtual asIScriptFunction *GetFactoryByDecl(const char *decl) const = 0;
  962. // Methods
  963. virtual asUINT GetMethodCount() const = 0;
  964. virtual asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual = true) const = 0;
  965. virtual asIScriptFunction *GetMethodByName(const char *name, bool getVirtual = true) const = 0;
  966. virtual asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual = true) const = 0;
  967. // Properties
  968. virtual asUINT GetPropertyCount() const = 0;
  969. virtual int GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, bool *isProtected = 0, int *offset = 0, bool *isReference = 0, asDWORD *accessMask = 0) const = 0;
  970. virtual const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const = 0;
  971. // Behaviours
  972. virtual asUINT GetBehaviourCount() const = 0;
  973. virtual asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const = 0;
  974. // Child types
  975. virtual asUINT GetChildFuncdefCount() const = 0;
  976. virtual asITypeInfo *GetChildFuncdef(asUINT index) const = 0;
  977. virtual asITypeInfo *GetParentType() const = 0;
  978. // Enums
  979. virtual asUINT GetEnumValueCount() const = 0;
  980. virtual const char *GetEnumValueByIndex(asUINT index, int *outValue) const = 0;
  981. // Typedef
  982. virtual int GetTypedefTypeId() const = 0;
  983. // Funcdef
  984. virtual asIScriptFunction *GetFuncdefSignature() const = 0;
  985. // User data
  986. virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
  987. virtual void *GetUserData(asPWORD type = 0) const = 0;
  988. protected:
  989. virtual ~asITypeInfo() {}
  990. };
  991. class asIScriptFunction
  992. {
  993. public:
  994. virtual asIScriptEngine *GetEngine() const = 0;
  995. // Memory management
  996. virtual int AddRef() const = 0;
  997. virtual int Release() const = 0;
  998. // Miscellaneous
  999. virtual int GetId() const = 0;
  1000. virtual asEFuncType GetFuncType() const = 0;
  1001. virtual const char *GetModuleName() const = 0;
  1002. virtual asIScriptModule *GetModule() const = 0;
  1003. virtual const char *GetScriptSectionName() const = 0;
  1004. virtual const char *GetConfigGroup() const = 0;
  1005. virtual asDWORD GetAccessMask() const = 0;
  1006. virtual void *GetAuxiliary() const = 0;
  1007. // Function signature
  1008. virtual asITypeInfo *GetObjectType() const = 0;
  1009. virtual const char *GetObjectName() const = 0;
  1010. virtual const char *GetName() const = 0;
  1011. virtual const char *GetNamespace() const = 0;
  1012. virtual const char *GetDeclaration(bool includeObjectName = true, bool includeNamespace = false, bool includeParamNames = false) const = 0;
  1013. virtual bool IsReadOnly() const = 0;
  1014. virtual bool IsPrivate() const = 0;
  1015. virtual bool IsProtected() const = 0;
  1016. virtual bool IsFinal() const = 0;
  1017. virtual bool IsOverride() const = 0;
  1018. virtual bool IsShared() const = 0;
  1019. virtual asUINT GetParamCount() const = 0;
  1020. virtual int GetParam(asUINT index, int *typeId, asDWORD *flags = 0, const char **name = 0, const char **defaultArg = 0) const = 0;
  1021. #ifdef AS_DEPRECATED
  1022. // Deprecated since 2.29.0, 2014-04-06
  1023. virtual int GetParamTypeId(asUINT index, asDWORD *flags = 0) const = 0;
  1024. #endif
  1025. virtual int GetReturnTypeId(asDWORD *flags = 0) const = 0;
  1026. // Type id for function pointers
  1027. virtual int GetTypeId() const = 0;
  1028. virtual bool IsCompatibleWithTypeId(int typeId) const = 0;
  1029. // Delegates
  1030. virtual void *GetDelegateObject() const = 0;
  1031. virtual asITypeInfo *GetDelegateObjectType() const = 0;
  1032. virtual asIScriptFunction *GetDelegateFunction() const = 0;
  1033. // Debug information
  1034. virtual asUINT GetVarCount() const = 0;
  1035. virtual int GetVar(asUINT index, const char **name, int *typeId = 0) const = 0;
  1036. virtual const char *GetVarDecl(asUINT index, bool includeNamespace = false) const = 0;
  1037. virtual int FindNextLineWithCode(int line) const = 0;
  1038. // For JIT compilation
  1039. virtual asDWORD *GetByteCode(asUINT *length = 0) = 0;
  1040. // User data
  1041. virtual void *SetUserData(void *userData, asPWORD type = 0) = 0;
  1042. virtual void *GetUserData(asPWORD type = 0) const = 0;
  1043. protected:
  1044. virtual ~asIScriptFunction() {};
  1045. };
  1046. class asIBinaryStream
  1047. {
  1048. public:
  1049. virtual void Read(void *ptr, asUINT size) = 0;
  1050. virtual void Write(const void *ptr, asUINT size) = 0;
  1051. public:
  1052. virtual ~asIBinaryStream() {}
  1053. };
  1054. class asILockableSharedBool
  1055. {
  1056. public:
  1057. // Memory management
  1058. virtual int AddRef() const = 0;
  1059. virtual int Release() const = 0;
  1060. // Value
  1061. virtual bool Get() const = 0;
  1062. virtual void Set(bool val) = 0;
  1063. // Thread management
  1064. virtual void Lock() const = 0;
  1065. virtual void Unlock() const = 0;
  1066. protected:
  1067. virtual ~asILockableSharedBool() {}
  1068. };
  1069. //-----------------------------------------------------------------
  1070. // Function pointers
  1071. // Template function to capture all global functions,
  1072. // except the ones using the generic calling convention
  1073. template <class T>
  1074. inline asSFuncPtr asFunctionPtr(T func)
  1075. {
  1076. // Mark this as a global function
  1077. asSFuncPtr p(2);
  1078. #ifdef AS_64BIT_PTR
  1079. // The size_t cast is to avoid a compiler warning with asFUNCTION(0)
  1080. // on 64bit, as 0 is interpreted as a 32bit int value
  1081. p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(size_t(func));
  1082. #else
  1083. // MSVC6 doesn't like the size_t cast above so I
  1084. // solved this with a separate code for 32bit.
  1085. p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);
  1086. #endif
  1087. return p;
  1088. }
  1089. // Specialization for functions using the generic calling convention
  1090. template<>
  1091. inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
  1092. {
  1093. // Mark this as a generic function
  1094. asSFuncPtr p(1);
  1095. p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);
  1096. return p;
  1097. }
  1098. #ifndef AS_NO_CLASS_METHODS
  1099. // Method pointers
  1100. // Declare a dummy class so that we can determine the size of a simple method pointer
  1101. class asCSimpleDummy {};
  1102. typedef void (asCSimpleDummy::*asSIMPLEMETHOD_t)();
  1103. const int SINGLE_PTR_SIZE = sizeof(asSIMPLEMETHOD_t);
  1104. // Define template
  1105. template <int N>
  1106. struct asSMethodPtr
  1107. {
  1108. template<class M>
  1109. static asSFuncPtr Convert(M Mthd)
  1110. {
  1111. // This version of the function should never be executed, nor compiled,
  1112. // as it would mean that the size of the method pointer cannot be determined.
  1113. int ERROR_UnsupportedMethodPtr[N-100];
  1114. asSFuncPtr p(0);
  1115. return p;
  1116. }
  1117. };
  1118. // Template specialization
  1119. template <>
  1120. struct asSMethodPtr<SINGLE_PTR_SIZE>
  1121. {
  1122. template<class M>
  1123. static asSFuncPtr Convert(M Mthd)
  1124. {
  1125. // Mark this as a class method
  1126. asSFuncPtr p(3);
  1127. p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE);
  1128. return p;
  1129. }
  1130. };
  1131. #if defined(_MSC_VER) && !defined(__MWERKS__)
  1132. // MSVC and Intel uses different sizes for different class method pointers
  1133. template <>
  1134. struct asSMethodPtr<SINGLE_PTR_SIZE+1*sizeof(int)>
  1135. {
  1136. template <class M>
  1137. static asSFuncPtr Convert(M Mthd)
  1138. {
  1139. // Mark this as a class method
  1140. asSFuncPtr p(3);
  1141. p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+sizeof(int));
  1142. return p;
  1143. }
  1144. };
  1145. template <>
  1146. struct asSMethodPtr<SINGLE_PTR_SIZE+2*sizeof(int)>
  1147. {
  1148. template <class M>
  1149. static asSFuncPtr Convert(M Mthd)
  1150. {
  1151. // On 32bit platforms with is where a class with virtual inheritance falls.
  1152. // On 64bit platforms we can also fall here if 8byte data alignments is used.
  1153. // Mark this as a class method
  1154. asSFuncPtr p(3);
  1155. p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+2*sizeof(int));
  1156. // Microsoft has a terrible optimization on class methods with virtual inheritance.
  1157. // They are hardcoding an important offset, which is not coming in the method pointer.
  1158. #if defined(_MSC_VER) && !defined(AS_64BIT_PTR)
  1159. // Method pointers for virtual inheritance is not supported,
  1160. // as it requires the location of the vbase table, which is
  1161. // only available to the C++ compiler, but not in the method
  1162. // pointer.
  1163. // You can get around this by forward declaring the class and
  1164. // storing the sizeof its method pointer in a constant. Example:
  1165. // class ClassWithVirtualInheritance;
  1166. // const int ClassWithVirtualInheritance_workaround = sizeof(void ClassWithVirtualInheritance::*());
  1167. // This will force the compiler to use the unknown type
  1168. // for the class, which falls under the next case
  1169. // Copy the virtual table index to the 4th dword so that AngelScript
  1170. // can properly detect and deny the use of methods with virtual inheritance.
  1171. *(reinterpret_cast<asDWORD*>(&p)+3) = *(reinterpret_cast<asDWORD*>(&p)+2);
  1172. #endif
  1173. return p;
  1174. }
  1175. };
  1176. template <>
  1177. struct asSMethodPtr<SINGLE_PTR_SIZE+3*sizeof(int)>
  1178. {
  1179. template <class M>
  1180. static asSFuncPtr Convert(M Mthd)
  1181. {
  1182. // Mark this as a class method
  1183. asSFuncPtr p(3);
  1184. p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+3*sizeof(int));
  1185. return p;
  1186. }
  1187. };
  1188. template <>
  1189. struct asSMethodPtr<SINGLE_PTR_SIZE+4*sizeof(int)>
  1190. {
  1191. template <class M>
  1192. static asSFuncPtr Convert(M Mthd)
  1193. {
  1194. // On 64bit platforms with 8byte data alignment
  1195. // the unknown class method pointers will come here.
  1196. // Mark this as a class method
  1197. asSFuncPtr p(3);
  1198. p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+4*sizeof(int));
  1199. return p;
  1200. }
  1201. };
  1202. #endif
  1203. #endif // AS_NO_CLASS_METHODS
  1204. //----------------------------------------------------------------
  1205. // JIT compiler
  1206. struct asSVMRegisters
  1207. {
  1208. asDWORD *programPointer; // points to current bytecode instruction
  1209. asDWORD *stackFramePointer; // function stack frame
  1210. asDWORD *stackPointer; // top of stack (grows downward)
  1211. asQWORD valueRegister; // temp register for primitives
  1212. void *objectRegister; // temp register for objects and handles
  1213. asITypeInfo *objectType; // type of object held in object register
  1214. bool doProcessSuspend; // whether or not the JIT should break out when it encounters a suspend instruction
  1215. asIScriptContext *ctx; // the active context
  1216. };
  1217. typedef void (*asJITFunction)(asSVMRegisters *registers, asPWORD jitArg);
  1218. class asIJITCompiler
  1219. {
  1220. public:
  1221. virtual int CompileFunction(asIScriptFunction *function, asJITFunction *output) = 0;
  1222. virtual void ReleaseJITFunction(asJITFunction func) = 0;
  1223. public:
  1224. virtual ~asIJITCompiler() {}
  1225. };
  1226. // Byte code instructions
  1227. enum asEBCInstr
  1228. {
  1229. asBC_PopPtr = 0,
  1230. asBC_PshGPtr = 1,
  1231. asBC_PshC4 = 2,
  1232. asBC_PshV4 = 3,
  1233. asBC_PSF = 4,
  1234. asBC_SwapPtr = 5,
  1235. asBC_NOT = 6,
  1236. asBC_PshG4 = 7,
  1237. asBC_LdGRdR4 = 8,
  1238. asBC_CALL = 9,
  1239. asBC_RET = 10,
  1240. asBC_JMP = 11,
  1241. asBC_JZ = 12,
  1242. asBC_JNZ = 13,
  1243. asBC_JS = 14,
  1244. asBC_JNS = 15,
  1245. asBC_JP = 16,
  1246. asBC_JNP = 17,
  1247. asBC_TZ = 18,
  1248. asBC_TNZ = 19,
  1249. asBC_TS = 20,
  1250. asBC_TNS = 21,
  1251. asBC_TP = 22,
  1252. asBC_TNP = 23,
  1253. asBC_NEGi = 24,
  1254. asBC_NEGf = 25,
  1255. asBC_NEGd = 26,
  1256. asBC_INCi16 = 27,
  1257. asBC_INCi8 = 28,
  1258. asBC_DECi16 = 29,
  1259. asBC_DECi8 = 30,
  1260. asBC_INCi = 31,
  1261. asBC_DECi = 32,
  1262. asBC_INCf = 33,
  1263. asBC_DECf = 34,
  1264. asBC_INCd = 35,
  1265. asBC_DECd = 36,
  1266. asBC_IncVi = 37,
  1267. asBC_DecVi = 38,
  1268. asBC_BNOT = 39,
  1269. asBC_BAND = 40,
  1270. asBC_BOR = 41,
  1271. asBC_BXOR = 42,
  1272. asBC_BSLL = 43,
  1273. asBC_BSRL = 44,
  1274. asBC_BSRA = 45,
  1275. asBC_COPY = 46,
  1276. asBC_PshC8 = 47,
  1277. asBC_PshVPtr = 48,
  1278. asBC_RDSPtr = 49,
  1279. asBC_CMPd = 50,
  1280. asBC_CMPu = 51,
  1281. asBC_CMPf = 52,
  1282. asBC_CMPi = 53,
  1283. asBC_CMPIi = 54,
  1284. asBC_CMPIf = 55,
  1285. asBC_CMPIu = 56,
  1286. asBC_JMPP = 57,
  1287. asBC_PopRPtr = 58,
  1288. asBC_PshRPtr = 59,
  1289. asBC_STR = 60,
  1290. asBC_CALLSYS = 61,
  1291. asBC_CALLBND = 62,
  1292. asBC_SUSPEND = 63,
  1293. asBC_ALLOC = 64,
  1294. asBC_FREE = 65,
  1295. asBC_LOADOBJ = 66,
  1296. asBC_STOREOBJ = 67,
  1297. asBC_GETOBJ = 68,
  1298. asBC_REFCPY = 69,
  1299. asBC_CHKREF = 70,
  1300. asBC_GETOBJREF = 71,
  1301. asBC_GETREF = 72,
  1302. asBC_PshNull = 73,
  1303. asBC_ClrVPtr = 74,
  1304. asBC_OBJTYPE = 75,
  1305. asBC_TYPEID = 76,
  1306. asBC_SetV4 = 77,
  1307. asBC_SetV8 = 78,
  1308. asBC_ADDSi = 79,
  1309. asBC_CpyVtoV4 = 80,
  1310. asBC_CpyVtoV8 = 81,
  1311. asBC_CpyVtoR4 = 82,
  1312. asBC_CpyVtoR8 = 83,
  1313. asBC_CpyVtoG4 = 84,
  1314. asBC_CpyRtoV4 = 85,
  1315. asBC_CpyRtoV8 = 86,
  1316. asBC_CpyGtoV4 = 87,
  1317. asBC_WRTV1 = 88,
  1318. asBC_WRTV2 = 89,
  1319. asBC_WRTV4 = 90,
  1320. asBC_WRTV8 = 91,
  1321. asBC_RDR1 = 92,
  1322. asBC_RDR2 = 93,
  1323. asBC_RDR4 = 94,
  1324. asBC_RDR8 = 95,
  1325. asBC_LDG = 96,
  1326. asBC_LDV = 97,
  1327. asBC_PGA = 98,
  1328. asBC_CmpPtr = 99,
  1329. asBC_VAR = 100,
  1330. asBC_iTOf = 101,
  1331. asBC_fTOi = 102,
  1332. asBC_uTOf = 103,
  1333. asBC_fTOu = 104,
  1334. asBC_sbTOi = 105,
  1335. asBC_swTOi = 106,
  1336. asBC_ubTOi = 107,
  1337. asBC_uwTOi = 108,
  1338. asBC_dTOi = 109,
  1339. asBC_dTOu = 110,
  1340. asBC_dTOf = 111,
  1341. asBC_iTOd = 112,
  1342. asBC_uTOd = 113,
  1343. asBC_fTOd = 114,
  1344. asBC_ADDi = 115,
  1345. asBC_SUBi = 116,
  1346. asBC_MULi = 117,
  1347. asBC_DIVi = 118,
  1348. asBC_MODi = 119,
  1349. asBC_ADDf = 120,
  1350. asBC_SUBf = 121,
  1351. asBC_MULf = 122,
  1352. asBC_DIVf = 123,
  1353. asBC_MODf = 124,
  1354. asBC_ADDd = 125,
  1355. asBC_SUBd = 126,
  1356. asBC_MULd = 127,
  1357. asBC_DIVd = 128,
  1358. asBC_MODd = 129,
  1359. asBC_ADDIi = 130,
  1360. asBC_SUBIi = 131,
  1361. asBC_MULIi = 132,
  1362. asBC_ADDIf = 133,
  1363. asBC_SUBIf = 134,
  1364. asBC_MULIf = 135,
  1365. asBC_SetG4 = 136,
  1366. asBC_ChkRefS = 137,
  1367. asBC_ChkNullV = 138,
  1368. asBC_CALLINTF = 139,
  1369. asBC_iTOb = 140,
  1370. asBC_iTOw = 141,
  1371. asBC_SetV1 = 142,
  1372. asBC_SetV2 = 143,
  1373. asBC_Cast = 144,
  1374. asBC_i64TOi = 145,
  1375. asBC_uTOi64 = 146,
  1376. asBC_iTOi64 = 147,
  1377. asBC_fTOi64 = 148,
  1378. asBC_dTOi64 = 149,
  1379. asBC_fTOu64 = 150,
  1380. asBC_dTOu64 = 151,
  1381. asBC_i64TOf = 152,
  1382. asBC_u64TOf = 153,
  1383. asBC_i64TOd = 154,
  1384. asBC_u64TOd = 155,
  1385. asBC_NEGi64 = 156,
  1386. asBC_INCi64 = 157,
  1387. asBC_DECi64 = 158,
  1388. asBC_BNOT64 = 159,
  1389. asBC_ADDi64 = 160,
  1390. asBC_SUBi64 = 161,
  1391. asBC_MULi64 = 162,
  1392. asBC_DIVi64 = 163,
  1393. asBC_MODi64 = 164,
  1394. asBC_BAND64 = 165,
  1395. asBC_BOR64 = 166,
  1396. asBC_BXOR64 = 167,
  1397. asBC_BSLL64 = 168,
  1398. asBC_BSRL64 = 169,
  1399. asBC_BSRA64 = 170,
  1400. asBC_CMPi64 = 171,
  1401. asBC_CMPu64 = 172,
  1402. asBC_ChkNullS = 173,
  1403. asBC_ClrHi = 174,
  1404. asBC_JitEntry = 175,
  1405. asBC_CallPtr = 176,
  1406. asBC_FuncPtr = 177,
  1407. asBC_LoadThisR = 178,
  1408. asBC_PshV8 = 179,
  1409. asBC_DIVu = 180,
  1410. asBC_MODu = 181,
  1411. asBC_DIVu64 = 182,
  1412. asBC_MODu64 = 183,
  1413. asBC_LoadRObjR = 184,
  1414. asBC_LoadVObjR = 185,
  1415. asBC_RefCpyV = 186,
  1416. asBC_JLowZ = 187,
  1417. asBC_JLowNZ = 188,
  1418. asBC_AllocMem = 189,
  1419. asBC_SetListSize = 190,
  1420. asBC_PshListElmnt = 191,
  1421. asBC_SetListType = 192,
  1422. asBC_POWi = 193,
  1423. asBC_POWu = 194,
  1424. asBC_POWf = 195,
  1425. asBC_POWd = 196,
  1426. asBC_POWdi = 197,
  1427. asBC_POWi64 = 198,
  1428. asBC_POWu64 = 199,
  1429. asBC_Thiscall1 = 200,
  1430. asBC_MAXBYTECODE = 201,
  1431. // Temporary tokens. Can't be output to the final program
  1432. asBC_VarDecl = 251,
  1433. asBC_Block = 252,
  1434. asBC_ObjInfo = 253,
  1435. asBC_LINE = 254,
  1436. asBC_LABEL = 255
  1437. };
  1438. // Instruction types
  1439. enum asEBCType
  1440. {
  1441. asBCTYPE_INFO = 0,
  1442. asBCTYPE_NO_ARG = 1,
  1443. asBCTYPE_W_ARG = 2,
  1444. asBCTYPE_wW_ARG = 3,
  1445. asBCTYPE_DW_ARG = 4,
  1446. asBCTYPE_rW_DW_ARG = 5,
  1447. asBCTYPE_QW_ARG = 6,
  1448. asBCTYPE_DW_DW_ARG = 7,
  1449. asBCTYPE_wW_rW_rW_ARG = 8,
  1450. asBCTYPE_wW_QW_ARG = 9,
  1451. asBCTYPE_wW_rW_ARG = 10,
  1452. asBCTYPE_rW_ARG = 11,
  1453. asBCTYPE_wW_DW_ARG = 12,
  1454. asBCTYPE_wW_rW_DW_ARG = 13,
  1455. asBCTYPE_rW_rW_ARG = 14,
  1456. asBCTYPE_wW_W_ARG = 15,
  1457. asBCTYPE_QW_DW_ARG = 16,
  1458. asBCTYPE_rW_QW_ARG = 17,
  1459. asBCTYPE_W_DW_ARG = 18,
  1460. asBCTYPE_rW_W_DW_ARG = 19,
  1461. asBCTYPE_rW_DW_DW_ARG = 20
  1462. };
  1463. // Instruction type sizes
  1464. const int asBCTypeSize[21] =
  1465. {
  1466. 0, // asBCTYPE_INFO
  1467. 1, // asBCTYPE_NO_ARG
  1468. 1, // asBCTYPE_W_ARG
  1469. 1, // asBCTYPE_wW_ARG
  1470. 2, // asBCTYPE_DW_ARG
  1471. 2, // asBCTYPE_rW_DW_ARG
  1472. 3, // asBCTYPE_QW_ARG
  1473. 3, // asBCTYPE_DW_DW_ARG
  1474. 2, // asBCTYPE_wW_rW_rW_ARG
  1475. 3, // asBCTYPE_wW_QW_ARG
  1476. 2, // asBCTYPE_wW_rW_ARG
  1477. 1, // asBCTYPE_rW_ARG
  1478. 2, // asBCTYPE_wW_DW_ARG
  1479. 3, // asBCTYPE_wW_rW_DW_ARG
  1480. 2, // asBCTYPE_rW_rW_ARG
  1481. 2, // asBCTYPE_wW_W_ARG
  1482. 4, // asBCTYPE_QW_DW_ARG
  1483. 3, // asBCTYPE_rW_QW_ARG
  1484. 2, // asBCTYPE_W_DW_ARG
  1485. 3, // asBCTYPE_rW_W_DW_ARG
  1486. 3 // asBCTYPE_rW_DW_DW_ARG
  1487. };
  1488. // Instruction info
  1489. struct asSBCInfo
  1490. {
  1491. asEBCInstr bc;
  1492. asEBCType type;
  1493. int stackInc;
  1494. const char *name;
  1495. };
  1496. #ifndef AS_64BIT_PTR
  1497. #define asBCTYPE_PTR_ARG asBCTYPE_DW_ARG
  1498. #define asBCTYPE_PTR_DW_ARG asBCTYPE_DW_DW_ARG
  1499. #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_DW_ARG
  1500. #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_DW_ARG
  1501. #ifndef AS_PTR_SIZE
  1502. #define AS_PTR_SIZE 1
  1503. #endif
  1504. #else
  1505. #define asBCTYPE_PTR_ARG asBCTYPE_QW_ARG
  1506. #define asBCTYPE_PTR_DW_ARG asBCTYPE_QW_DW_ARG
  1507. #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_QW_ARG
  1508. #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_QW_ARG
  1509. #ifndef AS_PTR_SIZE
  1510. #define AS_PTR_SIZE 2
  1511. #endif
  1512. #endif
  1513. #define asBCINFO(b,t,s) {asBC_##b, asBCTYPE_##t, s, #b}
  1514. #define asBCINFO_DUMMY(b) {asBC_MAXBYTECODE, asBCTYPE_INFO, 0, "BC_" #b}
  1515. const asSBCInfo asBCInfo[256] =
  1516. {
  1517. asBCINFO(PopPtr, NO_ARG, -AS_PTR_SIZE),
  1518. asBCINFO(PshGPtr, PTR_ARG, AS_PTR_SIZE),
  1519. asBCINFO(PshC4, DW_ARG, 1),
  1520. asBCINFO(PshV4, rW_ARG, 1),
  1521. asBCINFO(PSF, rW_ARG, AS_PTR_SIZE),
  1522. asBCINFO(SwapPtr, NO_ARG, 0),
  1523. asBCINFO(NOT, rW_ARG, 0),
  1524. asBCINFO(PshG4, PTR_ARG, 1),
  1525. asBCINFO(LdGRdR4, wW_PTR_ARG, 0),
  1526. asBCINFO(CALL, DW_ARG, 0xFFFF),
  1527. asBCINFO(RET, W_ARG, 0xFFFF),
  1528. asBCINFO(JMP, DW_ARG, 0),
  1529. asBCINFO(JZ, DW_ARG, 0),
  1530. asBCINFO(JNZ, DW_ARG, 0),
  1531. asBCINFO(JS, DW_ARG, 0),
  1532. asBCINFO(JNS, DW_ARG, 0),
  1533. asBCINFO(JP, DW_ARG, 0),
  1534. asBCINFO(JNP, DW_ARG, 0),
  1535. asBCINFO(TZ, NO_ARG, 0),
  1536. asBCINFO(TNZ, NO_ARG, 0),
  1537. asBCINFO(TS, NO_ARG, 0),
  1538. asBCINFO(TNS, NO_ARG, 0),
  1539. asBCINFO(TP, NO_ARG, 0),
  1540. asBCINFO(TNP, NO_ARG, 0),
  1541. asBCINFO(NEGi, rW_ARG, 0),
  1542. asBCINFO(NEGf, rW_ARG, 0),
  1543. asBCINFO(NEGd, rW_ARG, 0),
  1544. asBCINFO(INCi16, NO_ARG, 0),
  1545. asBCINFO(INCi8, NO_ARG, 0),
  1546. asBCINFO(DECi16, NO_ARG, 0),
  1547. asBCINFO(DECi8, NO_ARG, 0),
  1548. asBCINFO(INCi, NO_ARG, 0),
  1549. asBCINFO(DECi, NO_ARG, 0),
  1550. asBCINFO(INCf, NO_ARG, 0),
  1551. asBCINFO(DECf, NO_ARG, 0),
  1552. asBCINFO(INCd, NO_ARG, 0),
  1553. asBCINFO(DECd, NO_ARG, 0),
  1554. asBCINFO(IncVi, rW_ARG, 0),
  1555. asBCINFO(DecVi, rW_ARG, 0),
  1556. asBCINFO(BNOT, rW_ARG, 0),
  1557. asBCINFO(BAND, wW_rW_rW_ARG, 0),
  1558. asBCINFO(BOR, wW_rW_rW_ARG, 0),
  1559. asBCINFO(BXOR, wW_rW_rW_ARG, 0),
  1560. asBCINFO(BSLL, wW_rW_rW_ARG, 0),
  1561. asBCINFO(BSRL, wW_rW_rW_ARG, 0),
  1562. asBCINFO(BSRA, wW_rW_rW_ARG, 0),
  1563. asBCINFO(COPY, W_DW_ARG, -AS_PTR_SIZE),
  1564. asBCINFO(PshC8, QW_ARG, 2),
  1565. asBCINFO(PshVPtr, rW_ARG, AS_PTR_SIZE),
  1566. asBCINFO(RDSPtr, NO_ARG, 0),
  1567. asBCINFO(CMPd, rW_rW_ARG, 0),
  1568. asBCINFO(CMPu, rW_rW_ARG, 0),
  1569. asBCINFO(CMPf, rW_rW_ARG, 0),
  1570. asBCINFO(CMPi, rW_rW_ARG, 0),
  1571. asBCINFO(CMPIi, rW_DW_ARG, 0),
  1572. asBCINFO(CMPIf, rW_DW_ARG, 0),
  1573. asBCINFO(CMPIu, rW_DW_ARG, 0),
  1574. asBCINFO(JMPP, rW_ARG, 0),
  1575. asBCINFO(PopRPtr, NO_ARG, -AS_PTR_SIZE),
  1576. asBCINFO(PshRPtr, NO_ARG, AS_PTR_SIZE),
  1577. asBCINFO(STR, W_ARG, 1+AS_PTR_SIZE),
  1578. asBCINFO(CALLSYS, DW_ARG, 0xFFFF),
  1579. asBCINFO(CALLBND, DW_ARG, 0xFFFF),
  1580. asBCINFO(SUSPEND, NO_ARG, 0),
  1581. asBCINFO(ALLOC, PTR_DW_ARG, 0xFFFF),
  1582. asBCINFO(FREE, wW_PTR_ARG, 0),
  1583. asBCINFO(LOADOBJ, rW_ARG, 0),
  1584. asBCINFO(STOREOBJ, wW_ARG, 0),
  1585. asBCINFO(GETOBJ, W_ARG, 0),
  1586. asBCINFO(REFCPY, PTR_ARG, -AS_PTR_SIZE),
  1587. asBCINFO(CHKREF, NO_ARG, 0),
  1588. asBCINFO(GETOBJREF, W_ARG, 0),
  1589. asBCINFO(GETREF, W_ARG, 0),
  1590. asBCINFO(PshNull, NO_ARG, AS_PTR_SIZE),
  1591. asBCINFO(ClrVPtr, wW_ARG, 0),
  1592. asBCINFO(OBJTYPE, PTR_ARG, AS_PTR_SIZE),
  1593. asBCINFO(TYPEID, DW_ARG, 1),
  1594. asBCINFO(SetV4, wW_DW_ARG, 0),
  1595. asBCINFO(SetV8, wW_QW_ARG, 0),
  1596. asBCINFO(ADDSi, W_DW_ARG, 0),
  1597. asBCINFO(CpyVtoV4, wW_rW_ARG, 0),
  1598. asBCINFO(CpyVtoV8, wW_rW_ARG, 0),
  1599. asBCINFO(CpyVtoR4, rW_ARG, 0),
  1600. asBCINFO(CpyVtoR8, rW_ARG, 0),
  1601. asBCINFO(CpyVtoG4, rW_PTR_ARG, 0),
  1602. asBCINFO(CpyRtoV4, wW_ARG, 0),
  1603. asBCINFO(CpyRtoV8, wW_ARG, 0),
  1604. asBCINFO(CpyGtoV4, wW_PTR_ARG, 0),
  1605. asBCINFO(WRTV1, rW_ARG, 0),
  1606. asBCINFO(WRTV2, rW_ARG, 0),
  1607. asBCINFO(WRTV4, rW_ARG, 0),
  1608. asBCINFO(WRTV8, rW_ARG, 0),
  1609. asBCINFO(RDR1, wW_ARG, 0),
  1610. asBCINFO(RDR2, wW_ARG, 0),
  1611. asBCINFO(RDR4, wW_ARG, 0),
  1612. asBCINFO(RDR8, wW_ARG, 0),
  1613. asBCINFO(LDG, PTR_ARG, 0),
  1614. asBCINFO(LDV, rW_ARG, 0),
  1615. asBCINFO(PGA, PTR_ARG, AS_PTR_SIZE),
  1616. asBCINFO(CmpPtr, rW_rW_ARG, 0),
  1617. asBCINFO(VAR, rW_ARG, AS_PTR_SIZE),
  1618. asBCINFO(iTOf, rW_ARG, 0),
  1619. asBCINFO(fTOi, rW_ARG, 0),
  1620. asBCINFO(uTOf, rW_ARG, 0),
  1621. asBCINFO(fTOu, rW_ARG, 0),
  1622. asBCINFO(sbTOi, rW_ARG, 0),
  1623. asBCINFO(swTOi, rW_ARG, 0),
  1624. asBCINFO(ubTOi, rW_ARG, 0),
  1625. asBCINFO(uwTOi, rW_ARG, 0),
  1626. asBCINFO(dTOi, wW_rW_ARG, 0),
  1627. asBCINFO(dTOu, wW_rW_ARG, 0),
  1628. asBCINFO(dTOf, wW_rW_ARG, 0),
  1629. asBCINFO(iTOd, wW_rW_ARG, 0),
  1630. asBCINFO(uTOd, wW_rW_ARG, 0),
  1631. asBCINFO(fTOd, wW_rW_ARG, 0),
  1632. asBCINFO(ADDi, wW_rW_rW_ARG, 0),
  1633. asBCINFO(SUBi, wW_rW_rW_ARG, 0),
  1634. asBCINFO(MULi, wW_rW_rW_ARG, 0),
  1635. asBCINFO(DIVi, wW_rW_rW_ARG, 0),
  1636. asBCINFO(MODi, wW_rW_rW_ARG, 0),
  1637. asBCINFO(ADDf, wW_rW_rW_ARG, 0),
  1638. asBCINFO(SUBf, wW_rW_rW_ARG, 0),
  1639. asBCINFO(MULf, wW_rW_rW_ARG, 0),
  1640. asBCINFO(DIVf, wW_rW_rW_ARG, 0),
  1641. asBCINFO(MODf, wW_rW_rW_ARG, 0),
  1642. asBCINFO(ADDd, wW_rW_rW_ARG, 0),
  1643. asBCINFO(SUBd, wW_rW_rW_ARG, 0),
  1644. asBCINFO(MULd, wW_rW_rW_ARG, 0),
  1645. asBCINFO(DIVd, wW_rW_rW_ARG, 0),
  1646. asBCINFO(MODd, wW_rW_rW_ARG, 0),
  1647. asBCINFO(ADDIi, wW_rW_DW_ARG, 0),
  1648. asBCINFO(SUBIi, wW_rW_DW_ARG, 0),
  1649. asBCINFO(MULIi, wW_rW_DW_ARG, 0),
  1650. asBCINFO(ADDIf, wW_rW_DW_ARG, 0),
  1651. asBCINFO(SUBIf, wW_rW_DW_ARG, 0),
  1652. asBCINFO(MULIf, wW_rW_DW_ARG, 0),
  1653. asBCINFO(SetG4, PTR_DW_ARG, 0),
  1654. asBCINFO(ChkRefS, NO_ARG, 0),
  1655. asBCINFO(ChkNullV, rW_ARG, 0),
  1656. asBCINFO(CALLINTF, DW_ARG, 0xFFFF),
  1657. asBCINFO(iTOb, rW_ARG, 0),
  1658. asBCINFO(iTOw, rW_ARG, 0),
  1659. asBCINFO(SetV1, wW_DW_ARG, 0),
  1660. asBCINFO(SetV2, wW_DW_ARG, 0),
  1661. asBCINFO(Cast, DW_ARG, -AS_PTR_SIZE),
  1662. asBCINFO(i64TOi, wW_rW_ARG, 0),
  1663. asBCINFO(uTOi64, wW_rW_ARG, 0),
  1664. asBCINFO(iTOi64, wW_rW_ARG, 0),
  1665. asBCINFO(fTOi64, wW_rW_ARG, 0),
  1666. asBCINFO(dTOi64, rW_ARG, 0),
  1667. asBCINFO(fTOu64, wW_rW_ARG, 0),
  1668. asBCINFO(dTOu64, rW_ARG, 0),
  1669. asBCINFO(i64TOf, wW_rW_ARG, 0),
  1670. asBCINFO(u64TOf, wW_rW_ARG, 0),
  1671. asBCINFO(i64TOd, rW_ARG, 0),
  1672. asBCINFO(u64TOd, rW_ARG, 0),
  1673. asBCINFO(NEGi64, rW_ARG, 0),
  1674. asBCINFO(INCi64, NO_ARG, 0),
  1675. asBCINFO(DECi64, NO_ARG, 0),
  1676. asBCINFO(BNOT64, rW_ARG, 0),
  1677. asBCINFO(ADDi64, wW_rW_rW_ARG, 0),
  1678. asBCINFO(SUBi64, wW_rW_rW_ARG, 0),
  1679. asBCINFO(MULi64, wW_rW_rW_ARG, 0),
  1680. asBCINFO(DIVi64, wW_rW_rW_ARG, 0),
  1681. asBCINFO(MODi64, wW_rW_rW_ARG, 0),
  1682. asBCINFO(BAND64, wW_rW_rW_ARG, 0),
  1683. asBCINFO(BOR64, wW_rW_rW_ARG, 0),
  1684. asBCINFO(BXOR64, wW_rW_rW_ARG, 0),
  1685. asBCINFO(BSLL64, wW_rW_rW_ARG, 0),
  1686. asBCINFO(BSRL64, wW_rW_rW_ARG, 0),
  1687. asBCINFO(BSRA64, wW_rW_rW_ARG, 0),
  1688. asBCINFO(CMPi64, rW_rW_ARG, 0),
  1689. asBCINFO(CMPu64, rW_rW_ARG, 0),
  1690. asBCINFO(ChkNullS, W_ARG, 0),
  1691. asBCINFO(ClrHi, NO_ARG, 0),
  1692. asBCINFO(JitEntry, PTR_ARG, 0),
  1693. asBCINFO(CallPtr, rW_ARG, 0xFFFF),
  1694. asBCINFO(FuncPtr, PTR_ARG, AS_PTR_SIZE),
  1695. asBCINFO(LoadThisR, W_DW_ARG, 0),
  1696. asBCINFO(PshV8, rW_ARG, 2),
  1697. asBCINFO(DIVu, wW_rW_rW_ARG, 0),
  1698. asBCINFO(MODu, wW_rW_rW_ARG, 0),
  1699. asBCINFO(DIVu64, wW_rW_rW_ARG, 0),
  1700. asBCINFO(MODu64, wW_rW_rW_ARG, 0),
  1701. asBCINFO(LoadRObjR, rW_W_DW_ARG, 0),
  1702. asBCINFO(LoadVObjR, rW_W_DW_ARG, 0),
  1703. asBCINFO(RefCpyV, wW_PTR_ARG, 0),
  1704. asBCINFO(JLowZ, DW_ARG, 0),
  1705. asBCINFO(JLowNZ, DW_ARG, 0),
  1706. asBCINFO(AllocMem, wW_DW_ARG, 0),
  1707. asBCINFO(SetListSize, rW_DW_DW_ARG, 0),
  1708. asBCINFO(PshListElmnt, rW_DW_ARG, AS_PTR_SIZE),
  1709. asBCINFO(SetListType, rW_DW_DW_ARG, 0),
  1710. asBCINFO(POWi, wW_rW_rW_ARG, 0),
  1711. asBCINFO(POWu, wW_rW_rW_ARG, 0),
  1712. asBCINFO(POWf, wW_rW_rW_ARG, 0),
  1713. asBCINFO(POWd, wW_rW_rW_ARG, 0),
  1714. asBCINFO(POWdi, wW_rW_rW_ARG, 0),
  1715. asBCINFO(POWi64, wW_rW_rW_ARG, 0),
  1716. asBCINFO(POWu64, wW_rW_rW_ARG, 0),
  1717. asBCINFO(Thiscall1, DW_ARG, -AS_PTR_SIZE-1),
  1718. asBCINFO_DUMMY(201),
  1719. asBCINFO_DUMMY(202),
  1720. asBCINFO_DUMMY(203),
  1721. asBCINFO_DUMMY(204),
  1722. asBCINFO_DUMMY(205),
  1723. asBCINFO_DUMMY(206),
  1724. asBCINFO_DUMMY(207),
  1725. asBCINFO_DUMMY(208),
  1726. asBCINFO_DUMMY(209),
  1727. asBCINFO_DUMMY(210),
  1728. asBCINFO_DUMMY(211),
  1729. asBCINFO_DUMMY(212),
  1730. asBCINFO_DUMMY(213),
  1731. asBCINFO_DUMMY(214),
  1732. asBCINFO_DUMMY(215),
  1733. asBCINFO_DUMMY(216),
  1734. asBCINFO_DUMMY(217),
  1735. asBCINFO_DUMMY(218),
  1736. asBCINFO_DUMMY(219),
  1737. asBCINFO_DUMMY(220),
  1738. asBCINFO_DUMMY(221),
  1739. asBCINFO_DUMMY(222),
  1740. asBCINFO_DUMMY(223),
  1741. asBCINFO_DUMMY(224),
  1742. asBCINFO_DUMMY(225),
  1743. asBCINFO_DUMMY(226),
  1744. asBCINFO_DUMMY(227),
  1745. asBCINFO_DUMMY(228),
  1746. asBCINFO_DUMMY(229),
  1747. asBCINFO_DUMMY(230),
  1748. asBCINFO_DUMMY(231),
  1749. asBCINFO_DUMMY(232),
  1750. asBCINFO_DUMMY(233),
  1751. asBCINFO_DUMMY(234),
  1752. asBCINFO_DUMMY(235),
  1753. asBCINFO_DUMMY(236),
  1754. asBCINFO_DUMMY(237),
  1755. asBCINFO_DUMMY(238),
  1756. asBCINFO_DUMMY(239),
  1757. asBCINFO_DUMMY(240),
  1758. asBCINFO_DUMMY(241),
  1759. asBCINFO_DUMMY(242),
  1760. asBCINFO_DUMMY(243),
  1761. asBCINFO_DUMMY(244),
  1762. asBCINFO_DUMMY(245),
  1763. asBCINFO_DUMMY(246),
  1764. asBCINFO_DUMMY(247),
  1765. asBCINFO_DUMMY(248),
  1766. asBCINFO_DUMMY(249),
  1767. asBCINFO_DUMMY(250),
  1768. asBCINFO(VarDecl, W_ARG, 0),
  1769. asBCINFO(Block, INFO, 0),
  1770. asBCINFO(ObjInfo, rW_DW_ARG, 0),
  1771. asBCINFO(LINE, INFO, 0),
  1772. asBCINFO(LABEL, INFO, 0)
  1773. };
  1774. // Macros to access bytecode instruction arguments
  1775. #define asBC_DWORDARG(x) (*(((asDWORD*)x)+1))
  1776. #define asBC_INTARG(x) (*(int*)(((asDWORD*)x)+1))
  1777. #define asBC_QWORDARG(x) (*(asQWORD*)(((asDWORD*)x)+1))
  1778. #define asBC_FLOATARG(x) (*(float*)(((asDWORD*)x)+1))
  1779. #define asBC_PTRARG(x) (*(asPWORD*)(((asDWORD*)x)+1))
  1780. #define asBC_WORDARG0(x) (*(((asWORD*)x)+1))
  1781. #define asBC_WORDARG1(x) (*(((asWORD*)x)+2))
  1782. #define asBC_SWORDARG0(x) (*(((short*)x)+1))
  1783. #define asBC_SWORDARG1(x) (*(((short*)x)+2))
  1784. #define asBC_SWORDARG2(x) (*(((short*)x)+3))
  1785. // Urho3D: Include the wrapper macros file but only after they have been defined above
  1786. // This causes a large number of warnings, which could possibly be prevented with further
  1787. // changes to the library or the Urho Angelscript code
  1788. // Only include this file if we are NOT building the angelscript library itself,
  1789. // as Angelscript already provides generic wrappers for their classes
  1790. // (AS_IS_BUILDING is defined in the CMakeLists.txt file for the AngelScript (sub)library)
  1791. #ifndef AS_IS_BUILDING
  1792. #include "wrapmacros.h"
  1793. #endif
  1794. END_AS_NAMESPACE
  1795. #endif