/xbmc/visualizations/Vortex/angelscript/angelscript/include/angelscript.h

http://github.com/xbmc/xbmc · C++ Header · 1611 lines · 1244 code · 186 blank · 181 comment · 5 complexity · c7247513d0b574a5bc99bcaea1dc5269 MD5 · raw file

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