PageRenderTime 98ms CodeModel.GetById 10ms app.highlight 78ms RepoModel.GetById 1ms app.codeStats 0ms

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