angelscript.h 69 KB

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