angelscript.h 56 KB

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