diff --git a/Deer/src/Deer/Core/Log.cpp b/Deer/src/Deer/Core/Log.cpp index 2b55e9d..fbe068e 100755 --- a/Deer/src/Deer/Core/Log.cpp +++ b/Deer/src/Deer/Core/Log.cpp @@ -8,7 +8,7 @@ namespace Deer { void Log::init() { // spdlog::set_pattern("%^[%T] %n: %v%$"); - spdlog::set_pattern("%n: %v%$"); + spdlog::set_pattern("%v%$"); coreLogger = spdlog::stdout_color_mt("Core"); clientLogger = spdlog::stdout_color_mt("Client"); diff --git a/Deer/vendor/angelScript/include/angelscript.h b/Deer/vendor/angelScript/include/angelscript.h index 8a729f5..642edf1 100755 --- a/Deer/vendor/angelScript/include/angelscript.h +++ b/Deer/vendor/angelScript/include/angelscript.h @@ -28,14 +28,12 @@ andreas@angelcode.com */ - // // angelscript.h // // The script engine interface // - #ifndef ANGELSCRIPT_H #define ANGELSCRIPT_H @@ -45,20 +43,20 @@ #endif #ifdef AS_USE_NAMESPACE - #define BEGIN_AS_NAMESPACE namespace AngelScript { - #define END_AS_NAMESPACE } - #define AS_NAMESPACE_QUALIFIER AngelScript:: +#define BEGIN_AS_NAMESPACE namespace AngelScript { +#define END_AS_NAMESPACE } +#define AS_NAMESPACE_QUALIFIER AngelScript:: #else - #define BEGIN_AS_NAMESPACE - #define END_AS_NAMESPACE - #define AS_NAMESPACE_QUALIFIER :: +#define BEGIN_AS_NAMESPACE +#define END_AS_NAMESPACE +#define AS_NAMESPACE_QUALIFIER :: #endif BEGIN_AS_NAMESPACE // AngelScript version -#define ANGELSCRIPT_VERSION 23800 +#define ANGELSCRIPT_VERSION 23800 #define ANGELSCRIPT_VERSION_STRING "2.38.0 WIP" // Data types @@ -83,22 +81,22 @@ class asIStringFactory; // asQWORD = 64 bits // asPWORD = size of pointer // -typedef signed char asINT8; -typedef signed short asINT16; -typedef signed int asINT32; -typedef unsigned char asBYTE; +typedef signed char asINT8; +typedef signed short asINT16; +typedef signed int asINT32; +typedef unsigned char asBYTE; typedef unsigned short asWORD; -typedef unsigned int asUINT; +typedef unsigned int asUINT; #if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(__S3E__) || (defined(_MSC_VER) && defined(__clang__)) // size_t is not really correct, since it only guaranteed to be large enough to hold the segment size. // For example, on 16bit systems the size_t may be 16bits only even if pointers are 32bit. But nobody // is likely to use MSVC6 to compile for 16bit systems anymore, so this should be ok. -typedef size_t asPWORD; +typedef size_t asPWORD; #else -typedef uintptr_t asPWORD; +typedef uintptr_t asPWORD; #endif #ifdef __LP64__ -typedef unsigned int asDWORD; +typedef unsigned int asDWORD; typedef unsigned long asQWORD; typedef long asINT64; #else @@ -115,157 +113,152 @@ typedef __int64 asINT64; // Enumerations and constants // Return codes -enum asERetCodes -{ - asSUCCESS = 0, - asERROR = -1, - asCONTEXT_ACTIVE = -2, - asCONTEXT_NOT_FINISHED = -3, - asCONTEXT_NOT_PREPARED = -4, - asINVALID_ARG = -5, - asNO_FUNCTION = -6, - asNOT_SUPPORTED = -7, - asINVALID_NAME = -8, - asNAME_TAKEN = -9, - asINVALID_DECLARATION = -10, - asINVALID_OBJECT = -11, - asINVALID_TYPE = -12, - asALREADY_REGISTERED = -13, - asMULTIPLE_FUNCTIONS = -14, - asNO_MODULE = -15, - asNO_GLOBAL_VAR = -16, - asINVALID_CONFIGURATION = -17, - asINVALID_INTERFACE = -18, - asCANT_BIND_ALL_FUNCTIONS = -19, +enum asERetCodes { + asSUCCESS = 0, + asERROR = -1, + asCONTEXT_ACTIVE = -2, + asCONTEXT_NOT_FINISHED = -3, + asCONTEXT_NOT_PREPARED = -4, + asINVALID_ARG = -5, + asNO_FUNCTION = -6, + asNOT_SUPPORTED = -7, + asINVALID_NAME = -8, + asNAME_TAKEN = -9, + asINVALID_DECLARATION = -10, + asINVALID_OBJECT = -11, + asINVALID_TYPE = -12, + asALREADY_REGISTERED = -13, + asMULTIPLE_FUNCTIONS = -14, + asNO_MODULE = -15, + asNO_GLOBAL_VAR = -16, + asINVALID_CONFIGURATION = -17, + asINVALID_INTERFACE = -18, + asCANT_BIND_ALL_FUNCTIONS = -19, asLOWER_ARRAY_DIMENSION_NOT_REGISTERED = -20, - asWRONG_CONFIG_GROUP = -21, - asCONFIG_GROUP_IS_IN_USE = -22, - asILLEGAL_BEHAVIOUR_FOR_TYPE = -23, - asWRONG_CALLING_CONV = -24, - asBUILD_IN_PROGRESS = -25, - asINIT_GLOBAL_VARS_FAILED = -26, - asOUT_OF_MEMORY = -27, - asMODULE_IS_IN_USE = -28 + asWRONG_CONFIG_GROUP = -21, + asCONFIG_GROUP_IS_IN_USE = -22, + asILLEGAL_BEHAVIOUR_FOR_TYPE = -23, + asWRONG_CALLING_CONV = -24, + asBUILD_IN_PROGRESS = -25, + asINIT_GLOBAL_VARS_FAILED = -26, + asOUT_OF_MEMORY = -27, + asMODULE_IS_IN_USE = -28 }; // Engine properties -enum asEEngineProp -{ - asEP_ALLOW_UNSAFE_REFERENCES = 1, - asEP_OPTIMIZE_BYTECODE = 2, - asEP_COPY_SCRIPT_SECTIONS = 3, - asEP_MAX_STACK_SIZE = 4, - asEP_USE_CHARACTER_LITERALS = 5, - asEP_ALLOW_MULTILINE_STRINGS = 6, - asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7, - asEP_BUILD_WITHOUT_LINE_CUES = 8, - asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9, - asEP_REQUIRE_ENUM_SCOPE = 10, - asEP_SCRIPT_SCANNER = 11, - asEP_INCLUDE_JIT_INSTRUCTIONS = 12, - asEP_STRING_ENCODING = 13, - asEP_PROPERTY_ACCESSOR_MODE = 14, - asEP_EXPAND_DEF_ARRAY_TO_TMPL = 15, - asEP_AUTO_GARBAGE_COLLECT = 16, - asEP_DISALLOW_GLOBAL_VARS = 17, - asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT = 18, - asEP_COMPILER_WARNINGS = 19, +enum asEEngineProp { + asEP_ALLOW_UNSAFE_REFERENCES = 1, + asEP_OPTIMIZE_BYTECODE = 2, + asEP_COPY_SCRIPT_SECTIONS = 3, + asEP_MAX_STACK_SIZE = 4, + asEP_USE_CHARACTER_LITERALS = 5, + asEP_ALLOW_MULTILINE_STRINGS = 6, + asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7, + asEP_BUILD_WITHOUT_LINE_CUES = 8, + asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9, + asEP_REQUIRE_ENUM_SCOPE = 10, + asEP_SCRIPT_SCANNER = 11, + asEP_INCLUDE_JIT_INSTRUCTIONS = 12, + asEP_STRING_ENCODING = 13, + asEP_PROPERTY_ACCESSOR_MODE = 14, + asEP_EXPAND_DEF_ARRAY_TO_TMPL = 15, + asEP_AUTO_GARBAGE_COLLECT = 16, + asEP_DISALLOW_GLOBAL_VARS = 17, + asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT = 18, + asEP_COMPILER_WARNINGS = 19, asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE = 20, - asEP_ALTER_SYNTAX_NAMED_ARGS = 21, - asEP_DISABLE_INTEGER_DIVISION = 22, - asEP_DISALLOW_EMPTY_LIST_ELEMENTS = 23, - asEP_PRIVATE_PROP_AS_PROTECTED = 24, - asEP_ALLOW_UNICODE_IDENTIFIERS = 25, - asEP_HEREDOC_TRIM_MODE = 26, - asEP_MAX_NESTED_CALLS = 27, - asEP_GENERIC_CALL_MODE = 28, - asEP_INIT_STACK_SIZE = 29, - asEP_INIT_CALL_STACK_SIZE = 30, - asEP_MAX_CALL_STACK_SIZE = 31, - asEP_IGNORE_DUPLICATE_SHARED_INTF = 32, - asEP_NO_DEBUG_OUTPUT = 33, - asEP_DISABLE_SCRIPT_CLASS_GC = 34, - asEP_JIT_INTERFACE_VERSION = 35, - asEP_ALWAYS_IMPL_DEFAULT_COPY = 36, + asEP_ALTER_SYNTAX_NAMED_ARGS = 21, + asEP_DISABLE_INTEGER_DIVISION = 22, + asEP_DISALLOW_EMPTY_LIST_ELEMENTS = 23, + asEP_PRIVATE_PROP_AS_PROTECTED = 24, + asEP_ALLOW_UNICODE_IDENTIFIERS = 25, + asEP_HEREDOC_TRIM_MODE = 26, + asEP_MAX_NESTED_CALLS = 27, + asEP_GENERIC_CALL_MODE = 28, + asEP_INIT_STACK_SIZE = 29, + asEP_INIT_CALL_STACK_SIZE = 30, + asEP_MAX_CALL_STACK_SIZE = 31, + asEP_IGNORE_DUPLICATE_SHARED_INTF = 32, + asEP_NO_DEBUG_OUTPUT = 33, + asEP_DISABLE_SCRIPT_CLASS_GC = 34, + asEP_JIT_INTERFACE_VERSION = 35, + asEP_ALWAYS_IMPL_DEFAULT_COPY = 36, asEP_ALWAYS_IMPL_DEFAULT_COPY_CONSTRUCT = 37, - asEP_MEMBER_INIT_MODE = 38, - asEP_BOOL_CONVERSION_MODE = 39, + asEP_MEMBER_INIT_MODE = 38, + asEP_BOOL_CONVERSION_MODE = 39, asEP_LAST_PROPERTY }; // Calling conventions -enum asECallConvTypes -{ - asCALL_CDECL = 0, - asCALL_STDCALL = 1, +enum asECallConvTypes { + asCALL_CDECL = 0, + asCALL_STDCALL = 1, asCALL_THISCALL_ASGLOBAL = 2, - asCALL_THISCALL = 3, - asCALL_CDECL_OBJLAST = 4, - asCALL_CDECL_OBJFIRST = 5, - asCALL_GENERIC = 6, - asCALL_THISCALL_OBJLAST = 7, + asCALL_THISCALL = 3, + asCALL_CDECL_OBJLAST = 4, + asCALL_CDECL_OBJFIRST = 5, + asCALL_GENERIC = 6, + asCALL_THISCALL_OBJLAST = 7, asCALL_THISCALL_OBJFIRST = 8 }; // Object type flags -enum asEObjTypeFlags : asQWORD -{ - asOBJ_REF = (1<<0), - asOBJ_VALUE = (1<<1), - asOBJ_GC = (1<<2), - asOBJ_POD = (1<<3), - asOBJ_NOHANDLE = (1<<4), - asOBJ_SCOPED = (1<<5), - asOBJ_TEMPLATE = (1<<6), - asOBJ_ASHANDLE = (1<<7), - asOBJ_APP_CLASS = (1<<8), - asOBJ_APP_CLASS_CONSTRUCTOR = (1<<9), - asOBJ_APP_CLASS_DESTRUCTOR = (1<<10), - asOBJ_APP_CLASS_ASSIGNMENT = (1<<11), - asOBJ_APP_CLASS_COPY_CONSTRUCTOR = (1<<12), - asOBJ_APP_CLASS_C = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR), - asOBJ_APP_CLASS_CD = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR), - asOBJ_APP_CLASS_CA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT), - asOBJ_APP_CLASS_CK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), - asOBJ_APP_CLASS_CDA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT), - asOBJ_APP_CLASS_CDK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), - asOBJ_APP_CLASS_CAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), - asOBJ_APP_CLASS_CDAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), - asOBJ_APP_CLASS_D = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR), - asOBJ_APP_CLASS_DA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT), - asOBJ_APP_CLASS_DK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), - asOBJ_APP_CLASS_DAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), - asOBJ_APP_CLASS_A = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT), - asOBJ_APP_CLASS_AK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), - asOBJ_APP_CLASS_K = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), +enum asEObjTypeFlags : asQWORD { + asOBJ_REF = (1 << 0), + asOBJ_VALUE = (1 << 1), + asOBJ_GC = (1 << 2), + asOBJ_POD = (1 << 3), + asOBJ_NOHANDLE = (1 << 4), + asOBJ_SCOPED = (1 << 5), + asOBJ_TEMPLATE = (1 << 6), + asOBJ_ASHANDLE = (1 << 7), + asOBJ_APP_CLASS = (1 << 8), + asOBJ_APP_CLASS_CONSTRUCTOR = (1 << 9), + asOBJ_APP_CLASS_DESTRUCTOR = (1 << 10), + asOBJ_APP_CLASS_ASSIGNMENT = (1 << 11), + asOBJ_APP_CLASS_COPY_CONSTRUCTOR = (1 << 12), + asOBJ_APP_CLASS_C = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR), + asOBJ_APP_CLASS_CD = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR), + asOBJ_APP_CLASS_CA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT), + asOBJ_APP_CLASS_CK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), + asOBJ_APP_CLASS_CDA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT), + asOBJ_APP_CLASS_CDK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), + asOBJ_APP_CLASS_CAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), + asOBJ_APP_CLASS_CDAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), + asOBJ_APP_CLASS_D = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR), + asOBJ_APP_CLASS_DA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT), + asOBJ_APP_CLASS_DK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), + asOBJ_APP_CLASS_DAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), + asOBJ_APP_CLASS_A = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT), + asOBJ_APP_CLASS_AK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), + asOBJ_APP_CLASS_K = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_COPY_CONSTRUCTOR), asOBJ_APP_CLASS_MORE_CONSTRUCTORS = (asQWORD(1) << 31), - asOBJ_APP_PRIMITIVE = (1<<13), - asOBJ_APP_FLOAT = (1<<14), - asOBJ_APP_ARRAY = (1<<15), - asOBJ_APP_CLASS_ALLINTS = (1<<16), - asOBJ_APP_CLASS_ALLFLOATS = (1<<17), - asOBJ_NOCOUNT = (1<<18), - asOBJ_APP_CLASS_ALIGN8 = (1<<19), - asOBJ_IMPLICIT_HANDLE = (1<<20), - asOBJ_APP_CLASS_UNION = (asQWORD(1)<<32), - asOBJ_MASK_VALID_FLAGS = 0x1801FFFFFul, + asOBJ_APP_PRIMITIVE = (1 << 13), + asOBJ_APP_FLOAT = (1 << 14), + asOBJ_APP_ARRAY = (1 << 15), + asOBJ_APP_CLASS_ALLINTS = (1 << 16), + asOBJ_APP_CLASS_ALLFLOATS = (1 << 17), + asOBJ_NOCOUNT = (1 << 18), + asOBJ_APP_CLASS_ALIGN8 = (1 << 19), + asOBJ_IMPLICIT_HANDLE = (1 << 20), + asOBJ_APP_CLASS_UNION = (asQWORD(1) << 32), + asOBJ_MASK_VALID_FLAGS = 0x1801FFFFFul, // Internal flags - asOBJ_SCRIPT_OBJECT = (1<<21), - asOBJ_SHARED = (1<<22), - asOBJ_NOINHERIT = (1<<23), - asOBJ_FUNCDEF = (1<<24), - asOBJ_LIST_PATTERN = (1<<25), - asOBJ_ENUM = (1<<26), - asOBJ_TEMPLATE_SUBTYPE = (1<<27), - asOBJ_TYPEDEF = (1<<28), - asOBJ_ABSTRACT = (1<<29), - asOBJ_APP_ALIGN16 = (1<<30) + asOBJ_SCRIPT_OBJECT = (1 << 21), + asOBJ_SHARED = (1 << 22), + asOBJ_NOINHERIT = (1 << 23), + asOBJ_FUNCDEF = (1 << 24), + asOBJ_LIST_PATTERN = (1 << 25), + asOBJ_ENUM = (1 << 26), + asOBJ_TEMPLATE_SUBTYPE = (1 << 27), + asOBJ_TYPEDEF = (1 << 28), + asOBJ_ABSTRACT = (1 << 29), + asOBJ_APP_ALIGN16 = (1 << 30) }; // Behaviours -enum asEBehaviours -{ +enum asEBehaviours { // Value object memory management asBEHAVE_CONSTRUCT, asBEHAVE_LIST_CONSTRUCT, @@ -283,158 +276,149 @@ enum asEBehaviours // Garbage collection behaviours asBEHAVE_FIRST_GC, - asBEHAVE_GETREFCOUNT = asBEHAVE_FIRST_GC, - asBEHAVE_SETGCFLAG, - asBEHAVE_GETGCFLAG, - asBEHAVE_ENUMREFS, - asBEHAVE_RELEASEREFS, + asBEHAVE_GETREFCOUNT = asBEHAVE_FIRST_GC, + asBEHAVE_SETGCFLAG, + asBEHAVE_GETGCFLAG, + asBEHAVE_ENUMREFS, + asBEHAVE_RELEASEREFS, asBEHAVE_LAST_GC = asBEHAVE_RELEASEREFS, asBEHAVE_MAX }; // Context states -enum asEContextState -{ - asEXECUTION_FINISHED = 0, - asEXECUTION_SUSPENDED = 1, - asEXECUTION_ABORTED = 2, - asEXECUTION_EXCEPTION = 3, - asEXECUTION_PREPARED = 4, - asEXECUTION_UNINITIALIZED = 5, - asEXECUTION_ACTIVE = 6, - asEXECUTION_ERROR = 7, +enum asEContextState { + asEXECUTION_FINISHED = 0, + asEXECUTION_SUSPENDED = 1, + asEXECUTION_ABORTED = 2, + asEXECUTION_EXCEPTION = 3, + asEXECUTION_PREPARED = 4, + asEXECUTION_UNINITIALIZED = 5, + asEXECUTION_ACTIVE = 6, + asEXECUTION_ERROR = 7, asEXECUTION_DESERIALIZATION = 8 }; // Message types -enum asEMsgType -{ - asMSGTYPE_ERROR = 0, - asMSGTYPE_WARNING = 1, +enum asEMsgType { + asMSGTYPE_ERROR = 0, + asMSGTYPE_WARNING = 1, asMSGTYPE_INFORMATION = 2 }; // Garbage collector flags -enum asEGCFlags -{ - asGC_FULL_CYCLE = 1, - asGC_ONE_STEP = 2, +enum asEGCFlags { + asGC_FULL_CYCLE = 1, + asGC_ONE_STEP = 2, asGC_DESTROY_GARBAGE = 4, - asGC_DETECT_GARBAGE = 8 + asGC_DETECT_GARBAGE = 8 }; // Token classes -enum asETokenClass -{ - asTC_UNKNOWN = 0, - asTC_KEYWORD = 1, - asTC_VALUE = 2, +enum asETokenClass { + asTC_UNKNOWN = 0, + asTC_KEYWORD = 1, + asTC_VALUE = 2, asTC_IDENTIFIER = 3, - asTC_COMMENT = 4, + asTC_COMMENT = 4, asTC_WHITESPACE = 5 }; // Type id flags -enum asETypeIdFlags -{ - asTYPEID_VOID = 0, - asTYPEID_BOOL = 1, - asTYPEID_INT8 = 2, - asTYPEID_INT16 = 3, - asTYPEID_INT32 = 4, - asTYPEID_INT64 = 5, - asTYPEID_UINT8 = 6, - asTYPEID_UINT16 = 7, - asTYPEID_UINT32 = 8, - asTYPEID_UINT64 = 9, - asTYPEID_FLOAT = 10, - asTYPEID_DOUBLE = 11, - asTYPEID_OBJHANDLE = 0x40000000, - asTYPEID_HANDLETOCONST = 0x20000000, - asTYPEID_MASK_OBJECT = 0x1C000000, - asTYPEID_APPOBJECT = 0x04000000, - asTYPEID_SCRIPTOBJECT = 0x08000000, - asTYPEID_TEMPLATE = 0x10000000, - asTYPEID_MASK_SEQNBR = 0x03FFFFFF +enum asETypeIdFlags { + asTYPEID_VOID = 0, + asTYPEID_BOOL = 1, + asTYPEID_INT8 = 2, + asTYPEID_INT16 = 3, + asTYPEID_INT32 = 4, + asTYPEID_INT64 = 5, + asTYPEID_UINT8 = 6, + asTYPEID_UINT16 = 7, + asTYPEID_UINT32 = 8, + asTYPEID_UINT64 = 9, + asTYPEID_FLOAT = 10, + asTYPEID_DOUBLE = 11, + asTYPEID_OBJHANDLE = 0x40000000, + asTYPEID_HANDLETOCONST = 0x20000000, + asTYPEID_MASK_OBJECT = 0x1C000000, + asTYPEID_APPOBJECT = 0x04000000, + asTYPEID_SCRIPTOBJECT = 0x08000000, + asTYPEID_TEMPLATE = 0x10000000, + asTYPEID_MASK_SEQNBR = 0x03FFFFFF }; // Type modifiers -enum asETypeModifiers -{ - asTM_NONE = 0, - asTM_INREF = 1, - asTM_OUTREF = 2, +enum asETypeModifiers { + asTM_NONE = 0, + asTM_INREF = 1, + asTM_OUTREF = 2, asTM_INOUTREF = 3, - asTM_CONST = 4 + asTM_CONST = 4 }; // GetModule flags -enum asEGMFlags -{ - asGM_ONLY_IF_EXISTS = 0, +enum asEGMFlags { + asGM_ONLY_IF_EXISTS = 0, asGM_CREATE_IF_NOT_EXISTS = 1, - asGM_ALWAYS_CREATE = 2 + asGM_ALWAYS_CREATE = 2 }; // Compile flags -enum asECompileFlags -{ +enum asECompileFlags { asCOMP_ADD_TO_MODULE = 1 }; // Function types -enum asEFuncType -{ - asFUNC_DUMMY =-1, - asFUNC_SYSTEM = 0, - asFUNC_SCRIPT = 1, +enum asEFuncType { + asFUNC_DUMMY = -1, + asFUNC_SYSTEM = 0, + asFUNC_SCRIPT = 1, asFUNC_INTERFACE = 2, - asFUNC_VIRTUAL = 3, - asFUNC_FUNCDEF = 4, - asFUNC_IMPORTED = 5, - asFUNC_DELEGATE = 6, - asFUNC_TEMPLATE = 7 + asFUNC_VIRTUAL = 3, + asFUNC_FUNCDEF = 4, + asFUNC_IMPORTED = 5, + asFUNC_DELEGATE = 6, + asFUNC_TEMPLATE = 7 }; // Is the target a 64bit system? #if defined(__LP64__) || defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) - #ifndef AS_64BIT_PTR - #define AS_64BIT_PTR - #endif +#ifndef AS_64BIT_PTR +#define AS_64BIT_PTR +#endif #endif typedef void (*asFUNCTION_t)(); -typedef void (*asGENFUNC_t)(asIScriptGeneric *); -typedef void *(*asALLOCFUNC_t)(size_t); -typedef void (*asFREEFUNC_t)(void *); -typedef void (*asCLEANENGINEFUNC_t)(asIScriptEngine *); -typedef void (*asCLEANMODULEFUNC_t)(asIScriptModule *); -typedef void (*asCLEANCONTEXTFUNC_t)(asIScriptContext *); -typedef void (*asCLEANFUNCTIONFUNC_t)(asIScriptFunction *); -typedef void (*asCLEANTYPEINFOFUNC_t)(asITypeInfo *); -typedef void (*asCLEANSCRIPTOBJECTFUNC_t)(asIScriptObject *); -typedef asIScriptContext *(*asREQUESTCONTEXTFUNC_t)(asIScriptEngine *, void *); -typedef void (*asRETURNCONTEXTFUNC_t)(asIScriptEngine *, asIScriptContext *, void *); -typedef void (*asCIRCULARREFFUNC_t)(asITypeInfo *, const void *, void *); +typedef void (*asGENFUNC_t)(asIScriptGeneric*); +typedef void* (*asALLOCFUNC_t)(size_t); +typedef void (*asFREEFUNC_t)(void*); +typedef void (*asCLEANENGINEFUNC_t)(asIScriptEngine*); +typedef void (*asCLEANMODULEFUNC_t)(asIScriptModule*); +typedef void (*asCLEANCONTEXTFUNC_t)(asIScriptContext*); +typedef void (*asCLEANFUNCTIONFUNC_t)(asIScriptFunction*); +typedef void (*asCLEANTYPEINFOFUNC_t)(asITypeInfo*); +typedef void (*asCLEANSCRIPTOBJECTFUNC_t)(asIScriptObject*); +typedef asIScriptContext* (*asREQUESTCONTEXTFUNC_t)(asIScriptEngine*, void*); +typedef void (*asRETURNCONTEXTFUNC_t)(asIScriptEngine*, asIScriptContext*, void*); +typedef void (*asCIRCULARREFFUNC_t)(asITypeInfo*, const void*, void*); struct asSVMRegisters; typedef void (*asJITFunction)(asSVMRegisters* registers, asPWORD jitArg); // Check if the compiler can use C++11 features -#if !defined(_MSC_VER) || _MSC_VER >= 1700 // MSVC 2012 - #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) // gnuc 4.7 or clang - #if !(defined(__GNUC__) && defined(__cplusplus) && __cplusplus < 201103L) // gnuc and clang require compiler flag -std=c++11 - #if !defined(__SUNPRO_CC) // Oracle Solaris Studio - #define AS_CAN_USE_CPP11 1 - #endif - #endif - #endif +#if !defined(_MSC_VER) || _MSC_VER >= 1700 // MSVC 2012 +#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) // gnuc 4.7 or clang +#if !(defined(__GNUC__) && defined(__cplusplus) && __cplusplus < 201103L) // gnuc and clang require compiler flag -std=c++11 +#if !defined(__SUNPRO_CC) // Oracle Solaris Studio +#define AS_CAN_USE_CPP11 1 +#endif +#endif +#endif #endif // This macro does basically the same thing as offsetof defined in stddef.h, but // GNUC should not complain about the usage as I'm not using 0 as the base pointer. -#define asOFFSET(s,m) ((int)(size_t)(&reinterpret_cast(100000)->m)-100000) +#define asOFFSET(s, m) ((int)(size_t)(&reinterpret_cast(100000)->m) - 100000) #define asFUNCTION(f) asFunctionPtr(f) #if (defined(_MSC_VER) && _MSC_VER <= 1200) || (defined(__BORLANDC__) && __BORLANDC__ < 0x590) @@ -442,9 +426,9 @@ typedef void (*asJITFunction)(asSVMRegisters* registers, asPWORD jitArg); // so we need to use ordinary C style cast instead of static_cast. The drawback is that the compiler can't // check that the cast is really valid. // BCC v5.8 (C++Builder 2006) and earlier have a similar bug which forces us to fall back to a C-style cast. -#define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())((r (*)p)(f))) +#define asFUNCTIONPR(f, p, r) asFunctionPtr((void (*)())((r(*) p)(f))) #else -#define asFUNCTIONPR(f,p,r) asFunctionPtr(reinterpret_cast(static_cast(f))) +#define asFUNCTIONPR(f, p, r) asFunctionPtr(reinterpret_cast(static_cast(f))) #endif #ifndef AS_NO_CLASS_METHODS @@ -452,29 +436,31 @@ typedef void (*asJITFunction)(asSVMRegisters* registers, asPWORD jitArg); class asCUnknownClass; typedef void (asCUnknownClass::*asMETHOD_t)(); -struct asSFuncPtr -{ - asSFuncPtr(asBYTE f = 0) - { - for( size_t n = 0; n < sizeof(ptr.dummy); n++ ) +struct asSFuncPtr { + asSFuncPtr(asBYTE f = 0) { + for (size_t n = 0; n < sizeof(ptr.dummy); n++) ptr.dummy[n] = 0; flag = f; } - void CopyMethodPtr(const void *mthdPtr, size_t size) - { - for( size_t n = 0; n < size; n++ ) - ptr.dummy[n] = reinterpret_cast(mthdPtr)[n]; + void CopyMethodPtr(const void* mthdPtr, size_t size) { + for (size_t n = 0; n < size; n++) + ptr.dummy[n] = reinterpret_cast(mthdPtr)[n]; } - union - { + union { // The largest known method point is 20 bytes (MSVC 64bit), // but with 8byte alignment this becomes 24 bytes. So we need // to be able to store at least that much. char dummy[25]; - struct {asMETHOD_t mthd; char dummy[25-sizeof(asMETHOD_t)];} m; - struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f; + struct { + asMETHOD_t mthd; + char dummy[25 - sizeof(asMETHOD_t)]; + } m; + struct { + asFUNCTION_t func; + char dummy[25 - sizeof(asFUNCTION_t)]; + } f; } ptr; asBYTE flag; // 1 = generic, 2 = global func, 3 = method }; @@ -483,55 +469,52 @@ struct asSFuncPtr // A bug in BCC (QC #85374) makes it impossible to distinguish const/non-const method overloads // with static_cast<>. The workaround is to use an _implicit_cast instead. - #if __BORLANDC__ < 0x590 - // BCC v5.8 (C++Builder 2006) and earlier have an even more annoying bug which causes - // the "pretty" workaround below (with _implicit_cast<>) to fail. For these compilers - // we need to use a traditional C-style cast. - #define AS_METHOD_AMBIGUITY_CAST(t) (t) - #else -template - T _implicit_cast (T val) -{ return val; } - #define AS_METHOD_AMBIGUITY_CAST(t) AS_NAMESPACE_QUALIFIER _implicit_cast - #endif +#if __BORLANDC__ < 0x590 +// BCC v5.8 (C++Builder 2006) and earlier have an even more annoying bug which causes +// the "pretty" workaround below (with _implicit_cast<>) to fail. For these compilers +// we need to use a traditional C-style cast. +#define AS_METHOD_AMBIGUITY_CAST(t) (t) #else - #define AS_METHOD_AMBIGUITY_CAST(t) static_cast +template +T _implicit_cast(T val) { return val; } +#define AS_METHOD_AMBIGUITY_CAST(t) AS_NAMESPACE_QUALIFIER _implicit_cast +#endif +#else +#define AS_METHOD_AMBIGUITY_CAST(t) static_cast #endif -#define asMETHOD(c,m) asSMethodPtr::Convert((void (c::*)())(&c::m)) -#define asMETHODPR(c,m,p,r) asSMethodPtr::Convert(AS_METHOD_AMBIGUITY_CAST(r (c::*)p)(&c::m)) +#define asMETHOD(c, m) asSMethodPtr::Convert((void (c::*)())(&c::m)) +#define asMETHODPR(c, m, p, r) asSMethodPtr::Convert(AS_METHOD_AMBIGUITY_CAST(r(c::*) p)(&c::m)) #else // Class methods are disabled -struct asSFuncPtr -{ - asSFuncPtr(asBYTE f) - { - for( size_t n = 0; n < sizeof(ptr.dummy); n++ ) +struct asSFuncPtr { + asSFuncPtr(asBYTE f) { + for (size_t n = 0; n < sizeof(ptr.dummy); n++) ptr.dummy[n] = 0; flag = f; } - union - { + union { char dummy[25]; // largest known class method pointer - struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f; + struct { + asFUNCTION_t func; + char dummy[25 - sizeof(asFUNCTION_t)]; + } f; } ptr; asBYTE flag; // 1 = generic, 2 = global func }; #endif -struct asSMessageInfo -{ - const char *section; - int row; - int col; - asEMsgType type; - const char *message; +struct asSMessageInfo { + const char* section; + int row; + int col; + asEMsgType type; + const char* message; }; - // API functions // ANGELSCRIPT_EXPORT is defined when compiling the dll or lib @@ -541,54 +524,53 @@ struct asSMessageInfo // Don't define anything when linking statically to the lib #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) - #if defined(ANGELSCRIPT_EXPORT) - #define AS_API __declspec(dllexport) - #elif defined(ANGELSCRIPT_DLL_LIBRARY_IMPORT) - #define AS_API __declspec(dllimport) - #else // statically linked library - #define AS_API - #endif +#if defined(ANGELSCRIPT_EXPORT) +#define AS_API __declspec(dllexport) +#elif defined(ANGELSCRIPT_DLL_LIBRARY_IMPORT) +#define AS_API __declspec(dllimport) +#else // statically linked library +#define AS_API +#endif #elif defined(__GNUC__) - #if defined(ANGELSCRIPT_EXPORT) - #define AS_API __attribute__((visibility ("default"))) - #else - #define AS_API - #endif +#if defined(ANGELSCRIPT_EXPORT) +#define AS_API __attribute__((visibility("default"))) #else - #define AS_API +#define AS_API +#endif +#else +#define AS_API #endif #ifndef ANGELSCRIPT_DLL_MANUAL_IMPORT -extern "C" -{ - // Engine - AS_API asIScriptEngine *asCreateScriptEngine(asDWORD version = ANGELSCRIPT_VERSION); - AS_API const char *asGetLibraryVersion(); - AS_API const char *asGetLibraryOptions(); +extern "C" { +// Engine +AS_API asIScriptEngine* asCreateScriptEngine(asDWORD version = ANGELSCRIPT_VERSION); +AS_API const char* asGetLibraryVersion(); +AS_API const char* asGetLibraryOptions(); - // Context - AS_API asIScriptContext *asGetActiveContext(); +// Context +AS_API asIScriptContext* asGetActiveContext(); - // Thread support - AS_API int asPrepareMultithread(asIThreadManager *externalMgr = 0); - AS_API void asUnprepareMultithread(); - AS_API asIThreadManager *asGetThreadManager(); - AS_API void asAcquireExclusiveLock(); - AS_API void asReleaseExclusiveLock(); - AS_API void asAcquireSharedLock(); - AS_API void asReleaseSharedLock(); - AS_API int asAtomicInc(int &value); - AS_API int asAtomicDec(int &value); - AS_API int asThreadCleanup(); +// Thread support +AS_API int asPrepareMultithread(asIThreadManager* externalMgr = 0); +AS_API void asUnprepareMultithread(); +AS_API asIThreadManager* asGetThreadManager(); +AS_API void asAcquireExclusiveLock(); +AS_API void asReleaseExclusiveLock(); +AS_API void asAcquireSharedLock(); +AS_API void asReleaseSharedLock(); +AS_API int asAtomicInc(int& value); +AS_API int asAtomicDec(int& value); +AS_API int asThreadCleanup(); - // Memory management - AS_API int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc); - AS_API int asResetGlobalMemoryFunctions(); - AS_API void *asAllocMem(size_t size); - AS_API void asFreeMem(void *mem); +// Memory management +AS_API int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc); +AS_API int asResetGlobalMemoryFunctions(); +AS_API void* asAllocMem(size_t size); +AS_API void asFreeMem(void* mem); - // Auxiliary - AS_API asILockableSharedBool *asCreateLockableSharedBool(); +// Auxiliary +AS_API asILockableSharedBool* asCreateLockableSharedBool(); } #endif // ANGELSCRIPT_DLL_MANUAL_IMPORT @@ -600,58 +582,56 @@ END_AS_NAMESPACE #include BEGIN_AS_NAMESPACE -template -asUINT asGetTypeTraits() -{ +template +asUINT asGetTypeTraits() { #if defined(_MSC_VER) || defined(_LIBCPP_TYPE_TRAITS) || (__GNUC__ >= 5) || (defined(__clang__) && !defined(CLANG_PRE_STANDARD)) // MSVC, XCode/Clang, and gnuc 5+ // C++11 compliant code - bool hasConstructor = std::is_default_constructible::value && !std::is_trivially_default_constructible::value; - bool hasDestructor = std::is_destructible::value && !std::is_trivially_destructible::value; - bool hasAssignmentOperator = std::is_copy_assignable::value && !std::is_trivially_copy_assignable::value; - bool hasCopyConstructor = std::is_copy_constructible::value && !std::is_trivially_copy_constructible::value; + bool hasConstructor = std::is_default_constructible::value && !std::is_trivially_default_constructible::value; + bool hasDestructor = std::is_destructible::value && !std::is_trivially_destructible::value; + bool hasAssignmentOperator = std::is_copy_assignable::value && !std::is_trivially_copy_assignable::value; + bool hasCopyConstructor = std::is_copy_constructible::value && !std::is_trivially_copy_constructible::value; #elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || (defined(__clang__) && defined(CLANG_PRE_STANDARD)) // gnuc 4.8 is using a mix of C++11 standard and pre-standard templates - bool hasConstructor = std::is_default_constructible::value && !std::has_trivial_default_constructor::value; - bool hasDestructor = std::is_destructible::value && !std::is_trivially_destructible::value; - bool hasAssignmentOperator = std::is_copy_assignable::value && !std::has_trivial_copy_assign::value; - bool hasCopyConstructor = std::is_copy_constructible::value && !std::has_trivial_copy_constructor::value; + bool hasConstructor = std::is_default_constructible::value && !std::has_trivial_default_constructor::value; + bool hasDestructor = std::is_destructible::value && !std::is_trivially_destructible::value; + bool hasAssignmentOperator = std::is_copy_assignable::value && !std::has_trivial_copy_assign::value; + bool hasCopyConstructor = std::is_copy_constructible::value && !std::has_trivial_copy_constructor::value; #else // All other compilers and versions are assumed to use non C++11 compliant code until proven otherwise // Not fully C++11 compliant. The has_trivial checks were used while the standard was still // being elaborated, but were then removed in favor of the above is_trivially checks // http://stackoverflow.com/questions/12702103/writing-code-that-works-when-has-trivial-destructor-is-defined-instead-of-is // https://github.com/mozart/mozart2/issues/51 - bool hasConstructor = std::is_default_constructible::value && !std::has_trivial_default_constructor::value; - bool hasDestructor = std::is_destructible::value && !std::has_trivial_destructor::value; - bool hasAssignmentOperator = std::is_copy_assignable::value && !std::has_trivial_copy_assign::value; - bool hasCopyConstructor = std::is_copy_constructible::value && !std::has_trivial_copy_constructor::value; + bool hasConstructor = std::is_default_constructible::value && !std::has_trivial_default_constructor::value; + bool hasDestructor = std::is_destructible::value && !std::has_trivial_destructor::value; + bool hasAssignmentOperator = std::is_copy_assignable::value && !std::has_trivial_copy_assign::value; + bool hasCopyConstructor = std::is_copy_constructible::value && !std::has_trivial_copy_constructor::value; #endif - bool isFloat = std::is_floating_point::value; + bool isFloat = std::is_floating_point::value; bool isPrimitive = std::is_integral::value || std::is_pointer::value || std::is_enum::value; - bool isClass = std::is_class::value; - bool isArray = std::is_array::value; + bool isClass = std::is_class::value; + bool isArray = std::is_array::value; - if( isFloat ) + if (isFloat) return asOBJ_APP_FLOAT; - if( isPrimitive ) + if (isPrimitive) return asOBJ_APP_PRIMITIVE; - if( isClass ) - { + if (isClass) { asDWORD flags = asOBJ_APP_CLASS; - if( hasConstructor ) + if (hasConstructor) flags |= asOBJ_APP_CLASS_CONSTRUCTOR; - if( hasDestructor ) + if (hasDestructor) flags |= asOBJ_APP_CLASS_DESTRUCTOR; - if( hasAssignmentOperator ) + if (hasAssignmentOperator) flags |= asOBJ_APP_CLASS_ASSIGNMENT; - if( hasCopyConstructor ) + if (hasCopyConstructor) flags |= asOBJ_APP_CLASS_COPY_CONSTRUCTOR; return flags; } - if( isArray ) + if (isArray) return asOBJ_APP_ARRAY; // Unknown type traits @@ -662,565 +642,554 @@ asUINT asGetTypeTraits() // Interface declarations -class asIScriptEngine -{ -public: +class asIScriptEngine { + public: // Memory management virtual int AddRef() const = 0; virtual int Release() const = 0; virtual int ShutDownAndRelease() = 0; // Engine properties - virtual int SetEngineProperty(asEEngineProp property, asPWORD value) = 0; + virtual int SetEngineProperty(asEEngineProp property, asPWORD value) = 0; virtual asPWORD GetEngineProperty(asEEngineProp property) const = 0; // Compiler messages - virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv) = 0; + virtual int SetMessageCallback(const asSFuncPtr& callback, void* obj, asDWORD callConv) = 0; virtual int ClearMessageCallback() = 0; - virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message) = 0; + virtual int WriteMessage(const char* section, int row, int col, asEMsgType type, const char* message) = 0; // JIT Compiler - virtual int SetJITCompiler(asIJITCompilerAbstract *compiler) = 0; - virtual asIJITCompilerAbstract *GetJITCompiler() const = 0; + virtual int SetJITCompiler(asIJITCompilerAbstract* compiler) = 0; + virtual asIJITCompilerAbstract* GetJITCompiler() const = 0; // Global functions - virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0) = 0; - virtual asUINT GetGlobalFunctionCount() const = 0; - virtual asIScriptFunction *GetGlobalFunctionByIndex(asUINT index) const = 0; - virtual asIScriptFunction *GetGlobalFunctionByDecl(const char *declaration) const = 0; + virtual int RegisterGlobalFunction(const char* declaration, const asSFuncPtr& funcPointer, asDWORD callConv, void* auxiliary = 0) = 0; + virtual asUINT GetGlobalFunctionCount() const = 0; + virtual asIScriptFunction* GetGlobalFunctionByIndex(asUINT index) const = 0; + virtual asIScriptFunction* GetGlobalFunctionByDecl(const char* declaration) const = 0; // Global properties - virtual int RegisterGlobalProperty(const char *declaration, void *pointer) = 0; + virtual int RegisterGlobalProperty(const char* declaration, void* pointer) = 0; virtual asUINT GetGlobalPropertyCount() const = 0; - virtual int GetGlobalPropertyByIndex(asUINT index, const char **name, const char **nameSpace = 0, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0, asDWORD *accessMask = 0) const = 0; - virtual int GetGlobalPropertyIndexByName(const char *name) const = 0; - virtual int GetGlobalPropertyIndexByDecl(const char *decl) const = 0; + virtual int GetGlobalPropertyByIndex(asUINT index, const char** name, const char** nameSpace = 0, int* typeId = 0, bool* isConst = 0, const char** configGroup = 0, void** pointer = 0, asDWORD* accessMask = 0) const = 0; + virtual int GetGlobalPropertyIndexByName(const char* name) const = 0; + virtual int GetGlobalPropertyIndexByDecl(const char* decl) const = 0; // Object types - virtual int RegisterObjectType(const char *obj, int byteSize, asQWORD flags) = 0; - virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset, int compositeOffset = 0, bool isCompositeIndirect = false) = 0; - virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false) = 0; - virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false) = 0; - virtual int RegisterInterface(const char *name) = 0; - virtual int RegisterInterfaceMethod(const char *intf, const char *declaration) = 0; - virtual asUINT GetObjectTypeCount() const = 0; - virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const = 0; + virtual int RegisterObjectType(const char* obj, int byteSize, asQWORD flags) = 0; + virtual int RegisterObjectProperty(const char* obj, const char* declaration, int byteOffset, int compositeOffset = 0, bool isCompositeIndirect = false) = 0; + virtual int RegisterObjectMethod(const char* obj, const char* declaration, const asSFuncPtr& funcPointer, asDWORD callConv, void* auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false) = 0; + virtual int RegisterObjectBehaviour(const char* obj, asEBehaviours behaviour, const char* declaration, const asSFuncPtr& funcPointer, asDWORD callConv, void* auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false) = 0; + virtual int RegisterInterface(const char* name) = 0; + virtual int RegisterInterfaceMethod(const char* intf, const char* declaration) = 0; + virtual asUINT GetObjectTypeCount() const = 0; + virtual asITypeInfo* GetObjectTypeByIndex(asUINT index) const = 0; // String factory - virtual int RegisterStringFactory(const char *datatype, asIStringFactory *factory) = 0; + virtual int RegisterStringFactory(const char* datatype, asIStringFactory* factory) = 0; virtual int GetStringFactory(asDWORD* typeModifiers = 0, asIStringFactory** factory = 0) const = 0; #ifdef AS_DEPRECATED // deprecated since 2024-07-27, 2.38.0 - virtual int GetStringFactoryReturnTypeId(asDWORD *flags = 0) const = 0; + virtual int GetStringFactoryReturnTypeId(asDWORD* flags = 0) const = 0; #endif // Default array type - virtual int RegisterDefaultArrayType(const char *type) = 0; + virtual int RegisterDefaultArrayType(const char* type) = 0; virtual int GetDefaultArrayTypeId() const = 0; // Enums - virtual int RegisterEnum(const char *type) = 0; - virtual int RegisterEnumValue(const char *type, const char *name, int value) = 0; - virtual asUINT GetEnumCount() const = 0; - virtual asITypeInfo *GetEnumByIndex(asUINT index) const = 0; + virtual int RegisterEnum(const char* type) = 0; + virtual int RegisterEnumValue(const char* type, const char* name, int value) = 0; + virtual asUINT GetEnumCount() const = 0; + virtual asITypeInfo* GetEnumByIndex(asUINT index) const = 0; // Funcdefs - virtual int RegisterFuncdef(const char *decl) = 0; - virtual asUINT GetFuncdefCount() const = 0; - virtual asITypeInfo *GetFuncdefByIndex(asUINT index) const = 0; + virtual int RegisterFuncdef(const char* decl) = 0; + virtual asUINT GetFuncdefCount() const = 0; + virtual asITypeInfo* GetFuncdefByIndex(asUINT index) const = 0; // Typedefs - virtual int RegisterTypedef(const char *type, const char *decl) = 0; - virtual asUINT GetTypedefCount() const = 0; - virtual asITypeInfo *GetTypedefByIndex(asUINT index) const = 0; + virtual int RegisterTypedef(const char* type, const char* decl) = 0; + virtual asUINT GetTypedefCount() const = 0; + virtual asITypeInfo* GetTypedefByIndex(asUINT index) const = 0; // Configuration groups - virtual int BeginConfigGroup(const char *groupName) = 0; - virtual int EndConfigGroup() = 0; - virtual int RemoveConfigGroup(const char *groupName) = 0; - virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask) = 0; - virtual int SetDefaultNamespace(const char *nameSpace) = 0; - virtual const char *GetDefaultNamespace() const = 0; + virtual int BeginConfigGroup(const char* groupName) = 0; + virtual int EndConfigGroup() = 0; + virtual int RemoveConfigGroup(const char* groupName) = 0; + virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask) = 0; + virtual int SetDefaultNamespace(const char* nameSpace) = 0; + virtual const char* GetDefaultNamespace() const = 0; // Script modules - virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0; - virtual int DiscardModule(const char *module) = 0; - virtual asUINT GetModuleCount() const = 0; - virtual asIScriptModule *GetModuleByIndex(asUINT index) const = 0; + virtual asIScriptModule* GetModule(const char* module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0; + virtual int DiscardModule(const char* module) = 0; + virtual asUINT GetModuleCount() const = 0; + virtual asIScriptModule* GetModuleByIndex(asUINT index) const = 0; // Script functions - virtual int GetLastFunctionId() const = 0; - virtual asIScriptFunction *GetFunctionById(int funcId) const = 0; + virtual int GetLastFunctionId() const = 0; + virtual asIScriptFunction* GetFunctionById(int funcId) const = 0; // Type identification - virtual int GetTypeIdByDecl(const char *decl) const = 0; - virtual const char *GetTypeDeclaration(int typeId, bool includeNamespace = false) const = 0; - virtual int GetSizeOfPrimitiveType(int typeId) const = 0; - virtual asITypeInfo *GetTypeInfoById(int typeId) const = 0; - virtual asITypeInfo *GetTypeInfoByName(const char *name) const = 0; - virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const = 0; + virtual int GetTypeIdByDecl(const char* decl) const = 0; + virtual const char* GetTypeDeclaration(int typeId, bool includeNamespace = false) const = 0; + virtual int GetSizeOfPrimitiveType(int typeId) const = 0; + virtual asITypeInfo* GetTypeInfoById(int typeId) const = 0; + virtual asITypeInfo* GetTypeInfoByName(const char* name) const = 0; + virtual asITypeInfo* GetTypeInfoByDecl(const char* decl) const = 0; // Script execution - virtual asIScriptContext *CreateContext() = 0; - virtual void *CreateScriptObject(const asITypeInfo *type) = 0; - virtual void *CreateScriptObjectCopy(void *obj, const asITypeInfo *type) = 0; - virtual void *CreateUninitializedScriptObject(const asITypeInfo *type) = 0; - virtual asIScriptFunction *CreateDelegate(asIScriptFunction *func, void *obj) = 0; - virtual int AssignScriptObject(void *dstObj, void *srcObj, const asITypeInfo *type) = 0; - virtual void ReleaseScriptObject(void *obj, const asITypeInfo *type) = 0; - virtual void AddRefScriptObject(void *obj, const asITypeInfo *type) = 0; - virtual int RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo *toType, void **newPtr, bool useOnlyImplicitCast = false) = 0; - virtual asILockableSharedBool *GetWeakRefFlagOfScriptObject(void *obj, const asITypeInfo *type) const = 0; + virtual asIScriptContext* CreateContext() = 0; + virtual void* CreateScriptObject(const asITypeInfo* type) = 0; + virtual void* CreateScriptObjectCopy(void* obj, const asITypeInfo* type) = 0; + virtual void* CreateUninitializedScriptObject(const asITypeInfo* type) = 0; + virtual asIScriptFunction* CreateDelegate(asIScriptFunction* func, void* obj) = 0; + virtual int AssignScriptObject(void* dstObj, void* srcObj, const asITypeInfo* type) = 0; + virtual void ReleaseScriptObject(void* obj, const asITypeInfo* type) = 0; + virtual void AddRefScriptObject(void* obj, const asITypeInfo* type) = 0; + virtual int RefCastObject(void* obj, asITypeInfo* fromType, asITypeInfo* toType, void** newPtr, bool useOnlyImplicitCast = false) = 0; + virtual asILockableSharedBool* GetWeakRefFlagOfScriptObject(void* obj, const asITypeInfo* type) const = 0; // Context pooling - virtual asIScriptContext *RequestContext() = 0; - virtual void ReturnContext(asIScriptContext *ctx) = 0; - virtual int SetContextCallbacks(asREQUESTCONTEXTFUNC_t requestCtx, asRETURNCONTEXTFUNC_t returnCtx, void *param = 0) = 0; + virtual asIScriptContext* RequestContext() = 0; + virtual void ReturnContext(asIScriptContext* ctx) = 0; + virtual int SetContextCallbacks(asREQUESTCONTEXTFUNC_t requestCtx, asRETURNCONTEXTFUNC_t returnCtx, void* param = 0) = 0; // String interpretation - virtual asETokenClass ParseToken(const char *string, size_t stringLength = 0, asUINT *tokenLength = 0) const = 0; + virtual asETokenClass ParseToken(const char* string, size_t stringLength = 0, asUINT* tokenLength = 0) const = 0; // Garbage collection - virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE, asUINT numIterations = 1) = 0; - virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed = 0, asUINT *totalDetected = 0, asUINT *newObjects = 0, asUINT *totalNewDestroyed = 0) const = 0; - virtual int NotifyGarbageCollectorOfNewObject(void *obj, asITypeInfo *type) = 0; - virtual int GetObjectInGC(asUINT idx, asUINT *seqNbr = 0, void **obj = 0, asITypeInfo **type = 0) = 0; - virtual void GCEnumCallback(void *reference) = 0; - virtual void ForwardGCEnumReferences(void *ref, asITypeInfo *type) = 0; - virtual void ForwardGCReleaseReferences(void *ref, asITypeInfo *type) = 0; - virtual void SetCircularRefDetectedCallback(asCIRCULARREFFUNC_t callback, void *param = 0) = 0; + virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE, asUINT numIterations = 1) = 0; + virtual void GetGCStatistics(asUINT* currentSize, asUINT* totalDestroyed = 0, asUINT* totalDetected = 0, asUINT* newObjects = 0, asUINT* totalNewDestroyed = 0) const = 0; + virtual int NotifyGarbageCollectorOfNewObject(void* obj, asITypeInfo* type) = 0; + virtual int GetObjectInGC(asUINT idx, asUINT* seqNbr = 0, void** obj = 0, asITypeInfo** type = 0) = 0; + virtual void GCEnumCallback(void* reference) = 0; + virtual void ForwardGCEnumReferences(void* ref, asITypeInfo* type) = 0; + virtual void ForwardGCReleaseReferences(void* ref, asITypeInfo* type) = 0; + virtual void SetCircularRefDetectedCallback(asCIRCULARREFFUNC_t callback, void* param = 0) = 0; // User data - virtual void *SetUserData(void *data, asPWORD type = 0) = 0; - virtual void *GetUserData(asPWORD type = 0) const = 0; - virtual void SetEngineUserDataCleanupCallback(asCLEANENGINEFUNC_t callback, asPWORD type = 0) = 0; - virtual void SetModuleUserDataCleanupCallback(asCLEANMODULEFUNC_t callback, asPWORD type = 0) = 0; - virtual void SetContextUserDataCleanupCallback(asCLEANCONTEXTFUNC_t callback, asPWORD type = 0) = 0; - virtual void SetFunctionUserDataCleanupCallback(asCLEANFUNCTIONFUNC_t callback, asPWORD type = 0) = 0; - virtual void SetTypeInfoUserDataCleanupCallback(asCLEANTYPEINFOFUNC_t callback, asPWORD type = 0) = 0; - virtual void SetScriptObjectUserDataCleanupCallback(asCLEANSCRIPTOBJECTFUNC_t callback, asPWORD type = 0) = 0; + virtual void* SetUserData(void* data, asPWORD type = 0) = 0; + virtual void* GetUserData(asPWORD type = 0) const = 0; + virtual void SetEngineUserDataCleanupCallback(asCLEANENGINEFUNC_t callback, asPWORD type = 0) = 0; + virtual void SetModuleUserDataCleanupCallback(asCLEANMODULEFUNC_t callback, asPWORD type = 0) = 0; + virtual void SetContextUserDataCleanupCallback(asCLEANCONTEXTFUNC_t callback, asPWORD type = 0) = 0; + virtual void SetFunctionUserDataCleanupCallback(asCLEANFUNCTIONFUNC_t callback, asPWORD type = 0) = 0; + virtual void SetTypeInfoUserDataCleanupCallback(asCLEANTYPEINFOFUNC_t callback, asPWORD type = 0) = 0; + virtual void SetScriptObjectUserDataCleanupCallback(asCLEANSCRIPTOBJECTFUNC_t callback, asPWORD type = 0) = 0; // Exception handling - virtual int SetTranslateAppExceptionCallback(asSFuncPtr callback, void *param, int callConv) = 0; + virtual int SetTranslateAppExceptionCallback(asSFuncPtr callback, void* param, int callConv) = 0; -protected: + protected: virtual ~asIScriptEngine() {} }; -class asIStringFactory -{ -public: - virtual const void *GetStringConstant(const char *data, asUINT length) = 0; - virtual int ReleaseStringConstant(const void *str) = 0; - virtual int GetRawStringData(const void *str, char *data, asUINT *length) const = 0; +class asIStringFactory { + public: + virtual const void* GetStringConstant(const char* data, asUINT length) = 0; + virtual int ReleaseStringConstant(const void* str) = 0; + virtual int GetRawStringData(const void* str, char* data, asUINT* length) const = 0; -protected: + protected: virtual ~asIStringFactory() {} }; -class asIThreadManager -{ -protected: +class asIThreadManager { + protected: virtual ~asIThreadManager() {} }; -class asIScriptModule -{ -public: - virtual asIScriptEngine *GetEngine() const = 0; - virtual void SetName(const char *name) = 0; - virtual const char *GetName() const = 0; - virtual void Discard() = 0; +class asIScriptModule { + public: + virtual asIScriptEngine* GetEngine() const = 0; + virtual void SetName(const char* name) = 0; + virtual const char* GetName() const = 0; + virtual void Discard() = 0; // Compilation - virtual int AddScriptSection(const char *name, const char *code, size_t codeLength = 0, int lineOffset = 0) = 0; - virtual int Build() = 0; - virtual int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asIScriptFunction **outFunc) = 0; - virtual int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset) = 0; - virtual asDWORD SetAccessMask(asDWORD accessMask) = 0; - virtual int SetDefaultNamespace(const char *nameSpace) = 0; - virtual const char *GetDefaultNamespace() const = 0; + virtual int AddScriptSection(const char* name, const char* code, size_t codeLength = 0, int lineOffset = 0) = 0; + virtual int Build() = 0; + virtual int CompileFunction(const char* sectionName, const char* code, int lineOffset, asDWORD compileFlags, asIScriptFunction** outFunc) = 0; + virtual int CompileGlobalVar(const char* sectionName, const char* code, int lineOffset) = 0; + virtual asDWORD SetAccessMask(asDWORD accessMask) = 0; + virtual int SetDefaultNamespace(const char* nameSpace) = 0; + virtual const char* GetDefaultNamespace() const = 0; // Functions - virtual asUINT GetFunctionCount() const = 0; - virtual asIScriptFunction *GetFunctionByIndex(asUINT index) const = 0; - virtual asIScriptFunction *GetFunctionByDecl(const char *decl) const = 0; - virtual asIScriptFunction *GetFunctionByName(const char *name) const = 0; - virtual int RemoveFunction(asIScriptFunction *func) = 0; + virtual asUINT GetFunctionCount() const = 0; + virtual asIScriptFunction* GetFunctionByIndex(asUINT index) const = 0; + virtual asIScriptFunction* GetFunctionByDecl(const char* decl) const = 0; + virtual asIScriptFunction* GetFunctionByName(const char* name) const = 0; + virtual int RemoveFunction(asIScriptFunction* func) = 0; // Global variables - virtual int ResetGlobalVars(asIScriptContext *ctx = 0) = 0; - virtual asUINT GetGlobalVarCount() const = 0; - virtual int GetGlobalVarIndexByName(const char *name) const = 0; - virtual int GetGlobalVarIndexByDecl(const char *decl) const = 0; - virtual const char *GetGlobalVarDeclaration(asUINT index, bool includeNamespace = false) const = 0; - virtual int GetGlobalVar(asUINT index, const char **name, const char **nameSpace = 0, int *typeId = 0, bool *isConst = 0) const = 0; - virtual void *GetAddressOfGlobalVar(asUINT index) = 0; - virtual int RemoveGlobalVar(asUINT index) = 0; + virtual int ResetGlobalVars(asIScriptContext* ctx = 0) = 0; + virtual asUINT GetGlobalVarCount() const = 0; + virtual int GetGlobalVarIndexByName(const char* name) const = 0; + virtual int GetGlobalVarIndexByDecl(const char* decl) const = 0; + virtual const char* GetGlobalVarDeclaration(asUINT index, bool includeNamespace = false) const = 0; + virtual int GetGlobalVar(asUINT index, const char** name, const char** nameSpace = 0, int* typeId = 0, bool* isConst = 0) const = 0; + virtual void* GetAddressOfGlobalVar(asUINT index) = 0; + virtual int RemoveGlobalVar(asUINT index) = 0; // Type identification - virtual asUINT GetObjectTypeCount() const = 0; - virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const = 0; - virtual int GetTypeIdByDecl(const char *decl) const = 0; - virtual asITypeInfo *GetTypeInfoByName(const char *name) const = 0; - virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const = 0; + virtual asUINT GetObjectTypeCount() const = 0; + virtual asITypeInfo* GetObjectTypeByIndex(asUINT index) const = 0; + virtual int GetTypeIdByDecl(const char* decl) const = 0; + virtual asITypeInfo* GetTypeInfoByName(const char* name) const = 0; + virtual asITypeInfo* GetTypeInfoByDecl(const char* decl) const = 0; // Enums - virtual asUINT GetEnumCount() const = 0; - virtual asITypeInfo *GetEnumByIndex(asUINT index) const = 0; + virtual asUINT GetEnumCount() const = 0; + virtual asITypeInfo* GetEnumByIndex(asUINT index) const = 0; // Typedefs - virtual asUINT GetTypedefCount() const = 0; - virtual asITypeInfo *GetTypedefByIndex(asUINT index) const = 0; + virtual asUINT GetTypedefCount() const = 0; + virtual asITypeInfo* GetTypedefByIndex(asUINT index) const = 0; // Dynamic binding between modules - virtual asUINT GetImportedFunctionCount() const = 0; - virtual int GetImportedFunctionIndexByDecl(const char *decl) const = 0; - virtual const char *GetImportedFunctionDeclaration(asUINT importIndex) const = 0; - virtual const char *GetImportedFunctionSourceModule(asUINT importIndex) const = 0; - virtual int BindImportedFunction(asUINT importIndex, asIScriptFunction *func) = 0; - virtual int UnbindImportedFunction(asUINT importIndex) = 0; - virtual int BindAllImportedFunctions() = 0; - virtual int UnbindAllImportedFunctions() = 0; + virtual asUINT GetImportedFunctionCount() const = 0; + virtual int GetImportedFunctionIndexByDecl(const char* decl) const = 0; + virtual const char* GetImportedFunctionDeclaration(asUINT importIndex) const = 0; + virtual const char* GetImportedFunctionSourceModule(asUINT importIndex) const = 0; + virtual int BindImportedFunction(asUINT importIndex, asIScriptFunction* func) = 0; + virtual int UnbindImportedFunction(asUINT importIndex) = 0; + virtual int BindAllImportedFunctions() = 0; + virtual int UnbindAllImportedFunctions() = 0; // Byte code saving and loading - virtual int SaveByteCode(asIBinaryStream *out, bool stripDebugInfo = false) const = 0; - virtual int LoadByteCode(asIBinaryStream *in, bool *wasDebugInfoStripped = 0) = 0; + virtual int SaveByteCode(asIBinaryStream* out, bool stripDebugInfo = false) const = 0; + virtual int LoadByteCode(asIBinaryStream* in, bool* wasDebugInfoStripped = 0) = 0; // User data - virtual void *SetUserData(void *data, asPWORD type = 0) = 0; - virtual void *GetUserData(asPWORD type = 0) const = 0; + virtual void* SetUserData(void* data, asPWORD type = 0) = 0; + virtual void* GetUserData(asPWORD type = 0) const = 0; -protected: + protected: virtual ~asIScriptModule() {} }; -class asIScriptContext -{ -public: +class asIScriptContext { + public: // Memory management virtual int AddRef() const = 0; virtual int Release() const = 0; // Miscellaneous - virtual asIScriptEngine *GetEngine() const = 0; + virtual asIScriptEngine* GetEngine() const = 0; // Execution - virtual int Prepare(asIScriptFunction *func) = 0; - virtual int Unprepare() = 0; - virtual int Execute() = 0; - virtual int Abort() = 0; - virtual int Suspend() = 0; + virtual int Prepare(asIScriptFunction* func) = 0; + virtual int Unprepare() = 0; + virtual int Execute() = 0; + virtual int Abort() = 0; + virtual int Suspend() = 0; virtual asEContextState GetState() const = 0; - virtual int PushState() = 0; - virtual int PopState() = 0; - virtual bool IsNested(asUINT *nestCount = 0) const = 0; + virtual int PushState() = 0; + virtual int PopState() = 0; + virtual bool IsNested(asUINT* nestCount = 0) const = 0; // Object pointer for calling class methods - virtual int SetObject(void *obj) = 0; + virtual int SetObject(void* obj) = 0; // Arguments - virtual int SetArgByte(asUINT arg, asBYTE value) = 0; - virtual int SetArgWord(asUINT arg, asWORD value) = 0; - virtual int SetArgDWord(asUINT arg, asDWORD value) = 0; - virtual int SetArgQWord(asUINT arg, asQWORD value) = 0; - virtual int SetArgFloat(asUINT arg, float value) = 0; - virtual int SetArgDouble(asUINT arg, double value) = 0; - virtual int SetArgAddress(asUINT arg, void *addr) = 0; - virtual int SetArgObject(asUINT arg, void *obj) = 0; - virtual int SetArgVarType(asUINT arg, void *ptr, int typeId) = 0; - virtual void *GetAddressOfArg(asUINT arg) = 0; + virtual int SetArgByte(asUINT arg, asBYTE value) = 0; + virtual int SetArgWord(asUINT arg, asWORD value) = 0; + virtual int SetArgDWord(asUINT arg, asDWORD value) = 0; + virtual int SetArgQWord(asUINT arg, asQWORD value) = 0; + virtual int SetArgFloat(asUINT arg, float value) = 0; + virtual int SetArgDouble(asUINT arg, double value) = 0; + virtual int SetArgAddress(asUINT arg, void* addr) = 0; + virtual int SetArgObject(asUINT arg, void* obj) = 0; + virtual int SetArgVarType(asUINT arg, void* ptr, int typeId) = 0; + virtual void* GetAddressOfArg(asUINT arg) = 0; // Return value - virtual asBYTE GetReturnByte() = 0; - virtual asWORD GetReturnWord() = 0; + virtual asBYTE GetReturnByte() = 0; + virtual asWORD GetReturnWord() = 0; virtual asDWORD GetReturnDWord() = 0; virtual asQWORD GetReturnQWord() = 0; - virtual float GetReturnFloat() = 0; - virtual double GetReturnDouble() = 0; - virtual void *GetReturnAddress() = 0; - virtual void *GetReturnObject() = 0; - virtual void *GetAddressOfReturnValue() = 0; + virtual float GetReturnFloat() = 0; + virtual double GetReturnDouble() = 0; + virtual void* GetReturnAddress() = 0; + virtual void* GetReturnObject() = 0; + virtual void* GetAddressOfReturnValue() = 0; // Exception handling - virtual int SetException(const char *info, bool allowCatch = true) = 0; - virtual int GetExceptionLineNumber(int *column = 0, const char **sectionName = 0) = 0; - virtual asIScriptFunction *GetExceptionFunction() = 0; - virtual const char * GetExceptionString() = 0; - virtual bool WillExceptionBeCaught() = 0; - virtual int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv) = 0; - virtual void ClearExceptionCallback() = 0; + virtual int SetException(const char* info, bool allowCatch = true) = 0; + virtual int GetExceptionLineNumber(int* column = 0, const char** sectionName = 0) = 0; + virtual asIScriptFunction* GetExceptionFunction() = 0; + virtual const char* GetExceptionString() = 0; + virtual bool WillExceptionBeCaught() = 0; + virtual int SetExceptionCallback(asSFuncPtr callback, void* obj, int callConv) = 0; + virtual void ClearExceptionCallback() = 0; // Debugging - virtual int SetLineCallback(asSFuncPtr callback, void *obj, int callConv) = 0; - virtual void ClearLineCallback() = 0; - virtual asUINT GetCallstackSize() const = 0; - virtual asIScriptFunction *GetFunction(asUINT stackLevel = 0) = 0; - virtual int GetLineNumber(asUINT stackLevel = 0, int *column = 0, const char **sectionName = 0) = 0; - virtual int GetVarCount(asUINT stackLevel = 0) = 0; - virtual int GetVar(asUINT varIndex, asUINT stackLevel, const char** name, int* typeId = 0, asETypeModifiers* typeModifiers = 0, bool* isVarOnHeap = 0, int* stackOffset = 0) = 0; + virtual int SetLineCallback(asSFuncPtr callback, void* obj, int callConv) = 0; + virtual void ClearLineCallback() = 0; + virtual asUINT GetCallstackSize() const = 0; + virtual asIScriptFunction* GetFunction(asUINT stackLevel = 0) = 0; + virtual int GetLineNumber(asUINT stackLevel = 0, int* column = 0, const char** sectionName = 0) = 0; + virtual int GetVarCount(asUINT stackLevel = 0) = 0; + virtual int GetVar(asUINT varIndex, asUINT stackLevel, const char** name, int* typeId = 0, asETypeModifiers* typeModifiers = 0, bool* isVarOnHeap = 0, int* stackOffset = 0) = 0; #ifdef AS_DEPRECATED // deprecated since 2022-05-04, 2.36.0 - virtual const char *GetVarName(asUINT varIndex, asUINT stackLevel = 0) = 0; + virtual const char* GetVarName(asUINT varIndex, asUINT stackLevel = 0) = 0; #endif - virtual const char *GetVarDeclaration(asUINT varIndex, asUINT stackLevel = 0, bool includeNamespace = false) = 0; + virtual const char* GetVarDeclaration(asUINT varIndex, asUINT stackLevel = 0, bool includeNamespace = false) = 0; #ifdef AS_DEPRECATED // deprecated since 2022-05-04, 2.36.0 - virtual int GetVarTypeId(asUINT varIndex, asUINT stackLevel = 0) = 0; + virtual int GetVarTypeId(asUINT varIndex, asUINT stackLevel = 0) = 0; #endif - virtual void *GetAddressOfVar(asUINT varIndex, asUINT stackLevel = 0, bool dontDereference = false, bool returnAddressOfUnitializedObjects = false) = 0; - virtual bool IsVarInScope(asUINT varIndex, asUINT stackLevel = 0) = 0; - virtual int GetThisTypeId(asUINT stackLevel = 0) = 0; - virtual void *GetThisPointer(asUINT stackLevel = 0) = 0; - virtual asIScriptFunction *GetSystemFunction() = 0; + virtual void* GetAddressOfVar(asUINT varIndex, asUINT stackLevel = 0, bool dontDereference = false, bool returnAddressOfUnitializedObjects = false) = 0; + virtual bool IsVarInScope(asUINT varIndex, asUINT stackLevel = 0) = 0; + virtual int GetThisTypeId(asUINT stackLevel = 0) = 0; + virtual void* GetThisPointer(asUINT stackLevel = 0) = 0; + virtual asIScriptFunction* GetSystemFunction() = 0; // User data - virtual void *SetUserData(void *data, asPWORD type = 0) = 0; - virtual void *GetUserData(asPWORD type = 0) const = 0; + virtual void* SetUserData(void* data, asPWORD type = 0) = 0; + virtual void* GetUserData(asPWORD type = 0) const = 0; // Serialization virtual int StartDeserialization() = 0; virtual int FinishDeserialization() = 0; - virtual int PushFunction(asIScriptFunction *func, void *object) = 0; - virtual int GetStateRegisters(asUINT stackLevel, asIScriptFunction **callingSystemFunction, asIScriptFunction **initialFunction, asDWORD *origStackPointer, asDWORD *argumentsSize, asQWORD *valueRegister, void **objectRegister, asITypeInfo **objectTypeRegister) = 0; - virtual int GetCallStateRegisters(asUINT stackLevel, asDWORD *stackFramePointer, asIScriptFunction **currentFunction, asDWORD *programPointer, asDWORD *stackPointer, asDWORD *stackIndex) = 0; - virtual int SetStateRegisters(asUINT stackLevel, asIScriptFunction *callingSystemFunction, asIScriptFunction *initialFunction, asDWORD origStackPointer, asDWORD argumentsSize, asQWORD valueRegister, void *objectRegister, asITypeInfo *objectTypeRegister) = 0; - virtual int SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePointer, asIScriptFunction *currentFunction, asDWORD programPointer, asDWORD stackPointer, asDWORD stackIndex) = 0; + virtual int PushFunction(asIScriptFunction* func, void* object) = 0; + virtual int GetStateRegisters(asUINT stackLevel, asIScriptFunction** callingSystemFunction, asIScriptFunction** initialFunction, asDWORD* origStackPointer, asDWORD* argumentsSize, asQWORD* valueRegister, void** objectRegister, asITypeInfo** objectTypeRegister) = 0; + virtual int GetCallStateRegisters(asUINT stackLevel, asDWORD* stackFramePointer, asIScriptFunction** currentFunction, asDWORD* programPointer, asDWORD* stackPointer, asDWORD* stackIndex) = 0; + virtual int SetStateRegisters(asUINT stackLevel, asIScriptFunction* callingSystemFunction, asIScriptFunction* initialFunction, asDWORD origStackPointer, asDWORD argumentsSize, asQWORD valueRegister, void* objectRegister, asITypeInfo* objectTypeRegister) = 0; + virtual int SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePointer, asIScriptFunction* currentFunction, asDWORD programPointer, asDWORD stackPointer, asDWORD stackIndex) = 0; virtual int GetArgsOnStackCount(asUINT stackLevel) = 0; - virtual int GetArgOnStack(asUINT stackLevel, asUINT arg, int* typeId, asUINT *flags, void** address) = 0; + virtual int GetArgOnStack(asUINT stackLevel, asUINT arg, int* typeId, asUINT* flags, void** address) = 0; -protected: + protected: virtual ~asIScriptContext() {} }; -class asIScriptGeneric -{ -public: +class asIScriptGeneric { + public: // Miscellaneous - virtual asIScriptEngine *GetEngine() const = 0; - virtual asIScriptFunction *GetFunction() const = 0; - virtual void *GetAuxiliary() const = 0; + virtual asIScriptEngine* GetEngine() const = 0; + virtual asIScriptFunction* GetFunction() const = 0; + virtual void* GetAuxiliary() const = 0; // Object - virtual void *GetObject() = 0; - virtual int GetObjectTypeId() const = 0; + virtual void* GetObject() = 0; + virtual int GetObjectTypeId() const = 0; // Arguments - virtual int GetArgCount() const = 0; - virtual int GetArgTypeId(asUINT arg, asDWORD *flags = 0) const = 0; - virtual asBYTE GetArgByte(asUINT arg) = 0; - virtual asWORD GetArgWord(asUINT arg) = 0; + virtual int GetArgCount() const = 0; + virtual int GetArgTypeId(asUINT arg, asDWORD* flags = 0) const = 0; + virtual asBYTE GetArgByte(asUINT arg) = 0; + virtual asWORD GetArgWord(asUINT arg) = 0; virtual asDWORD GetArgDWord(asUINT arg) = 0; virtual asQWORD GetArgQWord(asUINT arg) = 0; - virtual float GetArgFloat(asUINT arg) = 0; - virtual double GetArgDouble(asUINT arg) = 0; - virtual void *GetArgAddress(asUINT arg) = 0; - virtual void *GetArgObject(asUINT arg) = 0; - virtual void *GetAddressOfArg(asUINT arg) = 0; + virtual float GetArgFloat(asUINT arg) = 0; + virtual double GetArgDouble(asUINT arg) = 0; + virtual void* GetArgAddress(asUINT arg) = 0; + virtual void* GetArgObject(asUINT arg) = 0; + virtual void* GetAddressOfArg(asUINT arg) = 0; // Return value - virtual int GetReturnTypeId(asDWORD *flags = 0) const = 0; - virtual int SetReturnByte(asBYTE val) = 0; - virtual int SetReturnWord(asWORD val) = 0; - virtual int SetReturnDWord(asDWORD val) = 0; - virtual int SetReturnQWord(asQWORD val) = 0; - virtual int SetReturnFloat(float val) = 0; - virtual int SetReturnDouble(double val) = 0; - virtual int SetReturnAddress(void *addr) = 0; - virtual int SetReturnObject(void *obj) = 0; - virtual void *GetAddressOfReturnLocation() = 0; + virtual int GetReturnTypeId(asDWORD* flags = 0) const = 0; + virtual int SetReturnByte(asBYTE val) = 0; + virtual int SetReturnWord(asWORD val) = 0; + virtual int SetReturnDWord(asDWORD val) = 0; + virtual int SetReturnQWord(asQWORD val) = 0; + virtual int SetReturnFloat(float val) = 0; + virtual int SetReturnDouble(double val) = 0; + virtual int SetReturnAddress(void* addr) = 0; + virtual int SetReturnObject(void* obj) = 0; + virtual void* GetAddressOfReturnLocation() = 0; -protected: + protected: virtual ~asIScriptGeneric() {} }; -class asIScriptObject -{ -public: +class asIScriptObject { + public: // Memory management - virtual int AddRef() const = 0; - virtual int Release() const = 0; - virtual asILockableSharedBool *GetWeakRefFlag() const = 0; + virtual int AddRef() const = 0; + virtual int Release() const = 0; + virtual asILockableSharedBool* GetWeakRefFlag() const = 0; // Type info - virtual int GetTypeId() const = 0; - virtual asITypeInfo *GetObjectType() const = 0; + virtual int GetTypeId() const = 0; + virtual asITypeInfo* GetObjectType() const = 0; // Class properties - virtual asUINT GetPropertyCount() const = 0; - virtual int GetPropertyTypeId(asUINT prop) const = 0; - virtual const char *GetPropertyName(asUINT prop) const = 0; - virtual void *GetAddressOfProperty(asUINT prop) = 0; + virtual asUINT GetPropertyCount() const = 0; + virtual int GetPropertyTypeId(asUINT prop) const = 0; + virtual const char* GetPropertyName(asUINT prop) const = 0; + virtual void* GetAddressOfProperty(asUINT prop) = 0; // Miscellaneous - virtual asIScriptEngine *GetEngine() const = 0; - virtual int CopyFrom(const asIScriptObject *other) = 0; + virtual asIScriptEngine* GetEngine() const = 0; + virtual int CopyFrom(const asIScriptObject* other) = 0; // User data - virtual void *SetUserData(void *data, asPWORD type = 0) = 0; - virtual void *GetUserData(asPWORD type = 0) const = 0; + virtual void* SetUserData(void* data, asPWORD type = 0) = 0; + virtual void* GetUserData(asPWORD type = 0) const = 0; -protected: + protected: virtual ~asIScriptObject() {} }; -class asITypeInfo -{ -public: +class asITypeInfo { + public: // Miscellaneous - virtual asIScriptEngine *GetEngine() const = 0; - virtual const char *GetConfigGroup() const = 0; - virtual asDWORD GetAccessMask() const = 0; - virtual asIScriptModule *GetModule() const = 0; + virtual asIScriptEngine* GetEngine() const = 0; + virtual const char* GetConfigGroup() const = 0; + virtual asDWORD GetAccessMask() const = 0; + virtual asIScriptModule* GetModule() const = 0; // Memory management virtual int AddRef() const = 0; virtual int Release() const = 0; // Type info - virtual const char *GetName() const = 0; - virtual const char *GetNamespace() const = 0; - virtual asITypeInfo *GetBaseType() const = 0; - virtual bool DerivesFrom(const asITypeInfo *objType) const = 0; - virtual asQWORD GetFlags() const = 0; - virtual asUINT GetSize() const = 0; - virtual int GetTypeId() const = 0; - virtual int GetSubTypeId(asUINT subTypeIndex = 0) const = 0; - virtual asITypeInfo *GetSubType(asUINT subTypeIndex = 0) const = 0; - virtual asUINT GetSubTypeCount() const = 0; + virtual const char* GetName() const = 0; + virtual const char* GetNamespace() const = 0; + virtual asITypeInfo* GetBaseType() const = 0; + virtual bool DerivesFrom(const asITypeInfo* objType) const = 0; + virtual asQWORD GetFlags() const = 0; + virtual asUINT GetSize() const = 0; + virtual int GetTypeId() const = 0; + virtual int GetSubTypeId(asUINT subTypeIndex = 0) const = 0; + virtual asITypeInfo* GetSubType(asUINT subTypeIndex = 0) const = 0; + virtual asUINT GetSubTypeCount() const = 0; // Interfaces - virtual asUINT GetInterfaceCount() const = 0; - virtual asITypeInfo *GetInterface(asUINT index) const = 0; - virtual bool Implements(const asITypeInfo *objType) const = 0; + virtual asUINT GetInterfaceCount() const = 0; + virtual asITypeInfo* GetInterface(asUINT index) const = 0; + virtual bool Implements(const asITypeInfo* objType) const = 0; // Factories - virtual asUINT GetFactoryCount() const = 0; - virtual asIScriptFunction *GetFactoryByIndex(asUINT index) const = 0; - virtual asIScriptFunction *GetFactoryByDecl(const char *decl) const = 0; + virtual asUINT GetFactoryCount() const = 0; + virtual asIScriptFunction* GetFactoryByIndex(asUINT index) const = 0; + virtual asIScriptFunction* GetFactoryByDecl(const char* decl) const = 0; // Methods - virtual asUINT GetMethodCount() const = 0; - virtual asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual = true) const = 0; - virtual asIScriptFunction *GetMethodByName(const char *name, bool getVirtual = true) const = 0; - virtual asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual = true) const = 0; + virtual asUINT GetMethodCount() const = 0; + virtual asIScriptFunction* GetMethodByIndex(asUINT index, bool getVirtual = true) const = 0; + virtual asIScriptFunction* GetMethodByName(const char* name, bool getVirtual = true) const = 0; + virtual asIScriptFunction* GetMethodByDecl(const char* decl, bool getVirtual = true) const = 0; // Properties - virtual asUINT GetPropertyCount() const = 0; - virtual int GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, bool *isProtected = 0, int *offset = 0, bool *isReference = 0, asDWORD *accessMask = 0, int *compositeOffset = 0, bool *isCompositeIndirect = 0) const = 0; - virtual const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const = 0; + virtual asUINT GetPropertyCount() const = 0; + virtual int GetProperty(asUINT index, const char** name, int* typeId = 0, bool* isPrivate = 0, bool* isProtected = 0, int* offset = 0, bool* isReference = 0, asDWORD* accessMask = 0, int* compositeOffset = 0, bool* isCompositeIndirect = 0) const = 0; + virtual const char* GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const = 0; // Behaviours - virtual asUINT GetBehaviourCount() const = 0; - virtual asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const = 0; + virtual asUINT GetBehaviourCount() const = 0; + virtual asIScriptFunction* GetBehaviourByIndex(asUINT index, asEBehaviours* outBehaviour) const = 0; // Child types - virtual asUINT GetChildFuncdefCount() const = 0; - virtual asITypeInfo *GetChildFuncdef(asUINT index) const = 0; - virtual asITypeInfo *GetParentType() const = 0; + virtual asUINT GetChildFuncdefCount() const = 0; + virtual asITypeInfo* GetChildFuncdef(asUINT index) const = 0; + virtual asITypeInfo* GetParentType() const = 0; // Enums - virtual asUINT GetEnumValueCount() const = 0; - virtual const char *GetEnumValueByIndex(asUINT index, int *outValue) const = 0; + virtual asUINT GetEnumValueCount() const = 0; + virtual const char* GetEnumValueByIndex(asUINT index, int* outValue) const = 0; // Typedef virtual int GetTypedefTypeId() const = 0; // Funcdef - virtual asIScriptFunction *GetFuncdefSignature() const = 0; + virtual asIScriptFunction* GetFuncdefSignature() const = 0; // User data - virtual void *SetUserData(void *data, asPWORD type = 0) = 0; - virtual void *GetUserData(asPWORD type = 0) const = 0; + virtual void* SetUserData(void* data, asPWORD type = 0) = 0; + virtual void* GetUserData(asPWORD type = 0) const = 0; -protected: + protected: virtual ~asITypeInfo() {} }; -class asIScriptFunction -{ -public: - virtual asIScriptEngine *GetEngine() const = 0; +class asIScriptFunction { + public: + virtual asIScriptEngine* GetEngine() const = 0; // Memory management - virtual int AddRef() const = 0; - virtual int Release() const = 0; + virtual int AddRef() const = 0; + virtual int Release() const = 0; // Miscellaneous - virtual int GetId() const = 0; - virtual asEFuncType GetFuncType() const = 0; - virtual const char *GetModuleName() const = 0; - virtual asIScriptModule *GetModule() const = 0; - virtual const char *GetScriptSectionName() const = 0; - virtual const char *GetConfigGroup() const = 0; - virtual asDWORD GetAccessMask() const = 0; - virtual void *GetAuxiliary() const = 0; + virtual int GetId() const = 0; + virtual asEFuncType GetFuncType() const = 0; + virtual const char* GetModuleName() const = 0; + virtual asIScriptModule* GetModule() const = 0; + virtual const char* GetScriptSectionName() const = 0; + virtual const char* GetConfigGroup() const = 0; + virtual asDWORD GetAccessMask() const = 0; + virtual void* GetAuxiliary() const = 0; // Function signature - virtual asITypeInfo *GetObjectType() const = 0; - virtual const char *GetObjectName() const = 0; - virtual const char *GetName() const = 0; - virtual const char *GetNamespace() const = 0; - virtual const char *GetDeclaration(bool includeObjectName = true, bool includeNamespace = false, bool includeParamNames = false) const = 0; - virtual bool IsReadOnly() const = 0; - virtual bool IsPrivate() const = 0; - virtual bool IsProtected() const = 0; - virtual bool IsFinal() const = 0; - virtual bool IsOverride() const = 0; - virtual bool IsShared() const = 0; - virtual bool IsExplicit() const = 0; - virtual bool IsProperty() const = 0; - virtual asUINT GetParamCount() const = 0; - virtual int GetParam(asUINT index, int *typeId, asDWORD *flags = 0, const char **name = 0, const char **defaultArg = 0) const = 0; - virtual int GetReturnTypeId(asDWORD *flags = 0) const = 0; + virtual asITypeInfo* GetObjectType() const = 0; + virtual const char* GetObjectName() const = 0; + virtual const char* GetName() const = 0; + virtual const char* GetNamespace() const = 0; + virtual const char* GetDeclaration(bool includeObjectName = true, bool includeNamespace = false, bool includeParamNames = false) const = 0; + virtual bool IsReadOnly() const = 0; + virtual bool IsPrivate() const = 0; + virtual bool IsProtected() const = 0; + virtual bool IsFinal() const = 0; + virtual bool IsOverride() const = 0; + virtual bool IsShared() const = 0; + virtual bool IsExplicit() const = 0; + virtual bool IsProperty() const = 0; + virtual asUINT GetParamCount() const = 0; + virtual int GetParam(asUINT index, int* typeId, asDWORD* flags = 0, const char** name = 0, const char** defaultArg = 0) const = 0; + virtual int GetReturnTypeId(asDWORD* flags = 0) const = 0; // Template functions - virtual asUINT GetSubTypeCount() const = 0; - virtual int GetSubTypeId(asUINT subTypeIndex = 0) const = 0; - virtual asITypeInfo *GetSubType(asUINT subTypeIndex = 0) const = 0; + virtual asUINT GetSubTypeCount() const = 0; + virtual int GetSubTypeId(asUINT subTypeIndex = 0) const = 0; + virtual asITypeInfo* GetSubType(asUINT subTypeIndex = 0) const = 0; // Type id for function pointers - virtual int GetTypeId() const = 0; - virtual bool IsCompatibleWithTypeId(int typeId) const = 0; + virtual int GetTypeId() const = 0; + virtual bool IsCompatibleWithTypeId(int typeId) const = 0; // Delegates - virtual void *GetDelegateObject() const = 0; - virtual asITypeInfo *GetDelegateObjectType() const = 0; - virtual asIScriptFunction *GetDelegateFunction() const = 0; + virtual void* GetDelegateObject() const = 0; + virtual asITypeInfo* GetDelegateObjectType() const = 0; + virtual asIScriptFunction* GetDelegateFunction() const = 0; // Debug information - virtual asUINT GetVarCount() const = 0; - virtual int GetVar(asUINT index, const char **name, int *typeId = 0) const = 0; - virtual const char *GetVarDecl(asUINT index, bool includeNamespace = false) const = 0; - virtual int FindNextLineWithCode(int line) const = 0; - virtual int GetDeclaredAt(const char** scriptSection, int* row, int* col) const = 0; + virtual asUINT GetVarCount() const = 0; + virtual int GetVar(asUINT index, const char** name, int* typeId = 0) const = 0; + virtual const char* GetVarDecl(asUINT index, bool includeNamespace = false) const = 0; + virtual int FindNextLineWithCode(int line) const = 0; + virtual int GetDeclaredAt(const char** scriptSection, int* row, int* col) const = 0; // For JIT compilation - virtual asDWORD *GetByteCode(asUINT *length = 0) = 0; - virtual int SetJITFunction(asJITFunction jitFunc) = 0; - virtual asJITFunction GetJITFunction() const = 0; + virtual asDWORD* GetByteCode(asUINT* length = 0) = 0; + virtual int SetJITFunction(asJITFunction jitFunc) = 0; + virtual asJITFunction GetJITFunction() const = 0; // User data - virtual void *SetUserData(void *userData, asPWORD type = 0) = 0; - virtual void *GetUserData(asPWORD type = 0) const = 0; + virtual void* SetUserData(void* userData, asPWORD type = 0) = 0; + virtual void* GetUserData(asPWORD type = 0) const = 0; -protected: + protected: virtual ~asIScriptFunction() {}; }; -class asIBinaryStream -{ -public: - virtual int Read(void *ptr, asUINT size) = 0; - virtual int Write(const void *ptr, asUINT size) = 0; +class asIBinaryStream { + public: + virtual int Read(void* ptr, asUINT size) = 0; + virtual int Write(const void* ptr, asUINT size) = 0; -public: + public: virtual ~asIBinaryStream() {} }; -class asILockableSharedBool -{ -public: +class asILockableSharedBool { + public: // Memory management virtual int AddRef() const = 0; virtual int Release() const = 0; @@ -1233,7 +1202,7 @@ public: virtual void Lock() const = 0; virtual void Unlock() const = 0; -protected: + protected: virtual ~asILockableSharedBool() {} }; @@ -1243,8 +1212,7 @@ protected: // Template function to capture all global functions, // except the ones using the generic calling convention template -inline asSFuncPtr asFunctionPtr(T func) -{ +inline asSFuncPtr asFunctionPtr(T func) { // Mark this as a global function asSFuncPtr p(2); @@ -1262,9 +1230,8 @@ inline asSFuncPtr asFunctionPtr(T func) } // Specialization for functions using the generic calling convention -template<> -inline asSFuncPtr asFunctionPtr(asGENFUNC_t func) -{ +template <> +inline asSFuncPtr asFunctionPtr(asGENFUNC_t func) { // Mark this as a generic function asSFuncPtr p(1); p.ptr.f.func = reinterpret_cast(func); @@ -1282,15 +1249,13 @@ const int SINGLE_PTR_SIZE = sizeof(asSIMPLEMETHOD_t); // Define template template -struct asSMethodPtr -{ - template - static asSFuncPtr Convert(M Mthd) - { +struct asSMethodPtr { + template + static asSFuncPtr Convert(M Mthd) { // This version of the function should never be executed, nor compiled, // as it would mean that the size of the method pointer cannot be determined. - int ERROR_UnsupportedMethodPtr[N-100]; + int ERROR_UnsupportedMethodPtr[N - 100]; asSFuncPtr p(0); return p; @@ -1299,11 +1264,9 @@ struct asSMethodPtr // Template specialization template <> -struct asSMethodPtr -{ - template - static asSFuncPtr Convert(M Mthd) - { +struct asSMethodPtr { + template + static asSFuncPtr Convert(M Mthd) { // Mark this as a class method asSFuncPtr p(3); p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE); @@ -1315,53 +1278,48 @@ struct asSMethodPtr // MSVC and Intel uses different sizes for different class method pointers template <> -struct asSMethodPtr -{ +struct asSMethodPtr { template - static asSFuncPtr Convert(M Mthd) - { + static asSFuncPtr Convert(M Mthd) { // Mark this as a class method asSFuncPtr p(3); - p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+sizeof(int)); + p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + sizeof(int)); return p; } }; template <> -struct asSMethodPtr -{ +struct asSMethodPtr { template - static asSFuncPtr Convert(M Mthd) - { + static asSFuncPtr Convert(M Mthd) { // On 32bit platforms with is where a class with virtual inheritance falls. // On 64bit platforms we can also fall here if 8byte data alignments is used. // Mark this as a class method asSFuncPtr p(3); - p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+2*sizeof(int)); + p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + 2 * sizeof(int)); // Microsoft has a terrible optimization on class methods with virtual inheritance. // They are hardcoding an important offset, which is not coming in the method pointer. #if defined(_MSC_VER) && !defined(AS_64BIT_PTR) - // Method pointers for virtual inheritance is not supported, - // as it requires the location of the vbase table, which is - // only available to the C++ compiler, but not in the method - // pointer. + // Method pointers for virtual inheritance is not supported, + // as it requires the location of the vbase table, which is + // only available to the C++ compiler, but not in the method + // pointer. - // You can get around this by forward declaring the class and - // storing the sizeof its method pointer in a constant. Example: + // You can get around this by forward declaring the class and + // storing the sizeof its method pointer in a constant. Example: - // class ClassWithVirtualInheritance; - // const int ClassWithVirtualInheritance_workaround = sizeof(void ClassWithVirtualInheritance::*()); + // class ClassWithVirtualInheritance; + // const int ClassWithVirtualInheritance_workaround = sizeof(void ClassWithVirtualInheritance::*()); - // This will force the compiler to use the unknown type - // for the class, which falls under the next case + // This will force the compiler to use the unknown type + // for the class, which falls under the next case - - // Copy the virtual table index to the 4th dword so that AngelScript - // can properly detect and deny the use of methods with virtual inheritance. - *(reinterpret_cast(&p)+3) = *(reinterpret_cast(&p)+2); + // Copy the virtual table index to the 4th dword so that AngelScript + // can properly detect and deny the use of methods with virtual inheritance. + *(reinterpret_cast(&p) + 3) = *(reinterpret_cast(&p) + 2); #endif return p; @@ -1369,30 +1327,26 @@ struct asSMethodPtr }; template <> -struct asSMethodPtr -{ +struct asSMethodPtr { template - static asSFuncPtr Convert(M Mthd) - { + static asSFuncPtr Convert(M Mthd) { // Mark this as a class method asSFuncPtr p(3); - p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+3*sizeof(int)); + p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + 3 * sizeof(int)); return p; } }; template <> -struct asSMethodPtr -{ +struct asSMethodPtr { template - static asSFuncPtr Convert(M Mthd) - { + static asSFuncPtr Convert(M Mthd) { // On 64bit platforms with 8byte data alignment // the unknown class method pointers will come here. // Mark this as a class method asSFuncPtr p(3); - p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE+4*sizeof(int)); + p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + 4 * sizeof(int)); return p; } }; @@ -1404,615 +1358,608 @@ struct asSMethodPtr //---------------------------------------------------------------- // JIT compiler -struct asSVMRegisters -{ - asDWORD *programPointer; // points to current bytecode instruction - asDWORD *stackFramePointer; // function stack frame - asDWORD *stackPointer; // top of stack (grows downward) - asQWORD valueRegister; // temp register for primitives - void *objectRegister; // temp register for objects and handles - asITypeInfo *objectType; // type of object held in object register - bool doProcessSuspend; // whether or not the JIT should break out when it encounters a suspend instruction - asIScriptContext *ctx; // the active context +struct asSVMRegisters { + asDWORD* programPointer; // points to current bytecode instruction + asDWORD* stackFramePointer; // function stack frame + asDWORD* stackPointer; // top of stack (grows downward) + asQWORD valueRegister; // temp register for primitives + void* objectRegister; // temp register for objects and handles + asITypeInfo* objectType; // type of object held in object register + bool doProcessSuspend; // whether or not the JIT should break out when it encounters a suspend instruction + asIScriptContext* ctx; // the active context }; -class asIJITCompilerAbstract -{ -public: +class asIJITCompilerAbstract { + public: virtual ~asIJITCompilerAbstract() {} }; // JIT Compiler interface version 1 -class asIJITCompiler : public asIJITCompilerAbstract -{ -public: - virtual int CompileFunction(asIScriptFunction *function, asJITFunction *output) = 0; +class asIJITCompiler : public asIJITCompilerAbstract { + public: + virtual int CompileFunction(asIScriptFunction* function, asJITFunction* output) = 0; virtual void ReleaseJITFunction(asJITFunction func) = 0; -public: + + public: virtual ~asIJITCompiler() {} }; // JIT Compiler interface version 2 -class asIJITCompilerV2 : public asIJITCompilerAbstract -{ -public: +class asIJITCompilerV2 : public asIJITCompilerAbstract { + public: virtual void NewFunction(asIScriptFunction* scriptFunc) = 0; - virtual void CleanFunction(asIScriptFunction *scriptFunc, asJITFunction jitFunc) = 0; -public: + virtual void CleanFunction(asIScriptFunction* scriptFunc, asJITFunction jitFunc) = 0; + + public: virtual ~asIJITCompilerV2() {} }; // Byte code instructions -enum asEBCInstr -{ - asBC_PopPtr = 0, - asBC_PshGPtr = 1, - asBC_PshC4 = 2, - asBC_PshV4 = 3, - asBC_PSF = 4, - asBC_SwapPtr = 5, - asBC_NOT = 6, - asBC_PshG4 = 7, - asBC_LdGRdR4 = 8, - asBC_CALL = 9, - asBC_RET = 10, - asBC_JMP = 11, - asBC_JZ = 12, - asBC_JNZ = 13, - asBC_JS = 14, - asBC_JNS = 15, - asBC_JP = 16, - asBC_JNP = 17, - asBC_TZ = 18, - asBC_TNZ = 19, - asBC_TS = 20, - asBC_TNS = 21, - asBC_TP = 22, - asBC_TNP = 23, - asBC_NEGi = 24, - asBC_NEGf = 25, - asBC_NEGd = 26, - asBC_INCi16 = 27, - asBC_INCi8 = 28, - asBC_DECi16 = 29, - asBC_DECi8 = 30, - asBC_INCi = 31, - asBC_DECi = 32, - asBC_INCf = 33, - asBC_DECf = 34, - asBC_INCd = 35, - asBC_DECd = 36, - asBC_IncVi = 37, - asBC_DecVi = 38, - asBC_BNOT = 39, - asBC_BAND = 40, - asBC_BOR = 41, - asBC_BXOR = 42, - asBC_BSLL = 43, - asBC_BSRL = 44, - asBC_BSRA = 45, - asBC_COPY = 46, - asBC_PshC8 = 47, - asBC_PshVPtr = 48, - asBC_RDSPtr = 49, - asBC_CMPd = 50, - asBC_CMPu = 51, - asBC_CMPf = 52, - asBC_CMPi = 53, - asBC_CMPIi = 54, - asBC_CMPIf = 55, - asBC_CMPIu = 56, - asBC_JMPP = 57, - asBC_PopRPtr = 58, - asBC_PshRPtr = 59, - asBC_STR = 60, - asBC_CALLSYS = 61, - asBC_CALLBND = 62, - asBC_SUSPEND = 63, - asBC_ALLOC = 64, - asBC_FREE = 65, - asBC_LOADOBJ = 66, - asBC_STOREOBJ = 67, - asBC_GETOBJ = 68, - asBC_REFCPY = 69, - asBC_CHKREF = 70, - asBC_GETOBJREF = 71, - asBC_GETREF = 72, - asBC_PshNull = 73, - asBC_ClrVPtr = 74, - asBC_OBJTYPE = 75, - asBC_TYPEID = 76, - asBC_SetV4 = 77, - asBC_SetV8 = 78, - asBC_ADDSi = 79, - asBC_CpyVtoV4 = 80, - asBC_CpyVtoV8 = 81, - asBC_CpyVtoR4 = 82, - asBC_CpyVtoR8 = 83, - asBC_CpyVtoG4 = 84, - asBC_CpyRtoV4 = 85, - asBC_CpyRtoV8 = 86, - asBC_CpyGtoV4 = 87, - asBC_WRTV1 = 88, - asBC_WRTV2 = 89, - asBC_WRTV4 = 90, - asBC_WRTV8 = 91, - asBC_RDR1 = 92, - asBC_RDR2 = 93, - asBC_RDR4 = 94, - asBC_RDR8 = 95, - asBC_LDG = 96, - asBC_LDV = 97, - asBC_PGA = 98, - asBC_CmpPtr = 99, - asBC_VAR = 100, - asBC_iTOf = 101, - asBC_fTOi = 102, - asBC_uTOf = 103, - asBC_fTOu = 104, - asBC_sbTOi = 105, - asBC_swTOi = 106, - asBC_ubTOi = 107, - asBC_uwTOi = 108, - asBC_dTOi = 109, - asBC_dTOu = 110, - asBC_dTOf = 111, - asBC_iTOd = 112, - asBC_uTOd = 113, - asBC_fTOd = 114, - asBC_ADDi = 115, - asBC_SUBi = 116, - asBC_MULi = 117, - asBC_DIVi = 118, - asBC_MODi = 119, - asBC_ADDf = 120, - asBC_SUBf = 121, - asBC_MULf = 122, - asBC_DIVf = 123, - asBC_MODf = 124, - asBC_ADDd = 125, - asBC_SUBd = 126, - asBC_MULd = 127, - asBC_DIVd = 128, - asBC_MODd = 129, - asBC_ADDIi = 130, - asBC_SUBIi = 131, - asBC_MULIi = 132, - asBC_ADDIf = 133, - asBC_SUBIf = 134, - asBC_MULIf = 135, - asBC_SetG4 = 136, - asBC_ChkRefS = 137, - asBC_ChkNullV = 138, - asBC_CALLINTF = 139, - asBC_iTOb = 140, - asBC_iTOw = 141, - asBC_SetV1 = 142, - asBC_SetV2 = 143, - asBC_Cast = 144, - asBC_i64TOi = 145, - asBC_uTOi64 = 146, - asBC_iTOi64 = 147, - asBC_fTOi64 = 148, - asBC_dTOi64 = 149, - asBC_fTOu64 = 150, - asBC_dTOu64 = 151, - asBC_i64TOf = 152, - asBC_u64TOf = 153, - asBC_i64TOd = 154, - asBC_u64TOd = 155, - asBC_NEGi64 = 156, - asBC_INCi64 = 157, - asBC_DECi64 = 158, - asBC_BNOT64 = 159, - asBC_ADDi64 = 160, - asBC_SUBi64 = 161, - asBC_MULi64 = 162, - asBC_DIVi64 = 163, - asBC_MODi64 = 164, - asBC_BAND64 = 165, - asBC_BOR64 = 166, - asBC_BXOR64 = 167, - asBC_BSLL64 = 168, - asBC_BSRL64 = 169, - asBC_BSRA64 = 170, - asBC_CMPi64 = 171, - asBC_CMPu64 = 172, - asBC_ChkNullS = 173, - asBC_ClrHi = 174, - asBC_JitEntry = 175, - asBC_CallPtr = 176, - asBC_FuncPtr = 177, - asBC_LoadThisR = 178, - asBC_PshV8 = 179, - asBC_DIVu = 180, - asBC_MODu = 181, - asBC_DIVu64 = 182, - asBC_MODu64 = 183, - asBC_LoadRObjR = 184, - asBC_LoadVObjR = 185, - asBC_RefCpyV = 186, - asBC_JLowZ = 187, - asBC_JLowNZ = 188, - asBC_AllocMem = 189, - asBC_SetListSize = 190, - asBC_PshListElmnt = 191, - asBC_SetListType = 192, - asBC_POWi = 193, - asBC_POWu = 194, - asBC_POWf = 195, - asBC_POWd = 196, - asBC_POWdi = 197, - asBC_POWi64 = 198, - asBC_POWu64 = 199, - asBC_Thiscall1 = 200, - asBC_MAXBYTECODE = 201, +enum asEBCInstr { + asBC_PopPtr = 0, + asBC_PshGPtr = 1, + asBC_PshC4 = 2, + asBC_PshV4 = 3, + asBC_PSF = 4, + asBC_SwapPtr = 5, + asBC_NOT = 6, + asBC_PshG4 = 7, + asBC_LdGRdR4 = 8, + asBC_CALL = 9, + asBC_RET = 10, + asBC_JMP = 11, + asBC_JZ = 12, + asBC_JNZ = 13, + asBC_JS = 14, + asBC_JNS = 15, + asBC_JP = 16, + asBC_JNP = 17, + asBC_TZ = 18, + asBC_TNZ = 19, + asBC_TS = 20, + asBC_TNS = 21, + asBC_TP = 22, + asBC_TNP = 23, + asBC_NEGi = 24, + asBC_NEGf = 25, + asBC_NEGd = 26, + asBC_INCi16 = 27, + asBC_INCi8 = 28, + asBC_DECi16 = 29, + asBC_DECi8 = 30, + asBC_INCi = 31, + asBC_DECi = 32, + asBC_INCf = 33, + asBC_DECf = 34, + asBC_INCd = 35, + asBC_DECd = 36, + asBC_IncVi = 37, + asBC_DecVi = 38, + asBC_BNOT = 39, + asBC_BAND = 40, + asBC_BOR = 41, + asBC_BXOR = 42, + asBC_BSLL = 43, + asBC_BSRL = 44, + asBC_BSRA = 45, + asBC_COPY = 46, + asBC_PshC8 = 47, + asBC_PshVPtr = 48, + asBC_RDSPtr = 49, + asBC_CMPd = 50, + asBC_CMPu = 51, + asBC_CMPf = 52, + asBC_CMPi = 53, + asBC_CMPIi = 54, + asBC_CMPIf = 55, + asBC_CMPIu = 56, + asBC_JMPP = 57, + asBC_PopRPtr = 58, + asBC_PshRPtr = 59, + asBC_STR = 60, + asBC_CALLSYS = 61, + asBC_CALLBND = 62, + asBC_SUSPEND = 63, + asBC_ALLOC = 64, + asBC_FREE = 65, + asBC_LOADOBJ = 66, + asBC_STOREOBJ = 67, + asBC_GETOBJ = 68, + asBC_REFCPY = 69, + asBC_CHKREF = 70, + asBC_GETOBJREF = 71, + asBC_GETREF = 72, + asBC_PshNull = 73, + asBC_ClrVPtr = 74, + asBC_OBJTYPE = 75, + asBC_TYPEID = 76, + asBC_SetV4 = 77, + asBC_SetV8 = 78, + asBC_ADDSi = 79, + asBC_CpyVtoV4 = 80, + asBC_CpyVtoV8 = 81, + asBC_CpyVtoR4 = 82, + asBC_CpyVtoR8 = 83, + asBC_CpyVtoG4 = 84, + asBC_CpyRtoV4 = 85, + asBC_CpyRtoV8 = 86, + asBC_CpyGtoV4 = 87, + asBC_WRTV1 = 88, + asBC_WRTV2 = 89, + asBC_WRTV4 = 90, + asBC_WRTV8 = 91, + asBC_RDR1 = 92, + asBC_RDR2 = 93, + asBC_RDR4 = 94, + asBC_RDR8 = 95, + asBC_LDG = 96, + asBC_LDV = 97, + asBC_PGA = 98, + asBC_CmpPtr = 99, + asBC_VAR = 100, + asBC_iTOf = 101, + asBC_fTOi = 102, + asBC_uTOf = 103, + asBC_fTOu = 104, + asBC_sbTOi = 105, + asBC_swTOi = 106, + asBC_ubTOi = 107, + asBC_uwTOi = 108, + asBC_dTOi = 109, + asBC_dTOu = 110, + asBC_dTOf = 111, + asBC_iTOd = 112, + asBC_uTOd = 113, + asBC_fTOd = 114, + asBC_ADDi = 115, + asBC_SUBi = 116, + asBC_MULi = 117, + asBC_DIVi = 118, + asBC_MODi = 119, + asBC_ADDf = 120, + asBC_SUBf = 121, + asBC_MULf = 122, + asBC_DIVf = 123, + asBC_MODf = 124, + asBC_ADDd = 125, + asBC_SUBd = 126, + asBC_MULd = 127, + asBC_DIVd = 128, + asBC_MODd = 129, + asBC_ADDIi = 130, + asBC_SUBIi = 131, + asBC_MULIi = 132, + asBC_ADDIf = 133, + asBC_SUBIf = 134, + asBC_MULIf = 135, + asBC_SetG4 = 136, + asBC_ChkRefS = 137, + asBC_ChkNullV = 138, + asBC_CALLINTF = 139, + asBC_iTOb = 140, + asBC_iTOw = 141, + asBC_SetV1 = 142, + asBC_SetV2 = 143, + asBC_Cast = 144, + asBC_i64TOi = 145, + asBC_uTOi64 = 146, + asBC_iTOi64 = 147, + asBC_fTOi64 = 148, + asBC_dTOi64 = 149, + asBC_fTOu64 = 150, + asBC_dTOu64 = 151, + asBC_i64TOf = 152, + asBC_u64TOf = 153, + asBC_i64TOd = 154, + asBC_u64TOd = 155, + asBC_NEGi64 = 156, + asBC_INCi64 = 157, + asBC_DECi64 = 158, + asBC_BNOT64 = 159, + asBC_ADDi64 = 160, + asBC_SUBi64 = 161, + asBC_MULi64 = 162, + asBC_DIVi64 = 163, + asBC_MODi64 = 164, + asBC_BAND64 = 165, + asBC_BOR64 = 166, + asBC_BXOR64 = 167, + asBC_BSLL64 = 168, + asBC_BSRL64 = 169, + asBC_BSRA64 = 170, + asBC_CMPi64 = 171, + asBC_CMPu64 = 172, + asBC_ChkNullS = 173, + asBC_ClrHi = 174, + asBC_JitEntry = 175, + asBC_CallPtr = 176, + asBC_FuncPtr = 177, + asBC_LoadThisR = 178, + asBC_PshV8 = 179, + asBC_DIVu = 180, + asBC_MODu = 181, + asBC_DIVu64 = 182, + asBC_MODu64 = 183, + asBC_LoadRObjR = 184, + asBC_LoadVObjR = 185, + asBC_RefCpyV = 186, + asBC_JLowZ = 187, + asBC_JLowNZ = 188, + asBC_AllocMem = 189, + asBC_SetListSize = 190, + asBC_PshListElmnt = 191, + asBC_SetListType = 192, + asBC_POWi = 193, + asBC_POWu = 194, + asBC_POWf = 195, + asBC_POWd = 196, + asBC_POWdi = 197, + asBC_POWi64 = 198, + asBC_POWu64 = 199, + asBC_Thiscall1 = 200, + asBC_MAXBYTECODE = 201, // Temporary tokens. Can't be output to the final program - asBC_TryBlock = 250, - asBC_VarDecl = 251, - asBC_Block = 252, - asBC_ObjInfo = 253, - asBC_LINE = 254, - asBC_LABEL = 255 + asBC_TryBlock = 250, + asBC_VarDecl = 251, + asBC_Block = 252, + asBC_ObjInfo = 253, + asBC_LINE = 254, + asBC_LABEL = 255 }; // Instruction types -enum asEBCType -{ - asBCTYPE_INFO = 0, - asBCTYPE_NO_ARG = 1, - asBCTYPE_W_ARG = 2, - asBCTYPE_wW_ARG = 3, - asBCTYPE_DW_ARG = 4, - asBCTYPE_rW_DW_ARG = 5, - asBCTYPE_QW_ARG = 6, - asBCTYPE_DW_DW_ARG = 7, +enum asEBCType { + asBCTYPE_INFO = 0, + asBCTYPE_NO_ARG = 1, + asBCTYPE_W_ARG = 2, + asBCTYPE_wW_ARG = 3, + asBCTYPE_DW_ARG = 4, + asBCTYPE_rW_DW_ARG = 5, + asBCTYPE_QW_ARG = 6, + asBCTYPE_DW_DW_ARG = 7, asBCTYPE_wW_rW_rW_ARG = 8, - asBCTYPE_wW_QW_ARG = 9, - asBCTYPE_wW_rW_ARG = 10, - asBCTYPE_rW_ARG = 11, - asBCTYPE_wW_DW_ARG = 12, + asBCTYPE_wW_QW_ARG = 9, + asBCTYPE_wW_rW_ARG = 10, + asBCTYPE_rW_ARG = 11, + asBCTYPE_wW_DW_ARG = 12, asBCTYPE_wW_rW_DW_ARG = 13, - asBCTYPE_rW_rW_ARG = 14, - asBCTYPE_wW_W_ARG = 15, - asBCTYPE_QW_DW_ARG = 16, - asBCTYPE_rW_QW_ARG = 17, - asBCTYPE_W_DW_ARG = 18, - asBCTYPE_rW_W_DW_ARG = 19, + asBCTYPE_rW_rW_ARG = 14, + asBCTYPE_wW_W_ARG = 15, + asBCTYPE_QW_DW_ARG = 16, + asBCTYPE_rW_QW_ARG = 17, + asBCTYPE_W_DW_ARG = 18, + asBCTYPE_rW_W_DW_ARG = 19, asBCTYPE_rW_DW_DW_ARG = 20 }; // Instruction type sizes const int asBCTypeSize[21] = -{ - 0, // asBCTYPE_INFO - 1, // asBCTYPE_NO_ARG - 1, // asBCTYPE_W_ARG - 1, // asBCTYPE_wW_ARG - 2, // asBCTYPE_DW_ARG - 2, // asBCTYPE_rW_DW_ARG - 3, // asBCTYPE_QW_ARG - 3, // asBCTYPE_DW_DW_ARG - 2, // asBCTYPE_wW_rW_rW_ARG - 3, // asBCTYPE_wW_QW_ARG - 2, // asBCTYPE_wW_rW_ARG - 1, // asBCTYPE_rW_ARG - 2, // asBCTYPE_wW_DW_ARG - 3, // asBCTYPE_wW_rW_DW_ARG - 2, // asBCTYPE_rW_rW_ARG - 2, // asBCTYPE_wW_W_ARG - 4, // asBCTYPE_QW_DW_ARG - 3, // asBCTYPE_rW_QW_ARG - 2, // asBCTYPE_W_DW_ARG - 3, // asBCTYPE_rW_W_DW_ARG - 3 // asBCTYPE_rW_DW_DW_ARG + { + 0, // asBCTYPE_INFO + 1, // asBCTYPE_NO_ARG + 1, // asBCTYPE_W_ARG + 1, // asBCTYPE_wW_ARG + 2, // asBCTYPE_DW_ARG + 2, // asBCTYPE_rW_DW_ARG + 3, // asBCTYPE_QW_ARG + 3, // asBCTYPE_DW_DW_ARG + 2, // asBCTYPE_wW_rW_rW_ARG + 3, // asBCTYPE_wW_QW_ARG + 2, // asBCTYPE_wW_rW_ARG + 1, // asBCTYPE_rW_ARG + 2, // asBCTYPE_wW_DW_ARG + 3, // asBCTYPE_wW_rW_DW_ARG + 2, // asBCTYPE_rW_rW_ARG + 2, // asBCTYPE_wW_W_ARG + 4, // asBCTYPE_QW_DW_ARG + 3, // asBCTYPE_rW_QW_ARG + 2, // asBCTYPE_W_DW_ARG + 3, // asBCTYPE_rW_W_DW_ARG + 3 // asBCTYPE_rW_DW_DW_ARG }; // Instruction info -struct asSBCInfo -{ - asEBCInstr bc; - asEBCType type; - int stackInc; - const char *name; +struct asSBCInfo { + asEBCInstr bc; + asEBCType type; + int stackInc; + const char* name; }; #ifndef AS_64BIT_PTR - #define asBCTYPE_PTR_ARG asBCTYPE_DW_ARG - #define asBCTYPE_PTR_DW_ARG asBCTYPE_DW_DW_ARG - #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_DW_ARG - #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_DW_ARG - #ifndef AS_PTR_SIZE - #define AS_PTR_SIZE 1 - #endif +#define asBCTYPE_PTR_ARG asBCTYPE_DW_ARG +#define asBCTYPE_PTR_DW_ARG asBCTYPE_DW_DW_ARG +#define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_DW_ARG +#define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_DW_ARG +#ifndef AS_PTR_SIZE +#define AS_PTR_SIZE 1 +#endif #else - #define asBCTYPE_PTR_ARG asBCTYPE_QW_ARG - #define asBCTYPE_PTR_DW_ARG asBCTYPE_QW_DW_ARG - #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_QW_ARG - #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_QW_ARG - #ifndef AS_PTR_SIZE - #define AS_PTR_SIZE 2 - #endif +#define asBCTYPE_PTR_ARG asBCTYPE_QW_ARG +#define asBCTYPE_PTR_DW_ARG asBCTYPE_QW_DW_ARG +#define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_QW_ARG +#define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_QW_ARG +#ifndef AS_PTR_SIZE +#define AS_PTR_SIZE 2 +#endif #endif -#define asBCINFO(b,t,s) {asBC_##b, asBCTYPE_##t, s, #b} +#define asBCINFO(b, t, s) {asBC_##b, asBCTYPE_##t, s, #b} #define asBCINFO_DUMMY(b) {asBC_MAXBYTECODE, asBCTYPE_INFO, 0, "BC_" #b} const asSBCInfo asBCInfo[256] = -{ - asBCINFO(PopPtr, NO_ARG, -AS_PTR_SIZE), - asBCINFO(PshGPtr, PTR_ARG, AS_PTR_SIZE), - asBCINFO(PshC4, DW_ARG, 1), - asBCINFO(PshV4, rW_ARG, 1), - asBCINFO(PSF, rW_ARG, AS_PTR_SIZE), - asBCINFO(SwapPtr, NO_ARG, 0), - asBCINFO(NOT, rW_ARG, 0), - asBCINFO(PshG4, PTR_ARG, 1), - asBCINFO(LdGRdR4, wW_PTR_ARG, 0), - asBCINFO(CALL, DW_ARG, 0xFFFF), - asBCINFO(RET, W_ARG, 0xFFFF), - asBCINFO(JMP, DW_ARG, 0), - asBCINFO(JZ, DW_ARG, 0), - asBCINFO(JNZ, DW_ARG, 0), - asBCINFO(JS, DW_ARG, 0), - asBCINFO(JNS, DW_ARG, 0), - asBCINFO(JP, DW_ARG, 0), - asBCINFO(JNP, DW_ARG, 0), - asBCINFO(TZ, NO_ARG, 0), - asBCINFO(TNZ, NO_ARG, 0), - asBCINFO(TS, NO_ARG, 0), - asBCINFO(TNS, NO_ARG, 0), - asBCINFO(TP, NO_ARG, 0), - asBCINFO(TNP, NO_ARG, 0), - asBCINFO(NEGi, rW_ARG, 0), - asBCINFO(NEGf, rW_ARG, 0), - asBCINFO(NEGd, rW_ARG, 0), - asBCINFO(INCi16, NO_ARG, 0), - asBCINFO(INCi8, NO_ARG, 0), - asBCINFO(DECi16, NO_ARG, 0), - asBCINFO(DECi8, NO_ARG, 0), - asBCINFO(INCi, NO_ARG, 0), - asBCINFO(DECi, NO_ARG, 0), - asBCINFO(INCf, NO_ARG, 0), - asBCINFO(DECf, NO_ARG, 0), - asBCINFO(INCd, NO_ARG, 0), - asBCINFO(DECd, NO_ARG, 0), - asBCINFO(IncVi, rW_ARG, 0), - asBCINFO(DecVi, rW_ARG, 0), - asBCINFO(BNOT, rW_ARG, 0), - asBCINFO(BAND, wW_rW_rW_ARG, 0), - asBCINFO(BOR, wW_rW_rW_ARG, 0), - asBCINFO(BXOR, wW_rW_rW_ARG, 0), - asBCINFO(BSLL, wW_rW_rW_ARG, 0), - asBCINFO(BSRL, wW_rW_rW_ARG, 0), - asBCINFO(BSRA, wW_rW_rW_ARG, 0), - asBCINFO(COPY, W_DW_ARG, -AS_PTR_SIZE), - asBCINFO(PshC8, QW_ARG, 2), - asBCINFO(PshVPtr, rW_ARG, AS_PTR_SIZE), - asBCINFO(RDSPtr, NO_ARG, 0), - asBCINFO(CMPd, rW_rW_ARG, 0), - asBCINFO(CMPu, rW_rW_ARG, 0), - asBCINFO(CMPf, rW_rW_ARG, 0), - asBCINFO(CMPi, rW_rW_ARG, 0), - asBCINFO(CMPIi, rW_DW_ARG, 0), - asBCINFO(CMPIf, rW_DW_ARG, 0), - asBCINFO(CMPIu, rW_DW_ARG, 0), - asBCINFO(JMPP, rW_ARG, 0), - asBCINFO(PopRPtr, NO_ARG, -AS_PTR_SIZE), - asBCINFO(PshRPtr, NO_ARG, AS_PTR_SIZE), - asBCINFO(STR, W_ARG, 1+AS_PTR_SIZE), - asBCINFO(CALLSYS, DW_ARG, 0xFFFF), - asBCINFO(CALLBND, DW_ARG, 0xFFFF), - asBCINFO(SUSPEND, NO_ARG, 0), - asBCINFO(ALLOC, PTR_DW_ARG, 0xFFFF), - asBCINFO(FREE, wW_PTR_ARG, 0), - asBCINFO(LOADOBJ, rW_ARG, 0), - asBCINFO(STOREOBJ, wW_ARG, 0), - asBCINFO(GETOBJ, W_ARG, 0), - asBCINFO(REFCPY, PTR_ARG, -AS_PTR_SIZE), - asBCINFO(CHKREF, NO_ARG, 0), - asBCINFO(GETOBJREF, W_ARG, 0), - asBCINFO(GETREF, W_ARG, 0), - asBCINFO(PshNull, NO_ARG, AS_PTR_SIZE), - asBCINFO(ClrVPtr, wW_ARG, 0), - asBCINFO(OBJTYPE, PTR_ARG, AS_PTR_SIZE), - asBCINFO(TYPEID, DW_ARG, 1), - asBCINFO(SetV4, wW_DW_ARG, 0), - asBCINFO(SetV8, wW_QW_ARG, 0), - asBCINFO(ADDSi, W_DW_ARG, 0), - asBCINFO(CpyVtoV4, wW_rW_ARG, 0), - asBCINFO(CpyVtoV8, wW_rW_ARG, 0), - asBCINFO(CpyVtoR4, rW_ARG, 0), - asBCINFO(CpyVtoR8, rW_ARG, 0), - asBCINFO(CpyVtoG4, rW_PTR_ARG, 0), - asBCINFO(CpyRtoV4, wW_ARG, 0), - asBCINFO(CpyRtoV8, wW_ARG, 0), - asBCINFO(CpyGtoV4, wW_PTR_ARG, 0), - asBCINFO(WRTV1, rW_ARG, 0), - asBCINFO(WRTV2, rW_ARG, 0), - asBCINFO(WRTV4, rW_ARG, 0), - asBCINFO(WRTV8, rW_ARG, 0), - asBCINFO(RDR1, wW_ARG, 0), - asBCINFO(RDR2, wW_ARG, 0), - asBCINFO(RDR4, wW_ARG, 0), - asBCINFO(RDR8, wW_ARG, 0), - asBCINFO(LDG, PTR_ARG, 0), - asBCINFO(LDV, rW_ARG, 0), - asBCINFO(PGA, PTR_ARG, AS_PTR_SIZE), - asBCINFO(CmpPtr, rW_rW_ARG, 0), - asBCINFO(VAR, rW_ARG, AS_PTR_SIZE), - asBCINFO(iTOf, rW_ARG, 0), - asBCINFO(fTOi, rW_ARG, 0), - asBCINFO(uTOf, rW_ARG, 0), - asBCINFO(fTOu, rW_ARG, 0), - asBCINFO(sbTOi, rW_ARG, 0), - asBCINFO(swTOi, rW_ARG, 0), - asBCINFO(ubTOi, rW_ARG, 0), - asBCINFO(uwTOi, rW_ARG, 0), - asBCINFO(dTOi, wW_rW_ARG, 0), - asBCINFO(dTOu, wW_rW_ARG, 0), - asBCINFO(dTOf, wW_rW_ARG, 0), - asBCINFO(iTOd, wW_rW_ARG, 0), - asBCINFO(uTOd, wW_rW_ARG, 0), - asBCINFO(fTOd, wW_rW_ARG, 0), - asBCINFO(ADDi, wW_rW_rW_ARG, 0), - asBCINFO(SUBi, wW_rW_rW_ARG, 0), - asBCINFO(MULi, wW_rW_rW_ARG, 0), - asBCINFO(DIVi, wW_rW_rW_ARG, 0), - asBCINFO(MODi, wW_rW_rW_ARG, 0), - asBCINFO(ADDf, wW_rW_rW_ARG, 0), - asBCINFO(SUBf, wW_rW_rW_ARG, 0), - asBCINFO(MULf, wW_rW_rW_ARG, 0), - asBCINFO(DIVf, wW_rW_rW_ARG, 0), - asBCINFO(MODf, wW_rW_rW_ARG, 0), - asBCINFO(ADDd, wW_rW_rW_ARG, 0), - asBCINFO(SUBd, wW_rW_rW_ARG, 0), - asBCINFO(MULd, wW_rW_rW_ARG, 0), - asBCINFO(DIVd, wW_rW_rW_ARG, 0), - asBCINFO(MODd, wW_rW_rW_ARG, 0), - asBCINFO(ADDIi, wW_rW_DW_ARG, 0), - asBCINFO(SUBIi, wW_rW_DW_ARG, 0), - asBCINFO(MULIi, wW_rW_DW_ARG, 0), - asBCINFO(ADDIf, wW_rW_DW_ARG, 0), - asBCINFO(SUBIf, wW_rW_DW_ARG, 0), - asBCINFO(MULIf, wW_rW_DW_ARG, 0), - asBCINFO(SetG4, PTR_DW_ARG, 0), - asBCINFO(ChkRefS, NO_ARG, 0), - asBCINFO(ChkNullV, rW_ARG, 0), - asBCINFO(CALLINTF, DW_ARG, 0xFFFF), - asBCINFO(iTOb, rW_ARG, 0), - asBCINFO(iTOw, rW_ARG, 0), - asBCINFO(SetV1, wW_DW_ARG, 0), - asBCINFO(SetV2, wW_DW_ARG, 0), - asBCINFO(Cast, DW_ARG, -AS_PTR_SIZE), - asBCINFO(i64TOi, wW_rW_ARG, 0), - asBCINFO(uTOi64, wW_rW_ARG, 0), - asBCINFO(iTOi64, wW_rW_ARG, 0), - asBCINFO(fTOi64, wW_rW_ARG, 0), - asBCINFO(dTOi64, rW_ARG, 0), - asBCINFO(fTOu64, wW_rW_ARG, 0), - asBCINFO(dTOu64, rW_ARG, 0), - asBCINFO(i64TOf, wW_rW_ARG, 0), - asBCINFO(u64TOf, wW_rW_ARG, 0), - asBCINFO(i64TOd, rW_ARG, 0), - asBCINFO(u64TOd, rW_ARG, 0), - asBCINFO(NEGi64, rW_ARG, 0), - asBCINFO(INCi64, NO_ARG, 0), - asBCINFO(DECi64, NO_ARG, 0), - asBCINFO(BNOT64, rW_ARG, 0), - asBCINFO(ADDi64, wW_rW_rW_ARG, 0), - asBCINFO(SUBi64, wW_rW_rW_ARG, 0), - asBCINFO(MULi64, wW_rW_rW_ARG, 0), - asBCINFO(DIVi64, wW_rW_rW_ARG, 0), - asBCINFO(MODi64, wW_rW_rW_ARG, 0), - asBCINFO(BAND64, wW_rW_rW_ARG, 0), - asBCINFO(BOR64, wW_rW_rW_ARG, 0), - asBCINFO(BXOR64, wW_rW_rW_ARG, 0), - asBCINFO(BSLL64, wW_rW_rW_ARG, 0), - asBCINFO(BSRL64, wW_rW_rW_ARG, 0), - asBCINFO(BSRA64, wW_rW_rW_ARG, 0), - asBCINFO(CMPi64, rW_rW_ARG, 0), - asBCINFO(CMPu64, rW_rW_ARG, 0), - asBCINFO(ChkNullS, W_ARG, 0), - asBCINFO(ClrHi, NO_ARG, 0), - asBCINFO(JitEntry, PTR_ARG, 0), - asBCINFO(CallPtr, rW_ARG, 0xFFFF), - asBCINFO(FuncPtr, PTR_ARG, AS_PTR_SIZE), - asBCINFO(LoadThisR, W_DW_ARG, 0), - asBCINFO(PshV8, rW_ARG, 2), - asBCINFO(DIVu, wW_rW_rW_ARG, 0), - asBCINFO(MODu, wW_rW_rW_ARG, 0), - asBCINFO(DIVu64, wW_rW_rW_ARG, 0), - asBCINFO(MODu64, wW_rW_rW_ARG, 0), - asBCINFO(LoadRObjR, rW_W_DW_ARG, 0), - asBCINFO(LoadVObjR, rW_W_DW_ARG, 0), - asBCINFO(RefCpyV, wW_PTR_ARG, 0), - asBCINFO(JLowZ, DW_ARG, 0), - asBCINFO(JLowNZ, DW_ARG, 0), - asBCINFO(AllocMem, wW_DW_ARG, 0), - asBCINFO(SetListSize, rW_DW_DW_ARG, 0), - asBCINFO(PshListElmnt, rW_DW_ARG, AS_PTR_SIZE), - asBCINFO(SetListType, rW_DW_DW_ARG, 0), - asBCINFO(POWi, wW_rW_rW_ARG, 0), - asBCINFO(POWu, wW_rW_rW_ARG, 0), - asBCINFO(POWf, wW_rW_rW_ARG, 0), - asBCINFO(POWd, wW_rW_rW_ARG, 0), - asBCINFO(POWdi, wW_rW_rW_ARG, 0), - asBCINFO(POWi64, wW_rW_rW_ARG, 0), - asBCINFO(POWu64, wW_rW_rW_ARG, 0), - asBCINFO(Thiscall1, DW_ARG, -AS_PTR_SIZE-1), + { + asBCINFO(PopPtr, NO_ARG, -AS_PTR_SIZE), + asBCINFO(PshGPtr, PTR_ARG, AS_PTR_SIZE), + asBCINFO(PshC4, DW_ARG, 1), + asBCINFO(PshV4, rW_ARG, 1), + asBCINFO(PSF, rW_ARG, AS_PTR_SIZE), + asBCINFO(SwapPtr, NO_ARG, 0), + asBCINFO(NOT, rW_ARG, 0), + asBCINFO(PshG4, PTR_ARG, 1), + asBCINFO(LdGRdR4, wW_PTR_ARG, 0), + asBCINFO(CALL, DW_ARG, 0xFFFF), + asBCINFO(RET, W_ARG, 0xFFFF), + asBCINFO(JMP, DW_ARG, 0), + asBCINFO(JZ, DW_ARG, 0), + asBCINFO(JNZ, DW_ARG, 0), + asBCINFO(JS, DW_ARG, 0), + asBCINFO(JNS, DW_ARG, 0), + asBCINFO(JP, DW_ARG, 0), + asBCINFO(JNP, DW_ARG, 0), + asBCINFO(TZ, NO_ARG, 0), + asBCINFO(TNZ, NO_ARG, 0), + asBCINFO(TS, NO_ARG, 0), + asBCINFO(TNS, NO_ARG, 0), + asBCINFO(TP, NO_ARG, 0), + asBCINFO(TNP, NO_ARG, 0), + asBCINFO(NEGi, rW_ARG, 0), + asBCINFO(NEGf, rW_ARG, 0), + asBCINFO(NEGd, rW_ARG, 0), + asBCINFO(INCi16, NO_ARG, 0), + asBCINFO(INCi8, NO_ARG, 0), + asBCINFO(DECi16, NO_ARG, 0), + asBCINFO(DECi8, NO_ARG, 0), + asBCINFO(INCi, NO_ARG, 0), + asBCINFO(DECi, NO_ARG, 0), + asBCINFO(INCf, NO_ARG, 0), + asBCINFO(DECf, NO_ARG, 0), + asBCINFO(INCd, NO_ARG, 0), + asBCINFO(DECd, NO_ARG, 0), + asBCINFO(IncVi, rW_ARG, 0), + asBCINFO(DecVi, rW_ARG, 0), + asBCINFO(BNOT, rW_ARG, 0), + asBCINFO(BAND, wW_rW_rW_ARG, 0), + asBCINFO(BOR, wW_rW_rW_ARG, 0), + asBCINFO(BXOR, wW_rW_rW_ARG, 0), + asBCINFO(BSLL, wW_rW_rW_ARG, 0), + asBCINFO(BSRL, wW_rW_rW_ARG, 0), + asBCINFO(BSRA, wW_rW_rW_ARG, 0), + asBCINFO(COPY, W_DW_ARG, -AS_PTR_SIZE), + asBCINFO(PshC8, QW_ARG, 2), + asBCINFO(PshVPtr, rW_ARG, AS_PTR_SIZE), + asBCINFO(RDSPtr, NO_ARG, 0), + asBCINFO(CMPd, rW_rW_ARG, 0), + asBCINFO(CMPu, rW_rW_ARG, 0), + asBCINFO(CMPf, rW_rW_ARG, 0), + asBCINFO(CMPi, rW_rW_ARG, 0), + asBCINFO(CMPIi, rW_DW_ARG, 0), + asBCINFO(CMPIf, rW_DW_ARG, 0), + asBCINFO(CMPIu, rW_DW_ARG, 0), + asBCINFO(JMPP, rW_ARG, 0), + asBCINFO(PopRPtr, NO_ARG, -AS_PTR_SIZE), + asBCINFO(PshRPtr, NO_ARG, AS_PTR_SIZE), + asBCINFO(STR, W_ARG, 1 + AS_PTR_SIZE), + asBCINFO(CALLSYS, DW_ARG, 0xFFFF), + asBCINFO(CALLBND, DW_ARG, 0xFFFF), + asBCINFO(SUSPEND, NO_ARG, 0), + asBCINFO(ALLOC, PTR_DW_ARG, 0xFFFF), + asBCINFO(FREE, wW_PTR_ARG, 0), + asBCINFO(LOADOBJ, rW_ARG, 0), + asBCINFO(STOREOBJ, wW_ARG, 0), + asBCINFO(GETOBJ, W_ARG, 0), + asBCINFO(REFCPY, PTR_ARG, -AS_PTR_SIZE), + asBCINFO(CHKREF, NO_ARG, 0), + asBCINFO(GETOBJREF, W_ARG, 0), + asBCINFO(GETREF, W_ARG, 0), + asBCINFO(PshNull, NO_ARG, AS_PTR_SIZE), + asBCINFO(ClrVPtr, wW_ARG, 0), + asBCINFO(OBJTYPE, PTR_ARG, AS_PTR_SIZE), + asBCINFO(TYPEID, DW_ARG, 1), + asBCINFO(SetV4, wW_DW_ARG, 0), + asBCINFO(SetV8, wW_QW_ARG, 0), + asBCINFO(ADDSi, W_DW_ARG, 0), + asBCINFO(CpyVtoV4, wW_rW_ARG, 0), + asBCINFO(CpyVtoV8, wW_rW_ARG, 0), + asBCINFO(CpyVtoR4, rW_ARG, 0), + asBCINFO(CpyVtoR8, rW_ARG, 0), + asBCINFO(CpyVtoG4, rW_PTR_ARG, 0), + asBCINFO(CpyRtoV4, wW_ARG, 0), + asBCINFO(CpyRtoV8, wW_ARG, 0), + asBCINFO(CpyGtoV4, wW_PTR_ARG, 0), + asBCINFO(WRTV1, rW_ARG, 0), + asBCINFO(WRTV2, rW_ARG, 0), + asBCINFO(WRTV4, rW_ARG, 0), + asBCINFO(WRTV8, rW_ARG, 0), + asBCINFO(RDR1, wW_ARG, 0), + asBCINFO(RDR2, wW_ARG, 0), + asBCINFO(RDR4, wW_ARG, 0), + asBCINFO(RDR8, wW_ARG, 0), + asBCINFO(LDG, PTR_ARG, 0), + asBCINFO(LDV, rW_ARG, 0), + asBCINFO(PGA, PTR_ARG, AS_PTR_SIZE), + asBCINFO(CmpPtr, rW_rW_ARG, 0), + asBCINFO(VAR, rW_ARG, AS_PTR_SIZE), + asBCINFO(iTOf, rW_ARG, 0), + asBCINFO(fTOi, rW_ARG, 0), + asBCINFO(uTOf, rW_ARG, 0), + asBCINFO(fTOu, rW_ARG, 0), + asBCINFO(sbTOi, rW_ARG, 0), + asBCINFO(swTOi, rW_ARG, 0), + asBCINFO(ubTOi, rW_ARG, 0), + asBCINFO(uwTOi, rW_ARG, 0), + asBCINFO(dTOi, wW_rW_ARG, 0), + asBCINFO(dTOu, wW_rW_ARG, 0), + asBCINFO(dTOf, wW_rW_ARG, 0), + asBCINFO(iTOd, wW_rW_ARG, 0), + asBCINFO(uTOd, wW_rW_ARG, 0), + asBCINFO(fTOd, wW_rW_ARG, 0), + asBCINFO(ADDi, wW_rW_rW_ARG, 0), + asBCINFO(SUBi, wW_rW_rW_ARG, 0), + asBCINFO(MULi, wW_rW_rW_ARG, 0), + asBCINFO(DIVi, wW_rW_rW_ARG, 0), + asBCINFO(MODi, wW_rW_rW_ARG, 0), + asBCINFO(ADDf, wW_rW_rW_ARG, 0), + asBCINFO(SUBf, wW_rW_rW_ARG, 0), + asBCINFO(MULf, wW_rW_rW_ARG, 0), + asBCINFO(DIVf, wW_rW_rW_ARG, 0), + asBCINFO(MODf, wW_rW_rW_ARG, 0), + asBCINFO(ADDd, wW_rW_rW_ARG, 0), + asBCINFO(SUBd, wW_rW_rW_ARG, 0), + asBCINFO(MULd, wW_rW_rW_ARG, 0), + asBCINFO(DIVd, wW_rW_rW_ARG, 0), + asBCINFO(MODd, wW_rW_rW_ARG, 0), + asBCINFO(ADDIi, wW_rW_DW_ARG, 0), + asBCINFO(SUBIi, wW_rW_DW_ARG, 0), + asBCINFO(MULIi, wW_rW_DW_ARG, 0), + asBCINFO(ADDIf, wW_rW_DW_ARG, 0), + asBCINFO(SUBIf, wW_rW_DW_ARG, 0), + asBCINFO(MULIf, wW_rW_DW_ARG, 0), + asBCINFO(SetG4, PTR_DW_ARG, 0), + asBCINFO(ChkRefS, NO_ARG, 0), + asBCINFO(ChkNullV, rW_ARG, 0), + asBCINFO(CALLINTF, DW_ARG, 0xFFFF), + asBCINFO(iTOb, rW_ARG, 0), + asBCINFO(iTOw, rW_ARG, 0), + asBCINFO(SetV1, wW_DW_ARG, 0), + asBCINFO(SetV2, wW_DW_ARG, 0), + asBCINFO(Cast, DW_ARG, -AS_PTR_SIZE), + asBCINFO(i64TOi, wW_rW_ARG, 0), + asBCINFO(uTOi64, wW_rW_ARG, 0), + asBCINFO(iTOi64, wW_rW_ARG, 0), + asBCINFO(fTOi64, wW_rW_ARG, 0), + asBCINFO(dTOi64, rW_ARG, 0), + asBCINFO(fTOu64, wW_rW_ARG, 0), + asBCINFO(dTOu64, rW_ARG, 0), + asBCINFO(i64TOf, wW_rW_ARG, 0), + asBCINFO(u64TOf, wW_rW_ARG, 0), + asBCINFO(i64TOd, rW_ARG, 0), + asBCINFO(u64TOd, rW_ARG, 0), + asBCINFO(NEGi64, rW_ARG, 0), + asBCINFO(INCi64, NO_ARG, 0), + asBCINFO(DECi64, NO_ARG, 0), + asBCINFO(BNOT64, rW_ARG, 0), + asBCINFO(ADDi64, wW_rW_rW_ARG, 0), + asBCINFO(SUBi64, wW_rW_rW_ARG, 0), + asBCINFO(MULi64, wW_rW_rW_ARG, 0), + asBCINFO(DIVi64, wW_rW_rW_ARG, 0), + asBCINFO(MODi64, wW_rW_rW_ARG, 0), + asBCINFO(BAND64, wW_rW_rW_ARG, 0), + asBCINFO(BOR64, wW_rW_rW_ARG, 0), + asBCINFO(BXOR64, wW_rW_rW_ARG, 0), + asBCINFO(BSLL64, wW_rW_rW_ARG, 0), + asBCINFO(BSRL64, wW_rW_rW_ARG, 0), + asBCINFO(BSRA64, wW_rW_rW_ARG, 0), + asBCINFO(CMPi64, rW_rW_ARG, 0), + asBCINFO(CMPu64, rW_rW_ARG, 0), + asBCINFO(ChkNullS, W_ARG, 0), + asBCINFO(ClrHi, NO_ARG, 0), + asBCINFO(JitEntry, PTR_ARG, 0), + asBCINFO(CallPtr, rW_ARG, 0xFFFF), + asBCINFO(FuncPtr, PTR_ARG, AS_PTR_SIZE), + asBCINFO(LoadThisR, W_DW_ARG, 0), + asBCINFO(PshV8, rW_ARG, 2), + asBCINFO(DIVu, wW_rW_rW_ARG, 0), + asBCINFO(MODu, wW_rW_rW_ARG, 0), + asBCINFO(DIVu64, wW_rW_rW_ARG, 0), + asBCINFO(MODu64, wW_rW_rW_ARG, 0), + asBCINFO(LoadRObjR, rW_W_DW_ARG, 0), + asBCINFO(LoadVObjR, rW_W_DW_ARG, 0), + asBCINFO(RefCpyV, wW_PTR_ARG, 0), + asBCINFO(JLowZ, DW_ARG, 0), + asBCINFO(JLowNZ, DW_ARG, 0), + asBCINFO(AllocMem, wW_DW_ARG, 0), + asBCINFO(SetListSize, rW_DW_DW_ARG, 0), + asBCINFO(PshListElmnt, rW_DW_ARG, AS_PTR_SIZE), + asBCINFO(SetListType, rW_DW_DW_ARG, 0), + asBCINFO(POWi, wW_rW_rW_ARG, 0), + asBCINFO(POWu, wW_rW_rW_ARG, 0), + asBCINFO(POWf, wW_rW_rW_ARG, 0), + asBCINFO(POWd, wW_rW_rW_ARG, 0), + asBCINFO(POWdi, wW_rW_rW_ARG, 0), + asBCINFO(POWi64, wW_rW_rW_ARG, 0), + asBCINFO(POWu64, wW_rW_rW_ARG, 0), + asBCINFO(Thiscall1, DW_ARG, -AS_PTR_SIZE - 1), - asBCINFO_DUMMY(201), - asBCINFO_DUMMY(202), - asBCINFO_DUMMY(203), - asBCINFO_DUMMY(204), - asBCINFO_DUMMY(205), - asBCINFO_DUMMY(206), - asBCINFO_DUMMY(207), - asBCINFO_DUMMY(208), - asBCINFO_DUMMY(209), - asBCINFO_DUMMY(210), - asBCINFO_DUMMY(211), - asBCINFO_DUMMY(212), - asBCINFO_DUMMY(213), - asBCINFO_DUMMY(214), - asBCINFO_DUMMY(215), - asBCINFO_DUMMY(216), - asBCINFO_DUMMY(217), - asBCINFO_DUMMY(218), - asBCINFO_DUMMY(219), - asBCINFO_DUMMY(220), - asBCINFO_DUMMY(221), - asBCINFO_DUMMY(222), - asBCINFO_DUMMY(223), - asBCINFO_DUMMY(224), - asBCINFO_DUMMY(225), - asBCINFO_DUMMY(226), - asBCINFO_DUMMY(227), - asBCINFO_DUMMY(228), - asBCINFO_DUMMY(229), - asBCINFO_DUMMY(230), - asBCINFO_DUMMY(231), - asBCINFO_DUMMY(232), - asBCINFO_DUMMY(233), - asBCINFO_DUMMY(234), - asBCINFO_DUMMY(235), - asBCINFO_DUMMY(236), - asBCINFO_DUMMY(237), - asBCINFO_DUMMY(238), - asBCINFO_DUMMY(239), - asBCINFO_DUMMY(240), - asBCINFO_DUMMY(241), - asBCINFO_DUMMY(242), - asBCINFO_DUMMY(243), - asBCINFO_DUMMY(244), - asBCINFO_DUMMY(245), - asBCINFO_DUMMY(246), - asBCINFO_DUMMY(247), - asBCINFO_DUMMY(248), - asBCINFO_DUMMY(249), + asBCINFO_DUMMY(201), + asBCINFO_DUMMY(202), + asBCINFO_DUMMY(203), + asBCINFO_DUMMY(204), + asBCINFO_DUMMY(205), + asBCINFO_DUMMY(206), + asBCINFO_DUMMY(207), + asBCINFO_DUMMY(208), + asBCINFO_DUMMY(209), + asBCINFO_DUMMY(210), + asBCINFO_DUMMY(211), + asBCINFO_DUMMY(212), + asBCINFO_DUMMY(213), + asBCINFO_DUMMY(214), + asBCINFO_DUMMY(215), + asBCINFO_DUMMY(216), + asBCINFO_DUMMY(217), + asBCINFO_DUMMY(218), + asBCINFO_DUMMY(219), + asBCINFO_DUMMY(220), + asBCINFO_DUMMY(221), + asBCINFO_DUMMY(222), + asBCINFO_DUMMY(223), + asBCINFO_DUMMY(224), + asBCINFO_DUMMY(225), + asBCINFO_DUMMY(226), + asBCINFO_DUMMY(227), + asBCINFO_DUMMY(228), + asBCINFO_DUMMY(229), + asBCINFO_DUMMY(230), + asBCINFO_DUMMY(231), + asBCINFO_DUMMY(232), + asBCINFO_DUMMY(233), + asBCINFO_DUMMY(234), + asBCINFO_DUMMY(235), + asBCINFO_DUMMY(236), + asBCINFO_DUMMY(237), + asBCINFO_DUMMY(238), + asBCINFO_DUMMY(239), + asBCINFO_DUMMY(240), + asBCINFO_DUMMY(241), + asBCINFO_DUMMY(242), + asBCINFO_DUMMY(243), + asBCINFO_DUMMY(244), + asBCINFO_DUMMY(245), + asBCINFO_DUMMY(246), + asBCINFO_DUMMY(247), + asBCINFO_DUMMY(248), + asBCINFO_DUMMY(249), - asBCINFO(TryBlock, DW_ARG, 0), - asBCINFO(VarDecl, W_ARG, 0), - asBCINFO(Block, INFO, 0), - asBCINFO(ObjInfo, rW_DW_ARG, 0), - asBCINFO(LINE, INFO, 0), - asBCINFO(LABEL, INFO, 0) -}; + asBCINFO(TryBlock, DW_ARG, 0), + asBCINFO(VarDecl, W_ARG, 0), + asBCINFO(Block, INFO, 0), + asBCINFO(ObjInfo, rW_DW_ARG, 0), + asBCINFO(LINE, INFO, 0), + asBCINFO(LABEL, INFO, 0)}; // Macros to access bytecode instruction arguments -#define asBC_DWORDARG(x) (*(((asDWORD*)x)+1)) -#define asBC_INTARG(x) (*(int*)(((asDWORD*)x)+1)) -#define asBC_QWORDARG(x) (*(asQWORD*)(((asDWORD*)x)+1)) -#define asBC_FLOATARG(x) (*(float*)(((asDWORD*)x)+1)) -#define asBC_PTRARG(x) (*(asPWORD*)(((asDWORD*)x)+1)) -#define asBC_WORDARG0(x) (*(((asWORD*)x)+1)) -#define asBC_WORDARG1(x) (*(((asWORD*)x)+2)) -#define asBC_SWORDARG0(x) (*(((short*)x)+1)) -#define asBC_SWORDARG1(x) (*(((short*)x)+2)) -#define asBC_SWORDARG2(x) (*(((short*)x)+3)) - +#define asBC_DWORDARG(x) (*(((asDWORD*)x) + 1)) +#define asBC_INTARG(x) (*(int*)(((asDWORD*)x) + 1)) +#define asBC_QWORDARG(x) (*(asQWORD*)(((asDWORD*)x) + 1)) +#define asBC_FLOATARG(x) (*(float*)(((asDWORD*)x) + 1)) +#define asBC_PTRARG(x) (*(asPWORD*)(((asDWORD*)x) + 1)) +#define asBC_WORDARG0(x) (*(((asWORD*)x) + 1)) +#define asBC_WORDARG1(x) (*(((asWORD*)x) + 2)) +#define asBC_SWORDARG0(x) (*(((short*)x) + 1)) +#define asBC_SWORDARG1(x) (*(((short*)x) + 2)) +#define asBC_SWORDARG2(x) (*(((short*)x) + 3)) END_AS_NAMESPACE diff --git a/Deer/vendor/angelScript/src/scriptbuilder.cpp b/Deer/vendor/angelScript/src/scriptbuilder.cpp index d8500d8..b47b6b8 100755 --- a/Deer/vendor/angelScript/src/scriptbuilder.cpp +++ b/Deer/vendor/angelScript/src/scriptbuilder.cpp @@ -1,6 +1,6 @@ #include "scriptbuilder.h" -#include #include +#include #ifdef _WIN32 #include // MultiByteToWideChar() #endif @@ -22,11 +22,9 @@ BEGIN_AS_NAMESPACE // Helper functions static string GetCurrentDir(); -static string GetAbsolutePath(const string &path); +static string GetAbsolutePath(const string& path); - -CScriptBuilder::CScriptBuilder() -{ +CScriptBuilder::CScriptBuilder() { engine = 0; module = 0; @@ -37,25 +35,23 @@ CScriptBuilder::CScriptBuilder() pragmaParam = 0; } -void CScriptBuilder::SetIncludeCallback(INCLUDECALLBACK_t callback, void *userParam) -{ +void CScriptBuilder::SetIncludeCallback(INCLUDECALLBACK_t callback, void* userParam) { includeCallback = callback; - includeParam = userParam; + includeParam = userParam; } -void CScriptBuilder::SetPragmaCallback(PRAGMACALLBACK_t callback, void *userParam) -{ +void CScriptBuilder::SetPragmaCallback(PRAGMACALLBACK_t callback, void* userParam) { pragmaCallback = callback; pragmaParam = userParam; } -int CScriptBuilder::StartNewModule(asIScriptEngine *inEngine, const char *moduleName) -{ - if(inEngine == 0 ) return -1; +int CScriptBuilder::StartNewModule(asIScriptEngine* inEngine, const char* moduleName) { + if (inEngine == 0) + return -1; engine = inEngine; module = inEngine->GetModule(moduleName, asGM_ALWAYS_CREATE); - if( module == 0 ) + if (module == 0) return -1; ClearAll(); @@ -63,47 +59,43 @@ int CScriptBuilder::StartNewModule(asIScriptEngine *inEngine, const char *module return 0; } -asIScriptEngine *CScriptBuilder::GetEngine() -{ +asIScriptEngine* CScriptBuilder::GetEngine() { return engine; } -asIScriptModule *CScriptBuilder::GetModule() -{ +asIScriptModule* CScriptBuilder::GetModule() { return module; } -unsigned int CScriptBuilder::GetSectionCount() const -{ +unsigned int CScriptBuilder::GetSectionCount() const { return (unsigned int)(includedScripts.size()); } -string CScriptBuilder::GetSectionName(unsigned int idx) const -{ - if( idx >= includedScripts.size() ) return ""; +string CScriptBuilder::GetSectionName(unsigned int idx) const { + if (idx >= includedScripts.size()) + return ""; #ifdef _WIN32 set::const_iterator it = includedScripts.begin(); #else set::const_iterator it = includedScripts.begin(); #endif - while( idx-- > 0 ) it++; + while (idx-- > 0) + it++; return *it; } // Returns 1 if the section was included // Returns 0 if the section was not included because it had already been included before // Returns <0 if there was an error -int CScriptBuilder::AddSectionFromFile(const char *filename) -{ +int CScriptBuilder::AddSectionFromFile(const char* filename) { // The file name stored in the set should be the fully resolved name because // it is possible to name the same file in multiple ways using relative paths. string fullpath = GetAbsolutePath(filename); - if( IncludeIfNotAlreadyIncluded(fullpath.c_str()) ) - { + if (IncludeIfNotAlreadyIncluded(fullpath.c_str())) { int r = LoadScriptSection(fullpath.c_str()); - if( r < 0 ) + if (r < 0) return r; else return 1; @@ -115,12 +107,10 @@ int CScriptBuilder::AddSectionFromFile(const char *filename) // Returns 1 if the section was included // Returns 0 if the section was not included because it had already been included before // Returns <0 if there was an error -int CScriptBuilder::AddSectionFromMemory(const char *sectionName, const char *scriptCode, unsigned int scriptLength, int lineOffset) -{ - if( IncludeIfNotAlreadyIncluded(sectionName) ) - { +int CScriptBuilder::AddSectionFromMemory(const char* sectionName, const char* scriptCode, unsigned int scriptLength, int lineOffset) { + if (IncludeIfNotAlreadyIncluded(sectionName)) { int r = ProcessScriptSection(scriptCode, scriptLength, sectionName, lineOffset); - if( r < 0 ) + if (r < 0) return r; else return 1; @@ -129,22 +119,18 @@ int CScriptBuilder::AddSectionFromMemory(const char *sectionName, const char *sc return 0; } -int CScriptBuilder::BuildModule() -{ +int CScriptBuilder::BuildModule() { return Build(); } -void CScriptBuilder::DefineWord(const char *word) -{ +void CScriptBuilder::DefineWord(const char* word) { string sword = word; - if( definedWords.find(sword) == definedWords.end() ) - { + if (definedWords.find(sword) == definedWords.end()) { definedWords.insert(sword); } } -void CScriptBuilder::ClearAll() -{ +void CScriptBuilder::ClearAll() { includedScripts.clear(); #if AS_PROCESS_METADATA == 1 @@ -158,11 +144,9 @@ void CScriptBuilder::ClearAll() #endif } -bool CScriptBuilder::IncludeIfNotAlreadyIncluded(const char *filename) -{ +bool CScriptBuilder::IncludeIfNotAlreadyIncluded(const char* filename) { string scriptFile = filename; - if( includedScripts.find(scriptFile) != includedScripts.end() ) - { + if (includedScripts.find(scriptFile) != includedScripts.end()) { // Already included return false; } @@ -173,29 +157,27 @@ bool CScriptBuilder::IncludeIfNotAlreadyIncluded(const char *filename) return true; } -int CScriptBuilder::LoadScriptSection(const char* filename) -{ +int CScriptBuilder::LoadScriptSection(const char* filename) { // Open the script file string scriptFile = filename; #if _MSC_VER >= 1500 && !defined(__S3E__) - #ifdef _WIN32 +#ifdef _WIN32 // Convert the filename from UTF8 to UTF16 wchar_t bufUTF16_name[10000] = {0}; wchar_t bufUTF16_mode[10] = {0}; MultiByteToWideChar(CP_UTF8, 0, filename, -1, bufUTF16_name, 10000); MultiByteToWideChar(CP_UTF8, 0, "rb", -1, bufUTF16_mode, 10); - FILE *f = 0; + FILE* f = 0; _wfopen_s(&f, bufUTF16_name, bufUTF16_mode); - #else +#else FILE* f = 0; fopen_s(&f, scriptFile.c_str(), "rb"); - #endif -#else - FILE *f = fopen(scriptFile.c_str(), "rb"); #endif - if( f == 0 ) - { +#else + FILE* f = fopen(scriptFile.c_str(), "rb"); +#endif + if (f == 0) { // Write a message to the engine's message callback string msg = "Failed to open script file '" + GetAbsolutePath(scriptFile) + "'"; engine->WriteMessage(filename, 0, 0, asMSGTYPE_ERROR, msg.c_str()); @@ -216,16 +198,14 @@ int CScriptBuilder::LoadScriptSection(const char* filename) // Read the entire file string code; size_t c = 0; - if( len > 0 ) - { + if (len > 0) { code.resize(len); c = fread(&code[0], len, 1, f); } fclose(f); - if( c == 0 && len > 0 ) - { + if (c == 0 && len > 0) { // Write a message to the engine's message callback string msg = "Failed to load script file '" + GetAbsolutePath(scriptFile) + "'"; engine->WriteMessage(filename, 0, 0, asMSGTYPE_ERROR, msg.c_str()); @@ -236,12 +216,11 @@ int CScriptBuilder::LoadScriptSection(const char* filename) return ProcessScriptSection(code.c_str(), (unsigned int)(code.length()), filename, 0); } -int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length, const char *sectionname, int lineOffset) -{ +int CScriptBuilder::ProcessScriptSection(const char* script, unsigned int length, const char* sectionname, int lineOffset) { vector includes; // Perform a superficial parsing of the script first to store the metadata - if( length ) + if (length) modifiedScript.assign(script, length); else modifiedScript = script; @@ -249,12 +228,10 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length // First perform the checks for #if directives to exclude code that shouldn't be compiled unsigned int pos = 0; int nested = 0; - while( pos < modifiedScript.size() ) - { + while (pos < modifiedScript.size()) { asUINT len = 0; asETokenClass t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if( t == asTC_UNKNOWN && modifiedScript[pos] == '#' && (pos + 1 < modifiedScript.size()) ) - { + if (t == asTC_UNKNOWN && modifiedScript[pos] == '#' && (pos + 1 < modifiedScript.size())) { int start = pos++; // Is this an #if directive? @@ -265,47 +242,37 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length pos += len; - if( token == "if" ) - { + if (token == "if") { t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if( t == asTC_WHITESPACE ) - { + if (t == asTC_WHITESPACE) { pos += len; t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); } - if( t == asTC_IDENTIFIER ) - { + if (t == asTC_IDENTIFIER) { string word; word.assign(&modifiedScript[pos], len); // Overwrite the #if directive with space characters to avoid compiler error pos += len; - OverwriteCode(start, pos-start); + OverwriteCode(start, pos - start); // Has this identifier been defined by the application or not? - if( definedWords.find(word) == definedWords.end() ) - { + if (definedWords.find(word) == definedWords.end()) { // Exclude all the code until and including the #endif pos = ExcludeCode(pos); - } - else - { + } else { nested++; } } - } - else if( token == "endif" ) - { + } else if (token == "endif") { // Only remove the #endif if there was a matching #if - if( nested > 0 ) - { - OverwriteCode(start, pos-start); + if (nested > 0) { + OverwriteCode(start, pos - start); nested--; } } - } - else + } else pos += len; } @@ -318,12 +285,10 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length // Then check for meta data and pre-processor directives pos = 0; - while( pos < modifiedScript.size() ) - { + while (pos < modifiedScript.size()) { asUINT len = 0; asETokenClass t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if( t == asTC_COMMENT || t == asTC_WHITESPACE ) - { + if (t == asTC_COMMENT || t == asTC_WHITESPACE) { pos += len; continue; } @@ -332,44 +297,35 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length #if AS_PROCESS_METADATA == 1 // Skip possible decorators before class and interface declarations - if (token == "shared" || token == "abstract" || token == "mixin" || token == "external") - { + if (token == "shared" || token == "abstract" || token == "mixin" || token == "external") { pos += len; continue; } // Check if class or interface so the metadata for members can be gathered - if( currentClass == "" && (token == "class" || token == "interface") ) - { + if (currentClass == "" && (token == "class" || token == "interface")) { // Get the identifier after "class" - do - { + do { pos += len; - if( pos >= modifiedScript.size() ) - { + if (pos >= modifiedScript.size()) { t = asTC_UNKNOWN; break; } t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - } while(t == asTC_COMMENT || t == asTC_WHITESPACE); + } while (t == asTC_COMMENT || t == asTC_WHITESPACE); - if( t == asTC_IDENTIFIER ) - { - currentClass = modifiedScript.substr(pos,len); + if (t == asTC_IDENTIFIER) { + currentClass = modifiedScript.substr(pos, len); // Search until first { or ; is encountered - while( pos < modifiedScript.length() ) - { + while (pos < modifiedScript.length()) { engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); // If start of class section encountered stop - if( modifiedScript[pos] == '{' ) - { + if (modifiedScript[pos] == '{') { pos += len; break; - } - else if (modifiedScript[pos] == ';') - { + } else if (modifiedScript[pos] == ';') { // The class declaration has ended and there are no children currentClass = ""; pos += len; @@ -385,27 +341,22 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length } // Check if end of class - if( currentClass != "" && token == "}" ) - { + if (currentClass != "" && token == "}") { currentClass = ""; pos += len; continue; } // Check if namespace so the metadata for members can be gathered - if( token == "namespace" ) - { + if (token == "namespace") { // Get the scope after "namespace". It can be composed of multiple nested namespaces, e.g. A::B::C - do - { - do - { + do { + do { pos += len; t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); } while (t == asTC_COMMENT || t == asTC_WHITESPACE); - if (t == asTC_IDENTIFIER) - { + if (t == asTC_IDENTIFIER) { if (currentNamespace != "") currentNamespace += "::"; currentNamespace += modifiedScript.substr(pos, len); @@ -413,13 +364,11 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length } while (t == asTC_IDENTIFIER || (t == asTC_KEYWORD && modifiedScript.substr(pos, len) == "::")); // Search until first { is encountered - while( pos < modifiedScript.length() ) - { + while (pos < modifiedScript.length()) { engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); // If start of namespace section encountered stop - if( modifiedScript[pos] == '{' ) - { + if (modifiedScript[pos] == '{') { pos += len; break; } @@ -432,15 +381,11 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length } // Check if end of namespace - if( currentNamespace != "" && token == "}" ) - { - size_t found = currentNamespace.rfind( "::" ); - if( found != string::npos ) - { - currentNamespace.erase( found ); - } - else - { + if (currentNamespace != "" && token == "}") { + size_t found = currentNamespace.rfind("::"); + if (found != string::npos) { + currentNamespace.erase(found); + } else { currentNamespace = ""; } pos += len; @@ -448,8 +393,7 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length } // Is this the start of metadata? - if( token == "[" ) - { + if (token == "[") { // Get the metadata string pos = ExtractMetadata(pos, metadata); @@ -458,140 +402,118 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length ExtractDeclaration(pos, name, declaration, type); // Store away the declaration in a map for lookup after the build has completed - if( type > 0 ) - { + if (type > 0) { SMetadataDecl decl(metadata, name, declaration, type, currentClass, currentNamespace); foundDeclarations.push_back(decl); } - } - else + } else #endif - // Is this a preprocessor directive? - if( token == "#" && (pos + 1 < modifiedScript.size()) ) - { - int start = pos++; + // Is this a preprocessor directive? + if (token == "#" && (pos + 1 < modifiedScript.size())) { + int start = pos++; - t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if (t == asTC_IDENTIFIER) - { - token.assign(&modifiedScript[pos], len); - if (token == "include") - { - pos += len; - t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if (t == asTC_WHITESPACE) - { + t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); + if (t == asTC_IDENTIFIER) { + token.assign(&modifiedScript[pos], len); + if (token == "include") { pos += len; t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - } + if (t == asTC_WHITESPACE) { + pos += len; + t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); + } - if (t == asTC_VALUE && len > 2 && (modifiedScript[pos] == '"' || modifiedScript[pos] == '\'')) - { - // Get the include file - string includefile; - includefile.assign(&modifiedScript[pos + 1], len - 2); + if (t == asTC_VALUE && len > 2 && (modifiedScript[pos] == '"' || modifiedScript[pos] == '\'')) { + // Get the include file + string includefile; + includefile.assign(&modifiedScript[pos + 1], len - 2); + pos += len; + + // Make sure the includeFile doesn't contain any line breaks + size_t p = includefile.find('\n'); + if (p != string::npos) { + // TODO: Show the correct line number for the error + string str = "Invalid file name for #include; it contains a line-break: '" + includefile.substr(0, p) + "'"; + engine->WriteMessage(sectionname, 0, 0, asMSGTYPE_ERROR, str.c_str()); + } else { + // Store it for later processing + includes.push_back(includefile); + + // Overwrite the include directive with space characters to avoid compiler error + OverwriteCode(start, pos - start); + } + } + } else if (token == "pragma") { + // Read until the end of the line pos += len; + for (; pos < modifiedScript.size() && modifiedScript[pos] != '\n'; pos++) + ; - // Make sure the includeFile doesn't contain any line breaks - size_t p = includefile.find('\n'); - if (p != string::npos) - { - // TODO: Show the correct line number for the error - string str = "Invalid file name for #include; it contains a line-break: '" + includefile.substr(0, p) + "'"; - engine->WriteMessage(sectionname, 0, 0, asMSGTYPE_ERROR, str.c_str()); + // Call the pragma callback + string pragmaText(&modifiedScript[start + 7], pos - start - 7); + int r = pragmaCallback ? pragmaCallback(pragmaText, *this, pragmaParam) : -1; + if (r < 0) { + // TODO: Report the correct line number + engine->WriteMessage(sectionname, 0, 0, asMSGTYPE_ERROR, "Invalid #pragma directive"); + return r; } - else - { - // Store it for later processing - includes.push_back(includefile); - // Overwrite the include directive with space characters to avoid compiler error - OverwriteCode(start, pos - start); - } + // Overwrite the pragma directive with space characters to avoid compiler error + OverwriteCode(start, pos - start); + } + } else { + // Check for lines starting with #!, e.g. shebang interpreter directive. These will be treated as comments and removed by the preprocessor + if (modifiedScript[pos] == '!') { + // Read until the end of the line + pos += len; + for (; pos < modifiedScript.size() && modifiedScript[pos] != '\n'; pos++) + ; + + // Overwrite the directive with space characters to avoid compiler error + OverwriteCode(start, pos - start); } } - else if (token == "pragma") - { - // Read until the end of the line - pos += len; - for (; pos < modifiedScript.size() && modifiedScript[pos] != '\n'; pos++); - - // Call the pragma callback - string pragmaText(&modifiedScript[start + 7], pos - start - 7); - int r = pragmaCallback ? pragmaCallback(pragmaText, *this, pragmaParam) : -1; - if (r < 0) - { - // TODO: Report the correct line number - engine->WriteMessage(sectionname, 0, 0, asMSGTYPE_ERROR, "Invalid #pragma directive"); - return r; - } - - // Overwrite the pragma directive with space characters to avoid compiler error - OverwriteCode(start, pos - start); - } } - else - { - // Check for lines starting with #!, e.g. shebang interpreter directive. These will be treated as comments and removed by the preprocessor - if (modifiedScript[pos] == '!') - { - // Read until the end of the line - pos += len; - for (; pos < modifiedScript.size() && modifiedScript[pos] != '\n'; pos++); - - // Overwrite the directive with space characters to avoid compiler error - OverwriteCode(start, pos - start); - } + // Don't search for metadata/includes within statement blocks or between tokens in statements + else { + pos = SkipStatement(pos); } - } - // Don't search for metadata/includes within statement blocks or between tokens in statements - else - { - pos = SkipStatement(pos); - } } // Build the actual script engine->SetEngineProperty(asEP_COPY_SCRIPT_SECTIONS, true); module->AddScriptSection(sectionname, modifiedScript.c_str(), modifiedScript.size(), lineOffset); - if( includes.size() > 0 ) - { + if (includes.size() > 0) { // If the callback has been set, then call it for each included file - if( includeCallback ) - { - for( int n = 0; n < (int)includes.size(); n++ ) - { + if (includeCallback) { + for (int n = 0; n < (int)includes.size(); n++) { int r = includeCallback(includes[n].c_str(), sectionname, this, includeParam); - if( r < 0 ) + if (r < 0) return r; } - } - else - { + } else { // By default we try to load the included file from the relative directory of the current file // Determine the path of the current script so that we can resolve relative paths for includes string path = sectionname; size_t posOfSlash = path.find_last_of("/\\"); - if( posOfSlash != string::npos ) - path.resize(posOfSlash+1); + if (posOfSlash != string::npos) + path.resize(posOfSlash + 1); else path = ""; // Load the included scripts - for( int n = 0; n < (int)includes.size(); n++ ) - { + for (int n = 0; n < (int)includes.size(); n++) { // If the include is a relative path, then prepend the path of the originating script - if( includes[n].find_first_of("/\\") != 0 && - includes[n].find_first_of(":") == string::npos ) - { + if (includes[n].find_first_of("/\\") != 0 && + includes[n].find_first_of(":") == string::npos) { includes[n] = path + includes[n]; } // Include the script section int r = AddSectionFromFile(includes[n].c_str()); - if( r < 0 ) + if (r < 0) return r; } } @@ -600,188 +522,156 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length return 0; } -int CScriptBuilder::Build() -{ +int CScriptBuilder::Build() { int r = module->Build(); - if( r < 0 ) + if (r < 0) return r; #if AS_PROCESS_METADATA == 1 // After the script has been built, the metadata strings should be // stored for later lookup by function id, type id, and variable index - for( int n = 0; n < (int)foundDeclarations.size(); n++ ) - { - SMetadataDecl *decl = &foundDeclarations[n]; + for (int n = 0; n < (int)foundDeclarations.size(); n++) { + SMetadataDecl* decl = &foundDeclarations[n]; module->SetDefaultNamespace(decl->nameSpace.c_str()); - if( decl->type == MDT_TYPE ) - { + if (decl->type == MDT_TYPE) { // Find the type id int typeId = module->GetTypeIdByDecl(decl->declaration.c_str()); - assert( typeId >= 0 ); - if( typeId >= 0 ) - typeMetadataMap.insert(map >::value_type(typeId, decl->metadata)); - } - else if( decl->type == MDT_FUNC ) - { - if( decl->parentClass == "" ) - { + assert(typeId >= 0); + if (typeId >= 0) + typeMetadataMap.insert(map>::value_type(typeId, decl->metadata)); + } else if (decl->type == MDT_FUNC) { + if (decl->parentClass == "") { // Find the function id - asIScriptFunction *func = module->GetFunctionByDecl(decl->declaration.c_str()); - assert( func ); - if( func ) - funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); - } - else - { + asIScriptFunction* func = module->GetFunctionByDecl(decl->declaration.c_str()); + assert(func); + if (func) + funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); + } else { // Find the method id int typeId = module->GetTypeIdByDecl(decl->parentClass.c_str()); - assert( typeId > 0 ); + assert(typeId > 0); map::iterator it = classMetadataMap.find(typeId); - if( it == classMetadataMap.end() ) - { + if (it == classMetadataMap.end()) { classMetadataMap.insert(map::value_type(typeId, SClassMetadata(decl->parentClass))); it = classMetadataMap.find(typeId); } - asITypeInfo *type = engine->GetTypeInfoById(typeId); - asIScriptFunction *func = type->GetMethodByDecl(decl->declaration.c_str()); - assert( func ); - if( func ) - it->second.funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); + asITypeInfo* type = engine->GetTypeInfoById(typeId); + asIScriptFunction* func = type->GetMethodByDecl(decl->declaration.c_str()); + assert(func); + if (func) + it->second.funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); } - } - else if( decl->type == MDT_VIRTPROP ) - { - if( decl->parentClass == "" ) - { + } else if (decl->type == MDT_VIRTPROP) { + if (decl->parentClass == "") { // Find the global virtual property accessors - asIScriptFunction *func = module->GetFunctionByName(("get_" + decl->declaration).c_str()); - if( func ) - funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); + asIScriptFunction* func = module->GetFunctionByName(("get_" + decl->declaration).c_str()); + if (func) + funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); func = module->GetFunctionByName(("set_" + decl->declaration).c_str()); - if( func ) - funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); - } - else - { + if (func) + funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); + } else { // Find the method virtual property accessors int typeId = module->GetTypeIdByDecl(decl->parentClass.c_str()); - assert( typeId > 0 ); + assert(typeId > 0); map::iterator it = classMetadataMap.find(typeId); - if( it == classMetadataMap.end() ) - { + if (it == classMetadataMap.end()) { classMetadataMap.insert(map::value_type(typeId, SClassMetadata(decl->parentClass))); it = classMetadataMap.find(typeId); } - asITypeInfo *type = engine->GetTypeInfoById(typeId); - asIScriptFunction *func = type->GetMethodByName(("get_" + decl->declaration).c_str()); - if( func ) - it->second.funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); + asITypeInfo* type = engine->GetTypeInfoById(typeId); + asIScriptFunction* func = type->GetMethodByName(("get_" + decl->declaration).c_str()); + if (func) + it->second.funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); func = type->GetMethodByName(("set_" + decl->declaration).c_str()); - if( func ) - it->second.funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); + if (func) + it->second.funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); } - } - else if( decl->type == MDT_VAR ) - { - if( decl->parentClass == "" ) - { + } else if (decl->type == MDT_VAR) { + if (decl->parentClass == "") { // Find the global variable index int varIdx = module->GetGlobalVarIndexByName(decl->declaration.c_str()); - assert( varIdx >= 0 ); - if( varIdx >= 0 ) - varMetadataMap.insert(map >::value_type(varIdx, decl->metadata)); - } - else - { - int typeId = module->GetTypeIdByDecl(decl->parentClass.c_str()); - assert( typeId > 0 ); - - // Add the classes if needed - map::iterator it = classMetadataMap.find(typeId); - if( it == classMetadataMap.end() ) - { - classMetadataMap.insert(map::value_type(typeId, SClassMetadata(decl->parentClass))); - it = classMetadataMap.find(typeId); - } - - // Add the variable to class - asITypeInfo *objectType = engine->GetTypeInfoById(typeId); - int idx = -1; - - // Search through all properties to get proper declaration - for( asUINT i = 0; i < (asUINT)objectType->GetPropertyCount(); ++i ) - { - const char *name; - objectType->GetProperty(i, &name); - if( decl->declaration == name ) - { - idx = i; - break; - } - } - - // If found, add it - assert( idx >= 0 ); - if( idx >= 0 ) it->second.varMetadataMap.insert(map >::value_type(idx, decl->metadata)); - } - } - else if (decl->type == MDT_FUNC_OR_VAR) - { - if (decl->parentClass == "") - { - // Find the global variable index - int varIdx = module->GetGlobalVarIndexByName(decl->name.c_str()); + assert(varIdx >= 0); if (varIdx >= 0) - varMetadataMap.insert(map >::value_type(varIdx, decl->metadata)); - else - { - asIScriptFunction *func = module->GetFunctionByDecl(decl->declaration.c_str()); - assert(func); - if (func) - funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); - } - } - else - { + varMetadataMap.insert(map>::value_type(varIdx, decl->metadata)); + } else { int typeId = module->GetTypeIdByDecl(decl->parentClass.c_str()); assert(typeId > 0); // Add the classes if needed map::iterator it = classMetadataMap.find(typeId); - if (it == classMetadataMap.end()) - { + if (it == classMetadataMap.end()) { classMetadataMap.insert(map::value_type(typeId, SClassMetadata(decl->parentClass))); it = classMetadataMap.find(typeId); } // Add the variable to class - asITypeInfo *objectType = engine->GetTypeInfoById(typeId); + asITypeInfo* objectType = engine->GetTypeInfoById(typeId); int idx = -1; // Search through all properties to get proper declaration - for (asUINT i = 0; i < (asUINT)objectType->GetPropertyCount(); ++i) - { - const char *name; + for (asUINT i = 0; i < (asUINT)objectType->GetPropertyCount(); ++i) { + const char* name; objectType->GetProperty(i, &name); - if (decl->name == name) - { + if (decl->declaration == name) { idx = i; break; } } // If found, add it - if (idx >= 0) - it->second.varMetadataMap.insert(map >::value_type(idx, decl->metadata)); - else - { - // Look for the matching method instead - asITypeInfo *type = engine->GetTypeInfoById(typeId); - asIScriptFunction *func = type->GetMethodByDecl(decl->declaration.c_str()); + assert(idx >= 0); + if (idx >= 0) + it->second.varMetadataMap.insert(map>::value_type(idx, decl->metadata)); + } + } else if (decl->type == MDT_FUNC_OR_VAR) { + if (decl->parentClass == "") { + // Find the global variable index + int varIdx = module->GetGlobalVarIndexByName(decl->name.c_str()); + if (varIdx >= 0) + varMetadataMap.insert(map>::value_type(varIdx, decl->metadata)); + else { + asIScriptFunction* func = module->GetFunctionByDecl(decl->declaration.c_str()); + assert(func); if (func) - it->second.funcMetadataMap.insert(map >::value_type(func->GetId(), decl->metadata)); + funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); + } + } else { + int typeId = module->GetTypeIdByDecl(decl->parentClass.c_str()); + assert(typeId > 0); + + // Add the classes if needed + map::iterator it = classMetadataMap.find(typeId); + if (it == classMetadataMap.end()) { + classMetadataMap.insert(map::value_type(typeId, SClassMetadata(decl->parentClass))); + it = classMetadataMap.find(typeId); + } + + // Add the variable to class + asITypeInfo* objectType = engine->GetTypeInfoById(typeId); + int idx = -1; + + // Search through all properties to get proper declaration + for (asUINT i = 0; i < (asUINT)objectType->GetPropertyCount(); ++i) { + const char* name; + objectType->GetProperty(i, &name); + if (decl->name == name) { + idx = i; + break; + } + } + + // If found, add it + if (idx >= 0) + it->second.varMetadataMap.insert(map>::value_type(idx, decl->metadata)); + else { + // Look for the matching method instead + asITypeInfo* type = engine->GetTypeInfoById(typeId); + asIScriptFunction* func = type->GetMethodByDecl(decl->declaration.c_str()); + if (func) + it->second.funcMetadataMap.insert(map>::value_type(func->GetId(), decl->metadata)); } } } @@ -792,54 +682,45 @@ int CScriptBuilder::Build() return 0; } -int CScriptBuilder::SkipStatement(int pos) -{ +int CScriptBuilder::SkipStatement(int pos) { asUINT len = 0; // Skip until ; or { whichever comes first - while( pos < (int)modifiedScript.length() && modifiedScript[pos] != ';' && modifiedScript[pos] != '{' ) - { + while (pos < (int)modifiedScript.length() && modifiedScript[pos] != ';' && modifiedScript[pos] != '{') { engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); pos += len; } // Skip entire statement block - if( pos < (int)modifiedScript.length() && modifiedScript[pos] == '{' ) - { + if (pos < (int)modifiedScript.length() && modifiedScript[pos] == '{') { pos += 1; // Find the end of the statement block int level = 1; - while( level > 0 && pos < (int)modifiedScript.size() ) - { + while (level > 0 && pos < (int)modifiedScript.size()) { asETokenClass t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if( t == asTC_KEYWORD ) - { - if( modifiedScript[pos] == '{' ) + if (t == asTC_KEYWORD) { + if (modifiedScript[pos] == '{') level++; - else if( modifiedScript[pos] == '}' ) + else if (modifiedScript[pos] == '}') level--; } pos += len; } - } - else + } else pos += 1; return pos; } // Overwrite all code with blanks until the matching #endif -int CScriptBuilder::ExcludeCode(int pos) -{ +int CScriptBuilder::ExcludeCode(int pos) { asUINT len = 0; int nested = 0; - while( pos < (int)modifiedScript.size() ) - { + while (pos < (int)modifiedScript.size()) { engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if( modifiedScript[pos] == '#' ) - { + if (modifiedScript[pos] == '#') { modifiedScript[pos] = ' '; pos++; @@ -849,21 +730,15 @@ int CScriptBuilder::ExcludeCode(int pos) token.assign(&modifiedScript[pos], len); OverwriteCode(pos, len); - if( token == "if" ) - { + if (token == "if") { nested++; - } - else if( token == "endif" ) - { - if( nested-- == 0 ) - { + } else if (token == "endif") { + if (nested-- == 0) { pos += len; break; } } - } - else if( modifiedScript[pos] != '\n' ) - { + } else if (modifiedScript[pos] != '\n') { OverwriteCode(pos, len); } pos += len; @@ -873,25 +748,21 @@ int CScriptBuilder::ExcludeCode(int pos) } // Overwrite all characters except line breaks with blanks -void CScriptBuilder::OverwriteCode(int start, int len) -{ - char *code = &modifiedScript[start]; - for( int n = 0; n < len; n++ ) - { - if( *code != '\n' ) +void CScriptBuilder::OverwriteCode(int start, int len) { + char* code = &modifiedScript[start]; + for (int n = 0; n < len; n++) { + if (*code != '\n') *code = ' '; code++; } } #if AS_PROCESS_METADATA == 1 -int CScriptBuilder::ExtractMetadata(int pos, vector &metadata) -{ +int CScriptBuilder::ExtractMetadata(int pos, vector& metadata) { metadata.clear(); // Extract all metadata. They can be separated by whitespace and comments - for (;;) - { + for (;;) { string metadataString = ""; // Overwrite the metadata with space characters to allow compilation @@ -902,11 +773,9 @@ int CScriptBuilder::ExtractMetadata(int pos, vector &metadata) int level = 1; asUINT len = 0; - while (level > 0 && pos < (int)modifiedScript.size()) - { + while (level > 0 && pos < (int)modifiedScript.size()) { asETokenClass t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - if (t == asTC_KEYWORD) - { + if (t == asTC_KEYWORD) { if (modifiedScript[pos] == '[') level++; else if (modifiedScript[pos] == ']') @@ -928,8 +797,7 @@ int CScriptBuilder::ExtractMetadata(int pos, vector &metadata) // Check for more metadata. Possibly separated by comments asETokenClass t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - while (t == asTC_COMMENT || t == asTC_WHITESPACE) - { + while (t == asTC_COMMENT || t == asTC_WHITESPACE) { pos += len; t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); } @@ -941,8 +809,7 @@ int CScriptBuilder::ExtractMetadata(int pos, vector &metadata) return pos; } -int CScriptBuilder::ExtractDeclaration(int pos, string &name, string &declaration, int &type) -{ +int CScriptBuilder::ExtractDeclaration(int pos, string& name, string& declaration, int& type) { declaration = ""; type = 0; @@ -953,40 +820,33 @@ int CScriptBuilder::ExtractDeclaration(int pos, string &name, string &declaratio asETokenClass t = asTC_WHITESPACE; // Skip white spaces, comments, and leading decorators - do - { + do { pos += len; t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); token.assign(&modifiedScript[pos], len); - } while ( t == asTC_WHITESPACE || t == asTC_COMMENT || - token == "private" || token == "protected" || - token == "shared" || token == "external" || - token == "final" || token == "abstract" ); + } while (t == asTC_WHITESPACE || t == asTC_COMMENT || + token == "private" || token == "protected" || + token == "shared" || token == "external" || + token == "final" || token == "abstract"); // We're expecting, either a class, interface, function, or variable declaration - if( t == asTC_KEYWORD || t == asTC_IDENTIFIER ) - { + if (t == asTC_KEYWORD || t == asTC_IDENTIFIER) { token.assign(&modifiedScript[pos], len); - if( token == "interface" || token == "class" || token == "enum" ) - { + if (token == "interface" || token == "class" || token == "enum") { // Skip white spaces and comments - do - { + do { pos += len; t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); - } while ( t == asTC_WHITESPACE || t == asTC_COMMENT ); + } while (t == asTC_WHITESPACE || t == asTC_COMMENT); - if( t == asTC_IDENTIFIER ) - { + if (t == asTC_IDENTIFIER) { type = MDT_TYPE; declaration.assign(&modifiedScript[pos], len); pos += len; return pos; } - } - else - { - // For function declarations, store everything up to the start of the + } else { + // For function declarations, store everything up to the start of the // statement block, except for succeeding decorators (final, override, etc) // For variable declaration store just the name as there can only be one @@ -997,65 +857,49 @@ int CScriptBuilder::ExtractDeclaration(int pos, string &name, string &declaratio int nestedParenthesis = 0; declaration.append(&modifiedScript[pos], len); pos += len; - for(; pos < (int)modifiedScript.size();) - { + for (; pos < (int)modifiedScript.size();) { t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); token.assign(&modifiedScript[pos], len); - if (t == asTC_KEYWORD) - { - if (token == "{" && nestedParenthesis == 0) - { - if (hasParenthesis) - { + if (t == asTC_KEYWORD) { + if (token == "{" && nestedParenthesis == 0) { + if (hasParenthesis) { // We've found the end of a function signature type = MDT_FUNC; - } - else - { + } else { // We've found a virtual property. Just keep the name declaration = name; type = MDT_VIRTPROP; } return pos; } - if ((token == "=" && !hasParenthesis) || token == ";") - { - if (hasParenthesis) - { + if ((token == "=" && !hasParenthesis) || token == ";") { + if (hasParenthesis) { // The declaration is ambigous. It can be a variable with initialization, or a function prototype type = MDT_FUNC_OR_VAR; - } - else - { + } else { // Substitute the declaration with just the name declaration = name; type = MDT_VAR; } return pos; - } - else if (token == "(") - { + } else if (token == "(") { nestedParenthesis++; // This is the first parenthesis we encounter. If the parenthesis isn't followed // by a statement block, then this is a variable declaration, in which case we // should only store the type and name of the variable, not the initialization parameters. hasParenthesis = true; - } - else if (token == ")") - { + } else if (token == ")") { nestedParenthesis--; } - } - else if( t == asTC_IDENTIFIER ) - { + } else if (t == asTC_IDENTIFIER) { // If a parenthesis is already found then the name is already known so it must not be overwritten - if( !hasParenthesis ) + if (!hasParenthesis) name = token; } // Skip trailing decorators - if( !hasParenthesis || nestedParenthesis > 0 || t != asTC_IDENTIFIER || (token != "final" && token != "override" && token != "delete" && token != "property")) + if (!hasParenthesis || nestedParenthesis > 0 || t != asTC_IDENTIFIER || (token != "final" && token != "override" && token != "delete" && token != "property")) declaration += token; pos += len; @@ -1066,56 +910,53 @@ int CScriptBuilder::ExtractDeclaration(int pos, string &name, string &declaratio return start; } -vector CScriptBuilder::GetMetadataForType(int typeId) -{ - map >::iterator it = typeMetadataMap.find(typeId); - if( it != typeMetadataMap.end() ) +vector CScriptBuilder::GetMetadataForType(int typeId) { + map>::iterator it = typeMetadataMap.find(typeId); + if (it != typeMetadataMap.end()) return it->second; return vector(); } -vector CScriptBuilder::GetMetadataForFunc(asIScriptFunction *func) -{ - if( func ) - { - map >::iterator it = funcMetadataMap.find(func->GetId()); - if( it != funcMetadataMap.end() ) +vector CScriptBuilder::GetMetadataForFunc(asIScriptFunction* func) { + if (func) { + map>::iterator it = funcMetadataMap.find(func->GetId()); + if (it != funcMetadataMap.end()) return it->second; } return vector(); } -vector CScriptBuilder::GetMetadataForVar(int varIdx) -{ - map >::iterator it = varMetadataMap.find(varIdx); - if( it != varMetadataMap.end() ) +vector CScriptBuilder::GetMetadataForVar(int varIdx) { + map>::iterator it = varMetadataMap.find(varIdx); + if (it != varMetadataMap.end()) return it->second; return vector(); } -vector CScriptBuilder::GetMetadataForTypeProperty(int typeId, int varIdx) -{ +vector CScriptBuilder::GetMetadataForTypeProperty(int typeId, int varIdx) { map::iterator typeIt = classMetadataMap.find(typeId); - if(typeIt == classMetadataMap.end()) return vector(); + if (typeIt == classMetadataMap.end()) + return vector(); - map >::iterator propIt = typeIt->second.varMetadataMap.find(varIdx); - if(propIt == typeIt->second.varMetadataMap.end()) return vector(); + map>::iterator propIt = typeIt->second.varMetadataMap.find(varIdx); + if (propIt == typeIt->second.varMetadataMap.end()) + return vector(); return propIt->second; } -vector CScriptBuilder::GetMetadataForTypeMethod(int typeId, asIScriptFunction *method) -{ - if( method ) - { +vector CScriptBuilder::GetMetadataForTypeMethod(int typeId, asIScriptFunction* method) { + if (method) { map::iterator typeIt = classMetadataMap.find(typeId); - if (typeIt == classMetadataMap.end()) return vector(); + if (typeIt == classMetadataMap.end()) + return vector(); - map >::iterator methodIt = typeIt->second.funcMetadataMap.find(method->GetId()); - if(methodIt == typeIt->second.funcMetadataMap.end()) return vector(); + map>::iterator methodIt = typeIt->second.funcMetadataMap.find(method->GetId()); + if (methodIt == typeIt->second.funcMetadataMap.end()) + return vector(); return methodIt->second; } @@ -1124,36 +965,32 @@ vector CScriptBuilder::GetMetadataForTypeMethod(int typeId, asIScriptFun } #endif -string GetAbsolutePath(const string &file) -{ +string GetAbsolutePath(const string& file) { string str = file; // If this is a relative path, complement it with the current path - if( !((str.length() > 0 && (str[0] == '/' || str[0] == '\\')) || - str.find(":") != string::npos) ) - { + if (!((str.length() > 0 && (str[0] == '/' || str[0] == '\\')) || + str.find(":") != string::npos)) { str = GetCurrentDir() + "/" + str; } // Replace backslashes for forward slashes size_t pos = 0; - while( (pos = str.find("\\", pos)) != string::npos ) + while ((pos = str.find("\\", pos)) != string::npos) str[pos] = '/'; // Replace /./ with / pos = 0; - while( (pos = str.find("/./", pos)) != string::npos ) - str.erase(pos+1, 2); + while ((pos = str.find("/./", pos)) != string::npos) + str.erase(pos + 1, 2); // For each /../ remove the parent dir and the /../ pos = 0; - while( (pos = str.find("/../")) != string::npos ) - { - size_t pos2 = str.rfind("/", pos-1); - if( pos2 != string::npos ) - str.erase(pos2, pos+3-pos2); - else - { + while ((pos = str.find("/../")) != string::npos) { + size_t pos2 = str.rfind("/", pos - 1); + if (pos2 != string::npos) + str.erase(pos2, pos + 3 - pos2); + else { // The path is invalid break; } @@ -1162,14 +999,12 @@ string GetAbsolutePath(const string &file) return str; } -string GetCurrentDir() -{ +string GetCurrentDir() { char buffer[1024]; #if defined(_MSC_VER) || defined(_WIN32) - #ifdef _WIN32_WCE +#ifdef _WIN32_WCE static TCHAR apppath[MAX_PATH] = TEXT(""); - if (!apppath[0]) - { + if (!apppath[0]) { GetModuleFileName(NULL, apppath, MAX_PATH); int appLen = _tcslen(apppath); @@ -1179,9 +1014,8 @@ string GetCurrentDir() // the path part of the exe's full-path filename // Safety is that we make sure not to walk off the front of the // array (in case the path is nothing more than a filename) - while (appLen > 1) - { - if (apppath[appLen-1] == TEXT('\\')) + while (appLen > 1) { + if (apppath[appLen - 1] == TEXT('\\')) break; appLen--; } @@ -1189,25 +1023,25 @@ string GetCurrentDir() // Terminate the string after the trailing backslash apppath[appLen] = TEXT('\0'); } - #ifdef _UNICODE - wcstombs(buffer, apppath, min(1024, wcslen(apppath)*sizeof(wchar_t))); - #else +#ifdef _UNICODE + wcstombs(buffer, apppath, min(1024, wcslen(apppath) * sizeof(wchar_t))); +#else memcpy(buffer, apppath, min(1024, strlen(apppath))); - #endif +#endif return buffer; - #elif defined(__S3E__) +#elif defined(__S3E__) // Marmalade uses its own portable C library return getcwd(buffer, (int)1024); - #elif _XBOX_VER >= 200 +#elif _XBOX_VER >= 200 // XBox 360 doesn't support the getcwd function, just use the root folder return "game:/"; - #elif defined(_M_ARM) +#elif defined(_M_ARM) // TODO: How to determine current working dir on Windows Phone? return ""; - #else +#else return _getcwd(buffer, (int)1024); - #endif // _MSC_VER +#endif // _MSC_VER #elif defined(__APPLE__) || defined(__linux__) return getcwd(buffer, 1024); #else @@ -1216,5 +1050,3 @@ string GetCurrentDir() } END_AS_NAMESPACE - - diff --git a/DeerStudio/headers/DeerStudio/AngelScriptEngine.h b/DeerStudio/headers/DeerStudio/AngelScriptEngine.h index f0e91ea..901d91e 100644 --- a/DeerStudio/headers/DeerStudio/AngelScriptEngine.h +++ b/DeerStudio/headers/DeerStudio/AngelScriptEngine.h @@ -1,4 +1,5 @@ #pragma once +#include "DeerRender/Tools/Memory.h" #include "DeerRender/Tools/Path.h" #include #include @@ -9,8 +10,10 @@ class asIScriptModule; class asIScriptContext; class asIScriptObject; class asIScriptFunction; +class asIScriptFunction; class asITypeInfo; class CScriptBuilder; +class asIScriptGeneric; namespace Deer { namespace AngelScriptEngine { @@ -20,6 +23,12 @@ namespace Deer { void render(); void deinitialize(); + struct ServiceExposedFunctionData { + asIScriptFunction* exposedFunction = nullptr; + asIScriptObject* exposedObject = nullptr; + std::string exposedFunctionName; + }; + struct Service { public: Service(asITypeInfo*); @@ -34,14 +43,25 @@ namespace Deer { void update(); void shutdown(); + void updateTypes(asIScriptModule*); + void registerApiExpose(); + protected: asITypeInfo* type = nullptr; asIScriptObject* object = nullptr; asIScriptFunction* updateFunction = nullptr; asIScriptFunction* initFunction = nullptr; asIScriptFunction* shutdownFunction = nullptr; + std::vector> exposedFunctions; + + std::string typeName; + + private: + void registerExposedFunction(asIScriptFunction*); }; + void service_exposed_generic_call(asIScriptGeneric*); + struct Panel : public Service { public: Panel(asITypeInfo*); @@ -52,6 +72,7 @@ namespace Deer { Panel& operator=(Panel&&) = default; void render(); + void updateTypes(asIScriptModule*); private: asIScriptFunction* renderFunction; @@ -93,7 +114,8 @@ namespace Deer { void render(); void shutdown(); - void extractTypes(); + void extract(asIScriptModule*); + void updateTypes(); inline void invalidate() { state = ModuleState::ExecutionError; } diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/Module.cpp b/DeerStudio/src/DeerStudio/AngelScriptEngine/Module.cpp index 1d83836..9b31c3a 100644 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/Module.cpp +++ b/DeerStudio/src/DeerStudio/AngelScriptEngine/Module.cpp @@ -7,27 +7,45 @@ namespace Deer { namespace AngelScriptEngine { Module::Module(const ModuleDescription& _mi) : moduleInfo(_mi) {} - void Module::extractTypes() { + void Module::extract(asIScriptModule* _module) { if (state != ModuleState::Built) return; - angelscriptModule = AngelScriptEngine::scriptEngine->GetModule(moduleInfo.moduleName.c_str()); - uint32_t typeCount = angelscriptModule->GetObjectTypeCount(); + angelscriptModule = _module; + scriptEngine->SetDefaultNamespace(moduleInfo.moduleName.c_str()); + uint32_t typeCount = angelscriptModule->GetObjectTypeCount(); for (uint32_t typeId = 0; typeId < typeCount; typeId++) { asITypeInfo* typeInfo = angelscriptModule->GetObjectTypeByIndex(typeId); if (ImplementsInterface(typeInfo, serviceBaseType)) { services.push_back({typeInfo}); + services.back().registerApiExpose(); } else if (ImplementsInterface(typeInfo, panelBaseType)) { panels.push_back({typeInfo}); + panels.back().registerApiExpose(); } } + scriptEngine->SetDefaultNamespace(""); + } + + void Module::updateTypes() { + if (state != ModuleState::Built) + return; + + angelscriptModule = AngelScriptEngine::scriptEngine->GetModule(moduleInfo.moduleName.c_str()); + + for (Service& service : services) + service.updateTypes(angelscriptModule); + + for (Panel& panel : panels) + panel.updateTypes(angelscriptModule); } void Module::init() { if (state != ModuleState::Built) return; + angelscriptModule->BindAllImportedFunctions(); for (Service& service : services) diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleLoading.cpp b/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleLoading.cpp index 62d6f99..c24ccb4 100644 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleLoading.cpp +++ b/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleLoading.cpp @@ -44,10 +44,12 @@ namespace Deer { } bool AngelScriptEngine::loadModule(Module& module) { + if (module.state != ModuleState::NotBuilt) + return false; + int err; module.state = ModuleState::Building; - DEER_CORE_TRACE("Loading module {}", module.moduleInfo.moduleName); for (const std::string& dependency : module.moduleInfo.module_requires) { if (!module_id.contains(dependency)) { DEER_CORE_ERROR("Failed to find dependency {} for module {}", @@ -79,6 +81,7 @@ namespace Deer { } } } + DEER_CORE_TRACE("Loading module {}", module.moduleInfo.moduleName); scriptBuilder.StartNewModule(scriptEngine, module.moduleInfo.moduleName.c_str()); if (err < 0) { @@ -109,6 +112,8 @@ namespace Deer { } module.state = ModuleState::Built; + module.extract(as_module); + return true; } @@ -151,12 +156,16 @@ namespace Deer { desc.modulePath = path.string(); + if (module_id.contains(desc.moduleName)) { + DEER_CORE_ERROR("Module name duplicated {}", path.string().c_str()); + return; + } + module_id[desc.moduleName] = modules.size(); modules.push_back({desc}); } void AngelScriptEngine::loadModules() { - generateAngelscriptPredefined(); const Path path = Path("Editor") / Path("Modules"); if (!fs::exists(path) || !fs::is_directory(path)) { @@ -173,14 +182,15 @@ namespace Deer { } for (Module& module : modules) { - saveAngelscriptPredefined(module.moduleInfo.modulePath); if (module.state == ModuleState::NotBuilt) { loadModule(module); + generateAngelscriptPredefined(); } + saveAngelscriptPredefined(module.moduleInfo.modulePath); } for (Module& module : modules) { - module.extractTypes(); + module.updateTypes(); } } } // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/Panel.cpp b/DeerStudio/src/DeerStudio/AngelScriptEngine/Panel.cpp index 8320cf0..690ddd4 100644 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/Panel.cpp +++ b/DeerStudio/src/DeerStudio/AngelScriptEngine/Panel.cpp @@ -12,6 +12,13 @@ namespace Deer { menuBarFunction = type->GetMethodByDecl("void menuBar()"); } + void Panel::updateTypes(asIScriptModule* typeInfo) { + Service::updateTypes(typeInfo); + + renderFunction = type->GetMethodByDecl("void render()"); + menuBarFunction = type->GetMethodByDecl("void menuBar()"); + } + void Panel::render() { // IMPLEMENT REMOVE PADDING if (menuBarFunction) { diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/PredefinedAngelScript.cpp b/DeerStudio/src/DeerStudio/AngelScriptEngine/PredefinedAngelScript.cpp index a6cc7b4..32f5674 100644 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/PredefinedAngelScript.cpp +++ b/DeerStudio/src/DeerStudio/AngelScriptEngine/PredefinedAngelScript.cpp @@ -4,6 +4,7 @@ // https://github.com/sashi0034/angel-lsp/blob/main/examples/OpenSiv3D/make_predefined.cpp ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#include "DeerRender/Log.h" #include "DeerStudio/AngelScriptEngine.h" #include "angelscript.h" @@ -71,6 +72,43 @@ void printEnumList(const asIScriptEngine& engine) { } } +void writeParameters(asIScriptFunction* function) { + for (int n = 0; n < function->GetParamCount(); n++) { + int typeId; + asDWORD flags; + const char* name; + const char* defaultArgument; + + function->GetParam(n, &typeId, &flags, &name, &defaultArgument); + + if (typeId == -1) { + stream << "?"; + } else { + asITypeInfo* ti = function->GetEngine()->GetTypeInfoById(typeId); + if (ti && (ti->GetFlags() & asOBJ_FUNCDEF)) { + stream << ti->GetName(); + } else { + const char* typeName = function->GetEngine()->GetTypeDeclaration(typeId, false); + stream << typeName; + } + } + + if (flags & asTM_INREF) + stream << " &in "; + else if (flags & asTM_OUTREF) + stream << " &out "; + else if (flags & asTM_INOUTREF) + stream << " &inout "; + + if (name) { + stream << " " << name; + } + + if (n != function->GetParamCount() - 1) + stream << ", "; + } +} + void printClassTypeList(const asIScriptEngine& engine) { for (int i = 0; i < engine.GetObjectTypeCount(); ++i) { asITypeInfo* t = engine.GetObjectTypeByIndex(i); @@ -109,7 +147,9 @@ void printClassTypeList(const asIScriptEngine& engine) { for (int j = 0; j < t->GetFactoryCount(); ++j) { asIScriptFunction* f = t->GetFactoryByIndex(j); - stream << "\t" << f->GetDeclaration(false, false, true) << ";\n"; + stream << "\t" << t->GetName() << "("; + writeParameters(f); + stream << ");\n"; } for (int j = 0; j < t->GetBehaviourCount(); ++j) { @@ -125,7 +165,21 @@ void printClassTypeList(const asIScriptEngine& engine) { for (int j = 0; j < t->GetMethodCount(); ++j) { const auto m = t->GetMethodByIndex(j); - stream << "\t" << m->GetDeclaration(false, false, true); + + stream << "\t"; + int methodReturnId = m->GetReturnTypeId(); + if (methodReturnId == -1) { + stream << "? "; + } else { + stream << t->GetEngine()->GetTypeDeclaration(methodReturnId) << " "; + } + + stream << m->GetName() << "("; + + writeParameters(m); + stream << ")"; + + // stream << "\t" << m->GetDeclaration(false, false, true); if (m->IsProperty()) stream << " property"; diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/Service.cpp b/DeerStudio/src/DeerStudio/AngelScriptEngine/Service.cpp index 757aad6..0660391 100644 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/Service.cpp +++ b/DeerStudio/src/DeerStudio/AngelScriptEngine/Service.cpp @@ -1,8 +1,11 @@ #include "DeerStudio/AngelScriptEngine.h" #include "DeerStudio/AngelScriptEngine/ErrorHandle.h" + #include "angelscript.h" +#include "scriptbuilder.h" #include #include +#include namespace Deer { namespace AngelScriptEngine { @@ -27,6 +30,11 @@ namespace Deer { object->AddRef(); AS_CHECK(scriptContext->Unprepare()); + for (Scope& exposedFunction : exposedFunctions) { + exposedFunction->exposedFunction = type->GetMethodByName(exposedFunction->exposedFunctionName.c_str()); + exposedFunction->exposedObject = object; + } + if (!initFunction) return; @@ -37,6 +45,214 @@ namespace Deer { AS_CHECK(scriptContext->Unprepare()); } + void Service::registerApiExpose() { + int functionCount = type->GetMethodCount(); + + for (int i = 0; i < functionCount; i++) { + asIScriptFunction* function = type->GetMethodByIndex(i); + + bool containsExposeMetadata = false; + std::vector metadata = scriptBuilder.GetMetadataForTypeMethod(type->GetTypeId(), function); + + for (std::string& meta : metadata) { + if (meta == "Expose") { + containsExposeMetadata = true; + break; + } + } + + if (!containsExposeMetadata) + continue; + + registerExposedFunction(function); + } + } + + void Service::registerExposedFunction(asIScriptFunction* function) { + asITypeInfo* returnType = scriptEngine->GetTypeInfoById(function->GetReturnTypeId()); + if (returnType && returnType->GetModule()) { + DEER_CORE_ERROR("Error registering function {}, you can not register engine non specific type for return type", function->GetDeclaration()); + return; + } + + std::string declaration; + declaration = scriptEngine->GetTypeDeclaration(function->GetReturnTypeId(), false); + + declaration += " "; + declaration += function->GetName(); + declaration += "("; + + int paramCount = function->GetParamCount(); + for (int n = 0; n < paramCount; n++) { + int typeId; + asDWORD flags; + const char* name; + const char* defaultArgument; + + function->GetParam(n, &typeId, &flags, &name, &defaultArgument); + asITypeInfo* paramType = scriptEngine->GetTypeInfoById(typeId); + if (paramType && paramType->GetModule()) { + DEER_CORE_ERROR("Error registering function {}, you can not register engine non specific type in parameter", function->GetDeclaration()); + return; + } + + const char* typeName = scriptEngine->GetTypeDeclaration(typeId, false); + declaration += typeName; + + if (flags & asTM_INREF) + declaration += " in "; + else if (flags & asTM_OUTREF) + declaration += " out "; + else if (flags & asTM_INOUTREF) + declaration += " inout "; + + if (name) { + declaration += " "; + declaration += name; + } + + if (defaultArgument) { + declaration += "= "; + declaration += defaultArgument; + } + + if (n != paramCount - 1) + declaration += ", "; + } + + declaration += ")"; + + exposedFunctions.push_back(MakeScope()); + ServiceExposedFunctionData* exposedFunctionData = exposedFunctions.back().get(); + + exposedFunctionData->exposedFunction = function; + exposedFunctionData->exposedFunctionName = function->GetName(); + exposedFunctionData->exposedObject = object; + + DEER_CORE_TRACE("Registering {}", declaration.c_str()); + scriptEngine->RegisterGlobalFunction(declaration.c_str(), asFUNCTION(service_exposed_generic_call), asCALL_GENERIC, exposedFunctionData); + } + + void service_exposed_generic_call(asIScriptGeneric* genericFun) { + AS_CHECK(scriptContext->PushState()); + + ServiceExposedFunctionData* data = (ServiceExposedFunctionData*)genericFun->GetAuxiliary(); + + AS_CHECK(scriptContext->Prepare(data->exposedFunction)); + AS_CHECK(scriptContext->SetObject(data->exposedObject)); + + int argCount = genericFun->GetArgCount(); + for (int i = 0; i < argCount; ++i) { + int typeId = genericFun->GetArgTypeId(i); + + if (typeId & asTYPEID_OBJHANDLE) { + void* obj = genericFun->GetAddressOfArg(i); + AS_CHECK(scriptContext->SetArgAddress(i, obj)); + } else if (typeId & asTYPEID_MASK_OBJECT) { + void* obj = genericFun->GetArgObject(i); + AS_CHECK(scriptContext->SetArgObject(i, obj)); + } else { + switch (typeId) { + case asTYPEID_BOOL: + case asTYPEID_INT8: + case asTYPEID_UINT8: + AS_CHECK(scriptContext->SetArgByte(i, genericFun->GetArgByte(i))); + break; + + case asTYPEID_INT16: + case asTYPEID_UINT16: + AS_CHECK(scriptContext->SetArgWord(i, genericFun->GetArgWord(i))); + break; + + case asTYPEID_INT32: + case asTYPEID_UINT32: + AS_CHECK(scriptContext->SetArgDWord(i, genericFun->GetArgDWord(i))); + break; + + case asTYPEID_INT64: + case asTYPEID_UINT64: + AS_CHECK(scriptContext->SetArgQWord(i, genericFun->GetArgQWord(i))); + break; + + case asTYPEID_FLOAT: + AS_CHECK(scriptContext->SetArgFloat(i, genericFun->GetArgFloat(i))); + break; + + case asTYPEID_DOUBLE: + AS_CHECK(scriptContext->SetArgDouble(i, genericFun->GetArgDouble(i))); + break; + + default: + AS_CHECK(scriptContext->SetArgObject(i, genericFun->GetArgObject(i))); + break; + } + } + } + + AS_CHECK(scriptContext->Execute()); + int retTypeId = genericFun->GetReturnTypeId(); + + if (retTypeId == asTYPEID_VOID) { + } else if (retTypeId & asTYPEID_OBJHANDLE) { + void* obj = scriptContext->GetReturnObject(); + genericFun->SetReturnObject(obj); + } else if (retTypeId & asTYPEID_MASK_OBJECT) { + void* obj = scriptContext->GetReturnObject(); + genericFun->SetReturnObject(obj); + } else { + switch (retTypeId) { + case asTYPEID_BOOL: + case asTYPEID_INT8: + case asTYPEID_UINT8: + genericFun->SetReturnByte(scriptContext->GetReturnByte()); + break; + + case asTYPEID_INT16: + case asTYPEID_UINT16: + genericFun->SetReturnWord(scriptContext->GetReturnWord()); + break; + + case asTYPEID_INT32: + case asTYPEID_UINT32: + genericFun->SetReturnDWord(scriptContext->GetReturnDWord()); + break; + + case asTYPEID_INT64: + case asTYPEID_UINT64: + genericFun->SetReturnQWord(scriptContext->GetReturnQWord()); + break; + + case asTYPEID_FLOAT: + genericFun->SetReturnFloat(scriptContext->GetReturnFloat()); + break; + + case asTYPEID_DOUBLE: + genericFun->SetReturnDouble(scriptContext->GetReturnDouble()); + break; + + default: + // value types returned by value + genericFun->SetReturnObject(scriptContext->GetReturnObject()); + break; + } + } + + AS_CHECK(scriptContext->PopState()); + } + + void Service::updateTypes(asIScriptModule* module) { + type = module->GetTypeInfoByName(typeName.c_str()); + + updateFunction = type->GetMethodByDecl("void update()"); + initFunction = type->GetMethodByDecl("void init()"); + shutdownFunction = type->GetMethodByDecl("void shutdown()"); + + for (Scope& exposedFunction : exposedFunctions) { + exposedFunction->exposedFunction = type->GetMethodByName(exposedFunction->exposedFunctionName.c_str()); + exposedFunction->exposedObject = object; + } + } + void Service::update() { if (!updateFunction) return; @@ -70,6 +286,8 @@ namespace Deer { Service::Service(asITypeInfo* _type) : type(_type) { + typeName = _type->GetName(); + updateFunction = type->GetMethodByDecl("void update()"); initFunction = type->GetMethodByDecl("void init()"); shutdownFunction = type->GetMethodByDecl("void shutdown()"); diff --git a/Editor/Modules/ActiveEntity/ActiveEntity.as b/Editor/Modules/ActiveEntity/ActiveEntity.as index 5607143..956d6ed 100644 --- a/Editor/Modules/ActiveEntity/ActiveEntity.as +++ b/Editor/Modules/ActiveEntity/ActiveEntity.as @@ -1,8 +1,21 @@ -Entity entity = Resource::getMainEnvironment().getRootEntity(); -Entity getActiveEntity() { - return entity; -} +class ActiveEntity : Service { + Entity entity; -void setActiveEntity(Entity ent) { - entity = ent; + [Expose] + Entity getActiveEntity() { + return entity; + } + [Expose] + void setActiveEntity(Entity ent) { + entity = ent; + } + + void init() { + entity = Resource::getMainEnvironment().getRootEntity(); + } + + [Expose] + void wtf() { + Engine::print("Exposed"); + } } diff --git a/Editor/Modules/EntityManipulation/MeshProperties.as b/Editor/Modules/EntityManipulation/MeshProperties.as index 4969dc7..79bfe34 100644 --- a/Editor/Modules/EntityManipulation/MeshProperties.as +++ b/Editor/Modules/EntityManipulation/MeshProperties.as @@ -57,4 +57,8 @@ class MeshComponentRender { entity.removeMeshComponent(); } } + + void init() { + ActiveEntity::wtf(); + } } diff --git a/Editor/Modules/EntityManipulation/PropertiesPannel.as b/Editor/Modules/EntityManipulation/PropertiesPannel.as index 324b89f..a8f6e9c 100644 --- a/Editor/Modules/EntityManipulation/PropertiesPannel.as +++ b/Editor/Modules/EntityManipulation/PropertiesPannel.as @@ -1,13 +1,10 @@ -import Entity getActiveEntity() from "ActiveEntity"; -import void setActiveEntity(Entity) from "ActiveEntity"; - class PropertiesPanel : Panel { float slider = 0; vec3 slid; vec3 slid2; void render() { - Entity entity = getActiveEntity(); + Entity entity = ActiveEntity::getActiveEntity(); // NAME // Id:0 [+ add component] @@ -60,7 +57,7 @@ class PropertiesPanel : Panel { } void renameEntityMenu() { - Entity entity = getActiveEntity(); + Entity entity = ActiveEntity::getActiveEntity(); if (!entity.isRoot) { if (UI::menuItem("Rename")) { diff --git a/Editor/Modules/Previewer/MeshPreview.as b/Editor/Modules/Previewer/MeshPreview.as index f57e071..2ab801d 100644 --- a/Editor/Modules/Previewer/MeshPreview.as +++ b/Editor/Modules/Previewer/MeshPreview.as @@ -1,19 +1,10 @@ -RenderService@ mainRenderService; - -FrameBuffer renderMeshPreview(GPUMesh mesh) { - return mainRenderService.renderMeshPreview(mesh); -} - -FrameBuffer renderMeshPreview(GPUMesh mesh, float fase) { - return mainRenderService.renderMeshPreview(mesh, fase); -} - -void setSceneCamera(SceneCamera sc) { -} - class RenderService : Service { + Environment env; + SceneCamera sceneCamera; + MeshComponent meshC; + Entity child; + void init() { - @mainRenderService = this; env = Resource::createLoadEnvironment("PreviewerEnv"); child = env.getRootEntity().createChild("Render"); @@ -27,30 +18,27 @@ class RenderService : Service { } + [Expose] FrameBuffer renderMeshPreview(GPUMesh mesh) { FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4); buffer.clearRGBA(0, 0, 0, 0); meshC.meshResource = mesh; child.transform.rotation = vec3(0, 0, 0); - mainRenderService.env.render(buffer, mainRenderService.sceneCamera); + env.render(buffer, sceneCamera); return buffer; } - FrameBuffer renderMeshPreview(GPUMesh mesh, float fase) { + [Expose] + FrameBuffer renderMeshPreview_fase(GPUMesh mesh, float fase) { FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4); buffer.clearRGBA(0, 0, 0, 0); meshC.meshResource = mesh; child.transform.rotation = vec3(0, (1-(1/(1+fase * fase)))*45, 0); - mainRenderService.env.render(buffer, mainRenderService.sceneCamera); + env.render(buffer, sceneCamera); return buffer; } - - Environment env; - SceneCamera sceneCamera; - MeshComponent meshC; - Entity child; } diff --git a/Editor/Modules/ResourceExplorer/ResourceExplorer.as b/Editor/Modules/ResourceExplorer/ResourceExplorer.as index 6e4973b..73d1eed 100644 --- a/Editor/Modules/ResourceExplorer/ResourceExplorer.as +++ b/Editor/Modules/ResourceExplorer/ResourceExplorer.as @@ -1,5 +1,3 @@ -import FrameBuffer renderMeshPreview(GPUMesh mesh) from "Previewer"; -import FrameBuffer renderMeshPreview(GPUMesh mesh, float fase) from "Previewer"; string selectedResource = ""; class ResourceExplorer : Panel { @@ -62,7 +60,7 @@ class ResourceExplorer : Panel { //} GPUMesh mesh = Resource::loadGPUMesh(filename); - frameBuffer = renderMeshPreview(mesh, fase); + frameBuffer = Previewer::renderMeshPreview_fase(mesh, fase); meshFrameBuffer[filename] = frameBuffer; alreadyRendered = true; diff --git a/Editor/Modules/Test/ActiveEntity.as b/Editor/Modules/Test/ActiveEntity.as new file mode 100644 index 0000000..26ff27c --- /dev/null +++ b/Editor/Modules/Test/ActiveEntity.as @@ -0,0 +1,8 @@ +class Test : Service { + void init() { + Engine::print("Initing"); + Entity entity = ActiveEntity::getActiveEntity(); + Engine::print(entity.name); + Engine::print("Ending"); + } +} diff --git a/Editor/Modules/Test/module.json b/Editor/Modules/Test/module.json new file mode 100644 index 0000000..80c3aec --- /dev/null +++ b/Editor/Modules/Test/module.json @@ -0,0 +1,5 @@ +{ + "patch": 1, + "name": "Test", + "requires": ["ActiveEntity"] +} diff --git a/Editor/Modules/TreeExplorer/Tree.as b/Editor/Modules/TreeExplorer/Tree.as index 25e214b..428dd34 100644 --- a/Editor/Modules/TreeExplorer/Tree.as +++ b/Editor/Modules/TreeExplorer/Tree.as @@ -1,6 +1,3 @@ -import Entity getActiveEntity() from "ActiveEntity"; -import void setActiveEntity(Entity) from "ActiveEntity"; - class EntityTreeRender { EntityTreeRender(Entity _entity) { entity = _entity; @@ -8,7 +5,7 @@ class EntityTreeRender { Entity entity; bool isActiveEntity() { - return entity == getActiveEntity(); + return entity == ActiveEntity::getActiveEntity(); } void renderEntity() { @@ -47,7 +44,7 @@ class EntityTreeRender { UI::contextItemPopup("POP_ENTITY_" + entity.id, Callback(this.renderContextMenu)); if (UI::isItemClicked(0)) { - setActiveEntity(entity); + ActiveEntity::setActiveEntity(entity); } } diff --git a/Editor/Modules/Viewport/Viewport.as b/Editor/Modules/Viewport/Viewport.as index cd33c64..4a2dba4 100644 --- a/Editor/Modules/Viewport/Viewport.as +++ b/Editor/Modules/Viewport/Viewport.as @@ -1,5 +1,3 @@ -import void setSceneCamera (SceneCamera sc) from "Previewer"; - class ViewportPanel : Panel { FrameBuffer frameBuffer; SceneCamera sceneCamera; @@ -68,7 +66,6 @@ class ViewportPanel : Panel { vertically--; sceneCamera.transform.position = sceneCamera.transform.position + vec3(0, vertically * vel, 0); - setSceneCamera(sceneCamera); } void init() {