angelscript.h 68 KB

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