angelscript.h 55 KB

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