angelscript.h 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2011 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 Öörni for Urho3D
  24. //
  25. // angelscript.h
  26. //
  27. // The script engine interface
  28. //
  29. #ifndef ANGELSCRIPT_H
  30. #define ANGELSCRIPT_H
  31. #include <stddef.h>
  32. #ifdef AS_USE_NAMESPACE
  33. #define BEGIN_AS_NAMESPACE namespace AngelScript {
  34. #define END_AS_NAMESPACE }
  35. #define AS_NAMESPACE_QUALIFIER AngelScript::
  36. #else
  37. #define BEGIN_AS_NAMESPACE
  38. #define END_AS_NAMESPACE
  39. #define AS_NAMESPACE_QUALIFIER
  40. #endif
  41. BEGIN_AS_NAMESPACE
  42. // AngelScript version
  43. #define ANGELSCRIPT_VERSION 22003
  44. #define ANGELSCRIPT_VERSION_STRING "2.20.3"
  45. // Data types
  46. class asIScriptEngine;
  47. class asIScriptModule;
  48. class asIScriptContext;
  49. class asIScriptGeneric;
  50. class asIScriptObject;
  51. class asIObjectType;
  52. class asIScriptFunction;
  53. class asIBinaryStream;
  54. class asIJITCompiler;
  55. // Enumerations and constants
  56. // Engine properties
  57. enum asEEngineProp
  58. {
  59. asEP_ALLOW_UNSAFE_REFERENCES = 1,
  60. asEP_OPTIMIZE_BYTECODE = 2,
  61. asEP_COPY_SCRIPT_SECTIONS = 3,
  62. asEP_MAX_STACK_SIZE = 4,
  63. asEP_USE_CHARACTER_LITERALS = 5,
  64. asEP_ALLOW_MULTILINE_STRINGS = 6,
  65. asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7,
  66. asEP_BUILD_WITHOUT_LINE_CUES = 8,
  67. asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9,
  68. asEP_REQUIRE_ENUM_SCOPE = 10,
  69. asEP_SCRIPT_SCANNER = 11,
  70. asEP_INCLUDE_JIT_INSTRUCTIONS = 12,
  71. asEP_STRING_ENCODING = 13,
  72. asEP_PROPERTY_ACCESSOR_MODE = 14,
  73. asEP_EXPAND_DEF_ARRAY_TO_TMPL = 15
  74. };
  75. // Calling conventions
  76. enum asECallConvTypes
  77. {
  78. asCALL_CDECL = 0,
  79. asCALL_STDCALL = 1,
  80. asCALL_THISCALL = 2,
  81. asCALL_CDECL_OBJLAST = 3,
  82. asCALL_CDECL_OBJFIRST = 4,
  83. asCALL_GENERIC = 5
  84. };
  85. // Object type flags
  86. enum asEObjTypeFlags
  87. {
  88. asOBJ_REF = 0x01,
  89. asOBJ_VALUE = 0x02,
  90. asOBJ_GC = 0x04,
  91. asOBJ_POD = 0x08,
  92. asOBJ_NOHANDLE = 0x10,
  93. asOBJ_SCOPED = 0x20,
  94. asOBJ_TEMPLATE = 0x40,
  95. asOBJ_APP_CLASS = 0x100,
  96. asOBJ_APP_CLASS_CONSTRUCTOR = 0x200,
  97. asOBJ_APP_CLASS_DESTRUCTOR = 0x400,
  98. asOBJ_APP_CLASS_ASSIGNMENT = 0x800,
  99. asOBJ_APP_CLASS_COPY_CONSTRUCTOR = 0x1000,
  100. asOBJ_APP_CLASS_C = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR),
  101. asOBJ_APP_CLASS_CD = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR),
  102. asOBJ_APP_CLASS_CA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  103. asOBJ_APP_CLASS_CK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  104. asOBJ_APP_CLASS_CDA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  105. asOBJ_APP_CLASS_CDK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  106. asOBJ_APP_CLASS_CAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  107. asOBJ_APP_CLASS_CDAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  108. asOBJ_APP_CLASS_D = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR),
  109. asOBJ_APP_CLASS_DA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  110. asOBJ_APP_CLASS_DK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  111. asOBJ_APP_CLASS_DAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  112. asOBJ_APP_CLASS_A = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT),
  113. asOBJ_APP_CLASS_AK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  114. asOBJ_APP_CLASS_K = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
  115. asOBJ_APP_PRIMITIVE = 0x2000,
  116. asOBJ_APP_FLOAT = 0x4000,
  117. asOBJ_MASK_VALID_FLAGS = 0x7F7F,
  118. asOBJ_SCRIPT_OBJECT = 0x10000
  119. };
  120. // Behaviours
  121. enum asEBehaviours
  122. {
  123. // Value object memory management
  124. asBEHAVE_CONSTRUCT,
  125. asBEHAVE_DESTRUCT,
  126. // Reference object memory management
  127. asBEHAVE_FACTORY,
  128. asBEHAVE_LIST_FACTORY,
  129. asBEHAVE_ADDREF,
  130. asBEHAVE_RELEASE,
  131. // Object operators
  132. asBEHAVE_VALUE_CAST,
  133. asBEHAVE_IMPLICIT_VALUE_CAST,
  134. asBEHAVE_REF_CAST,
  135. asBEHAVE_IMPLICIT_REF_CAST,
  136. #ifdef AS_DEPRECATED
  137. asBEHAVE_INDEX,
  138. #endif
  139. asBEHAVE_TEMPLATE_CALLBACK,
  140. // Garbage collection behaviours
  141. asBEHAVE_FIRST_GC,
  142. asBEHAVE_GETREFCOUNT = asBEHAVE_FIRST_GC,
  143. asBEHAVE_SETGCFLAG,
  144. asBEHAVE_GETGCFLAG,
  145. asBEHAVE_ENUMREFS,
  146. asBEHAVE_RELEASEREFS,
  147. asBEHAVE_LAST_GC = asBEHAVE_RELEASEREFS,
  148. asBEHAVE_MAX
  149. };
  150. // Return codes
  151. enum asERetCodes
  152. {
  153. asSUCCESS = 0,
  154. asERROR = -1,
  155. asCONTEXT_ACTIVE = -2,
  156. asCONTEXT_NOT_FINISHED = -3,
  157. asCONTEXT_NOT_PREPARED = -4,
  158. asINVALID_ARG = -5,
  159. asNO_FUNCTION = -6,
  160. asNOT_SUPPORTED = -7,
  161. asINVALID_NAME = -8,
  162. asNAME_TAKEN = -9,
  163. asINVALID_DECLARATION = -10,
  164. asINVALID_OBJECT = -11,
  165. asINVALID_TYPE = -12,
  166. asALREADY_REGISTERED = -13,
  167. asMULTIPLE_FUNCTIONS = -14,
  168. asNO_MODULE = -15,
  169. asNO_GLOBAL_VAR = -16,
  170. asINVALID_CONFIGURATION = -17,
  171. asINVALID_INTERFACE = -18,
  172. asCANT_BIND_ALL_FUNCTIONS = -19,
  173. asLOWER_ARRAY_DIMENSION_NOT_REGISTERED = -20,
  174. asWRONG_CONFIG_GROUP = -21,
  175. asCONFIG_GROUP_IS_IN_USE = -22,
  176. asILLEGAL_BEHAVIOUR_FOR_TYPE = -23,
  177. asWRONG_CALLING_CONV = -24,
  178. asBUILD_IN_PROGRESS = -25,
  179. asINIT_GLOBAL_VARS_FAILED = -26
  180. };
  181. // Context states
  182. enum asEContextState
  183. {
  184. asEXECUTION_FINISHED = 0,
  185. asEXECUTION_SUSPENDED = 1,
  186. asEXECUTION_ABORTED = 2,
  187. asEXECUTION_EXCEPTION = 3,
  188. asEXECUTION_PREPARED = 4,
  189. asEXECUTION_UNINITIALIZED = 5,
  190. asEXECUTION_ACTIVE = 6,
  191. asEXECUTION_ERROR = 7
  192. };
  193. // Message types
  194. enum asEMsgType
  195. {
  196. asMSGTYPE_ERROR = 0,
  197. asMSGTYPE_WARNING = 1,
  198. asMSGTYPE_INFORMATION = 2
  199. };
  200. // Garbage collector flags
  201. enum asEGCFlags
  202. {
  203. asGC_FULL_CYCLE = 1,
  204. asGC_ONE_STEP = 2,
  205. asGC_DESTROY_GARBAGE = 4,
  206. asGC_DETECT_GARBAGE = 8
  207. };
  208. // Token classes
  209. enum asETokenClass
  210. {
  211. asTC_UNKNOWN = 0,
  212. asTC_KEYWORD = 1,
  213. asTC_VALUE = 2,
  214. asTC_IDENTIFIER = 3,
  215. asTC_COMMENT = 4,
  216. asTC_WHITESPACE = 5
  217. };
  218. // Prepare flags
  219. const int asPREPARE_PREVIOUS = -1;
  220. // Config groups
  221. const char * const asALL_MODULES = (const char * const)-1;
  222. // Type id flags
  223. enum asETypeIdFlags
  224. {
  225. asTYPEID_VOID = 0,
  226. asTYPEID_BOOL = 1,
  227. asTYPEID_INT8 = 2,
  228. asTYPEID_INT16 = 3,
  229. asTYPEID_INT32 = 4,
  230. asTYPEID_INT64 = 5,
  231. asTYPEID_UINT8 = 6,
  232. asTYPEID_UINT16 = 7,
  233. asTYPEID_UINT32 = 8,
  234. asTYPEID_UINT64 = 9,
  235. asTYPEID_FLOAT = 10,
  236. asTYPEID_DOUBLE = 11,
  237. asTYPEID_OBJHANDLE = 0x40000000,
  238. asTYPEID_HANDLETOCONST = 0x20000000,
  239. asTYPEID_MASK_OBJECT = 0x1C000000,
  240. asTYPEID_APPOBJECT = 0x04000000,
  241. asTYPEID_SCRIPTOBJECT = 0x08000000,
  242. asTYPEID_TEMPLATE = 0x10000000,
  243. asTYPEID_MASK_SEQNBR = 0x03FFFFFF
  244. };
  245. // Type modifiers
  246. enum asETypeModifiers
  247. {
  248. asTM_NONE = 0,
  249. asTM_INREF = 1,
  250. asTM_OUTREF = 2,
  251. asTM_INOUTREF = 3
  252. };
  253. // GetModule flags
  254. enum asEGMFlags
  255. {
  256. asGM_ONLY_IF_EXISTS = 0,
  257. asGM_CREATE_IF_NOT_EXISTS = 1,
  258. asGM_ALWAYS_CREATE = 2
  259. };
  260. // Compile flags
  261. enum asECompileFlags
  262. {
  263. asCOMP_ADD_TO_MODULE = 1
  264. };
  265. // Function types
  266. enum asEFuncType
  267. {
  268. asFUNC_DUMMY =-1,
  269. asFUNC_SYSTEM = 0,
  270. asFUNC_SCRIPT = 1,
  271. asFUNC_INTERFACE = 2,
  272. asFUNC_VIRTUAL = 3,
  273. asFUNC_FUNCDEF = 4,
  274. asFUNC_IMPORTED = 5
  275. };
  276. //
  277. // asBYTE = 8 bits
  278. // asWORD = 16 bits
  279. // asDWORD = 32 bits
  280. // asQWORD = 64 bits
  281. // asPWORD = size of pointer
  282. //
  283. typedef unsigned char asBYTE;
  284. typedef unsigned short asWORD;
  285. typedef unsigned int asUINT;
  286. typedef size_t asPWORD;
  287. #ifdef __LP64__
  288. typedef unsigned int asDWORD;
  289. typedef unsigned long asQWORD;
  290. typedef long asINT64;
  291. #else
  292. typedef unsigned long asDWORD;
  293. #if defined(__GNUC__) || defined(__MWERKS__)
  294. typedef unsigned long long asQWORD;
  295. typedef long long asINT64;
  296. #else
  297. typedef unsigned __int64 asQWORD;
  298. typedef __int64 asINT64;
  299. #endif
  300. #endif
  301. typedef void (*asFUNCTION_t)();
  302. typedef void (*asGENFUNC_t)(asIScriptGeneric *);
  303. typedef void *(*asALLOCFUNC_t)(size_t);
  304. typedef void (*asFREEFUNC_t)(void *);
  305. typedef void (*asCLEANENGINEFUNC_t)(asIScriptEngine *);
  306. typedef void (*asCLEANCONTEXTFUNC_t)(asIScriptContext *);
  307. typedef void (*asCLEANFUNCTIONFUNC_t)(asIScriptFunction *);
  308. #define asFUNCTION(f) asFunctionPtr(f)
  309. #if (defined(_MSC_VER) && _MSC_VER <= 1200) || (defined(__BORLANDC__) && __BORLANDC__ < 0x590)
  310. // MSVC 6 has a bug that prevents it from properly compiling using the correct asFUNCTIONPR with operator >
  311. // so we need to use ordinary C style cast instead of static_cast. The drawback is that the compiler can't
  312. // check that the cast is really valid.
  313. // BCC v5.8 (C++Builder 2006) and earlier have a similar bug which forces us to fall back to a C-style cast.
  314. #define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())((r (*)p)(f)))
  315. #else
  316. #define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())(static_cast<r (*)p>(f)))
  317. #endif
  318. #ifndef AS_NO_CLASS_METHODS
  319. class asCUnknownClass;
  320. typedef void (asCUnknownClass::*asMETHOD_t)();
  321. struct asSFuncPtr
  322. {
  323. // Urho3D: modified for smaller executable size
  324. asSFuncPtr();
  325. asSFuncPtr(asBYTE f);
  326. union
  327. {
  328. // Urho3D: modified for smaller executable size
  329. struct {asMETHOD_t mthd;} m;
  330. struct {asFUNCTION_t func;} f;
  331. } ptr;
  332. asBYTE flag; // 1 = generic, 2 = global func, 3 = method
  333. };
  334. #if defined(__BORLANDC__)
  335. // A bug in BCC (QC #85374) makes it impossible to distinguish const/non-const method overloads
  336. // with static_cast<>. The workaround is to use an _implicit_cast instead.
  337. #if __BORLANDC__ < 0x590
  338. // BCC v5.8 (C++Builder 2006) and earlier have an even more annoying bug which causes
  339. // the "pretty" workaround below (with _implicit_cast<>) to fail. For these compilers
  340. // we need to use a traditional C-style cast.
  341. #define AS_METHOD_AMBIGUITY_CAST(t) (t)
  342. #else
  343. template <typename T>
  344. T _implicit_cast (T val)
  345. { return val; }
  346. #define AS_METHOD_AMBIGUITY_CAST(t) AS_NAMESPACE_QUALIFIER _implicit_cast<t >
  347. #endif
  348. #else
  349. #define AS_METHOD_AMBIGUITY_CAST(t) static_cast<t >
  350. #endif
  351. #define asMETHOD(c,m) asSMethodPtr<sizeof(void (c::*)())>::Convert((void (c::*)())(&c::m))
  352. #define asMETHODPR(c,m,p,r) asSMethodPtr<sizeof(void (c::*)())>::Convert(AS_METHOD_AMBIGUITY_CAST(r (c::*)p)(&c::m))
  353. #else // Class methods are disabled
  354. struct asSFuncPtr
  355. {
  356. union
  357. {
  358. // Urho3D: modified for smaller executable size
  359. struct {asFUNCTION_t func;} f;
  360. } ptr;
  361. asBYTE flag; // 1 = generic, 2 = global func
  362. };
  363. #endif
  364. struct asSMessageInfo
  365. {
  366. const char *section;
  367. int row;
  368. int col;
  369. asEMsgType type;
  370. const char *message;
  371. };
  372. // API functions
  373. // ANGELSCRIPT_EXPORT is defined when compiling the dll or lib
  374. // ANGELSCRIPT_DLL_LIBRARY_IMPORT is defined when dynamically linking to the
  375. // dll through the link lib automatically generated by MSVC++
  376. // ANGELSCRIPT_DLL_MANUAL_IMPORT is defined when manually loading the dll
  377. // Don't define anything when linking statically to the lib
  378. #if defined(WIN32) || defined(__CYGWIN__)
  379. #if defined(ANGELSCRIPT_EXPORT)
  380. #define AS_API __declspec(dllexport)
  381. #elif defined(ANGELSCRIPT_DLL_LIBRARY_IMPORT)
  382. #define AS_API __declspec(dllimport)
  383. #else // statically linked library
  384. #define AS_API
  385. #endif
  386. #elif defined(__GNUC__)
  387. #if defined(ANGELSCRIPT_EXPORT)
  388. #define AS_API __attribute__((visibility ("default")))
  389. #else
  390. #define AS_API
  391. #endif
  392. #else
  393. #define AS_API
  394. #endif
  395. #ifndef ANGELSCRIPT_DLL_MANUAL_IMPORT
  396. extern "C"
  397. {
  398. // Engine
  399. AS_API asIScriptEngine * asCreateScriptEngine(asDWORD version);
  400. AS_API const char * asGetLibraryVersion();
  401. AS_API const char * asGetLibraryOptions();
  402. // Context
  403. AS_API asIScriptContext * asGetActiveContext();
  404. // Thread support
  405. AS_API int asThreadCleanup();
  406. // Memory management
  407. AS_API int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);
  408. AS_API int asResetGlobalMemoryFunctions();
  409. }
  410. #endif // ANGELSCRIPT_DLL_MANUAL_IMPORT
  411. // Interface declarations
  412. class asIScriptEngine
  413. {
  414. public:
  415. // Memory management
  416. virtual int AddRef() const = 0;
  417. virtual int Release() const = 0;
  418. // Engine properties
  419. virtual int SetEngineProperty(asEEngineProp property, asPWORD value) = 0;
  420. virtual asPWORD GetEngineProperty(asEEngineProp property) const = 0;
  421. // Compiler messages
  422. virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv) = 0;
  423. virtual int ClearMessageCallback() = 0;
  424. virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message) = 0;
  425. // JIT Compiler
  426. virtual int SetJITCompiler(asIJITCompiler *compiler) = 0;
  427. virtual asIJITCompiler *GetJITCompiler() const = 0;
  428. // Global functions
  429. virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
  430. virtual int GetGlobalFunctionCount() const = 0;
  431. virtual int GetGlobalFunctionIdByIndex(asUINT index) const = 0;
  432. // Global properties
  433. virtual int RegisterGlobalProperty(const char *declaration, void *pointer) = 0;
  434. virtual int GetGlobalPropertyCount() const = 0;
  435. virtual int GetGlobalPropertyByIndex(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0) const = 0;
  436. // Object types
  437. virtual int RegisterObjectType(const char *obj, int byteSize, asDWORD flags) = 0;
  438. virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset) = 0;
  439. virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
  440. virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
  441. virtual int RegisterInterface(const char *name) = 0;
  442. virtual int RegisterInterfaceMethod(const char *intf, const char *declaration) = 0;
  443. virtual int GetObjectTypeCount() const = 0;
  444. virtual asIObjectType *GetObjectTypeByIndex(asUINT index) const = 0;
  445. // String factory
  446. virtual int RegisterStringFactory(const char *datatype, const asSFuncPtr &factoryFunc, asDWORD callConv) = 0;
  447. virtual int GetStringFactoryReturnTypeId() const = 0;
  448. // Default array type
  449. virtual int RegisterDefaultArrayType(const char *type) = 0;
  450. virtual int GetDefaultArrayTypeId() const = 0;
  451. // Enums
  452. virtual int RegisterEnum(const char *type) = 0;
  453. virtual int RegisterEnumValue(const char *type, const char *name, int value) = 0;
  454. virtual int GetEnumCount() const = 0;
  455. virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **configGroup = 0) const = 0;
  456. virtual int GetEnumValueCount(int enumTypeId) const = 0;
  457. virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
  458. // Funcdefs
  459. virtual int RegisterFuncdef(const char *decl) = 0;
  460. virtual int GetFuncdefCount() const = 0;
  461. virtual asIScriptFunction *GetFuncdefByIndex(asUINT index, const char **configGroup = 0) const = 0;
  462. // Typedefs
  463. virtual int RegisterTypedef(const char *type, const char *decl) = 0;
  464. virtual int GetTypedefCount() const = 0;
  465. virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **configGroup = 0) const = 0;
  466. // Configuration groups
  467. virtual int BeginConfigGroup(const char *groupName) = 0;
  468. virtual int EndConfigGroup() = 0;
  469. virtual int RemoveConfigGroup(const char *groupName) = 0;
  470. virtual int SetConfigGroupModuleAccess(const char *groupName, const char *module, bool hasAccess) = 0;
  471. // Script modules
  472. virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0;
  473. virtual int DiscardModule(const char *module) = 0;
  474. // Script functions
  475. virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const = 0;
  476. // Type identification
  477. virtual asIObjectType *GetObjectTypeById(int typeId) const = 0;
  478. virtual int GetTypeIdByDecl(const char *decl) const = 0;
  479. virtual const char *GetTypeDeclaration(int typeId) const = 0;
  480. virtual int GetSizeOfPrimitiveType(int typeId) const = 0;
  481. // Script execution
  482. virtual asIScriptContext *CreateContext() = 0;
  483. virtual void *CreateScriptObject(int typeId) = 0;
  484. virtual void *CreateScriptObjectCopy(void *obj, int typeId) = 0;
  485. virtual void CopyScriptObject(void *dstObj, void *srcObj, int typeId) = 0;
  486. virtual void ReleaseScriptObject(void *obj, int typeId) = 0;
  487. virtual void AddRefScriptObject(void *obj, int typeId) = 0;
  488. virtual bool IsHandleCompatibleWithObject(void *obj, int objTypeId, int handleTypeId) const = 0;
  489. // String interpretation
  490. virtual asETokenClass ParseToken(const char *string, size_t stringLength = 0, int *tokenLength = 0) const = 0;
  491. // Garbage collection
  492. virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE) = 0;
  493. virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed = 0, asUINT *totalDetected = 0) const = 0;
  494. virtual void NotifyGarbageCollectorOfNewObject(void *obj, int typeId) = 0;
  495. virtual void GCEnumCallback(void *reference) = 0;
  496. // User data
  497. virtual void *SetUserData(void *data) = 0;
  498. virtual void *GetUserData() const = 0;
  499. virtual void SetEngineUserDataCleanupCallback(asCLEANENGINEFUNC_t callback) = 0;
  500. virtual void SetContextUserDataCleanupCallback(asCLEANCONTEXTFUNC_t callback) = 0;
  501. virtual void SetFunctionUserDataCleanupCallback(asCLEANFUNCTIONFUNC_t callback) = 0;
  502. protected:
  503. virtual ~asIScriptEngine() {}
  504. };
  505. class asIScriptModule
  506. {
  507. public:
  508. virtual asIScriptEngine *GetEngine() const = 0;
  509. virtual void SetName(const char *name) = 0;
  510. virtual const char *GetName() const = 0;
  511. // Compilation
  512. virtual int AddScriptSection(const char *name, const char *code, size_t codeLength = 0, int lineOffset = 0) = 0;
  513. virtual int Build() = 0;
  514. virtual int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asIScriptFunction **outFunc) = 0;
  515. virtual int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset) = 0;
  516. // Functions
  517. virtual int GetFunctionCount() const = 0;
  518. virtual int GetFunctionIdByIndex(int index) const = 0;
  519. virtual int GetFunctionIdByName(const char *name) const = 0;
  520. virtual int GetFunctionIdByDecl(const char *decl) const = 0;
  521. virtual asIScriptFunction *GetFunctionDescriptorByIndex(int index) const = 0;
  522. virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const = 0;
  523. virtual int RemoveFunction(int funcId) = 0;
  524. // Global variables
  525. virtual int ResetGlobalVars() = 0;
  526. virtual int GetGlobalVarCount() const = 0;
  527. virtual int GetGlobalVarIndexByName(const char *name) const = 0;
  528. virtual int GetGlobalVarIndexByDecl(const char *decl) const = 0;
  529. virtual const char *GetGlobalVarDeclaration(asUINT index) const = 0;
  530. virtual int GetGlobalVar(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0) const = 0;
  531. virtual void *GetAddressOfGlobalVar(asUINT index) = 0;
  532. virtual int RemoveGlobalVar(asUINT index) = 0;
  533. // Type identification
  534. virtual int GetObjectTypeCount() const = 0;
  535. virtual asIObjectType *GetObjectTypeByIndex(asUINT index) const = 0;
  536. virtual int GetTypeIdByDecl(const char *decl) const = 0;
  537. // Enums
  538. virtual int GetEnumCount() const = 0;
  539. virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId) const = 0;
  540. virtual int GetEnumValueCount(int enumTypeId) const = 0;
  541. virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
  542. // Typedefs
  543. virtual int GetTypedefCount() const = 0;
  544. virtual const char *GetTypedefByIndex(asUINT index, int *typeId) const = 0;
  545. // Dynamic binding between modules
  546. virtual int GetImportedFunctionCount() const = 0;
  547. virtual int GetImportedFunctionIndexByDecl(const char *decl) const = 0;
  548. virtual const char *GetImportedFunctionDeclaration(int importIndex) const = 0;
  549. virtual const char *GetImportedFunctionSourceModule(int importIndex) const = 0;
  550. virtual int BindImportedFunction(int importIndex, int funcId) = 0;
  551. virtual int UnbindImportedFunction(int importIndex) = 0;
  552. virtual int BindAllImportedFunctions() = 0;
  553. virtual int UnbindAllImportedFunctions() = 0;
  554. // Bytecode saving and loading
  555. virtual int SaveByteCode(asIBinaryStream *out) const = 0;
  556. virtual int LoadByteCode(asIBinaryStream *in) = 0;
  557. #ifdef AS_DEPRECATED
  558. virtual const char *GetGlobalVarName(int index) const = 0;
  559. virtual int GetGlobalVarTypeId(int index, bool *isConst = 0) const = 0;
  560. #endif
  561. protected:
  562. virtual ~asIScriptModule() {}
  563. };
  564. class asIScriptContext
  565. {
  566. public:
  567. // Memory management
  568. virtual int AddRef() const = 0;
  569. virtual int Release() const = 0;
  570. // Miscellaneous
  571. virtual asIScriptEngine *GetEngine() const = 0;
  572. // Execution
  573. virtual int Prepare(int funcId) = 0;
  574. virtual int Unprepare() = 0;
  575. virtual int SetObject(void *obj) = 0;
  576. virtual int Execute() = 0;
  577. virtual int Abort() = 0;
  578. virtual int Suspend() = 0;
  579. virtual asEContextState GetState() const = 0;
  580. // Arguments
  581. virtual int SetArgByte(asUINT arg, asBYTE value) = 0;
  582. virtual int SetArgWord(asUINT arg, asWORD value) = 0;
  583. virtual int SetArgDWord(asUINT arg, asDWORD value) = 0;
  584. virtual int SetArgQWord(asUINT arg, asQWORD value) = 0;
  585. virtual int SetArgFloat(asUINT arg, float value) = 0;
  586. virtual int SetArgDouble(asUINT arg, double value) = 0;
  587. virtual int SetArgAddress(asUINT arg, void *addr) = 0;
  588. virtual int SetArgObject(asUINT arg, void *obj) = 0;
  589. virtual void *GetAddressOfArg(asUINT arg) = 0;
  590. // Return value
  591. virtual asBYTE GetReturnByte() = 0;
  592. virtual asWORD GetReturnWord() = 0;
  593. virtual asDWORD GetReturnDWord() = 0;
  594. virtual asQWORD GetReturnQWord() = 0;
  595. virtual float GetReturnFloat() = 0;
  596. virtual double GetReturnDouble() = 0;
  597. virtual void *GetReturnAddress() = 0;
  598. virtual void *GetReturnObject() = 0;
  599. virtual void *GetAddressOfReturnValue() = 0;
  600. // Exception handling
  601. virtual int SetException(const char *string) = 0;
  602. virtual int GetExceptionLineNumber(int *column = 0, const char **sectionName = 0) = 0;
  603. virtual int GetExceptionFunction() = 0;
  604. virtual const char *GetExceptionString() = 0;
  605. virtual int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
  606. virtual void ClearExceptionCallback() = 0;
  607. // Debugging
  608. virtual int SetLineCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
  609. virtual void ClearLineCallback() = 0;
  610. virtual asUINT GetCallstackSize() = 0;
  611. virtual asIScriptFunction *GetFunction(asUINT stackLevel = 0) = 0;
  612. virtual int GetLineNumber(asUINT stackLevel = 0, int *column = 0, const char **sectionName = 0) = 0;
  613. virtual int GetVarCount(asUINT stackLevel = 0) = 0;
  614. virtual const char *GetVarName(int varIndex, asUINT stackLevel = 0) = 0;
  615. virtual const char *GetVarDeclaration(int varIndex, asUINT stackLevel = 0) = 0;
  616. virtual int GetVarTypeId(int varIndex, asUINT stackLevel = 0) = 0;
  617. virtual void *GetAddressOfVar(int varIndex, asUINT stackLevel = 0) = 0;
  618. virtual int GetThisTypeId(asUINT stackLevel = 0) = 0;
  619. virtual void *GetThisPointer(asUINT stackLevel = 0) = 0;
  620. // User data
  621. virtual void *SetUserData(void *data) = 0;
  622. virtual void *GetUserData() const = 0;
  623. #ifdef AS_DEPRECATED
  624. // Deprecated since 2.20.0
  625. virtual int GetCurrentLineNumber(int *column = 0, const char **sectionName = 0) = 0;
  626. virtual int GetCurrentFunction() = 0;
  627. #endif
  628. protected:
  629. virtual ~asIScriptContext() {}
  630. };
  631. class asIScriptGeneric
  632. {
  633. public:
  634. // Miscellaneous
  635. virtual asIScriptEngine *GetEngine() const = 0;
  636. virtual int GetFunctionId() const = 0;
  637. virtual asIScriptFunction *GetFunctionDescriptor() const = 0;
  638. virtual void *GetFunctionUserData() const = 0;
  639. // Object
  640. virtual void *GetObject() = 0;
  641. virtual int GetObjectTypeId() const = 0;
  642. // Arguments
  643. virtual int GetArgCount() const = 0;
  644. virtual int GetArgTypeId(asUINT arg) const = 0;
  645. virtual asBYTE GetArgByte(asUINT arg) = 0;
  646. virtual asWORD GetArgWord(asUINT arg) = 0;
  647. virtual asDWORD GetArgDWord(asUINT arg) = 0;
  648. virtual asQWORD GetArgQWord(asUINT arg) = 0;
  649. virtual float GetArgFloat(asUINT arg) = 0;
  650. virtual double GetArgDouble(asUINT arg) = 0;
  651. virtual void *GetArgAddress(asUINT arg) = 0;
  652. virtual void *GetArgObject(asUINT arg) = 0;
  653. virtual void *GetAddressOfArg(asUINT arg) = 0;
  654. // Return value
  655. virtual int GetReturnTypeId() const = 0;
  656. virtual int SetReturnByte(asBYTE val) = 0;
  657. virtual int SetReturnWord(asWORD val) = 0;
  658. virtual int SetReturnDWord(asDWORD val) = 0;
  659. virtual int SetReturnQWord(asQWORD val) = 0;
  660. virtual int SetReturnFloat(float val) = 0;
  661. virtual int SetReturnDouble(double val) = 0;
  662. virtual int SetReturnAddress(void *addr) = 0;
  663. virtual int SetReturnObject(void *obj) = 0;
  664. virtual void *GetAddressOfReturnLocation() = 0;
  665. protected:
  666. virtual ~asIScriptGeneric() {}
  667. };
  668. class asIScriptObject
  669. {
  670. public:
  671. // Memory management
  672. virtual int AddRef() const = 0;
  673. virtual int Release() const = 0;
  674. // Type info
  675. virtual int GetTypeId() const = 0;
  676. virtual asIObjectType *GetObjectType() const = 0;
  677. // Class properties
  678. virtual int GetPropertyCount() const = 0;
  679. virtual int GetPropertyTypeId(asUINT prop) const = 0;
  680. virtual const char *GetPropertyName(asUINT prop) const = 0;
  681. virtual void *GetAddressOfProperty(asUINT prop) = 0;
  682. virtual asIScriptEngine *GetEngine() const = 0;
  683. virtual int CopyFrom(asIScriptObject *other) = 0;
  684. protected:
  685. virtual ~asIScriptObject() {}
  686. };
  687. class asIObjectType
  688. {
  689. public:
  690. virtual asIScriptEngine *GetEngine() const = 0;
  691. virtual const char *GetConfigGroup() const = 0;
  692. // Memory management
  693. virtual int AddRef() const = 0;
  694. virtual int Release() const = 0;
  695. // Type info
  696. virtual const char *GetName() const = 0;
  697. virtual asIObjectType *GetBaseType() const = 0;
  698. virtual asDWORD GetFlags() const = 0;
  699. virtual asUINT GetSize() const = 0;
  700. virtual int GetTypeId() const = 0;
  701. virtual int GetSubTypeId() const = 0;
  702. // Interfaces
  703. virtual int GetInterfaceCount() const = 0;
  704. virtual asIObjectType *GetInterface(asUINT index) const = 0;
  705. // Factories
  706. virtual int GetFactoryCount() const = 0;
  707. virtual int GetFactoryIdByIndex(int index) const = 0;
  708. virtual int GetFactoryIdByDecl(const char *decl) const = 0;
  709. // Methods
  710. virtual int GetMethodCount() const = 0;
  711. virtual int GetMethodIdByIndex(int index, bool getVirtual = true) const = 0;
  712. virtual int GetMethodIdByName(const char *name, bool getVirtual = true) const = 0;
  713. virtual int GetMethodIdByDecl(const char *decl, bool getVirtual = true) const = 0;
  714. virtual asIScriptFunction *GetMethodDescriptorByIndex(int index, bool getVirtual = true) const = 0;
  715. // Properties
  716. virtual int GetPropertyCount() const = 0;
  717. virtual int GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, int *offset = 0) const = 0;
  718. virtual const char *GetPropertyDeclaration(asUINT index) const = 0;
  719. // Behaviours
  720. virtual int GetBehaviourCount() const = 0;
  721. virtual int GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const = 0;
  722. #ifdef AS_DEPRECATED
  723. virtual int GetPropertyTypeId(asUINT prop) const = 0;
  724. virtual const char *GetPropertyName(asUINT prop) const = 0;
  725. virtual bool IsPropertyPrivate(asUINT prop) const = 0;
  726. virtual int GetPropertyOffset(asUINT prop) const = 0;
  727. #endif
  728. protected:
  729. virtual ~asIObjectType() {}
  730. };
  731. class asIScriptFunction
  732. {
  733. public:
  734. virtual asIScriptEngine *GetEngine() const = 0;
  735. // Memory management
  736. virtual int AddRef() const = 0;
  737. virtual int Release() const = 0;
  738. virtual int GetId() const = 0;
  739. virtual asEFuncType GetFuncType() const = 0;
  740. virtual const char *GetModuleName() const = 0;
  741. virtual const char *GetScriptSectionName() const = 0;
  742. virtual const char *GetConfigGroup() const = 0;
  743. virtual asIObjectType *GetObjectType() const = 0;
  744. virtual const char *GetObjectName() const = 0;
  745. virtual const char *GetName() const = 0;
  746. virtual const char *GetDeclaration(bool includeObjectName = true) const = 0;
  747. virtual bool IsReadOnly() const = 0;
  748. virtual bool IsPrivate() const = 0;
  749. virtual int GetParamCount() const = 0;
  750. virtual int GetParamTypeId(int index, asDWORD *flags = 0) const = 0;
  751. virtual int GetReturnTypeId() const = 0;
  752. // Debug information
  753. virtual int GetVarCount() const = 0;
  754. virtual int GetVar(asUINT index, const char **name, int *typeId = 0) const = 0;
  755. virtual const char * GetVarDecl(asUINT index) const = 0;
  756. // For JIT compilation
  757. virtual asDWORD *GetByteCode(asUINT *length = 0) = 0;
  758. // User data
  759. virtual void *SetUserData(void *userData) = 0;
  760. virtual void *GetUserData() const = 0;
  761. #ifdef AS_DEPRECATED
  762. virtual bool IsClassMethod() const = 0;
  763. virtual bool IsInterfaceMethod() const = 0;
  764. #endif
  765. protected:
  766. virtual ~asIScriptFunction() {};
  767. };
  768. class asIBinaryStream
  769. {
  770. public:
  771. virtual void Read(void *ptr, asUINT size) = 0;
  772. virtual void Write(const void *ptr, asUINT size) = 0;
  773. public:
  774. virtual ~asIBinaryStream() {}
  775. };
  776. //-----------------------------------------------------------------
  777. // Function pointers
  778. // Use our own memset() and memcpy() implementations for better portability
  779. inline void asMemClear(void *_p, size_t size)
  780. {
  781. char *p = (char *)_p;
  782. const char *e = p + size;
  783. for( ; p < e; p++ )
  784. *p = 0;
  785. }
  786. inline void asMemCopy(void *_d, const void *_s, size_t size)
  787. {
  788. char *d = (char *)_d;
  789. const char *s = (const char *)_s;
  790. const char *e = s + size;
  791. for( ; s < e; d++, s++ )
  792. *d = *s;
  793. }
  794. // Template function to capture all global functions,
  795. // except the ones using the generic calling convention
  796. template <class T>
  797. inline asSFuncPtr asFunctionPtr(T func)
  798. {
  799. // Urho3D: modified for smaller executable size
  800. asSFuncPtr p(2);
  801. p.ptr.f.func = (asFUNCTION_t)(size_t)func;
  802. return p;
  803. }
  804. // Specialization for functions using the generic calling convention
  805. template<>
  806. inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
  807. {
  808. // Urho3D: modified for smaller executable size
  809. asSFuncPtr p(1);
  810. p.ptr.f.func = (asFUNCTION_t)func;
  811. return p;
  812. }
  813. #ifndef AS_NO_CLASS_METHODS
  814. // Method pointers
  815. // Declare a dummy class so that we can determine the size of a simple method pointer
  816. class asCSimpleDummy {};
  817. typedef void (asCSimpleDummy::*asSIMPLEMETHOD_t)();
  818. const int SINGLE_PTR_SIZE = sizeof(asSIMPLEMETHOD_t);
  819. // Define template
  820. template <int N>
  821. struct asSMethodPtr
  822. {
  823. template<class M>
  824. static asSFuncPtr Convert(M Mthd)
  825. {
  826. // This version of the function should never be executed, nor compiled,
  827. // as it would mean that the size of the method pointer cannot be determined.
  828. int ERROR_UnsupportedMethodPtr[N-100];
  829. return 0;
  830. }
  831. };
  832. // Template specialization
  833. template <>
  834. struct asSMethodPtr<SINGLE_PTR_SIZE>
  835. {
  836. template<class M>
  837. static asSFuncPtr Convert(M Mthd)
  838. {
  839. // Urho3D: modified for smaller executable size
  840. asSFuncPtr p(3);
  841. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE);
  842. return p;
  843. }
  844. };
  845. #if defined(_MSC_VER) && !defined(__MWERKS__)
  846. // MSVC and Intel uses different sizes for different class method pointers
  847. template <>
  848. struct asSMethodPtr<SINGLE_PTR_SIZE+1*sizeof(int)>
  849. {
  850. template <class M>
  851. static asSFuncPtr Convert(M Mthd)
  852. {
  853. // Urho3D: modified for smaller executable size
  854. asSFuncPtr p(3);
  855. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+sizeof(int));
  856. return p;
  857. }
  858. };
  859. template <>
  860. struct asSMethodPtr<SINGLE_PTR_SIZE+2*sizeof(int)>
  861. {
  862. template <class M>
  863. static asSFuncPtr Convert(M Mthd)
  864. {
  865. // On 32bit platforms with is where a class with virtual inheritance falls.
  866. // On 64bit platforms we can also fall here if 8byte data alignments is used.
  867. // Urho3D: modified for smaller executable size
  868. asSFuncPtr p(3);
  869. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+2*sizeof(int));
  870. /*
  871. // Microsoft has a terrible optimization on class methods with virtual inheritance.
  872. // They are hardcoding an important offset, which is not coming in the method pointer.
  873. #ifdef _MSC_VER
  874. if( sizeof(void*) == 4 )
  875. {
  876. // Method pointers for virtual inheritance is not supported,
  877. // as it requires the location of the vbase table, which is
  878. // only available to the C++ compiler, but not in the method
  879. // pointer.
  880. // You can get around this by forward declaring the class and
  881. // storing the sizeof its method pointer in a constant. Example:
  882. // class ClassWithVirtualInheritance;
  883. // const int ClassWithVirtualInheritance_workaround = sizeof(void ClassWithVirtualInheritance::*());
  884. // This will force the compiler to use the unknown type
  885. // for the class, which falls under the next case
  886. // Copy the virtual table index to the 4th dword so that AngelScript
  887. // can properly detect and deny the use of methods with virtual inheritance.
  888. *(((asDWORD*)&p)+3) = *(((asDWORD*)&p)+2);
  889. }
  890. #endif
  891. */
  892. return p;
  893. }
  894. };
  895. template <>
  896. struct asSMethodPtr<SINGLE_PTR_SIZE+3*sizeof(int)>
  897. {
  898. template <class M>
  899. static asSFuncPtr Convert(M Mthd)
  900. {
  901. // Urho3D: modified for smaller executable size
  902. asSFuncPtr p(3);
  903. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+3*sizeof(int));
  904. return p;
  905. }
  906. };
  907. template <>
  908. struct asSMethodPtr<SINGLE_PTR_SIZE+4*sizeof(int)>
  909. {
  910. template <class M>
  911. static asSFuncPtr Convert(M Mthd)
  912. {
  913. // On 64bit platforms with 8byte data alignment
  914. // the unknown class method pointers will come here.
  915. // Urho3D: modified for smaller executable size
  916. asSFuncPtr p(3);
  917. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+4*sizeof(int));
  918. return p;
  919. }
  920. };
  921. #endif
  922. #endif // AS_NO_CLASS_METHODS
  923. //----------------------------------------------------------------
  924. // JIT compiler
  925. struct asSVMRegisters
  926. {
  927. asDWORD *programPointer; // points to current bytecode instruction
  928. asDWORD *stackFramePointer; // function stack frame
  929. asDWORD *stackPointer; // top of stack (grows downward)
  930. asQWORD valueRegister; // temp register for primitives
  931. void *objectRegister; // temp register for objects and handles
  932. asIObjectType *objectType; // type of object held in object register
  933. bool doProcessSuspend; // whether or not the JIT should break out when it encounters a suspend instruction
  934. };
  935. typedef void (*asJITFunction)(asSVMRegisters *registers, asDWORD entryId);
  936. class asIJITCompiler
  937. {
  938. public:
  939. virtual int CompileFunction(asIScriptFunction *function, asJITFunction *output) = 0;
  940. virtual void ReleaseJITFunction(asJITFunction func) = 0;
  941. public:
  942. virtual ~asIJITCompiler() {}
  943. };
  944. // Byte code instructions
  945. enum asEBCInstr
  946. {
  947. asBC_POP = 0,
  948. asBC_PUSH = 1,
  949. asBC_PshC4 = 2,
  950. asBC_PshV4 = 3,
  951. asBC_PSF = 4,
  952. asBC_SWAP4 = 5,
  953. asBC_NOT = 6,
  954. asBC_PshG4 = 7,
  955. asBC_LdGRdR4 = 8,
  956. asBC_CALL = 9,
  957. asBC_RET = 10,
  958. asBC_JMP = 11,
  959. asBC_JZ = 12,
  960. asBC_JNZ = 13,
  961. asBC_JS = 14,
  962. asBC_JNS = 15,
  963. asBC_JP = 16,
  964. asBC_JNP = 17,
  965. asBC_TZ = 18,
  966. asBC_TNZ = 19,
  967. asBC_TS = 20,
  968. asBC_TNS = 21,
  969. asBC_TP = 22,
  970. asBC_TNP = 23,
  971. asBC_NEGi = 24,
  972. asBC_NEGf = 25,
  973. asBC_NEGd = 26,
  974. asBC_INCi16 = 27,
  975. asBC_INCi8 = 28,
  976. asBC_DECi16 = 29,
  977. asBC_DECi8 = 30,
  978. asBC_INCi = 31,
  979. asBC_DECi = 32,
  980. asBC_INCf = 33,
  981. asBC_DECf = 34,
  982. asBC_INCd = 35,
  983. asBC_DECd = 36,
  984. asBC_IncVi = 37,
  985. asBC_DecVi = 38,
  986. asBC_BNOT = 39,
  987. asBC_BAND = 40,
  988. asBC_BOR = 41,
  989. asBC_BXOR = 42,
  990. asBC_BSLL = 43,
  991. asBC_BSRL = 44,
  992. asBC_BSRA = 45,
  993. asBC_COPY = 46,
  994. asBC_PshC8 = 47,
  995. asBC_RDS8 = 48,
  996. asBC_SWAP8 = 49,
  997. asBC_CMPd = 50,
  998. asBC_CMPu = 51,
  999. asBC_CMPf = 52,
  1000. asBC_CMPi = 53,
  1001. asBC_CMPIi = 54,
  1002. asBC_CMPIf = 55,
  1003. asBC_CMPIu = 56,
  1004. asBC_JMPP = 57,
  1005. asBC_PopRPtr = 58,
  1006. asBC_PshRPtr = 59,
  1007. asBC_STR = 60,
  1008. asBC_CALLSYS = 61,
  1009. asBC_CALLBND = 62,
  1010. asBC_SUSPEND = 63,
  1011. asBC_ALLOC = 64,
  1012. asBC_FREE = 65,
  1013. asBC_LOADOBJ = 66,
  1014. asBC_STOREOBJ = 67,
  1015. asBC_GETOBJ = 68,
  1016. asBC_REFCPY = 69,
  1017. asBC_CHKREF = 70,
  1018. asBC_GETOBJREF = 71,
  1019. asBC_GETREF = 72,
  1020. asBC_SWAP48 = 73,
  1021. asBC_SWAP84 = 74,
  1022. asBC_OBJTYPE = 75,
  1023. asBC_TYPEID = 76,
  1024. asBC_SetV4 = 77,
  1025. asBC_SetV8 = 78,
  1026. asBC_ADDSi = 79,
  1027. asBC_CpyVtoV4 = 80,
  1028. asBC_CpyVtoV8 = 81,
  1029. asBC_CpyVtoR4 = 82,
  1030. asBC_CpyVtoR8 = 83,
  1031. asBC_CpyVtoG4 = 84,
  1032. asBC_CpyRtoV4 = 85,
  1033. asBC_CpyRtoV8 = 86,
  1034. asBC_CpyGtoV4 = 87,
  1035. asBC_WRTV1 = 88,
  1036. asBC_WRTV2 = 89,
  1037. asBC_WRTV4 = 90,
  1038. asBC_WRTV8 = 91,
  1039. asBC_RDR1 = 92,
  1040. asBC_RDR2 = 93,
  1041. asBC_RDR4 = 94,
  1042. asBC_RDR8 = 95,
  1043. asBC_LDG = 96,
  1044. asBC_LDV = 97,
  1045. asBC_PGA = 98,
  1046. asBC_RDS4 = 99,
  1047. asBC_VAR = 100,
  1048. asBC_iTOf = 101,
  1049. asBC_fTOi = 102,
  1050. asBC_uTOf = 103,
  1051. asBC_fTOu = 104,
  1052. asBC_sbTOi = 105,
  1053. asBC_swTOi = 106,
  1054. asBC_ubTOi = 107,
  1055. asBC_uwTOi = 108,
  1056. asBC_dTOi = 109,
  1057. asBC_dTOu = 110,
  1058. asBC_dTOf = 111,
  1059. asBC_iTOd = 112,
  1060. asBC_uTOd = 113,
  1061. asBC_fTOd = 114,
  1062. asBC_ADDi = 115,
  1063. asBC_SUBi = 116,
  1064. asBC_MULi = 117,
  1065. asBC_DIVi = 118,
  1066. asBC_MODi = 119,
  1067. asBC_ADDf = 120,
  1068. asBC_SUBf = 121,
  1069. asBC_MULf = 122,
  1070. asBC_DIVf = 123,
  1071. asBC_MODf = 124,
  1072. asBC_ADDd = 125,
  1073. asBC_SUBd = 126,
  1074. asBC_MULd = 127,
  1075. asBC_DIVd = 128,
  1076. asBC_MODd = 129,
  1077. asBC_ADDIi = 130,
  1078. asBC_SUBIi = 131,
  1079. asBC_MULIi = 132,
  1080. asBC_ADDIf = 133,
  1081. asBC_SUBIf = 134,
  1082. asBC_MULIf = 135,
  1083. asBC_SetG4 = 136,
  1084. asBC_ChkRefS = 137,
  1085. asBC_ChkNullV = 138,
  1086. asBC_CALLINTF = 139,
  1087. asBC_iTOb = 140,
  1088. asBC_iTOw = 141,
  1089. asBC_SetV1 = 142,
  1090. asBC_SetV2 = 143,
  1091. asBC_Cast = 144,
  1092. asBC_i64TOi = 145,
  1093. asBC_uTOi64 = 146,
  1094. asBC_iTOi64 = 147,
  1095. asBC_fTOi64 = 148,
  1096. asBC_dTOi64 = 149,
  1097. asBC_fTOu64 = 150,
  1098. asBC_dTOu64 = 151,
  1099. asBC_i64TOf = 152,
  1100. asBC_u64TOf = 153,
  1101. asBC_i64TOd = 154,
  1102. asBC_u64TOd = 155,
  1103. asBC_NEGi64 = 156,
  1104. asBC_INCi64 = 157,
  1105. asBC_DECi64 = 158,
  1106. asBC_BNOT64 = 159,
  1107. asBC_ADDi64 = 160,
  1108. asBC_SUBi64 = 161,
  1109. asBC_MULi64 = 162,
  1110. asBC_DIVi64 = 163,
  1111. asBC_MODi64 = 164,
  1112. asBC_BAND64 = 165,
  1113. asBC_BOR64 = 166,
  1114. asBC_BXOR64 = 167,
  1115. asBC_BSLL64 = 168,
  1116. asBC_BSRL64 = 169,
  1117. asBC_BSRA64 = 170,
  1118. asBC_CMPi64 = 171,
  1119. asBC_CMPu64 = 172,
  1120. asBC_ChkNullS = 173,
  1121. asBC_ClrHi = 174,
  1122. asBC_JitEntry = 175,
  1123. asBC_CallPtr = 176,
  1124. asBC_FuncPtr = 177,
  1125. asBC_LoadThisR = 178,
  1126. asBC_PshV8 = 179,
  1127. asBC_DIVu = 180,
  1128. asBC_MODu = 181,
  1129. asBC_DIVu64 = 182,
  1130. asBC_MODu64 = 183,
  1131. asBC_LoadRObjR = 184,
  1132. asBC_LoadVObjR = 185,
  1133. asBC_MAXBYTECODE = 186,
  1134. // Temporary tokens. Can't be output to the final program
  1135. asBC_Block = 252,
  1136. asBC_ObjInfo = 253,
  1137. asBC_LINE = 254,
  1138. asBC_LABEL = 255
  1139. };
  1140. // Instruction types
  1141. enum asEBCType
  1142. {
  1143. asBCTYPE_INFO = 0,
  1144. asBCTYPE_NO_ARG = 1,
  1145. asBCTYPE_W_ARG = 2,
  1146. asBCTYPE_wW_ARG = 3,
  1147. asBCTYPE_DW_ARG = 4,
  1148. asBCTYPE_rW_DW_ARG = 5,
  1149. asBCTYPE_QW_ARG = 6,
  1150. asBCTYPE_DW_DW_ARG = 7,
  1151. asBCTYPE_wW_rW_rW_ARG = 8,
  1152. asBCTYPE_wW_QW_ARG = 9,
  1153. asBCTYPE_wW_rW_ARG = 10,
  1154. asBCTYPE_rW_ARG = 11,
  1155. asBCTYPE_wW_DW_ARG = 12,
  1156. asBCTYPE_wW_rW_DW_ARG = 13,
  1157. asBCTYPE_rW_rW_ARG = 14,
  1158. asBCTYPE_wW_W_ARG = 15,
  1159. asBCTYPE_QW_DW_ARG = 16,
  1160. asBCTYPE_rW_QW_ARG = 17,
  1161. asBCTYPE_W_DW_ARG = 18,
  1162. asBCTYPE_rW_W_DW_ARG = 19
  1163. };
  1164. // Instruction type sizes
  1165. const int asBCTypeSize[20] =
  1166. {
  1167. 0, // asBCTYPE_INFO
  1168. 1, // asBCTYPE_NO_ARG
  1169. 1, // asBCTYPE_W_ARG
  1170. 1, // asBCTYPE_wW_ARG
  1171. 2, // asBCTYPE_DW_ARG
  1172. 2, // asBCTYPE_rW_DW_ARG
  1173. 3, // asBCTYPE_QW_ARG
  1174. 3, // asBCTYPE_DW_DW_ARG
  1175. 2, // asBCTYPE_wW_rW_rW_ARG
  1176. 3, // asBCTYPE_wW_QW_ARG
  1177. 2, // asBCTYPE_wW_rW_ARG
  1178. 1, // asBCTYPE_rW_ARG
  1179. 2, // asBCTYPE_wW_DW_ARG
  1180. 3, // asBCTYPE_wW_rW_DW_ARG
  1181. 2, // asBCTYPE_rW_rW_ARG
  1182. 2, // asBCTYPE_wW_W_ARG
  1183. 4, // asBCTYPE_QW_DW_ARG
  1184. 3, // asBCTYPE_rW_QW_ARG
  1185. 2, // asBCTYPE_W_DW_ARG
  1186. 3 // asBCTYPE_rW_W_DW_ARG
  1187. };
  1188. // Instruction info
  1189. struct asSBCInfo
  1190. {
  1191. asEBCInstr bc;
  1192. asEBCType type;
  1193. int stackInc;
  1194. const char *name;
  1195. };
  1196. #ifndef AS_64BIT_PTR
  1197. #define asBCTYPE_PTR_ARG asBCTYPE_DW_ARG
  1198. #define asBCTYPE_PTR_DW_ARG asBCTYPE_DW_DW_ARG
  1199. #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_DW_ARG
  1200. #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_DW_ARG
  1201. #ifndef AS_PTR_SIZE
  1202. #define AS_PTR_SIZE 1
  1203. #endif
  1204. #else
  1205. #define asBCTYPE_PTR_ARG asBCTYPE_QW_ARG
  1206. #define asBCTYPE_PTR_DW_ARG asBCTYPE_QW_DW_ARG
  1207. #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_QW_ARG
  1208. #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_QW_ARG
  1209. #ifndef AS_PTR_SIZE
  1210. #define AS_PTR_SIZE 2
  1211. #endif
  1212. #endif
  1213. #define asBCINFO(b,t,s) {asBC_##b, asBCTYPE_##t, s, #b}
  1214. #define asBCINFO_DUMMY(b) {asEBCInstr(b), asBCTYPE_INFO, 0, "BC_" #b}
  1215. const asSBCInfo asBCInfo[256] =
  1216. {
  1217. asBCINFO(POP, W_ARG, 0xFFFF),
  1218. asBCINFO(PUSH, W_ARG, 0xFFFF),
  1219. asBCINFO(PshC4, DW_ARG, 1),
  1220. asBCINFO(PshV4, rW_ARG, 1),
  1221. asBCINFO(PSF, rW_ARG, AS_PTR_SIZE),
  1222. asBCINFO(SWAP4, NO_ARG, 0),
  1223. asBCINFO(NOT, rW_ARG, 0),
  1224. asBCINFO(PshG4, PTR_ARG, 1),
  1225. asBCINFO(LdGRdR4, wW_PTR_ARG, 0),
  1226. asBCINFO(CALL, DW_ARG, 0xFFFF),
  1227. asBCINFO(RET, W_ARG, 0xFFFF),
  1228. asBCINFO(JMP, DW_ARG, 0),
  1229. asBCINFO(JZ, DW_ARG, 0),
  1230. asBCINFO(JNZ, DW_ARG, 0),
  1231. asBCINFO(JS, DW_ARG, 0),
  1232. asBCINFO(JNS, DW_ARG, 0),
  1233. asBCINFO(JP, DW_ARG, 0),
  1234. asBCINFO(JNP, DW_ARG, 0),
  1235. asBCINFO(TZ, NO_ARG, 0),
  1236. asBCINFO(TNZ, NO_ARG, 0),
  1237. asBCINFO(TS, NO_ARG, 0),
  1238. asBCINFO(TNS, NO_ARG, 0),
  1239. asBCINFO(TP, NO_ARG, 0),
  1240. asBCINFO(TNP, NO_ARG, 0),
  1241. asBCINFO(NEGi, rW_ARG, 0),
  1242. asBCINFO(NEGf, rW_ARG, 0),
  1243. asBCINFO(NEGd, rW_ARG, 0),
  1244. asBCINFO(INCi16, NO_ARG, 0),
  1245. asBCINFO(INCi8, NO_ARG, 0),
  1246. asBCINFO(DECi16, NO_ARG, 0),
  1247. asBCINFO(DECi8, NO_ARG, 0),
  1248. asBCINFO(INCi, NO_ARG, 0),
  1249. asBCINFO(DECi, NO_ARG, 0),
  1250. asBCINFO(INCf, NO_ARG, 0),
  1251. asBCINFO(DECf, NO_ARG, 0),
  1252. asBCINFO(INCd, NO_ARG, 0),
  1253. asBCINFO(DECd, NO_ARG, 0),
  1254. asBCINFO(IncVi, rW_ARG, 0),
  1255. asBCINFO(DecVi, rW_ARG, 0),
  1256. asBCINFO(BNOT, rW_ARG, 0),
  1257. asBCINFO(BAND, wW_rW_rW_ARG, 0),
  1258. asBCINFO(BOR, wW_rW_rW_ARG, 0),
  1259. asBCINFO(BXOR, wW_rW_rW_ARG, 0),
  1260. asBCINFO(BSLL, wW_rW_rW_ARG, 0),
  1261. asBCINFO(BSRL, wW_rW_rW_ARG, 0),
  1262. asBCINFO(BSRA, wW_rW_rW_ARG, 0),
  1263. asBCINFO(COPY, W_DW_ARG, -AS_PTR_SIZE),
  1264. asBCINFO(PshC8, QW_ARG, 2),
  1265. asBCINFO(RDS8, NO_ARG, 2-AS_PTR_SIZE),
  1266. asBCINFO(SWAP8, NO_ARG, 0),
  1267. asBCINFO(CMPd, rW_rW_ARG, 0),
  1268. asBCINFO(CMPu, rW_rW_ARG, 0),
  1269. asBCINFO(CMPf, rW_rW_ARG, 0),
  1270. asBCINFO(CMPi, rW_rW_ARG, 0),
  1271. asBCINFO(CMPIi, rW_DW_ARG, 0),
  1272. asBCINFO(CMPIf, rW_DW_ARG, 0),
  1273. asBCINFO(CMPIu, rW_DW_ARG, 0),
  1274. asBCINFO(JMPP, rW_ARG, 0),
  1275. asBCINFO(PopRPtr, NO_ARG, -AS_PTR_SIZE),
  1276. asBCINFO(PshRPtr, NO_ARG, AS_PTR_SIZE),
  1277. asBCINFO(STR, W_ARG, 1+AS_PTR_SIZE),
  1278. asBCINFO(CALLSYS, DW_ARG, 0xFFFF),
  1279. asBCINFO(CALLBND, DW_ARG, 0xFFFF),
  1280. asBCINFO(SUSPEND, NO_ARG, 0),
  1281. asBCINFO(ALLOC, PTR_DW_ARG, 0xFFFF),
  1282. asBCINFO(FREE, wW_PTR_ARG, 0),
  1283. asBCINFO(LOADOBJ, rW_ARG, 0),
  1284. asBCINFO(STOREOBJ, wW_ARG, 0),
  1285. asBCINFO(GETOBJ, W_ARG, 0),
  1286. asBCINFO(REFCPY, PTR_ARG, -AS_PTR_SIZE),
  1287. asBCINFO(CHKREF, NO_ARG, 0),
  1288. asBCINFO(GETOBJREF, W_ARG, 0),
  1289. asBCINFO(GETREF, W_ARG, 0),
  1290. asBCINFO(SWAP48, NO_ARG, 0),
  1291. asBCINFO(SWAP84, NO_ARG, 0),
  1292. asBCINFO(OBJTYPE, PTR_ARG, AS_PTR_SIZE),
  1293. asBCINFO(TYPEID, DW_ARG, 1),
  1294. asBCINFO(SetV4, wW_DW_ARG, 0),
  1295. asBCINFO(SetV8, wW_QW_ARG, 0),
  1296. asBCINFO(ADDSi, W_DW_ARG, 0),
  1297. asBCINFO(CpyVtoV4, wW_rW_ARG, 0),
  1298. asBCINFO(CpyVtoV8, wW_rW_ARG, 0),
  1299. asBCINFO(CpyVtoR4, rW_ARG, 0),
  1300. asBCINFO(CpyVtoR8, rW_ARG, 0),
  1301. asBCINFO(CpyVtoG4, rW_PTR_ARG, 0),
  1302. asBCINFO(CpyRtoV4, wW_ARG, 0),
  1303. asBCINFO(CpyRtoV8, wW_ARG, 0),
  1304. asBCINFO(CpyGtoV4, wW_PTR_ARG, 0),
  1305. asBCINFO(WRTV1, rW_ARG, 0),
  1306. asBCINFO(WRTV2, rW_ARG, 0),
  1307. asBCINFO(WRTV4, rW_ARG, 0),
  1308. asBCINFO(WRTV8, rW_ARG, 0),
  1309. asBCINFO(RDR1, wW_ARG, 0),
  1310. asBCINFO(RDR2, wW_ARG, 0),
  1311. asBCINFO(RDR4, wW_ARG, 0),
  1312. asBCINFO(RDR8, wW_ARG, 0),
  1313. asBCINFO(LDG, PTR_ARG, 0),
  1314. asBCINFO(LDV, rW_ARG, 0),
  1315. asBCINFO(PGA, PTR_ARG, AS_PTR_SIZE),
  1316. asBCINFO(RDS4, NO_ARG, 1-AS_PTR_SIZE),
  1317. asBCINFO(VAR, rW_ARG, AS_PTR_SIZE),
  1318. asBCINFO(iTOf, rW_ARG, 0),
  1319. asBCINFO(fTOi, rW_ARG, 0),
  1320. asBCINFO(uTOf, rW_ARG, 0),
  1321. asBCINFO(fTOu, rW_ARG, 0),
  1322. asBCINFO(sbTOi, rW_ARG, 0),
  1323. asBCINFO(swTOi, rW_ARG, 0),
  1324. asBCINFO(ubTOi, rW_ARG, 0),
  1325. asBCINFO(uwTOi, rW_ARG, 0),
  1326. asBCINFO(dTOi, wW_rW_ARG, 0),
  1327. asBCINFO(dTOu, wW_rW_ARG, 0),
  1328. asBCINFO(dTOf, wW_rW_ARG, 0),
  1329. asBCINFO(iTOd, wW_rW_ARG, 0),
  1330. asBCINFO(uTOd, wW_rW_ARG, 0),
  1331. asBCINFO(fTOd, wW_rW_ARG, 0),
  1332. asBCINFO(ADDi, wW_rW_rW_ARG, 0),
  1333. asBCINFO(SUBi, wW_rW_rW_ARG, 0),
  1334. asBCINFO(MULi, wW_rW_rW_ARG, 0),
  1335. asBCINFO(DIVi, wW_rW_rW_ARG, 0),
  1336. asBCINFO(MODi, wW_rW_rW_ARG, 0),
  1337. asBCINFO(ADDf, wW_rW_rW_ARG, 0),
  1338. asBCINFO(SUBf, wW_rW_rW_ARG, 0),
  1339. asBCINFO(MULf, wW_rW_rW_ARG, 0),
  1340. asBCINFO(DIVf, wW_rW_rW_ARG, 0),
  1341. asBCINFO(MODf, wW_rW_rW_ARG, 0),
  1342. asBCINFO(ADDd, wW_rW_rW_ARG, 0),
  1343. asBCINFO(SUBd, wW_rW_rW_ARG, 0),
  1344. asBCINFO(MULd, wW_rW_rW_ARG, 0),
  1345. asBCINFO(DIVd, wW_rW_rW_ARG, 0),
  1346. asBCINFO(MODd, wW_rW_rW_ARG, 0),
  1347. asBCINFO(ADDIi, wW_rW_DW_ARG, 0),
  1348. asBCINFO(SUBIi, wW_rW_DW_ARG, 0),
  1349. asBCINFO(MULIi, wW_rW_DW_ARG, 0),
  1350. asBCINFO(ADDIf, wW_rW_DW_ARG, 0),
  1351. asBCINFO(SUBIf, wW_rW_DW_ARG, 0),
  1352. asBCINFO(MULIf, wW_rW_DW_ARG, 0),
  1353. asBCINFO(SetG4, PTR_DW_ARG, 0),
  1354. asBCINFO(ChkRefS, NO_ARG, 0),
  1355. asBCINFO(ChkNullV, rW_ARG, 0),
  1356. asBCINFO(CALLINTF, DW_ARG, 0xFFFF),
  1357. asBCINFO(iTOb, rW_ARG, 0),
  1358. asBCINFO(iTOw, rW_ARG, 0),
  1359. asBCINFO(SetV1, wW_DW_ARG, 0),
  1360. asBCINFO(SetV2, wW_DW_ARG, 0),
  1361. asBCINFO(Cast, DW_ARG, -AS_PTR_SIZE),
  1362. asBCINFO(i64TOi, wW_rW_ARG, 0),
  1363. asBCINFO(uTOi64, wW_rW_ARG, 0),
  1364. asBCINFO(iTOi64, wW_rW_ARG, 0),
  1365. asBCINFO(fTOi64, wW_rW_ARG, 0),
  1366. asBCINFO(dTOi64, rW_ARG, 0),
  1367. asBCINFO(fTOu64, wW_rW_ARG, 0),
  1368. asBCINFO(dTOu64, rW_ARG, 0),
  1369. asBCINFO(i64TOf, wW_rW_ARG, 0),
  1370. asBCINFO(u64TOf, wW_rW_ARG, 0),
  1371. asBCINFO(i64TOd, rW_ARG, 0),
  1372. asBCINFO(u64TOd, rW_ARG, 0),
  1373. asBCINFO(NEGi64, rW_ARG, 0),
  1374. asBCINFO(INCi64, NO_ARG, 0),
  1375. asBCINFO(DECi64, NO_ARG, 0),
  1376. asBCINFO(BNOT64, rW_ARG, 0),
  1377. asBCINFO(ADDi64, wW_rW_rW_ARG, 0),
  1378. asBCINFO(SUBi64, wW_rW_rW_ARG, 0),
  1379. asBCINFO(MULi64, wW_rW_rW_ARG, 0),
  1380. asBCINFO(DIVi64, wW_rW_rW_ARG, 0),
  1381. asBCINFO(MODi64, wW_rW_rW_ARG, 0),
  1382. asBCINFO(BAND64, wW_rW_rW_ARG, 0),
  1383. asBCINFO(BOR64, wW_rW_rW_ARG, 0),
  1384. asBCINFO(BXOR64, wW_rW_rW_ARG, 0),
  1385. asBCINFO(BSLL64, wW_rW_rW_ARG, 0),
  1386. asBCINFO(BSRL64, wW_rW_rW_ARG, 0),
  1387. asBCINFO(BSRA64, wW_rW_rW_ARG, 0),
  1388. asBCINFO(CMPi64, rW_rW_ARG, 0),
  1389. asBCINFO(CMPu64, rW_rW_ARG, 0),
  1390. asBCINFO(ChkNullS, W_ARG, 0),
  1391. asBCINFO(ClrHi, NO_ARG, 0),
  1392. asBCINFO(JitEntry, W_ARG, 0),
  1393. asBCINFO(CallPtr, rW_ARG, 0xFFFF),
  1394. asBCINFO(FuncPtr, PTR_ARG, AS_PTR_SIZE),
  1395. asBCINFO(LoadThisR, W_DW_ARG, 0),
  1396. asBCINFO(PshV8, rW_ARG, 2),
  1397. asBCINFO(DIVu, wW_rW_rW_ARG, 0),
  1398. asBCINFO(MODu, wW_rW_rW_ARG, 0),
  1399. asBCINFO(DIVu64, wW_rW_rW_ARG, 0),
  1400. asBCINFO(MODu64, wW_rW_rW_ARG, 0),
  1401. asBCINFO(LoadRObjR, rW_W_DW_ARG, 0),
  1402. asBCINFO(LoadVObjR, rW_W_DW_ARG, 0),
  1403. asBCINFO_DUMMY(186),
  1404. asBCINFO_DUMMY(187),
  1405. asBCINFO_DUMMY(188),
  1406. asBCINFO_DUMMY(189),
  1407. asBCINFO_DUMMY(190),
  1408. asBCINFO_DUMMY(191),
  1409. asBCINFO_DUMMY(192),
  1410. asBCINFO_DUMMY(193),
  1411. asBCINFO_DUMMY(194),
  1412. asBCINFO_DUMMY(195),
  1413. asBCINFO_DUMMY(196),
  1414. asBCINFO_DUMMY(197),
  1415. asBCINFO_DUMMY(198),
  1416. asBCINFO_DUMMY(199),
  1417. asBCINFO_DUMMY(200),
  1418. asBCINFO_DUMMY(201),
  1419. asBCINFO_DUMMY(202),
  1420. asBCINFO_DUMMY(203),
  1421. asBCINFO_DUMMY(204),
  1422. asBCINFO_DUMMY(205),
  1423. asBCINFO_DUMMY(206),
  1424. asBCINFO_DUMMY(207),
  1425. asBCINFO_DUMMY(208),
  1426. asBCINFO_DUMMY(209),
  1427. asBCINFO_DUMMY(210),
  1428. asBCINFO_DUMMY(211),
  1429. asBCINFO_DUMMY(212),
  1430. asBCINFO_DUMMY(213),
  1431. asBCINFO_DUMMY(214),
  1432. asBCINFO_DUMMY(215),
  1433. asBCINFO_DUMMY(216),
  1434. asBCINFO_DUMMY(217),
  1435. asBCINFO_DUMMY(218),
  1436. asBCINFO_DUMMY(219),
  1437. asBCINFO_DUMMY(220),
  1438. asBCINFO_DUMMY(221),
  1439. asBCINFO_DUMMY(222),
  1440. asBCINFO_DUMMY(223),
  1441. asBCINFO_DUMMY(224),
  1442. asBCINFO_DUMMY(225),
  1443. asBCINFO_DUMMY(226),
  1444. asBCINFO_DUMMY(227),
  1445. asBCINFO_DUMMY(228),
  1446. asBCINFO_DUMMY(229),
  1447. asBCINFO_DUMMY(230),
  1448. asBCINFO_DUMMY(231),
  1449. asBCINFO_DUMMY(232),
  1450. asBCINFO_DUMMY(233),
  1451. asBCINFO_DUMMY(234),
  1452. asBCINFO_DUMMY(235),
  1453. asBCINFO_DUMMY(236),
  1454. asBCINFO_DUMMY(237),
  1455. asBCINFO_DUMMY(238),
  1456. asBCINFO_DUMMY(239),
  1457. asBCINFO_DUMMY(240),
  1458. asBCINFO_DUMMY(241),
  1459. asBCINFO_DUMMY(242),
  1460. asBCINFO_DUMMY(243),
  1461. asBCINFO_DUMMY(244),
  1462. asBCINFO_DUMMY(245),
  1463. asBCINFO_DUMMY(246),
  1464. asBCINFO_DUMMY(247),
  1465. asBCINFO_DUMMY(248),
  1466. asBCINFO_DUMMY(249),
  1467. asBCINFO_DUMMY(250),
  1468. asBCINFO_DUMMY(251),
  1469. asBCINFO(Block, INFO, 0),
  1470. asBCINFO(ObjInfo, rW_DW_ARG, 0),
  1471. asBCINFO(LINE, INFO, 0),
  1472. asBCINFO(LABEL, INFO, 0)
  1473. };
  1474. // Macros to access bytecode instruction arguments
  1475. #define asBC_DWORDARG(x) (asDWORD(*(x+1)))
  1476. #define asBC_INTARG(x) (int(*(x+1)))
  1477. #define asBC_QWORDARG(x) (*(asQWORD*)(x+1))
  1478. #define asBC_FLOATARG(x) (*(float*)(x+1))
  1479. #define asBC_PTRARG(x) (*(asPTRWORD*)(x+1))
  1480. #define asBC_WORDARG0(x) (*(((asWORD*)x)+1))
  1481. #define asBC_WORDARG1(x) (*(((asWORD*)x)+2))
  1482. #define asBC_SWORDARG0(x) (*(((short*)x)+1))
  1483. #define asBC_SWORDARG1(x) (*(((short*)x)+2))
  1484. #define asBC_SWORDARG2(x) (*(((short*)x)+3))
  1485. END_AS_NAMESPACE
  1486. #endif