angelscript.h 61 KB

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