angelscript.h 67 KB

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