Forráskód Böngészése

Updated to AngelScript 2.23.0 WIP.
Removed the AngelScript datatype caching optimization, as it was possibly causing a VariantMap crash in the editor.

Lasse Öörni 14 éve
szülő
commit
a1049eab4e
63 módosított fájl, 4237 hozzáadás és 3299 törlés
  1. 1 1
      Docs/Urho3D.dox
  2. 2 2
      Engine/IO/FileWatcher.cpp
  3. 2 3
      Engine/Script/Script.cpp
  4. 1 1
      Readme.txt
  5. 53 52
      ThirdParty/AngelScript/include/angelscript.h
  6. 5 5
      ThirdParty/AngelScript/source/as_array.h
  7. 2 2
      ThirdParty/AngelScript/source/as_atomic.h
  8. 229 121
      ThirdParty/AngelScript/source/as_builder.cpp
  9. 51 47
      ThirdParty/AngelScript/source/as_builder.h
  10. 9 3
      ThirdParty/AngelScript/source/as_bytecode.cpp
  11. 6 1
      ThirdParty/AngelScript/source/as_bytecode.h
  12. 26 19
      ThirdParty/AngelScript/source/as_callfunc.cpp
  13. 12 2
      ThirdParty/AngelScript/source/as_callfunc.h
  14. 34 37
      ThirdParty/AngelScript/source/as_callfunc_arm.cpp
  15. 235 235
      ThirdParty/AngelScript/source/as_callfunc_arm_gcc.S
  16. 242 242
      ThirdParty/AngelScript/source/as_callfunc_arm_msvc.asm
  17. 2 4
      ThirdParty/AngelScript/source/as_callfunc_mips.cpp
  18. 1 3
      ThirdParty/AngelScript/source/as_callfunc_ppc.cpp
  19. 1 3
      ThirdParty/AngelScript/source/as_callfunc_ppc_64.cpp
  20. 1 3
      ThirdParty/AngelScript/source/as_callfunc_sh4.cpp
  21. 16 66
      ThirdParty/AngelScript/source/as_callfunc_x64_gcc.cpp
  22. 3 5
      ThirdParty/AngelScript/source/as_callfunc_x64_mingw.cpp
  23. 3 5
      ThirdParty/AngelScript/source/as_callfunc_x64_msvc.cpp
  24. 48 49
      ThirdParty/AngelScript/source/as_callfunc_x86.cpp
  25. 1 3
      ThirdParty/AngelScript/source/as_callfunc_xenon.cpp
  26. 56 70
      ThirdParty/AngelScript/source/as_compiler.cpp
  27. 5 7
      ThirdParty/AngelScript/source/as_compiler.h
  28. 61 46
      ThirdParty/AngelScript/source/as_config.h
  29. 1 42
      ThirdParty/AngelScript/source/as_configgroup.cpp
  30. 1 18
      ThirdParty/AngelScript/source/as_configgroup.h
  31. 177 148
      ThirdParty/AngelScript/source/as_context.cpp
  32. 6 6
      ThirdParty/AngelScript/source/as_context.h
  33. 2 2
      ThirdParty/AngelScript/source/as_criticalsection.h
  34. 12 27
      ThirdParty/AngelScript/source/as_datatype.cpp
  35. 5 14
      ThirdParty/AngelScript/source/as_datatype.h
  36. 1 1
      ThirdParty/AngelScript/source/as_debug.h
  37. 3 5
      ThirdParty/AngelScript/source/as_gc.cpp
  38. 2 2
      ThirdParty/AngelScript/source/as_gc.h
  39. 3 12
      ThirdParty/AngelScript/source/as_generic.cpp
  40. 0 5
      ThirdParty/AngelScript/source/as_generic.h
  41. 2 1
      ThirdParty/AngelScript/source/as_globalproperty.cpp
  42. 5 1
      ThirdParty/AngelScript/source/as_memory.cpp
  43. 4 2
      ThirdParty/AngelScript/source/as_memory.h
  44. 111 48
      ThirdParty/AngelScript/source/as_module.cpp
  45. 13 12
      ThirdParty/AngelScript/source/as_module.h
  46. 17 21
      ThirdParty/AngelScript/source/as_objecttype.cpp
  47. 3 9
      ThirdParty/AngelScript/source/as_objecttype.h
  48. 7 1
      ThirdParty/AngelScript/source/as_outputbuffer.cpp
  49. 6 1
      ThirdParty/AngelScript/source/as_outputbuffer.h
  50. 1880 1383
      ThirdParty/AngelScript/source/as_parser.cpp
  51. 45 83
      ThirdParty/AngelScript/source/as_parser.h
  52. 479 201
      ThirdParty/AngelScript/source/as_restore.cpp
  53. 16 11
      ThirdParty/AngelScript/source/as_restore.h
  54. 214 121
      ThirdParty/AngelScript/source/as_scriptengine.cpp
  55. 16 29
      ThirdParty/AngelScript/source/as_scriptengine.h
  56. 46 21
      ThirdParty/AngelScript/source/as_scriptfunction.cpp
  57. 7 9
      ThirdParty/AngelScript/source/as_scriptfunction.h
  58. 15 10
      ThirdParty/AngelScript/source/as_scriptobject.cpp
  59. 2 2
      ThirdParty/AngelScript/source/as_string.cpp
  60. 12 11
      ThirdParty/AngelScript/source/as_texts.h
  61. 1 1
      ThirdParty/AngelScript/source/as_thread.h
  62. 8 1
      ThirdParty/AngelScript/source/as_variablescope.cpp
  63. 7 1
      ThirdParty/AngelScript/source/as_variablescope.h

+ 1 - 1
Docs/Urho3D.dox

@@ -60,7 +60,7 @@ Urho3D is greatly inspired by OGRE (http://www.ogre3d.org/) and Horde3D (http://
 
 Urho3D uses the following third-party libraries:
 
-- AngelScript 2.22.2 (http://www.angelcode.com/angelscript/)
+- AngelScript 2.23.0 WIP (http://www.angelcode.com/angelscript/)
 - FreeType 2.3.12 (http://www.freetype.org/)
 - GLee 5.4 (http://elf-stone.com/)
 - GLFW 3.0 WIP (http://www.glfw.org/)

+ 2 - 2
Engine/IO/FileWatcher.cpp

@@ -108,7 +108,7 @@ void FileWatcher::StopWatching()
 void FileWatcher::ThreadFunction()
 {
 #if defined(WIN32) && defined(ENABLE_FILEWATCHER)
-    char buffer[BUFFERSIZE];
+    unsigned char buffer[BUFFERSIZE];
     DWORD bytesFilled = 0;
     
     while (shouldRun_)
@@ -125,7 +125,7 @@ void FileWatcher::ThreadFunction()
         {
             unsigned offset = 0;
             
-            for (;;)
+            while (offset < bytesFilled)
             {
                 FILE_NOTIFY_INFORMATION* record = (FILE_NOTIFY_INFORMATION*)&buffer[offset];
                 

+ 2 - 3
Engine/Script/Script.cpp

@@ -255,7 +255,7 @@ void Script::DumpAPI()
         const char* propertyName;
         const char* propertyDeclaration;
         int typeId;
-        scriptEngine_->GetGlobalPropertyByIndex(i, &propertyName, &typeId);
+        scriptEngine_->GetGlobalPropertyByIndex(i, &propertyName, 0, &typeId);
         propertyDeclaration = scriptEngine_->GetTypeDeclaration(typeId);
         
         String type(propertyDeclaration);
@@ -377,8 +377,7 @@ void Script::MessageCallback(const asSMessageInfo* msg)
 
 void Script::ExceptionCallback(asIScriptContext* context)
 {
-    int funcId = context->GetExceptionFunction();
-    const asIScriptFunction *function = scriptEngine_->GetFunctionById(funcId);
+    asIScriptFunction *function = context->GetExceptionFunction();
     String message = "Exception '" + String(context->GetExceptionString()) + "' in '" +
         String(function->GetDeclaration()) + "'";
     

+ 1 - 1
Readme.txt

@@ -36,7 +36,7 @@ Urho3D is greatly inspired by OGRE (http://www.ogre3d.org) and Horde3D
   http://timothylottes.blogspot.com/2011/04/nvidia-fxaa-ii-for-console.html
 
 Urho3D uses the following third-party libraries:
-- AngelScript 2.22.2 (http://www.angelcode.com/angelscript/)
+- AngelScript 2.23.0 WIP (http://www.angelcode.com/angelscript/)
 - FreeType 2.3.12 (http://www.freetype.org/)
 - GLee 5.4 (http://elf-stone.com/)
 - GLFW 3.0 WIP (http://www.glfw.org/)

+ 53 - 52
ThirdParty/AngelScript/include/angelscript.h

@@ -41,6 +41,9 @@
 #define ANGELSCRIPT_H
 
 #include <stddef.h>
+#ifndef _MSC_VER
+#include <stdint.h>
+#endif
 
 #ifdef AS_USE_NAMESPACE
  #define BEGIN_AS_NAMESPACE namespace AngelScript {
@@ -56,8 +59,8 @@ BEGIN_AS_NAMESPACE
 
 // AngelScript version
 
-#define ANGELSCRIPT_VERSION        22202
-#define ANGELSCRIPT_VERSION_STRING "2.22.2"
+#define ANGELSCRIPT_VERSION        22300
+#define ANGELSCRIPT_VERSION_STRING "2.23.0 WIP"
 
 // Data types
 
@@ -142,7 +145,8 @@ enum asEObjTypeFlags
 	asOBJ_APP_FLOAT                  = 0x4000,
 	asOBJ_APP_CLASS_ALLINTS          = 0x8000,
 	asOBJ_APP_CLASS_ALLFLOATS        = 0x10000,
-	asOBJ_MASK_VALID_FLAGS           = 0x1FFFF,
+	asOBJ_NOCOUNT                    = 0x20000,
+	asOBJ_MASK_VALID_FLAGS           = 0x3FFFF,
 	asOBJ_SCRIPT_OBJECT              = 0x80000,
 	asOBJ_SHARED                     = 0x100000,
 	asOBJ_NOINHERIT                  = 0x200000
@@ -256,9 +260,6 @@ enum asETokenClass
 // Prepare flags
 const int asPREPARE_PREVIOUS = -1;
 
-// Config groups
-const char * const asALL_MODULES = (const char * const)-1;
-
 // Type id flags
 enum asETypeIdFlags
 {
@@ -328,7 +329,14 @@ enum asEFuncType
 typedef unsigned char  asBYTE;
 typedef unsigned short asWORD;
 typedef unsigned int   asUINT;
-typedef size_t         asPWORD;
+#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC6 
+	// 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;
+#else
+	typedef uintptr_t      asPWORD;
+#endif
 #ifdef __LP64__
     typedef unsigned int  asDWORD;
     typedef unsigned long asQWORD;
@@ -336,8 +344,8 @@ typedef size_t         asPWORD;
 #else
     typedef unsigned long asDWORD;
   #if defined(__GNUC__) || defined(__MWERKS__)
-    typedef unsigned long long asQWORD;
-    typedef long long asINT64;
+    typedef uint64_t asQWORD;
+    typedef int64_t asINT64;
   #else
     typedef unsigned __int64 asQWORD;
     typedef __int64 asINT64;
@@ -513,7 +521,9 @@ public:
 	// Global properties
 	virtual int    RegisterGlobalProperty(const char *declaration, void *pointer) = 0;
 	virtual asUINT GetGlobalPropertyCount() const = 0;
-	virtual int    GetGlobalPropertyByIndex(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0) 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, asDWORD flags) = 0;
@@ -524,6 +534,7 @@ public:
 	virtual int            RegisterInterfaceMethod(const char *intf, const char *declaration) = 0;
 	virtual asUINT         GetObjectTypeCount() const = 0;
 	virtual asIObjectType *GetObjectTypeByIndex(asUINT index) const = 0;
+	virtual asIObjectType *GetObjectTypeByName(const char *name) const = 0;
 
 	// String factory
 	virtual int RegisterStringFactory(const char *datatype, const asSFuncPtr &factoryFunc, asDWORD callConv) = 0;
@@ -537,29 +548,26 @@ public:
 	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 const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **configGroup = 0) const = 0;
+	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **nameSpace = 0, const char **configGroup = 0, asDWORD *accessMask = 0) const = 0;
 	virtual int         GetEnumValueCount(int enumTypeId) const = 0;
 	virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
 
 	// Funcdefs
 	virtual int                RegisterFuncdef(const char *decl) = 0;
 	virtual asUINT             GetFuncdefCount() const = 0;
-	virtual asIScriptFunction *GetFuncdefByIndex(asUINT index, const char **configGroup = 0) const = 0;
+	virtual asIScriptFunction *GetFuncdefByIndex(asUINT index) const = 0;
 
 	// Typedefs
 	virtual int         RegisterTypedef(const char *type, const char *decl) = 0;
 	virtual asUINT      GetTypedefCount() const = 0;
-	virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **configGroup = 0) const = 0;
+	virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **nameSpace = 0, const char **configGroup = 0, asDWORD *accessMask = 0) const = 0;
 
 	// Configuration groups
-	virtual int BeginConfigGroup(const char *groupName) = 0;
-	virtual int EndConfigGroup() = 0;
-	virtual int RemoveConfigGroup(const char *groupName) = 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;
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-04
-	virtual int SetConfigGroupModuleAccess(const char *groupName, const char *module, bool hasAccess) = 0;
-#endif
+	virtual int     SetDefaultNamespace(const char *nameSpace) = 0;
 
 	// Script modules
 	virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0;
@@ -567,15 +575,11 @@ public:
 
 	// Script functions
 	virtual asIScriptFunction *GetFunctionById(int funcId) const = 0;
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-03
-	virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const = 0;
-#endif
 
 	// Type identification
 	virtual asIObjectType *GetObjectTypeById(int typeId) const = 0;
 	virtual int            GetTypeIdByDecl(const char *decl) const = 0;
-	virtual const char    *GetTypeDeclaration(int typeId) const = 0;
+	virtual const char    *GetTypeDeclaration(int typeId, bool includeNamespace = false) const = 0;
 	virtual int            GetSizeOfPrimitiveType(int typeId) const = 0;
 
 	// Script execution
@@ -595,7 +599,7 @@ public:
 	// Garbage collection
 	virtual int  GarbageCollect(asDWORD flags = asGC_FULL_CYCLE) = 0;
 	virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed = 0, asUINT *totalDetected = 0, asUINT *newObjects = 0, asUINT *totalNewDestroyed = 0) const = 0;
-	virtual void NotifyGarbageCollectorOfNewObject(void *obj, int typeId) = 0;
+	virtual void NotifyGarbageCollectorOfNewObject(void *obj, asIObjectType *type) = 0;
 	virtual void GCEnumCallback(void *reference) = 0;
 
 	// User data
@@ -624,6 +628,7 @@ public:
 	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;
 
 	// Functions
 	virtual asUINT             GetFunctionCount() const = 0;
@@ -633,20 +638,16 @@ public:
 	virtual asIScriptFunction *GetFunctionByIndex(asUINT index) const = 0;
 	virtual asIScriptFunction *GetFunctionByDecl(const char *decl) const = 0;
 	virtual asIScriptFunction *GetFunctionByName(const char *name) const = 0;
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-03
-	virtual asIScriptFunction *GetFunctionDescriptorByIndex(asUINT index) const = 0;
-	virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const = 0;
-#endif
 	virtual int                RemoveFunction(int funcId) = 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) const = 0;
-	virtual int         GetGlobalVar(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0) 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;
 
@@ -657,13 +658,13 @@ public:
 
 	// Enums
 	virtual asUINT      GetEnumCount() const = 0;
-	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId) const = 0;
+	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **nameSpace = 0) const = 0;
 	virtual int         GetEnumValueCount(int enumTypeId) const = 0;
 	virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
 
 	// Typedefs
 	virtual asUINT      GetTypedefCount() const = 0;
-	virtual const char *GetTypedefByIndex(asUINT index, int *typeId) const = 0;
+	virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **nameSpace = 0) const = 0;
 
 	// Dynamic binding between modules
 	virtual asUINT      GetImportedFunctionCount() const = 0;
@@ -730,12 +731,12 @@ public:
 	virtual void   *GetAddressOfReturnValue() = 0;
 
 	// Exception handling
-	virtual int         SetException(const char *string) = 0;
-	virtual int         GetExceptionLineNumber(int *column = 0, const char **sectionName = 0) = 0;
-	virtual int         GetExceptionFunction() = 0;
-	virtual const char *GetExceptionString() = 0;
-	virtual int         SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
-	virtual void        ClearExceptionCallback() = 0;
+	virtual int                SetException(const char *string) = 0;
+	virtual int                GetExceptionLineNumber(int *column = 0, const char **sectionName = 0) = 0;
+	virtual asIScriptFunction *GetExceptionFunction() = 0;
+	virtual const char *       GetExceptionString() = 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;
@@ -751,6 +752,7 @@ public:
 	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) = 0;
@@ -767,10 +769,6 @@ public:
 	virtual asIScriptEngine   *GetEngine() const = 0;
 	virtual int                GetFunctionId() const = 0;
 	virtual asIScriptFunction *GetFunction() const = 0;
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-03
-	virtual asIScriptFunction *GetFunctionDescriptor() const = 0;
-#endif
 	virtual void              *GetFunctionUserData() const = 0;
 
 	// Object
@@ -835,6 +833,7 @@ class asIObjectType
 public:
 	virtual asIScriptEngine *GetEngine() const = 0;
 	virtual const char      *GetConfigGroup() const = 0;
+	virtual asDWORD          GetAccessMask() const = 0;
 
 	// Memory management
 	virtual int AddRef() const = 0;
@@ -842,6 +841,7 @@ public:
 
 	// Type info
 	virtual const char      *GetName() const = 0;
+	virtual	const char      *GetNamespace() const = 0;
 	virtual asIObjectType   *GetBaseType() const = 0;
 	virtual bool             DerivesFrom(const asIObjectType *objType) const = 0;
 	virtual asDWORD          GetFlags() const = 0;
@@ -870,14 +870,10 @@ public:
 	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;
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-03
-	virtual asIScriptFunction *GetMethodDescriptorByIndex(asUINT index, bool getVirtual = true) const = 0;
-#endif
 
 	// Properties
 	virtual asUINT      GetPropertyCount() const = 0;
-	virtual int         GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, int *offset = 0, bool *isReference = 0) const = 0;
+	virtual int         GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, int *offset = 0, bool *isReference = 0, asDWORD *accessMask = 0) const = 0;
 	virtual const char *GetPropertyDeclaration(asUINT index) const = 0;
 
 	// Behaviours
@@ -906,12 +902,17 @@ public:
 	virtual const char      *GetModuleName() const = 0;
 	virtual const char      *GetScriptSectionName() const = 0;
 	virtual const char      *GetConfigGroup() const = 0;
+	virtual asDWORD          GetAccessMask() const = 0;
 	virtual asIObjectType   *GetObjectType() const = 0;
 	virtual const char      *GetObjectName() const = 0;
 	virtual const char      *GetName() const = 0;
-	virtual const char      *GetDeclaration(bool includeObjectName = true) const = 0;
+	virtual const char      *GetNamespace() const = 0;
+	virtual const char      *GetDeclaration(bool includeObjectName = true, bool includeNamespace = false) const = 0;
 	virtual bool             IsReadOnly() const = 0;
 	virtual bool             IsPrivate() const = 0;
+	virtual bool             IsFinal() const = 0;
+	virtual bool             IsOverride() const = 0;
+	virtual bool             IsShared() const = 0;
 
 	virtual asUINT           GetParamCount() const = 0;
 	virtual int              GetParamTypeId(asUINT index, asDWORD *flags = 0) const = 0;
@@ -1690,7 +1691,7 @@ const asSBCInfo asBCInfo[256] =
 #define asBC_INTARG(x)    (int(*(x+1)))
 #define asBC_QWORDARG(x)  (*(asQWORD*)(x+1))
 #define asBC_FLOATARG(x)  (*(float*)(x+1))
-#define asBC_PTRARG(x)    (*(asPTRWORD*)(x+1))
+#define asBC_PTRARG(x)    (*(asPWORD*)(x+1))
 #define asBC_WORDARG0(x)  (*(((asWORD*)x)+1))
 #define asBC_WORDARG1(x)  (*(((asWORD*)x)+2))
 #define asBC_SWORDARG0(x) (*(((short*)x)+1))

+ 5 - 5
ThirdParty/AngelScript/source/as_array.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2009 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -69,8 +69,8 @@ public:
 	void Concatenate(const asCArray<T> &);
 	void Concatenate(T*, unsigned int count);
 
-	bool Exists(const T &element);
-	int  IndexOf(const T &element);
+	bool Exists(T &element) const;
+	int  IndexOf(T &element) const;
 	void RemoveIndex(size_t index);     // Removes the entry without reordering the array
 	void RemoveValue(const T &element);
 
@@ -321,13 +321,13 @@ void asCArray<T>::Concatenate(T* array, unsigned int count)
 }
 
 template <class T>
-bool asCArray<T>::Exists(const T &e)
+bool asCArray<T>::Exists(T &e) const
 {
 	return IndexOf(e) == -1 ? false : true;
 }
 
 template <class T>
-int asCArray<T>::IndexOf(const T &e)
+int asCArray<T>::IndexOf(T &e) const
 {
 	for( size_t n = 0; n < length; n++ )
 		if( array[n] == e ) return (int)n;

+ 2 - 2
ThirdParty/AngelScript/source/as_atomic.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2009 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -65,7 +65,7 @@ protected:
 	asDWORD value;
 
 #if !defined(AS_NO_THREADS) && defined(AS_NO_ATOMIC)
-	DECLARECRITICALSECTION(cs);
+	DECLARECRITICALSECTION(cs)
 #endif
 };
 

+ 229 - 121
ThirdParty/AngelScript/source/as_builder.cpp

@@ -57,6 +57,7 @@ asCBuilder::asCBuilder(asCScriptEngine *engine, asCModule *module)
 
 asCBuilder::~asCBuilder()
 {
+#ifndef AS_NO_COMPILER
 	asUINT n;
 
 	// Free all functions
@@ -160,6 +161,15 @@ asCBuilder::~asCBuilder()
 			funcDefs[n] = 0;
 		}
 	}
+
+#endif // AS_NO_COMPILER
+}
+
+void asCBuilder::Reset()
+{
+	numErrors = 0;
+	numWarnings = 0;
+	preMessage.isSet = false;
 }
 
 #ifndef AS_NO_COMPILER
@@ -176,9 +186,7 @@ int asCBuilder::AddCode(const char *name, const char *code, int codeLength, int
 
 int asCBuilder::Build()
 {
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	ParseScripts();
 
@@ -199,9 +207,7 @@ int asCBuilder::Build()
 
 int asCBuilder::CompileGlobalVar(const char *sectionName, const char *code, int lineOffset)
 {
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	// Add the string to the script code
 	asCScriptCode *script = asNEW(asCScriptCode);
@@ -229,7 +235,7 @@ int asCBuilder::CompileGlobalVar(const char *sectionName, const char *code, int
 	node = node->firstChild;
 	node->DisconnectParent();
 	// TODO: namespace: How should we allow informing the namespace? Perhaps the module 
-	//                  needs a SetDefaultNamepace() method that can be called before
+	//                  needs a SetDefaultNamespace() method that can be called before
 	RegisterGlobalVar(node, script, "");
 
 	CompileGlobalVariables();
@@ -277,9 +283,7 @@ int asCBuilder::CompileFunction(const char *sectionName, const char *code, int l
 {
 	asASSERT(outFunc != 0);
 
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	// Add the string to the script code
 	asCScriptCode *script = asNEW(asCScriptCode);
@@ -308,7 +312,7 @@ int asCBuilder::CompileFunction(const char *sectionName, const char *code, int l
 	node = node->firstChild;
 
 	// TODO: namespace: How should we allow informing the namespace? Perhaps the module 
-	//                  needs a SetDefaultNamepace() method that can be called before
+	//                  needs a SetDefaultNamespace() method that can be called before
 
 	// Create the function
 	bool isConstructor, isDestructor, isPrivate, isFinal, isOverride, isShared;
@@ -411,8 +415,6 @@ void asCBuilder::ParseScripts()
 		for( n = 0; n < interfaceDeclarations.GetLength(); n++ )
 		{
 			sClassDeclaration *decl = interfaceDeclarations[n];
-			if( decl->isExistingShared ) continue; // TODO: shared: Should really verify that the methods match the original
-
 			asCScriptNode *node = decl->node->firstChild->next;
 			while( node )
 			{
@@ -420,22 +422,26 @@ void asCBuilder::ParseScripts()
 				if( node->nodeType == snFunction )
 				{
 					node->DisconnectParent();
-					RegisterScriptFunction(engine->GetNextScriptFunctionId(), node, decl->script, decl->objType, true);
+					RegisterScriptFunction(engine->GetNextScriptFunctionId(), node, decl->script, decl->objType, true, false, "", decl->isExistingShared);
 				}
 				else if( node->nodeType == snVirtualProperty )
 				{
 					node->DisconnectParent();
-					RegisterVirtualProperty(node, decl->script, decl->objType, true, false);
+					RegisterVirtualProperty(node, decl->script, decl->objType, true, false, "", decl->isExistingShared);
 				}
 
 				node = next;
 			}
 		}
 
+#ifdef AS_DEPRECATED
+	// Deprecated since 2.23.0 - 2012-01-30
+
 		// Now the interfaces have been completely established, now we need to determine if
 		// the same interface has already been registered before, and if so reuse the interface id.
 		// TODO: deprecate this. interfaces should be explicitly marked as shared
 		module->ResolveInterfaceIds();
+#endif
 
 		// Register script methods found in the structures
 		for( n = 0; n < classDeclarations.GetLength(); n++ )
@@ -667,25 +673,24 @@ void asCBuilder::CompileFunctions()
 #endif
 
 // Called from module and engine
-int asCBuilder::ParseDataType(const char *datatype, asCDataType *result)
+int asCBuilder::ParseDataType(const char *datatype, asCDataType *result, const asCString &implicitNamespace, bool isReturnType)
 {
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	asCScriptCode source;
 	source.SetCode("", datatype, true);
 
 	asCParser parser(this);
-	int r = parser.ParseDataType(&source);
+	int r = parser.ParseDataType(&source, isReturnType);
 	if( r < 0 )
 		return asINVALID_TYPE;
 
 	// Get data type and property name
 	asCScriptNode *dataType = parser.GetScriptNode()->firstChild;
 
-	// TODO: namespace: Use correct implicit namespace
-	*result = CreateDataTypeFromNode(dataType, &source, "", true);
+	*result = CreateDataTypeFromNode(dataType, &source, implicitNamespace, true);
+	if( isReturnType )
+		*result = ModifyDataTypeFromNode(*result, dataType->next, &source, 0, 0);
 
 	if( numErrors > 0 )
 		return asINVALID_TYPE;
@@ -695,9 +700,7 @@ int asCBuilder::ParseDataType(const char *datatype, asCDataType *result)
 
 int asCBuilder::ParseTemplateDecl(const char *decl, asCString *name, asCString *subtypeName)
 {
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	asCScriptCode source;
 	source.SetCode("", decl, true);
@@ -724,9 +727,7 @@ int asCBuilder::ParseTemplateDecl(const char *decl, asCString *name, asCString *
 
 int asCBuilder::VerifyProperty(asCDataType *dt, const char *decl, asCString &name, asCDataType &type, const asCString &ns)
 {
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	if( dt )
 	{
@@ -821,13 +822,6 @@ asCGlobalProperty *asCBuilder::GetGlobalProperty(const char *prop, const asCStri
 				// Determine if the module has access to the property
 				if( module->accessMask & props[n]->accessMask )
 				{
-#ifdef AS_DEPRECATED
-					// deprecated since 2011-10-04
-					// Find the config group for the global property
-					asCConfigGroup *group = engine->FindConfigGroupForGlobalVar(props[n]->id);
-					if( !group || group->HasModuleAccess(module->name.AddressOf()) )
-						continue;
-#endif
 					if( isAppProp ) *isAppProp = true;
 					return props[n];
 				}
@@ -840,6 +834,7 @@ asCGlobalProperty *asCBuilder::GetGlobalProperty(const char *prop, const asCStri
 			}
 		}
 
+#ifndef AS_NO_COMPILER
 	// TODO: optimize: Improve linear search
 	// Check properties being compiled now
 	asCArray<sGlobalVariableDescription *> &gvars = globVariables;
@@ -858,6 +853,9 @@ asCGlobalProperty *asCBuilder::GetGlobalProperty(const char *prop, const asCStri
 			return p;
 		}
 	}
+#else
+	UNUSED_VAR(constantValue);
+#endif
 
 	// TODO: optimize: Improve linear search
 	// Check previously compiled global variables
@@ -877,9 +875,7 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec
 {
 	// TODO: Can't we use GetParsedFunctionDetails to do most of what is done in this function?
 
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	asCScriptCode source;
 	source.SetCode(TXT_SYSTEM_FUNCTION, decl, true);
@@ -891,8 +887,11 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec
 
 	asCScriptNode *node = parser.GetScriptNode();
 
-	// Find name
+	// Determine scope
 	asCScriptNode *n = node->firstChild->next->next;
+	func->nameSpace = GetScopeFromNode(n, &source, &n);
+
+	// Find name
 	func->name.Assign(&source.code[n->tokenPos], n->tokenLength);
 
 	// Initialize a script function object for registration
@@ -1005,11 +1004,9 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec
 	return 0;
 }
 
-int asCBuilder::ParseVariableDeclaration(const char *decl, asCObjectProperty *var)
+int asCBuilder::ParseVariableDeclaration(const char *decl, const asCString &implicitNamespace, asCString &outName, asCString &outNamespace, asCDataType &outDt)
 {
-	numErrors = 0;
-	numWarnings = 0;
-	preMessage.isSet = false;
+	Reset();
 
 	asCScriptCode source;
 	source.SetCode(TXT_VARIABLE_DECL, decl, true);
@@ -1022,13 +1019,21 @@ int asCBuilder::ParseVariableDeclaration(const char *decl, asCObjectProperty *va
 
 	asCScriptNode *node = parser.GetScriptNode();
 
-	// Find name
+	// Determine the scope from declaration
 	asCScriptNode *n = node->firstChild->next;
-	var->name.Assign(&source.code[n->tokenPos], n->tokenLength);
+	asCString scope = GetScopeFromNode(n, &source, &n);
+	if( scope == "" )
+		outNamespace = implicitNamespace;
+	else if( scope == "::" )
+		outNamespace = "";
+	else
+		outNamespace = scope;
+
+	// Find name
+	outName.Assign(&source.code[n->tokenPos], n->tokenLength);
 
 	// Initialize a script variable object for registration
-	// TODO: namespace: Use correct implicit namespace
-	var->type = CreateDataTypeFromNode(node->firstChild, &source, "");
+	outDt = CreateDataTypeFromNode(node->firstChild, &source, implicitNamespace);
 
 	if( numErrors > 0 || numWarnings > 0 )
 		return asINVALID_DECLARATION;
@@ -1123,6 +1128,7 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri
 
 	// TODO: Property names must be checked against function names
 
+#ifndef AS_NO_COMPILER
 	// Check against class types
 	asUINT n;
 	for( n = 0; n < classDeclarations.GetLength(); n++ )
@@ -1180,6 +1186,7 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri
 			return -1;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -2439,35 +2446,66 @@ void asCBuilder::AddDefaultConstructor(asCObjectType *objType, asCScriptCode *fi
 
 int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, const asCString &ns)
 {
-	// Grab the name of the enumeration
+	// Is it a shared enum?
+	bool isShared = false;
+	asCObjectType *existingSharedType = 0;
 	asCScriptNode *tmp = node->firstChild;
-	asASSERT(snDataType == tmp->nodeType);
+	if( tmp->nodeType == snIdentifier && file->TokenEquals(tmp->tokenPos, tmp->tokenLength, SHARED_TOKEN) )
+	{
+		isShared = true;
+		tmp = tmp->next;
+	}
 
+	// Grab the name of the enumeration
 	asCString name;
+	asASSERT(snDataType == tmp->nodeType);
 	asASSERT(snIdentifier == tmp->firstChild->nodeType);
 	name.Assign(&file->code[tmp->firstChild->tokenPos], tmp->firstChild->tokenLength);
 
+	if( isShared )
+	{
+		// Look for a pre-existing shared enum with the same signature
+		for( asUINT n = 0; n < engine->classTypes.GetLength(); n++ )
+		{
+			asCObjectType *o = engine->classTypes[n];
+			if( o &&
+				o->IsShared() &&
+				(o->flags & asOBJ_ENUM) &&
+				o->name == name &&
+				o->nameSpace == ns )
+			{
+				existingSharedType = o;
+				break;
+			}
+		}
+	}
+
 	// Check the name and add the enum
 	int r = CheckNameConflict(name.AddressOf(), tmp->firstChild, file, ns);
 	if( asSUCCESS == r )
 	{
 		asCObjectType *st;
-		asCDataType dataType;
 
-		st = asNEW(asCObjectType)(engine);
-		dataType.CreatePrimitive(ttInt, false);
-
-		st->flags     = asOBJ_ENUM;
-		st->size      = 4;
-		st->name      = name;
-		st->nameSpace = ns;
+		if( existingSharedType )
+			st = existingSharedType;
+		else
+		{
+			st = asNEW(asCObjectType)(engine);
 
+			st->flags     = asOBJ_ENUM;
+			if( isShared )
+				st->flags |= asOBJ_SHARED;
+			st->size      = 4;
+			st->name      = name;
+			st->nameSpace = ns;
+		}
 		module->enumTypes.PushLast(st);
 		st->AddRef();
 
 		// TODO: cleanup: Should the enum type really be stored in the engine->classTypes? 
 		//                http://www.gamedev.net/topic/616912-c-header-file-shared-with-scripts/page__gopid__4895940
-		engine->classTypes.PushLast(st);
+		if( !existingSharedType )
+			engine->classTypes.PushLast(st);
 
 		// Store the location of this declaration for reference in name collisions
 		sClassDeclaration *decl = asNEW(sClassDeclaration);
@@ -2487,68 +2525,96 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, const asC
 
 			asCString name(&file->code[tmp->tokenPos], tmp->tokenLength);
 
-			// Check for name conflict errors with other values in the enum
-			r = 0;
-			for( size_t n = globVariables.GetLength(); n-- > 0; )
+			if( existingSharedType )
 			{
-				sGlobalVariableDescription *gvar = globVariables[n];
-				if( gvar->datatype != type )
-					break;
+				// If this is a pre-existent shared enum, then just double check 
+				// that the value is already defined in the original declaration
+				bool found = false;
+				for( size_t n = 0; n < st->enumValues.GetLength(); n++ )
+					if( st->enumValues[n]->name == name )
+					{
+						found = true;
+						break;
+					}
 
-				if( gvar->name == name &&
-					gvar->property->nameSpace == ns )
+				if( !found )
 				{
-					r = asNAME_TAKEN;
+					int r, c;
+					file->ConvertPosToRowCol(tmp->tokenPos, &r, &c);
+					WriteError(file->name.AddressOf(), TXT_SHARED_DOESNT_MATCH_ORIGINAL, r, c);
 					break;
 				}
-			}
-			if( asSUCCESS != r )
-			{
-				int r, c;
-				file->ConvertPosToRowCol(tmp->tokenPos, &r, &c);
-
-				asCString str;
-				str.Format(TXT_NAME_CONFLICT_s_ALREADY_USED, name.AddressOf());
-				WriteError(file->name.AddressOf(), str.AddressOf(), r, c);
 
 				tmp = tmp->next;
 				if( tmp && tmp->nodeType == snAssignment )
 					tmp = tmp->next;
 				continue;
 			}
-
-			// Check for assignment
-			asCScriptNode *asnNode = tmp->next;
-			if( asnNode && snAssignment == asnNode->nodeType )
-				asnNode->DisconnectParent();
 			else
-				asnNode = 0;
+			{
+				// Check for name conflict errors with other values in the enum
+				r = 0;
+				for( size_t n = globVariables.GetLength(); n-- > 0; )
+				{
+					sGlobalVariableDescription *gvar = globVariables[n];
+					if( gvar->datatype != type )
+						break;
+
+					if( gvar->name == name &&
+						gvar->property->nameSpace == ns )
+					{
+						r = asNAME_TAKEN;
+						break;
+					}
+				}
+				if( asSUCCESS != r )
+				{
+					int r, c;
+					file->ConvertPosToRowCol(tmp->tokenPos, &r, &c);
 
-			// Create the global variable description so the enum value can be evaluated
-			sGlobalVariableDescription *gvar = asNEW(sGlobalVariableDescription);
-			globVariables.PushLast(gvar);
+					asCString str;
+					str.Format(TXT_NAME_CONFLICT_s_ALREADY_USED, name.AddressOf());
+					WriteError(file->name.AddressOf(), str.AddressOf(), r, c);
 
-			gvar->script		  = file;
-			gvar->idNode          = 0;
-			gvar->nextNode		  = asnNode;
-			gvar->name			  = name;
-			gvar->datatype		  = type;
-			// No need to allocate space on the global memory stack since the values are stored in the asCObjectType
-			gvar->index			  = 0;
-			gvar->isCompiled	  = false;
-			gvar->isPureConstant  = true;
-			gvar->isEnumValue     = true;
-			gvar->constantValue   = 0xdeadbeef;
+					tmp = tmp->next;
+					if( tmp && tmp->nodeType == snAssignment )
+						tmp = tmp->next;
+					continue;
+				}
 
-			// Allocate dummy property so we can compile the value. 
-			// This will be removed later on so we don't add it to the engine.
-			gvar->property            = asNEW(asCGlobalProperty);
-			gvar->property->name      = name;
-			gvar->property->nameSpace = ns;
-			gvar->property->type      = gvar->datatype;
-			gvar->property->id        = 0;
+				// Check for assignment
+				asCScriptNode *asnNode = tmp->next;
+				if( asnNode && snAssignment == asnNode->nodeType )
+					asnNode->DisconnectParent();
+				else
+					asnNode = 0;
+
+				// Create the global variable description so the enum value can be evaluated
+				sGlobalVariableDescription *gvar = asNEW(sGlobalVariableDescription);
+				globVariables.PushLast(gvar);
+
+				gvar->script		  = file;
+				gvar->idNode          = 0;
+				gvar->nextNode		  = asnNode;
+				gvar->name			  = name;
+				gvar->datatype		  = type;
+				// No need to allocate space on the global memory stack since the values are stored in the asCObjectType
+				gvar->index			  = 0;
+				gvar->isCompiled	  = false;
+				gvar->isPureConstant  = true;
+				gvar->isEnumValue     = true;
+				gvar->constantValue   = 0xdeadbeef;
+
+				// Allocate dummy property so we can compile the value. 
+				// This will be removed later on so we don't add it to the engine.
+				gvar->property            = asNEW(asCGlobalProperty);
+				gvar->property->name      = name;
+				gvar->property->nameSpace = ns;
+				gvar->property->type      = gvar->datatype;
+				gvar->property->id        = 0;
 
-			tmp = tmp->next;
+				tmp = tmp->next;
+			}
 		}
 	}
 
@@ -2754,7 +2820,7 @@ asCString asCBuilder::GetCleanExpressionString(asCScriptNode *node, asCScriptCod
 }
 
 #ifndef AS_NO_COMPILER
-int asCBuilder::RegisterScriptFunction(int funcId, asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, const asCString &ns)
+int asCBuilder::RegisterScriptFunction(int funcId, asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, const asCString &ns, bool isExistingShared)
 {
 	asCString                  name;
 	asCDataType                returnType;
@@ -2771,6 +2837,42 @@ int asCBuilder::RegisterScriptFunction(int funcId, asCScriptNode *node, asCScrip
 
 	GetParsedFunctionDetails(node, file, objType, name, returnType, parameterTypes, inOutFlags, defaultArgs, isConstMethod, isConstructor, isDestructor, isPrivate, isOverride, isFinal, isShared);
 
+	if( isExistingShared ) 
+	{
+		asASSERT( objType );
+
+		// Should validate that the function really exists in the class/interface
+		bool found = false;
+		if( isConstructor || isDestructor )
+		{
+			// TODO: shared: Should check the existance of these too
+			found = true;
+		}
+		else
+		{
+			for( asUINT n = 0; n < objType->methods.GetLength(); n++ )
+			{
+				asCScriptFunction *func = engine->scriptFunctions[objType->methods[n]];
+				if( func->name == name &&
+					func->IsSignatureExceptNameEqual(returnType, parameterTypes, inOutFlags, objType, isConstMethod) )
+				{
+					found = true;
+					break;
+				}
+			}
+		}
+
+		if( !found )
+		{
+			int r, c;
+			file->ConvertPosToRowCol(node->tokenPos, &r, &c);
+			WriteError(file->name.AddressOf(), TXT_SHARED_DOESNT_MATCH_ORIGINAL, r, c);
+		}
+
+		node->Destroy(engine);
+		return 0;
+	}
+
 	// Check for name conflicts
 	if( !isConstructor && !isDestructor )
 	{
@@ -2804,7 +2906,7 @@ int asCBuilder::RegisterScriptFunction(int funcId, asCScriptNode *node, asCScrip
 			name = "~" + name;
 	}
 
-	bool isExistingShared = false;
+	isExistingShared = false;
 	if( !isInterface )
 	{
 		sFunctionDescription *func = asNEW(sFunctionDescription);
@@ -3152,8 +3254,15 @@ int asCBuilder::RegisterScriptFunctionWithSignature(int funcId, asCScriptNode *n
 	return 0;
 }
 
-int asCBuilder::RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, const asCString &ns)
+int asCBuilder::RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, const asCString &ns, bool isExistingShared)
 {
+	if( isExistingShared ) 
+	{
+		// TODO: shared: Should validate that the function really exists in the class/interface
+		node->Destroy(engine);
+		return 0;
+	}
+
 	if( engine->ep.propertyAccessorMode != 2 )
 	{
 		int r, c;
@@ -3453,12 +3562,6 @@ void asCBuilder::GetFunctionDescriptions(const char *name, asCArray<int> &funcs,
 			// Verify if the module has access to the function
 			if( module->accessMask & f->accessMask )
 			{
-#ifdef AS_DEPRECATED
-				// deprecated since 2011-10-04
-				// Find the config group for the global function
-				asCConfigGroup *group = engine->FindConfigGroupForFunction(f->id);
-				if( !group || group->HasModuleAccess(module->name.AddressOf()) )
-#endif
 				funcs.PushLast(f->id);
 			}
 		}
@@ -3629,14 +3732,7 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod
 				isImplicitHandle = true;
 
 			// Make sure the module has access to the object type
-#ifdef AS_DEPRECATED
-			// deprecated since 2011-10-04
-			// Find the config group for the object type
-			asCConfigGroup *group = engine->FindConfigGroupForObjectType(ot);
-			if( !module || ((module->accessMask & ot->accessMask) && (!group || group->HasModuleAccess(module->name.AddressOf()))) )
-#else
 			if( !module || (module->accessMask & ot->accessMask) )
-#endif
 			{
 				if(asOBJ_TYPEDEF == (ot->flags & asOBJ_TYPEDEF))
 				{
@@ -3822,7 +3918,7 @@ asCDataType asCBuilder::ModifyDataTypeFromNode(const asCDataType &type, asCScrip
 			inOutFlags && *inOutFlags == asTM_INOUTREF )
 		{
 			// Verify that the base type support &inout parameter types
-			if( !dt.IsObject() || dt.IsObjectHandle() || !dt.GetObjectType()->beh.addref || !dt.GetObjectType()->beh.release )
+			if( !dt.IsObject() || dt.IsObjectHandle() || !((dt.GetObjectType()->flags & asOBJ_NOCOUNT) || (dt.GetObjectType()->beh.addref && dt.GetObjectType()->beh.release)) )
 			{
 				int r, c;
 				file->ConvertPosToRowCol(node->firstChild->tokenPos, &r, &c);
@@ -3835,6 +3931,14 @@ asCDataType asCBuilder::ModifyDataTypeFromNode(const asCDataType &type, asCScrip
 
 	if( n && n->tokenType == ttPlus )
 	{
+		// Autohandles are not supported for types with NOCOUNT
+		if( dt.GetObjectType()->flags & asOBJ_NOCOUNT )
+		{
+			int r, c;
+			file->ConvertPosToRowCol(node->firstChild->tokenPos, &r, &c);
+			WriteError(file->name.AddressOf(), TXT_AUTOHANDLE_CANNOT_BE_USED_FOR_NOCOUNT, r, c);
+		}
+
 		if( autoHandle ) *autoHandle = true;
 	}
 
@@ -3904,6 +4008,8 @@ asCScriptFunction *asCBuilder::GetFuncDef(const char *type)
 	return 0;
 }
 
+#ifndef AS_NO_COMPILER
+
 int asCBuilder::GetEnumValueFromObjectType(asCObjectType *objType, const char *name, asCDataType &outDt, asDWORD &outValue)
 {
 	if( !objType || !(objType->flags & asOBJ_ENUM) )
@@ -3973,4 +4079,6 @@ int asCBuilder::GetEnumValue(const char *name, asCDataType &outDt, asDWORD &outV
 	return 0;
 }
 
+#endif // AS_NO_COMPILER
+
 END_AS_NAMESPACE

+ 51 - 47
ThirdParty/AngelScript/source/as_builder.h

@@ -50,6 +50,8 @@
 
 BEGIN_AS_NAMESPACE
 
+#ifndef AS_NO_COMPILER
+
 struct sExplicitSignature
 {
 	sExplicitSignature(int argCount = 0) : argTypes(argCount), argModifiers(argCount), argNames(argCount), defaultArgs(argCount) {}
@@ -108,7 +110,7 @@ struct sFuncDef
 	int idx;
 };
 
-class asCCompiler;
+#endif // AS_NO_COMPILER
 
 class asCBuilder
 {
@@ -118,10 +120,10 @@ public:
 
 	// These methods are used by the application interface
 	int VerifyProperty(asCDataType *dt, const char *decl, asCString &outName, asCDataType &outType, const asCString &ns);
-	int ParseDataType(const char *datatype, asCDataType *result);
+	int ParseDataType(const char *datatype, asCDataType *result, const asCString &implicitNamespace, bool isReturnType = false);
 	int ParseTemplateDecl(const char *decl, asCString *name, asCString *subtypeName);
 	int ParseFunctionDeclaration(asCObjectType *type, const char *decl, asCScriptFunction *func, bool isSystemFunction, asCArray<bool> *paramAutoHandles = 0, bool *returnAutoHandle = 0);
-	int ParseVariableDeclaration(const char *decl, asCObjectProperty *var);
+	int ParseVariableDeclaration(const char *decl, const asCString &implicitNamespace, asCString &outName, asCString &outNamespace, asCDataType &outDt);
 	int CheckNameConflict(const char *name, asCScriptNode *node, asCScriptCode *code, const asCString &ns);
 	int CheckNameConflictMember(asCObjectType *type, const char *name, asCScriptNode *node, asCScriptCode *code, bool isProperty);
 
@@ -133,58 +135,33 @@ public:
 	int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset);
 #endif
 
-	void WriteInfo(const char *scriptname, const char *msg, int r, int c, bool preMessage);
-	void WriteError(const char *scriptname, const char *msg, int r, int c);
-	void WriteWarning(const char *scriptname, const char *msg, int r, int c);
-
 protected:
-	friend class asCCompiler;
 	friend class asCModule;
 	friend class asCParser;
 
+	void               Reset();
+
+	void               WriteInfo(const char *scriptname, const char *msg, int r, int c, bool preMessage);
+	void               WriteError(const char *scriptname, const char *msg, int r, int c);
+	void               WriteWarning(const char *scriptname, const char *msg, int r, int c);
+
 	asCObjectProperty *GetObjectProperty(asCDataType &obj, const char *prop);
 	asCGlobalProperty *GetGlobalProperty(const char *prop, const asCString &ns, bool *isCompiled, bool *isPureConstant, asQWORD *constantValue, bool *isAppProp);
 
 	asCScriptFunction *GetFunctionDescription(int funcId);
-	void GetFunctionDescriptions(const char *name, asCArray<int> &funcs, const asCString &ns);
-	void GetObjectMethodDescriptions(const char *name, asCObjectType *objectType, asCArray<int> &methods, bool objIsConst, const asCString &scope = "");
+	void               GetFunctionDescriptions(const char *name, asCArray<int> &funcs, const asCString &ns);
+	void               GetObjectMethodDescriptions(const char *name, asCObjectType *objectType, asCArray<int> &methods, bool objIsConst, const asCString &scope = "");
 
-	int  ValidateDefaultArgs(asCScriptCode *script, asCScriptNode *node, asCScriptFunction *func);
-	asCString GetCleanExpressionString(asCScriptNode *n, asCScriptCode *file);
+	int                ValidateDefaultArgs(asCScriptCode *script, asCScriptNode *node, asCScriptFunction *func);
+	asCString          GetCleanExpressionString(asCScriptNode *n, asCScriptCode *file);
 
-	asCString GetScopeFromNode(asCScriptNode *n, asCScriptCode *script, asCScriptNode **next = 0);
-
-#ifndef AS_NO_COMPILER
-	int RegisterScriptFunction(int funcID, asCScriptNode *node, asCScriptCode *file, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, const asCString &ns = "");
-	int RegisterScriptFunctionWithSignature(int funcID, asCScriptNode *node, asCScriptCode *file, asCString &name, sExplicitSignature *signature, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, bool isPrivate = false, bool isConst = false, bool isFinal = false, bool isOverride = false, bool treatAsProperty = false, const asCString &ns = "");
-	int RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, const asCString &ns = "");
-	int RegisterImportedFunction(int funcID, asCScriptNode *node, asCScriptCode *file, const asCString &ns);
-	int RegisterGlobalVar(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
-	int RegisterClass(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
-	int RegisterInterface(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
-	int RegisterEnum(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
-	int RegisterTypedef(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
-	int RegisterFuncDef(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
-	void CompleteFuncDef(sFuncDef *funcDef);
-	void CompileClasses();
-	void GetParsedFunctionDetails(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, asCString &name, asCDataType &returnType, asCArray<asCDataType> &parameterTypes, asCArray<asETypeModifiers> &inOutFlags, asCArray<asCString *> &defaultArgs, bool &isConstMethod, bool &isConstructor, bool &isDestructor, bool &isPrivate, bool &isOverride, bool &isFinal, bool &isShared);
-	bool DoesMethodExist(asCObjectType *objType, int methodId, asUINT *methodIndex = 0);
-	void AddDefaultConstructor(asCObjectType *objType, asCScriptCode *file);
-	asCObjectProperty *AddPropertyToClass(sClassDeclaration *c, const asCString &name, const asCDataType &type, bool isPrivate, asCScriptCode *file = 0, asCScriptNode *node = 0);
-	int CreateVirtualFunction(asCScriptFunction *func, int idx);
-	void ParseScripts();
-	void RegisterTypesFromScript(asCScriptNode *node, asCScriptCode *script, const asCString &ns);
-	void RegisterNonTypesFromScript(asCScriptNode *node, asCScriptCode *script, const asCString &ns);
-	void CompileFunctions();
-	void CompileGlobalVariables();
-#endif
+	asCString          GetScopeFromNode(asCScriptNode *n, asCScriptCode *script, asCScriptNode **next = 0);
 
 	asCObjectType     *GetObjectType(const char *type, const asCString &ns);
 	asCScriptFunction *GetFuncDef(const char *type);
 	asCObjectType     *GetObjectTypeFromTypesKnownByObject(const char *type, asCObjectType *currentType);
-
-	int GetEnumValueFromObjectType(asCObjectType *objType, const char *name, asCDataType &outDt, asDWORD &outValue);
-	int GetEnumValue(const char *name, asCDataType &outDt, asDWORD &outValue, const asCString &ns);
+	asCDataType        CreateDataTypeFromNode(asCScriptNode *node, asCScriptCode *file, const asCString &implicitNamespace, bool acceptHandleForScope = false, asCObjectType *currentType = 0);
+	asCDataType        ModifyDataTypeFromNode(const asCDataType &type, asCScriptNode *node, asCScriptCode *file, asETypeModifiers *inOutFlag, bool *autoHandle);
 
 	struct preMessage_t
 	{
@@ -197,6 +174,38 @@ protected:
 	int numErrors;
 	int numWarnings;
 
+	asCScriptEngine *engine;
+	asCModule       *module;
+
+#ifndef AS_NO_COMPILER
+protected:
+	friend class asCCompiler;
+
+	int                RegisterScriptFunction(int funcID, asCScriptNode *node, asCScriptCode *file, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, const asCString &ns = "", bool isExistingShared = false);
+	int                RegisterScriptFunctionWithSignature(int funcID, asCScriptNode *node, asCScriptCode *file, asCString &name, sExplicitSignature *signature, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, bool isPrivate = false, bool isConst = false, bool isFinal = false, bool isOverride = false, bool treatAsProperty = false, const asCString &ns = "");
+	int                RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, const asCString &ns = "", bool isExistingShared = false);
+	int                RegisterImportedFunction(int funcID, asCScriptNode *node, asCScriptCode *file, const asCString &ns);
+	int                RegisterGlobalVar(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
+	int                RegisterClass(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
+	int                RegisterInterface(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
+	int                RegisterEnum(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
+	int                RegisterTypedef(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
+	int                RegisterFuncDef(asCScriptNode *node, asCScriptCode *file, const asCString &ns);
+	void               CompleteFuncDef(sFuncDef *funcDef);
+	void               CompileClasses();
+	void               GetParsedFunctionDetails(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, asCString &name, asCDataType &returnType, asCArray<asCDataType> &parameterTypes, asCArray<asETypeModifiers> &inOutFlags, asCArray<asCString *> &defaultArgs, bool &isConstMethod, bool &isConstructor, bool &isDestructor, bool &isPrivate, bool &isOverride, bool &isFinal, bool &isShared);
+	bool               DoesMethodExist(asCObjectType *objType, int methodId, asUINT *methodIndex = 0);
+	void               AddDefaultConstructor(asCObjectType *objType, asCScriptCode *file);
+	asCObjectProperty *AddPropertyToClass(sClassDeclaration *c, const asCString &name, const asCDataType &type, bool isPrivate, asCScriptCode *file = 0, asCScriptNode *node = 0);
+	int                CreateVirtualFunction(asCScriptFunction *func, int idx);
+	void               ParseScripts();
+	void               RegisterTypesFromScript(asCScriptNode *node, asCScriptCode *script, const asCString &ns);
+	void               RegisterNonTypesFromScript(asCScriptNode *node, asCScriptCode *script, const asCString &ns);
+	void               CompileFunctions();
+	void               CompileGlobalVariables();
+	int                GetEnumValueFromObjectType(asCObjectType *objType, const char *name, asCDataType &outDt, asDWORD &outValue);
+	int                GetEnumValue(const char *name, asCDataType &outDt, asDWORD &outValue, const asCString &ns);
+
 	asCArray<asCScriptCode *>              scripts;
 	asCArray<sFunctionDescription *>       functions;
 	asCArray<sGlobalVariableDescription *> globVariables;
@@ -204,12 +213,7 @@ protected:
 	asCArray<sClassDeclaration *>          interfaceDeclarations;
 	asCArray<sClassDeclaration *>          namedTypeDeclarations;
 	asCArray<sFuncDef *>                   funcDefs;
-
-	asCScriptEngine *engine;
-	asCModule *module;
-
-	asCDataType CreateDataTypeFromNode(asCScriptNode *node, asCScriptCode *file, const asCString &implicitNamespace, bool acceptHandleForScope = false, asCObjectType *currentType = 0);
-	asCDataType ModifyDataTypeFromNode(const asCDataType &type, asCScriptNode *node, asCScriptCode *file, asETypeModifiers *inOutFlag, bool *autoHandle);
+#endif
 };
 
 END_AS_NAMESPACE

+ 9 - 3
ThirdParty/AngelScript/source/as_bytecode.cpp

@@ -38,6 +38,9 @@
 #include <stdio.h> // fopen(), fprintf(), fclose()
 
 #include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_bytecode.h"
 #include "as_debug.h" // mkdir()
 #include "as_array.h"
@@ -1334,7 +1337,7 @@ void asCByteCode::Alloc(asEBCInstr instr, void *objID, int funcID, int pop)
 	last->stackInc = -pop; // BC_ALLOC
 
 	asASSERT(asBCInfo[instr].type == asBCTYPE_PTR_DW_ARG);
-	*ARG_PTR(last->arg) = (asPTRWORD)(size_t)objID;
+	*ARG_PTR(last->arg) = (asPWORD)objID;
 	*((int*)(ARG_DW(last->arg)+AS_PTR_SIZE)) = funcID;
 
     // Add a JitEntry instruction after function calls so that JIT's can resume execution
@@ -2122,7 +2125,7 @@ int asCByteCode::InstrW_PTR(asEBCInstr bc, short a, void *param)
 
 	last->op       = bc;
 	last->wArg[0]  = a;
-	*ARG_PTR(last->arg) = (asPTRWORD)(size_t)param;
+	*ARG_PTR(last->arg) = (asPWORD)param;
 	last->size     = asBCTypeSize[asBCInfo[bc].type];
 	last->stackInc = asBCInfo[bc].stackInc;
 
@@ -2330,7 +2333,7 @@ int asCByteCode::InstrPTR(asEBCInstr bc, void *param)
 
 	last->op = bc;
 	asASSERT(asBCInfo[bc].type == asBCTYPE_PTR_ARG);
-	*ARG_PTR(last->arg) = (asPTRWORD)(size_t)param;
+	*ARG_PTR(last->arg) = (asPWORD)param;
 	last->size     = asBCTypeSize[asBCInfo[bc].type];
 	last->stackInc = asBCInfo[bc].stackInc;
 
@@ -2502,3 +2505,6 @@ void cByteInstruction::Remove()
 }
 
 END_AS_NAMESPACE
+
+#endif // AS_NO_COMPILER
+

+ 6 - 1
ThirdParty/AngelScript/source/as_bytecode.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -41,6 +41,9 @@
 #define AS_BYTECODE_H
 
 #include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_array.h"
 
 BEGIN_AS_NAMESPACE
@@ -192,4 +195,6 @@ public:
 
 END_AS_NAMESPACE
 
+#endif // AS_NO_COMPILER
+
 #endif

+ 26 - 19
ThirdParty/AngelScript/source/as_callfunc.cpp

@@ -48,7 +48,7 @@ int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv,
 {
 	memset(internal, 0, sizeof(asSSystemFunctionInterface));
 
-	internal->func = (size_t)ptr.ptr.f.func;
+	internal->func = ptr.ptr.f.func;
 
 	// Was a compatible calling convention specified?
 	if( internal->func )
@@ -419,7 +419,7 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 			popSize += AS_PTR_SIZE;
 
 			// Check for null pointer
-			obj = (void*)*(size_t*)(args);
+			obj = (void*)*(asPWORD*)(args);
 			if( obj == 0 )
 			{
 				context->SetInternalException(TXT_NULL_POINTER_ACCESS);
@@ -433,9 +433,9 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 			// On GNUC + ARM the lsb of the offset is used to indicate a virtual function
 			// and the whole offset is thus shifted one bit left to keep the original
 			// offset resolution
-			obj = (void*)(size_t(obj) + (sysFunc->baseOffset>>1));
+			obj = (void*)(asPWORD(obj) + (sysFunc->baseOffset>>1));
 #else
-			obj = (void*)(size_t(obj) + sysFunc->baseOffset);
+			obj = (void*)(asPWORD(obj) + sysFunc->baseOffset);
 #endif
 
 			// Skip the object pointer
@@ -447,7 +447,7 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 	if( descr->returnType.IsObject() && !descr->returnType.IsReference() && !descr->returnType.IsObjectHandle() )
 	{
 		// Get the address of the location for the return value from the stack
-		retPointer = (void*)*(size_t*)(args);
+		retPointer = (void*)*(asPWORD*)(args);
 		popSize += AS_PTR_SIZE;
 		args += AS_PTR_SIZE;
 
@@ -456,7 +456,9 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 	}
 
 
+	context->callingSystemFunction = descr;
 	retQW = CallSystemFunctionNative(context, descr, obj, args, sysFunc->hostReturnInMemory ? retPointer : 0, retQW2);
+	context->callingSystemFunction = 0;
 
 #if defined(COMPLEX_OBJS_PASSED_BY_REF) || defined(AS_LARGE_OBJS_PASSED_BY_REF)
 	if( sysFunc->takesObjByVal )
@@ -470,23 +472,25 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 		int spos = 0;
 		for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
 		{
-			if( descr->parameterTypes[n].IsObject() &&
-				!descr->parameterTypes[n].IsObjectHandle() && 
-				!descr->parameterTypes[n].IsReference() && (
+			bool needFree = false;
+			asCDataType &dt = descr->parameterTypes[n];
 #ifdef COMPLEX_OBJS_PASSED_BY_REF				
-				(descr->parameterTypes[n].GetObjectType()->flags & COMPLEX_MASK) ||
-#endif				
+			if( dt.GetObjectType() && dt.GetObjectType()->flags & COMPLEX_MASK ) needFree = true;
+#endif
 #ifdef AS_LARGE_OBJS_PASSED_BY_REF
-				(descr->parameterTypes[n].GetSizeInMemoryDWords() >= AS_LARGE_OBJ_MIN_SIZE) ||
+			if( dt.GetSizeInMemoryDWords() >= AS_LARGE_OBJ_MIN_SIZE ) needFree = true;
 #endif
-				0) )
+			if( needFree &&
+				dt.IsObject() &&
+				!dt.IsObjectHandle() && 
+				!dt.IsReference() )
 			{
-				void *obj = (void*)*(size_t*)&args[spos];
+				void *obj = (void*)*(asPWORD*)&args[spos];
 				spos += AS_PTR_SIZE;
 
 #ifndef AS_CALLEE_DESTROY_OBJ_BY_VAL
 				// If the called function doesn't destroy objects passed by value we must do so here
-				asSTypeBehaviour *beh = &descr->parameterTypes[n].GetObjectType()->beh;
+				asSTypeBehaviour *beh = &dt.GetObjectType()->beh;
 				if( beh->destruct )
 					engine->CallObjectMethod(obj, beh->destruct);
 #endif
@@ -494,7 +498,7 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 				engine->CallFree(obj);
 			}
 			else
-				spos += descr->parameterTypes[n].GetSizeOnStackDWords();
+				spos += dt.GetSizeOnStackDWords();
 		}
 	}
 #endif
@@ -510,10 +514,13 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 			retQW >>= 32;
 #endif
 
-			context->regs.objectRegister = (void*)(size_t)retQW;
+			context->regs.objectRegister = (void*)(asPWORD)retQW;
 
 			if( sysFunc->returnAutoHandle && context->regs.objectRegister )
+			{
+				asASSERT( !(descr->returnType.GetObjectType()->flags & asOBJ_NOCOUNT) );
 				engine->CallObjectMethod(context->regs.objectRegister, descr->returnType.GetObjectType()->beh.addref);
+			}
 		}
 		else
 		{
@@ -631,11 +638,11 @@ int CallSystemFunction(int id, asCContext *context, void *objectPointer)
 		int spos = 0;
 		for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
 		{
-			if( sysFunc->paramAutoHandles[n] && *(size_t*)&args[spos] != 0 )
+			if( sysFunc->paramAutoHandles[n] && *(asPWORD*)&args[spos] != 0 )
 			{
 				// Call the release method on the type
-				engine->CallObjectMethod((void*)*(size_t*)&args[spos], descr->parameterTypes[n].GetObjectType()->beh.release);
-				*(size_t*)&args[spos] = 0;
+				engine->CallObjectMethod((void*)*(asPWORD*)&args[spos], descr->parameterTypes[n].GetObjectType()->beh.release);
+				*(asPWORD*)&args[spos] = 0;
 			}
 
 			if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() )

+ 12 - 2
ThirdParty/AngelScript/source/as_callfunc.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2009 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -56,6 +56,16 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i
 
 int CallSystemFunction(int id, asCContext *context, void *objectPointer);
 
+inline asPWORD FuncPtrToUInt(asFUNCTION_t func)
+{
+	// A little trickery as the C++ standard doesn't allow direct 
+	// conversion between function pointer and data pointer
+	union { asFUNCTION_t func; asPWORD idx; } u;
+	u.func = func;
+
+	return u.idx;
+}
+
 enum internalCallConv
 {
 	ICC_GENERIC_FUNC,
@@ -78,7 +88,7 @@ enum internalCallConv
 
 struct asSSystemFunctionInterface
 {
-	size_t               func;
+	asFUNCTION_t         func;
 	int                  baseOffset;
 	internalCallConv     callConv;
 	int                  scriptReturnSize;

+ 34 - 37
ThirdParty/AngelScript/source/as_callfunc_arm.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -49,11 +49,11 @@
 
 BEGIN_AS_NAMESPACE
 
-extern "C" asQWORD armFunc(const asDWORD *, int, size_t);
-extern "C" asQWORD armFuncR0(const asDWORD *, int, size_t, asDWORD r0);
-extern "C" asQWORD armFuncR0R1(const asDWORD *, int, size_t, asDWORD r0, asDWORD r1);
-extern "C" asQWORD armFuncObjLast(const asDWORD *, int, size_t, asDWORD obj);
-extern "C" asQWORD armFuncR0ObjLast(const asDWORD *, int, size_t, asDWORD r0, asDWORD obj);
+extern "C" asQWORD armFunc(const asDWORD *, int, asFUNCTION_t);
+extern "C" asQWORD armFuncR0(const asDWORD *, int, asFUNCTION_t, asDWORD r0);
+extern "C" asQWORD armFuncR0R1(const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD r1);
+extern "C" asQWORD armFuncObjLast(const asDWORD *, int, asFUNCTION_t, asDWORD obj);
+extern "C" asQWORD armFuncR0ObjLast(const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD obj);
 
 asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/)
 {
@@ -61,10 +61,10 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf;
 	int callConv = sysFunc->callConv;
 
-	asQWORD  retQW             = 0;
-	void    *func              = (void*)sysFunc->func;
-	int      paramSize         = sysFunc->paramSize;
-	asDWORD *vftable;
+	asQWORD       retQW             = 0;
+	asFUNCTION_t  func              = sysFunc->func;
+	int           paramSize         = sysFunc->paramSize;
+	asFUNCTION_t *vftable;
 
 	if( sysFunc->hostReturnInMemory )
 	{
@@ -80,7 +80,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		int dpos = 1;
 		for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
 		{
-            if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() )
+			if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() )
 			{
 #ifdef COMPLEX_OBJS_PASSED_BY_REF
 				if( descr->parameterTypes[n].GetObjectType()->flags & COMPLEX_MASK )
@@ -114,54 +114,51 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		args = &paramBuffer[1];
 	}
 
-	context->isCallingSystemFunction = true;
-
 	switch( callConv )
 	{
 	case ICC_CDECL_RETURNINMEM:     // fall through
 	case ICC_STDCALL_RETURNINMEM:
-        retQW = armFuncR0(args, paramSize<<2, (asDWORD)func, (asDWORD) retPointer);
-        break;
-    case ICC_CDECL:     // fall through
-    case ICC_STDCALL:
-		retQW = armFunc(args, paramSize<<2, (asDWORD)func);
+		retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)retPointer);
+		break;
+	case ICC_CDECL:     // fall through
+	case ICC_STDCALL:
+		retQW = armFunc(args, paramSize<<2, func);
 		break;
-    case ICC_THISCALL:  // fall through
+	case ICC_THISCALL:  // fall through
 	case ICC_CDECL_OBJFIRST:
-        retQW = armFuncR0(args, paramSize<<2, (asDWORD)func, (asDWORD) obj);
-        break;
-    case ICC_THISCALL_RETURNINMEM:
+		retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)obj);
+		break;
+	case ICC_THISCALL_RETURNINMEM:
 #ifndef __GNUC__
-        retQW = armFuncR0R1(args, paramSize<<2, (asDWORD)func, (asDWORD) obj, (asDWORD) retPointer);
+		retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)obj, (asDWORD)retPointer);
 		break;
 #endif
-    case ICC_CDECL_OBJFIRST_RETURNINMEM:
-        retQW = armFuncR0R1(args, paramSize<<2, (asDWORD)func, (asDWORD) retPointer, (asDWORD) obj);
+	case ICC_CDECL_OBJFIRST_RETURNINMEM:
+		retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
 		break;
 	case ICC_VIRTUAL_THISCALL:
 		// Get virtual function table from the object pointer
-		vftable = *(asDWORD**)obj;
-        retQW = armFuncR0(args, paramSize<<2, vftable[asDWORD(func)>>2], (asDWORD) obj);
-        break;
-    case ICC_VIRTUAL_THISCALL_RETURNINMEM:
+		vftable = *(asFUNCTION_t**)obj;
+		retQW = armFuncR0(args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj);
+		break;
+	case ICC_VIRTUAL_THISCALL_RETURNINMEM:
 		// Get virtual function table from the object pointer
-		vftable = *(asDWORD**)obj;
+		vftable = *(asFUNCTION_t**)obj;
 #ifndef __GNUC__
-        retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[asDWORD(func)>>2], (asDWORD) retPointer, (asDWORD) obj);
+		retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)retPointer, (asDWORD)obj);
 #else
-        retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[asDWORD(func)>>2], (asDWORD) obj, (asDWORD) retPointer);
+		retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj, (asDWORD)retPointer);
 #endif
 		break;
 	case ICC_CDECL_OBJLAST:
-		retQW = armFuncObjLast(args, paramSize<<2, (asDWORD)func, (asDWORD) obj);
-        break;
-    case ICC_CDECL_OBJLAST_RETURNINMEM:
-		retQW = armFuncR0ObjLast(args, paramSize<<2, (asDWORD)func, (asDWORD) retPointer, (asDWORD) obj);
+		retQW = armFuncObjLast(args, paramSize<<2, func, (asDWORD)obj);
+		break;
+	case ICC_CDECL_OBJLAST_RETURNINMEM:
+		retQW = armFuncR0ObjLast(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
 		break;
 	default:
 		context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
 	}
-	context->isCallingSystemFunction = false;
 
 	return retQW;
 }

+ 235 - 235
ThirdParty/AngelScript/source/as_callfunc_arm_gcc.S

@@ -1,235 +1,235 @@
-/*
-  AngelCode Scripting Library
-  Copyright (c) 2003-2009 Andreas Jonsson
-
-  This software is provided 'as-is', without any express or implied
-  warranty. In no event will the authors be held liable for any
-  damages arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any
-  purpose, including commercial applications, and to alter it and
-  redistribute it freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you
-     must not claim that you wrote the original software. If you use
-     this software in a product, an acknowledgment in the product
-     documentation would be appreciated but is not required.
-
-  2. Altered source versions must be plainly marked as such, and
-     must not be misrepresented as being the original software.
-
-  3. This notice may not be removed or altered from any source
-     distribution.
-
-  The original version of this library can be located at:
-  http://www.angelcode.com/angelscript/
-
-  Andreas Jonsson
-  [email protected]
-*/
-
-
-// Assembly routines for the ARM call convention
-// Written by Fredrik Ehnbom in June 2009
-
-// Adapted to GNUC by darktemplar216 in September 2009
-
-#if defined(__arm__) || defined(__ARM__)
-
-.global armFunc
-.global armFuncR0
-.global armFuncR0R1
-.global armFuncObjLast
-.global armFuncR0ObjLast
-    
-armFunc:
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  // arg table
-    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  // function address
-    mov     r8, #0
-
-    beq     nomoreargs
-
-    // Load the first 4 arguments into r0-r3
-    cmp     r7, #4
-    ldrge   r0, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r1, [r6],#4
-    cmp     r7, #3*4
-    ldrge   r2, [r6],#4
-    cmp     r7, #4*4
-    ldrge   r3, [r6],#4
-    ble     nomoreargs
-
-    // Load the rest of the arguments onto the stack
-    sub     r7, r7, #4*4    // skip the 4 registers already loaded into r0-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-stackargsloop:
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     stackargsloop
-nomoreargs:
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    ldmia   sp!, {r4-r8, pc}
-
-armFuncObjLast:
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  // arg table
-    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  // function address
-    mov     r8, #0
-
-    mov     r0, r3          // objlast. might get overwritten
-    str     r3, [sp, #-4]!  // objlast again.
-
-    beq     nomoreargsarmFuncObjLast
-
-    // Load the first 4 arguments into r0-r3
-    cmp     r7, #4
-    ldrge   r0, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r1, [r6],#4
-    ldrlt   r1, [sp]    
-    cmp     r7, #3*4
-    ldrge   r2, [r6],#4
-    ldrlt   r2, [sp]
-    cmp     r7, #4*4
-    ldrge   r3, [r6],#4
-    ldrlt   r3, [sp]
-    ble     nomoreargsarmFuncObjLast
-
-    // Load the rest of the arguments onto the stack
-    sub     r7, r7, #4*4    // skip the 4 registers already loaded into r0-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-stackargslooparmFuncObjLast:
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     stackargslooparmFuncObjLast
-nomoreargsarmFuncObjLast:
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    add     sp, sp, #4
-    ldmia   sp!, {r4-r8, pc}
-
-armFuncR0ObjLast:
-    stmdb   sp!, {r4-r8, lr}
-    ldr     r7, [sp,#6*4]
-    str     r7, [sp,#-4]!
-
-    mov     r6, r0  // arg table
-    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  // function address
-    mov     r8, #0
-
-    mov     r0, r3      // r0 explicitly set
-    ldr     r1, [sp]    // objlast.  might get overwritten
-
-    beq     nomoreargsarmFuncR0ObjLast
-
-    // Load the first 3 arguments into r1-r3
-    cmp     r7, #1*4
-    ldrge   r1, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r2, [r6],#4
-    ldrlt   r2, [sp]
-    cmp     r7, #3*4
-    ldrge   r3, [r6],#4
-    ldrlt   r3, [sp]
-    ble     nomoreargsarmFuncR0ObjLast
-
-    // Load the rest of the arguments onto the stack
-    sub     r7, r7, #3*4    // skip the 3 registers already loaded into r1-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-stackargslooparmFuncR0ObjLast:
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     stackargslooparmFuncR0ObjLast
-nomoreargsarmFuncR0ObjLast:
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    add     sp, sp, #4
-    ldmia   sp!, {r4-r8, pc}
-
-
-armFuncR0:
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  // arg table
-    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  // function address
-    mov     r8, #0
-
-    mov     r0, r3  // r0 explicitly set
-
-    beq     nomoreargsarmFuncR0
-
-    // Load the first 3 arguments into r1-r3
-    cmp     r7, #1*4
-    ldrge   r1, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r2, [r6],#4
-    cmp     r7, #3*4
-    ldrge   r3, [r6],#4
-    ble     nomoreargsarmFuncR0
-
-    // Load the rest of the arguments onto the stack
-    sub     r7, r7, #3*4    // skip the 3 registers already loaded into r1-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-stackargslooparmFuncR0:
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     stackargslooparmFuncR0
-nomoreargsarmFuncR0:
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    ldmia   sp!, {r4-r8, pc}
-
-
-armFuncR0R1:
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  // arg table
-    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  // function address
-    mov     r8, #0
-
-    mov     r0, r3          // r0 explicitly set
-    ldr     r1, [sp, #6*4]  // r1 explicitly set too
-
-    beq     nomoreargsarmFuncR0R1
-
-    // Load the first 2 arguments into r2-r3
-    cmp     r7, #1*4
-    ldrge   r2, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r3, [r6],#4
-    ble     nomoreargsarmFuncR0R1
-
-    // Load the rest of the arguments onto the stack
-    sub     r7, r7, #2*4    // skip the 2 registers already loaded into r2-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-stackargslooparmFuncR0R1:
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     stackargslooparmFuncR0R1
-nomoreargsarmFuncR0R1:
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    ldmia   sp!, {r4-r8, pc}
-
-#endif
+/*
+  AngelCode Scripting Library
+  Copyright (c) 2003-2009 Andreas Jonsson
+
+  This software is provided 'as-is', without any express or implied
+  warranty. In no event will the authors be held liable for any
+  damages arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any
+  purpose, including commercial applications, and to alter it and
+  redistribute it freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you
+     must not claim that you wrote the original software. If you use
+     this software in a product, an acknowledgment in the product
+     documentation would be appreciated but is not required.
+
+  2. Altered source versions must be plainly marked as such, and
+     must not be misrepresented as being the original software.
+
+  3. This notice may not be removed or altered from any source
+     distribution.
+
+  The original version of this library can be located at:
+  http://www.angelcode.com/angelscript/
+
+  Andreas Jonsson
+  [email protected]
+*/
+
+
+// Assembly routines for the ARM call convention
+// Written by Fredrik Ehnbom in June 2009
+
+// Adapted to GNUC by darktemplar216 in September 2009
+
+#if defined(__arm__) || defined(__ARM__)
+
+.global armFunc
+.global armFuncR0
+.global armFuncR0R1
+.global armFuncObjLast
+.global armFuncR0ObjLast
+    
+armFunc:
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  // arg table
+    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  // function address
+    mov     r8, #0
+
+    beq     nomoreargs
+
+    // Load the first 4 arguments into r0-r3
+    cmp     r7, #4
+    ldrge   r0, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r1, [r6],#4
+    cmp     r7, #3*4
+    ldrge   r2, [r6],#4
+    cmp     r7, #4*4
+    ldrge   r3, [r6],#4
+    ble     nomoreargs
+
+    // Load the rest of the arguments onto the stack
+    sub     r7, r7, #4*4    // skip the 4 registers already loaded into r0-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+stackargsloop:
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     stackargsloop
+nomoreargs:
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    ldmia   sp!, {r4-r8, pc}
+
+armFuncObjLast:
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  // arg table
+    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  // function address
+    mov     r8, #0
+
+    mov     r0, r3          // objlast. might get overwritten
+    str     r3, [sp, #-4]!  // objlast again.
+
+    beq     nomoreargsarmFuncObjLast
+
+    // Load the first 4 arguments into r0-r3
+    cmp     r7, #4
+    ldrge   r0, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r1, [r6],#4
+    ldrlt   r1, [sp]    
+    cmp     r7, #3*4
+    ldrge   r2, [r6],#4
+    ldrlt   r2, [sp]
+    cmp     r7, #4*4
+    ldrge   r3, [r6],#4
+    ldrlt   r3, [sp]
+    ble     nomoreargsarmFuncObjLast
+
+    // Load the rest of the arguments onto the stack
+    sub     r7, r7, #4*4    // skip the 4 registers already loaded into r0-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+stackargslooparmFuncObjLast:
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     stackargslooparmFuncObjLast
+nomoreargsarmFuncObjLast:
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    add     sp, sp, #4
+    ldmia   sp!, {r4-r8, pc}
+
+armFuncR0ObjLast:
+    stmdb   sp!, {r4-r8, lr}
+    ldr     r7, [sp,#6*4]
+    str     r7, [sp,#-4]!
+
+    mov     r6, r0  // arg table
+    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  // function address
+    mov     r8, #0
+
+    mov     r0, r3      // r0 explicitly set
+    ldr     r1, [sp]    // objlast.  might get overwritten
+
+    beq     nomoreargsarmFuncR0ObjLast
+
+    // Load the first 3 arguments into r1-r3
+    cmp     r7, #1*4
+    ldrge   r1, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r2, [r6],#4
+    ldrlt   r2, [sp]
+    cmp     r7, #3*4
+    ldrge   r3, [r6],#4
+    ldrlt   r3, [sp]
+    ble     nomoreargsarmFuncR0ObjLast
+
+    // Load the rest of the arguments onto the stack
+    sub     r7, r7, #3*4    // skip the 3 registers already loaded into r1-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+stackargslooparmFuncR0ObjLast:
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     stackargslooparmFuncR0ObjLast
+nomoreargsarmFuncR0ObjLast:
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    add     sp, sp, #4
+    ldmia   sp!, {r4-r8, pc}
+
+
+armFuncR0:
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  // arg table
+    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  // function address
+    mov     r8, #0
+
+    mov     r0, r3  // r0 explicitly set
+
+    beq     nomoreargsarmFuncR0
+
+    // Load the first 3 arguments into r1-r3
+    cmp     r7, #1*4
+    ldrge   r1, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r2, [r6],#4
+    cmp     r7, #3*4
+    ldrge   r3, [r6],#4
+    ble     nomoreargsarmFuncR0
+
+    // Load the rest of the arguments onto the stack
+    sub     r7, r7, #3*4    // skip the 3 registers already loaded into r1-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+stackargslooparmFuncR0:
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     stackargslooparmFuncR0
+nomoreargsarmFuncR0:
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    ldmia   sp!, {r4-r8, pc}
+
+
+armFuncR0R1:
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  // arg table
+    movs    r7, r1  // arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  // function address
+    mov     r8, #0
+
+    mov     r0, r3          // r0 explicitly set
+    ldr     r1, [sp, #6*4]  // r1 explicitly set too
+
+    beq     nomoreargsarmFuncR0R1
+
+    // Load the first 2 arguments into r2-r3
+    cmp     r7, #1*4
+    ldrge   r2, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r3, [r6],#4
+    ble     nomoreargsarmFuncR0R1
+
+    // Load the rest of the arguments onto the stack
+    sub     r7, r7, #2*4    // skip the 2 registers already loaded into r2-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+stackargslooparmFuncR0R1:
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     stackargslooparmFuncR0R1
+nomoreargsarmFuncR0R1:
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    ldmia   sp!, {r4-r8, pc}
+
+#endif

+ 242 - 242
ThirdParty/AngelScript/source/as_callfunc_arm_msvc.asm

@@ -1,242 +1,242 @@
-;
-;  AngelCode Scripting Library
-;  Copyright (c) 2003-2009 Andreas Jonsson
-;
-;  This software is provided 'as-is', without any express or implied
-;  warranty. In no event will the authors be held liable for any
-;  damages arising from the use of this software.
-;
-;  Permission is granted to anyone to use this software for any
-;  purpose, including commercial applications, and to alter it and
-;  redistribute it freely, subject to the following restrictions:
-;
-;  1. The origin of this software must not be misrepresented; you
-;     must not claim that you wrote the original software. If you use
-;     this software in a product, an acknowledgment in the product
-;     documentation would be appreciated but is not required.
-;
-;  2. Altered source versions must be plainly marked as such, and
-;     must not be misrepresented as being the original software.
-;
-;  3. This notice may not be removed or altered from any source
-;     distribution.
-;
-;  The original version of this library can be located at:
-;  http://www.angelcode.com/angelscript/
-;
-;  Andreas Jonsson
-;  [email protected]
-;
-
-
-; Assembly routines for the ARM call convention
-; Written by Fredrik Ehnbom in June 2009
-
-; MSVC currently doesn't support inline assembly for the ARM platform
-; so this separate file is needed.
-
-
-    AREA	|.rdata|, DATA, READONLY
-    EXPORT |armFunc|
-    EXPORT armFuncR0
-    EXPORT armFuncR0R1
-    EXPORT armFuncObjLast
-    EXPORT armFuncR0ObjLast
-    
-
-    AREA	|.text|, CODE, ARM
-
-|armFunc| PROC
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  ; arg table
-    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  ; function address
-    mov     r8, #0
-
-    beq     |nomoreargs|
-
-    ; Load the first 4 arguments into r0-r3
-    cmp     r7, #4
-    ldrge   r0, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r1, [r6],#4
-    cmp     r7, #3*4
-    ldrge   r2, [r6],#4
-    cmp     r7, #4*4
-    ldrge   r3, [r6],#4
-    ble     |nomoreargs|
-
-    ; Load the rest of the arguments onto the stack
-    sub     r7, r7, #4*4    ; skip the 4 registers already loaded into r0-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-|stackargsloop|
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     |stackargsloop|
-|nomoreargs|
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    ldmia   sp!, {r4-r8, pc}
-    ENDP
-
-armFuncObjLast PROC
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  ; arg table
-    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  ; function address
-    mov     r8, #0
-
-    mov     r0, r3          ; objlast. might get overwritten
-    str     r3, [sp, #-4]!  ; objlast again.
-
-    beq     |nomoreargs@armFuncObjLast|
-
-    ; Load the first 4 arguments into r0-r3
-    cmp     r7, #4
-    ldrge   r0, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r1, [r6],#4
-    ldrlt   r1, [sp]    
-    cmp     r7, #3*4
-    ldrge   r2, [r6],#4
-    ldrlt   r2, [sp]
-    cmp     r7, #4*4
-    ldrge   r3, [r6],#4
-    ldrlt   r3, [sp]
-    ble     |nomoreargs@armFuncObjLast|
-
-    ; Load the rest of the arguments onto the stack
-    sub     r7, r7, #4*4    ; skip the 4 registers already loaded into r0-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-|stackargsloop@armFuncObjLast|
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     |stackargsloop@armFuncObjLast|
-|nomoreargs@armFuncObjLast|
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    add     sp, sp, #4
-    ldmia   sp!, {r4-r8, pc}
-    ENDP
-
-armFuncR0ObjLast PROC
-    stmdb   sp!, {r4-r8, lr}
-    ldr     r7, [sp,#6*4]
-    str     r7, [sp,#-4]!
-
-    mov     r6, r0  ; arg table
-    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  ; function address
-    mov     r8, #0
-
-    mov     r0, r3      ; r0 explicitly set
-    ldr     r1, [sp]    ; objlast.  might get overwritten
-
-    beq     |nomoreargs@armFuncR0ObjLast|
-
-    ; Load the first 3 arguments into r1-r3
-    cmp     r7, #1*4
-    ldrge   r1, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r2, [r6],#4
-    ldrlt   r2, [sp]
-    cmp     r7, #3*4
-    ldrge   r3, [r6],#4
-    ldrlt   r3, [sp]
-    ble     |nomoreargs@armFuncR0ObjLast|
-
-    ; Load the rest of the arguments onto the stack
-    sub     r7, r7, #3*4    ; skip the 3 registers already loaded into r1-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-|stackargsloop@armFuncR0ObjLast|
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     |stackargsloop@armFuncR0ObjLast|
-|nomoreargs@armFuncR0ObjLast|
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    add     sp, sp, #4
-    ldmia   sp!, {r4-r8, pc}
-    ENDP
-
-armFuncR0 PROC
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  ; arg table
-    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  ; function address
-    mov     r8, #0
-
-    mov     r0, r3  ; r0 explicitly set
-
-    beq     |nomoreargs@armFuncR0|
-
-    ; Load the first 3 arguments into r1-r3
-    cmp     r7, #1*4
-    ldrge   r1, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r2, [r6],#4
-    cmp     r7, #3*4
-    ldrge   r3, [r6],#4
-    ble     |nomoreargs@armFuncR0|
-
-    ; Load the rest of the arguments onto the stack
-    sub     r7, r7, #3*4    ; skip the 3 registers already loaded into r1-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-|stackargsloop@armFuncR0|
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     |stackargsloop@armFuncR0|
-|nomoreargs@armFuncR0|
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    ldmia   sp!, {r4-r8, pc}
-    ENDP
-
-armFuncR0R1 PROC
-    stmdb   sp!, {r4-r8, lr}
-    mov     r6, r0  ; arg table
-    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
-    mov     r4, r2  ; function address
-    mov     r8, #0
-
-    mov     r0, r3          ; r0 explicitly set
-    ldr     r1, [sp, #6*4]  ; r1 explicitly set too
-
-    beq     |nomoreargs@armFuncR0R1|
-
-    ; Load the first 2 arguments into r2-r3
-    cmp     r7, #1*4
-    ldrge   r2, [r6],#4
-    cmp     r7, #2*4
-    ldrge   r3, [r6],#4
-    ble     |nomoreargs@armFuncR0R1|
-
-    ; Load the rest of the arguments onto the stack
-    sub     r7, r7, #2*4    ; skip the 2 registers already loaded into r2-r3
-    sub     sp, sp, r7
-    mov     r8, r7
-|stackargsloop@armFuncR0R1|
-    ldr     r5, [r6], #4
-    str     r5, [sp], #4
-    subs    r7, r7, #4
-    bne     |stackargsloop@armFuncR0R1|
-|nomoreargs@armFuncR0R1|
-    sub     sp, sp, r8
-    blx     r4
-    add     sp, sp, r8
-    ldmia   sp!, {r4-r8, pc}
-    ENDP
-
-    END
+;
+;  AngelCode Scripting Library
+;  Copyright (c) 2003-2009 Andreas Jonsson
+;
+;  This software is provided 'as-is', without any express or implied
+;  warranty. In no event will the authors be held liable for any
+;  damages arising from the use of this software.
+;
+;  Permission is granted to anyone to use this software for any
+;  purpose, including commercial applications, and to alter it and
+;  redistribute it freely, subject to the following restrictions:
+;
+;  1. The origin of this software must not be misrepresented; you
+;     must not claim that you wrote the original software. If you use
+;     this software in a product, an acknowledgment in the product
+;     documentation would be appreciated but is not required.
+;
+;  2. Altered source versions must be plainly marked as such, and
+;     must not be misrepresented as being the original software.
+;
+;  3. This notice may not be removed or altered from any source
+;     distribution.
+;
+;  The original version of this library can be located at:
+;  http://www.angelcode.com/angelscript/
+;
+;  Andreas Jonsson
+;  [email protected]
+;
+
+
+; Assembly routines for the ARM call convention
+; Written by Fredrik Ehnbom in June 2009
+
+; MSVC currently doesn't support inline assembly for the ARM platform
+; so this separate file is needed.
+
+
+    AREA	|.rdata|, DATA, READONLY
+    EXPORT |armFunc|
+    EXPORT armFuncR0
+    EXPORT armFuncR0R1
+    EXPORT armFuncObjLast
+    EXPORT armFuncR0ObjLast
+    
+
+    AREA	|.text|, CODE, ARM
+
+|armFunc| PROC
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  ; arg table
+    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  ; function address
+    mov     r8, #0
+
+    beq     |nomoreargs|
+
+    ; Load the first 4 arguments into r0-r3
+    cmp     r7, #4
+    ldrge   r0, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r1, [r6],#4
+    cmp     r7, #3*4
+    ldrge   r2, [r6],#4
+    cmp     r7, #4*4
+    ldrge   r3, [r6],#4
+    ble     |nomoreargs|
+
+    ; Load the rest of the arguments onto the stack
+    sub     r7, r7, #4*4    ; skip the 4 registers already loaded into r0-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+|stackargsloop|
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     |stackargsloop|
+|nomoreargs|
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    ldmia   sp!, {r4-r8, pc}
+    ENDP
+
+armFuncObjLast PROC
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  ; arg table
+    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  ; function address
+    mov     r8, #0
+
+    mov     r0, r3          ; objlast. might get overwritten
+    str     r3, [sp, #-4]!  ; objlast again.
+
+    beq     |nomoreargs@armFuncObjLast|
+
+    ; Load the first 4 arguments into r0-r3
+    cmp     r7, #4
+    ldrge   r0, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r1, [r6],#4
+    ldrlt   r1, [sp]    
+    cmp     r7, #3*4
+    ldrge   r2, [r6],#4
+    ldrlt   r2, [sp]
+    cmp     r7, #4*4
+    ldrge   r3, [r6],#4
+    ldrlt   r3, [sp]
+    ble     |nomoreargs@armFuncObjLast|
+
+    ; Load the rest of the arguments onto the stack
+    sub     r7, r7, #4*4    ; skip the 4 registers already loaded into r0-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+|stackargsloop@armFuncObjLast|
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     |stackargsloop@armFuncObjLast|
+|nomoreargs@armFuncObjLast|
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    add     sp, sp, #4
+    ldmia   sp!, {r4-r8, pc}
+    ENDP
+
+armFuncR0ObjLast PROC
+    stmdb   sp!, {r4-r8, lr}
+    ldr     r7, [sp,#6*4]
+    str     r7, [sp,#-4]!
+
+    mov     r6, r0  ; arg table
+    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  ; function address
+    mov     r8, #0
+
+    mov     r0, r3      ; r0 explicitly set
+    ldr     r1, [sp]    ; objlast.  might get overwritten
+
+    beq     |nomoreargs@armFuncR0ObjLast|
+
+    ; Load the first 3 arguments into r1-r3
+    cmp     r7, #1*4
+    ldrge   r1, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r2, [r6],#4
+    ldrlt   r2, [sp]
+    cmp     r7, #3*4
+    ldrge   r3, [r6],#4
+    ldrlt   r3, [sp]
+    ble     |nomoreargs@armFuncR0ObjLast|
+
+    ; Load the rest of the arguments onto the stack
+    sub     r7, r7, #3*4    ; skip the 3 registers already loaded into r1-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+|stackargsloop@armFuncR0ObjLast|
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     |stackargsloop@armFuncR0ObjLast|
+|nomoreargs@armFuncR0ObjLast|
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    add     sp, sp, #4
+    ldmia   sp!, {r4-r8, pc}
+    ENDP
+
+armFuncR0 PROC
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  ; arg table
+    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  ; function address
+    mov     r8, #0
+
+    mov     r0, r3  ; r0 explicitly set
+
+    beq     |nomoreargs@armFuncR0|
+
+    ; Load the first 3 arguments into r1-r3
+    cmp     r7, #1*4
+    ldrge   r1, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r2, [r6],#4
+    cmp     r7, #3*4
+    ldrge   r3, [r6],#4
+    ble     |nomoreargs@armFuncR0|
+
+    ; Load the rest of the arguments onto the stack
+    sub     r7, r7, #3*4    ; skip the 3 registers already loaded into r1-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+|stackargsloop@armFuncR0|
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     |stackargsloop@armFuncR0|
+|nomoreargs@armFuncR0|
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    ldmia   sp!, {r4-r8, pc}
+    ENDP
+
+armFuncR0R1 PROC
+    stmdb   sp!, {r4-r8, lr}
+    mov     r6, r0  ; arg table
+    movs    r7, r1  ; arg size (also set the condition code flags so that we detect if there are no arguments)
+    mov     r4, r2  ; function address
+    mov     r8, #0
+
+    mov     r0, r3          ; r0 explicitly set
+    ldr     r1, [sp, #6*4]  ; r1 explicitly set too
+
+    beq     |nomoreargs@armFuncR0R1|
+
+    ; Load the first 2 arguments into r2-r3
+    cmp     r7, #1*4
+    ldrge   r2, [r6],#4
+    cmp     r7, #2*4
+    ldrge   r3, [r6],#4
+    ble     |nomoreargs@armFuncR0R1|
+
+    ; Load the rest of the arguments onto the stack
+    sub     r7, r7, #2*4    ; skip the 2 registers already loaded into r2-r3
+    sub     sp, sp, r7
+    mov     r8, r7
+|stackargsloop@armFuncR0R1|
+    ldr     r5, [r6], #4
+    str     r5, [sp], #4
+    subs    r7, r7, #4
+    bne     |stackargsloop@armFuncR0R1|
+|nomoreargs@armFuncR0R1|
+    sub     sp, sp, r8
+    blx     r4
+    add     sp, sp, r8
+    ldmia   sp!, {r4-r8, pc}
+    ENDP
+
+    END

+ 2 - 4
ThirdParty/AngelScript/source/as_callfunc_mips.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -210,7 +210,7 @@ asm(
 // so this isn't really used...
 asQWORD GetReturnedDouble()
 {
-	asQWORD d;
+	asQWORD d = 0;
 
 	printf("Broken!!!");
 /*
@@ -292,7 +292,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		args = &paramBuffer[1];
 	}
 
-	context->isCallingSystemFunction = true;
 	switch( callConv )
 	{
 	case ICC_CDECL:
@@ -322,7 +321,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	default:
 		context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
 	}
-	context->isCallingSystemFunction = false;
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )

+ 1 - 3
ThirdParty/AngelScript/source/as_callfunc_ppc.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -622,7 +622,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	}
 	
 	int callConv = sysFunc->callConv;
-	context->isCallingSystemFunction = true;
 	switch( callConv )
 	{
 	case ICC_CDECL:
@@ -652,7 +651,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	default:
 		context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
 	}
-	context->isCallingSystemFunction = false;
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )

+ 1 - 3
ThirdParty/AngelScript/source/as_callfunc_ppc_64.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -710,7 +710,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	}
 	
 	// one last verification to make sure things are how we expect
-	context->isCallingSystemFunction = true;
 	switch( callConv )
 	{
 	case ICC_CDECL:
@@ -740,7 +739,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	default:
 		context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
 	}
-	context->isCallingSystemFunction = false;
 
 	if( sysFunc->hostReturnFloat )
 	{

+ 1 - 3
ThirdParty/AngelScript/source/as_callfunc_sh4.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -340,7 +340,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		args = &paramBuffer[1];
 	}
 
-	context->isCallingSystemFunction = true;
 	switch( callConv )
 	{
 	case ICC_CDECL:
@@ -370,7 +369,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	default:
 		context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
 	}
-	context->isCallingSystemFunction = false;
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )

+ 16 - 66
ThirdParty/AngelScript/source/as_callfunc_x64_gcc.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -74,47 +74,6 @@ typedef asQWORD ( *funcptr_t )( void );
 		: name                                   \
 	)
 
-
-static asDWORD GetReturnedFloat()
-{
-	float   retval = 0.0f;
-	asDWORD ret    = 0;
-
-	__asm__ __volatile__ (
-		"lea      %0, %%rax\n"
-		"movss    %%xmm0, (%%rax)"
-		: /* no output */
-		: "m" (retval)
-		: "%rax", "%xmm0"
-	);
-
-	// We need to avoid implicit conversions from float to unsigned - we need
-	// a bit-wise-correct-and-complete copy of the value 
-	memcpy( &ret, &retval, sizeof( ret ) );
-
-	return ( asDWORD )ret;
-}
-
-static asQWORD GetReturnedDouble()
-{
-	double  retval = 0.0f;
-	asQWORD ret    = 0;
-
-	__asm__ __volatile__ (
-		"lea     %0, %%rax\n"
-		"movlpd  %%xmm0, (%%rax)"
-		: /* no optput */
-		: "m" (retval)
-		: "%rax", "%xmm0"
-	);
-
-	// We need to avoid implicit conversions from double to unsigned long long - we need
-	// a bit-wise-correct-and-complete copy of the value 
-	memcpy( &ret, &retval, sizeof( ret ) );
-
-	return ret;
-}
-
 static void __attribute__((noinline)) GetReturnedXmm0Xmm1(asQWORD &a, asQWORD &b)
 {
 	__asm__ __volatile__ (
@@ -128,11 +87,11 @@ static void __attribute__((noinline)) GetReturnedXmm0Xmm1(asQWORD &a, asQWORD &b
 	);
 }
 
-static asQWORD __attribute__((noinline)) X64_CallFunction( const asQWORD *args, int cnt, void *func ) 
+static asQWORD __attribute__((noinline)) X64_CallFunction( const asQWORD *args, int cnt, funcptr_t func ) 
 {
-	asQWORD retval;
-	asQWORD ( *call )() = (asQWORD (*)())func;
-	int     i           = 0;
+	asQWORD   retval;
+	funcptr_t call    = func;
+	int       i       = 0;
 
 	// Backup the stack pointer and then align it to 16 bytes.
 	// The R15 register is guaranteed to maintain its value over function
@@ -198,13 +157,13 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	asSSystemFunctionInterface *sysFunc            = descr->sysFuncIntf;
 	int                         callConv           = sysFunc->callConv;
 	asQWORD                     retQW              = 0;
-	void                       *func               = ( void * )sysFunc->func;
 	asDWORD                    *stack_pointer      = args;
 	funcptr_t                  *vftable            = NULL;
 	int                         totalArgumentCount = 0;
 	int                         n                  = 0;
 	int                         param_post         = 0;
 	int                         argIndex           = 0;
+	funcptr_t                   func               = (funcptr_t)sysFunc->func;
 
 	if( sysFunc->hostReturnInMemory ) 
 	{
@@ -215,8 +174,8 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	// Determine the real function pointer in case of virtual method
 	if ( obj && ( callConv == ICC_VIRTUAL_THISCALL || callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM ) ) 
 	{
-		vftable = *( ( funcptr_t ** )obj );
-		func    = ( void * )vftable[( asQWORD )func >> 3];
+		vftable = *((funcptr_t**)obj);
+		func = vftable[FuncPtrToUInt(asFUNCTION_t(func)) >> 3];
 	}
 
 	// Determine the type of the arguments, and prepare the input array for the X64_CallFunction 
@@ -228,7 +187,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		case ICC_CDECL_RETURNINMEM:
 		case ICC_STDCALL_RETURNINMEM: 
 		{
-			paramBuffer[0] = (size_t)retPointer;
+			paramBuffer[0] = (asPWORD)retPointer;
 			argsType[0] = x64INTARG;
 
 			argIndex = 1;
@@ -239,7 +198,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		case ICC_VIRTUAL_THISCALL:
 		case ICC_CDECL_OBJFIRST: 
 		{
-			paramBuffer[0] = (size_t)obj;
+			paramBuffer[0] = (asPWORD)obj;
 			argsType[0] = x64INTARG;
 
 			argIndex = 1;
@@ -250,8 +209,8 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		case ICC_VIRTUAL_THISCALL_RETURNINMEM:
 		case ICC_CDECL_OBJFIRST_RETURNINMEM: 
 		{
-			paramBuffer[0] = (size_t)retPointer;
-			paramBuffer[1] = (size_t)obj;
+			paramBuffer[0] = (asPWORD)retPointer;
+			paramBuffer[1] = (asPWORD)obj;
 			argsType[0] = x64INTARG;
 			argsType[1] = x64INTARG;
 
@@ -264,7 +223,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 			break;
 		case ICC_CDECL_OBJLAST_RETURNINMEM: 
 		{
-			paramBuffer[0] = (size_t)retPointer;
+			paramBuffer[0] = (asPWORD)retPointer;
 			argsType[0] = x64INTARG;
 
 			argIndex = 1;
@@ -374,7 +333,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	// For the CDECL_OBJ_LAST calling convention we need to add the object pointer as the last argument
 	if( param_post )
 	{
-		paramBuffer[argIndex] = (size_t)obj;
+		paramBuffer[argIndex] = (asPWORD)obj;
 		argsType[argIndex] = x64INTARG;
 		argIndex++;
 	}
@@ -435,21 +394,12 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		}
 	}
 
-	context->isCallingSystemFunction = true;
-	retQW = X64_CallFunction( tempBuff, used_stack_args, (asDWORD*)func );
+	retQW = X64_CallFunction( tempBuff, used_stack_args, func );
 	ASM_GET_REG( "%rdx", retQW2 );
-	context->isCallingSystemFunction = false;
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )
-	{
-		if( sysFunc->hostReturnSize == 1 )
-			*(asDWORD*)&retQW = GetReturnedFloat();
-		else if( sysFunc->hostReturnSize == 2 )
-			retQW = GetReturnedDouble();
-		else
-			GetReturnedXmm0Xmm1(retQW, retQW2);
-	}
+		GetReturnedXmm0Xmm1(retQW, retQW2);
 
 	return retQW;
 }

+ 3 - 5
ThirdParty/AngelScript/source/as_callfunc_x64_mingw.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -213,7 +213,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	{
 		// Get the true function pointer from the virtual function table
 		vftable = *(void***)obj;
-		func = vftable[size_t(func)>>3];
+		func = vftable[asPWORD(func)>>3];
 	}
 
 	// Move the arguments to the buffer
@@ -292,9 +292,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		allArgBuffer[paramSize++] = (asQWORD)obj;
 	}
 
-	context->isCallingSystemFunction = true;
-	retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize*8, (size_t)func);
-	context->isCallingSystemFunction = false;
+	retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize*8, (asPWORD)func);
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )

+ 3 - 5
ThirdParty/AngelScript/source/as_callfunc_x64_msvc.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -91,7 +91,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	{
 		// Get the true function pointer from the virtual function table
 		vftable = *(void***)obj;
-		func = vftable[size_t(func)>>2];
+		func = vftable[asPWORD(func)>>2];
 	}
 
 	// Move the arguments to the buffer
@@ -170,9 +170,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		allArgBuffer[paramSize++] = (asQWORD)obj;
 	}
 
-	context->isCallingSystemFunction = true;
-	retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize*8, (size_t)func);
-	context->isCallingSystemFunction = false;
+	retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize*8, (asPWORD)func);
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )

+ 48 - 49
ThirdParty/AngelScript/source/as_callfunc_x86.cpp

@@ -72,24 +72,24 @@ BEGIN_AS_NAMESPACE
 #define _S(x) _TOSTRING(x)
 #define _TOSTRING(x) #x
 
-typedef asQWORD (*t_CallCDeclQW)(const asDWORD *, int, size_t);
-typedef asQWORD (*t_CallCDeclQWObj)(void *obj, const asDWORD *, int, size_t);
-typedef asDWORD (*t_CallCDeclRetByRef)(const asDWORD *, int, size_t, void *);
-typedef asDWORD (*t_CallCDeclObjRetByRef)(void *obj, const asDWORD *, int, size_t, void *);
-typedef asQWORD (*t_CallSTDCallQW)(const asDWORD *, int, size_t);
-typedef asQWORD (*t_CallThisCallQW)(const void *, const asDWORD *, int, size_t);
-typedef asDWORD (*t_CallThisCallRetByRef)(const void *, const asDWORD *, int, size_t, void *);
+typedef asQWORD (*t_CallCDeclQW)(const asDWORD *, int, asFUNCTION_t);
+typedef asQWORD (*t_CallCDeclQWObj)(void *obj, const asDWORD *, int, asFUNCTION_t);
+typedef asDWORD (*t_CallCDeclRetByRef)(const asDWORD *, int, asFUNCTION_t, void *);
+typedef asDWORD (*t_CallCDeclObjRetByRef)(void *obj, const asDWORD *, int, asFUNCTION_t, void *);
+typedef asQWORD (*t_CallSTDCallQW)(const asDWORD *, int, asFUNCTION_t);
+typedef asQWORD (*t_CallThisCallQW)(const void *, const asDWORD *, int, asFUNCTION_t);
+typedef asDWORD (*t_CallThisCallRetByRef)(const void *, const asDWORD *, int, asFUNCTION_t, void *);
 
 // Prototypes
-void CallCDeclFunction(const asDWORD *args, int paramSize, size_t func);
-void CallCDeclFunctionObjLast(const void *obj, const asDWORD *args, int paramSize, size_t func);
-void CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, int paramSize, size_t func);
-void CallCDeclFunctionRetByRef_impl(const asDWORD *args, int paramSize, size_t func, void *retPtr);
-void CallCDeclFunctionRetByRefObjLast_impl(const void *obj, const asDWORD *args, int paramSize, size_t func, void *retPtr);
-void CallCDeclFunctionRetByRefObjFirst_impl(const void *obj, const asDWORD *args, int paramSize, size_t func, void *retPtr);
-void CallSTDCallFunction(const asDWORD *args, int paramSize, size_t func);
-void CallThisCallFunction(const void *obj, const asDWORD *args, int paramSize, size_t func);
-void CallThisCallFunctionRetByRef_impl(const void *, const asDWORD *, int, size_t, void *retPtr);
+void CallCDeclFunction(const asDWORD *args, int paramSize, asFUNCTION_t func);
+void CallCDeclFunctionObjLast(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func);
+void CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func);
+void CallCDeclFunctionRetByRef_impl(const asDWORD *args, int paramSize, asFUNCTION_t func, void *retPtr);
+void CallCDeclFunctionRetByRefObjLast_impl(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func, void *retPtr);
+void CallCDeclFunctionRetByRefObjFirst_impl(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func, void *retPtr);
+void CallSTDCallFunction(const asDWORD *args, int paramSize, asFUNCTION_t func);
+void CallThisCallFunction(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func);
+void CallThisCallFunctionRetByRef_impl(const void *, const asDWORD *, int, asFUNCTION_t, void *retPtr);
 
 // Initialize function pointers
 const t_CallCDeclQW CallCDeclFunctionQWord = (t_CallCDeclQW)CallCDeclFunction;
@@ -110,7 +110,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	asCScriptEngine            *engine    = context->engine;
 	asSSystemFunctionInterface *sysFunc   = descr->sysFuncIntf;
 
-	asQWORD retQW;
+	asQWORD retQW = 0;
 
 	// Prepare the parameters
 	int paramSize = sysFunc->paramSize;
@@ -157,81 +157,80 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	}
 
 	// Make the actual call
-	void *func = (void*)sysFunc->func;
+	asFUNCTION_t func = sysFunc->func;
 	int callConv = sysFunc->callConv;
 	if( sysFunc->hostReturnInMemory )
 		callConv++;
 
-	asDWORD *vftable;
-	context->isCallingSystemFunction = true;
 	switch( callConv )
 	{
 	case ICC_CDECL:
-		retQW = CallCDeclFunctionQWord(args, paramSize<<2, (size_t)func);
+		retQW = CallCDeclFunctionQWord(args, paramSize<<2, func);
 		break;
 
 	case ICC_CDECL_RETURNINMEM:
-		retQW = CallCDeclFunctionRetByRef(args, paramSize<<2, (size_t)func, retPointer);
+		retQW = CallCDeclFunctionRetByRef(args, paramSize<<2, func, retPointer);
 		break;
 
 	case ICC_STDCALL:
-		retQW = CallSTDCallFunctionQWord(args, paramSize<<2, (size_t)func);
+		retQW = CallSTDCallFunctionQWord(args, paramSize<<2, func);
 		break;
 
 	case ICC_STDCALL_RETURNINMEM:
 		// Push the return pointer on the stack
 		paramSize++;
 		args--;
-		*(size_t*)args = (size_t)retPointer;
+		*(asPWORD*)args = (size_t)retPointer;
 
-		retQW = CallSTDCallFunctionQWord(args, paramSize<<2, (size_t)func);
+		retQW = CallSTDCallFunctionQWord(args, paramSize<<2, func);
 		break;
 
 	case ICC_THISCALL:
-		retQW = CallThisCallFunctionQWord(obj, args, paramSize<<2, (size_t)func);
+		retQW = CallThisCallFunctionQWord(obj, args, paramSize<<2, func);
 		break;
 
 	case ICC_THISCALL_RETURNINMEM:
-		retQW = CallThisCallFunctionRetByRef(obj, args, paramSize<<2, (size_t)func, retPointer);
+		retQW = CallThisCallFunctionRetByRef(obj, args, paramSize<<2, func, retPointer);
 		break;
 
 	case ICC_VIRTUAL_THISCALL:
-		// Get virtual function table from the object pointer
-		vftable = *(asDWORD**)obj;
-
-		retQW = CallThisCallFunctionQWord(obj, args, paramSize<<2, vftable[size_t(func)>>2]);
+		{
+			// Get virtual function table from the object pointer
+			asFUNCTION_t *vftable = *(asFUNCTION_t**)obj;
+			retQW = CallThisCallFunctionQWord(obj, args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2]);
+		}
 		break;
 
 	case ICC_VIRTUAL_THISCALL_RETURNINMEM:
-		// Get virtual function table from the object pointer
-		vftable = *(asDWORD**)obj;
-
-		retQW = CallThisCallFunctionRetByRef(obj, args, paramSize<<2, vftable[size_t(func)>>2], retPointer);
+		{
+			// Get virtual function table from the object pointer
+			asFUNCTION_t *vftable = *(asFUNCTION_t**)obj;
+			retQW = CallThisCallFunctionRetByRef(obj, args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2], retPointer);
+		}
 		break;
 
 	case ICC_CDECL_OBJLAST:
-		retQW = CallCDeclFunctionQWordObjLast(obj, args, paramSize<<2, (size_t)func);
+		retQW = CallCDeclFunctionQWordObjLast(obj, args, paramSize<<2, func);
 		break;
 
 	case ICC_CDECL_OBJLAST_RETURNINMEM:
 		// Call the system object method as a cdecl with the obj ref as the last parameter
-		retQW = CallCDeclFunctionRetByRefObjLast(obj, args, paramSize<<2, (size_t)func, retPointer);
+		retQW = CallCDeclFunctionRetByRefObjLast(obj, args, paramSize<<2, func, retPointer);
 		break;
 
 	case ICC_CDECL_OBJFIRST:
 		// Call the system object method as a cdecl with the obj ref as the first parameter
-		retQW = CallCDeclFunctionQWordObjFirst(obj, args, paramSize<<2, (size_t)func);
+		retQW = CallCDeclFunctionQWordObjFirst(obj, args, paramSize<<2, func);
 		break;
 
 	case ICC_CDECL_OBJFIRST_RETURNINMEM:
 		// Call the system object method as a cdecl with the obj ref as the first parameter
-		retQW = CallCDeclFunctionRetByRefObjFirst(obj, args, paramSize<<2, (size_t)func, retPointer);
+		retQW = CallCDeclFunctionRetByRefObjFirst(obj, args, paramSize<<2, func, retPointer);
 		break;
 
 	default:
 		context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
 	}
-	context->isCallingSystemFunction = false;
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )
@@ -255,7 +254,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 #endif
 
 
-void NOINLINE CallCDeclFunction(const asDWORD *args, int paramSize, size_t func)
+void NOINLINE CallCDeclFunction(const asDWORD *args, int paramSize, asFUNCTION_t func)
 {
 #if defined ASM_INTEL
 
@@ -349,7 +348,7 @@ endcopy:
 #endif
 }
 
-void NOINLINE CallCDeclFunctionObjLast(const void *obj, const asDWORD *args, int paramSize, size_t func)
+void NOINLINE CallCDeclFunctionObjLast(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func)
 {
 #if defined ASM_INTEL
 
@@ -444,7 +443,7 @@ endcopy:
 #endif
 }
 
-void NOINLINE CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, int paramSize, size_t func)
+void NOINLINE CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func)
 {
 #if defined ASM_INTEL
 
@@ -539,7 +538,7 @@ endcopy:
 #endif
 }
 
-void NOINLINE CallCDeclFunctionRetByRefObjFirst_impl(const void *obj, const asDWORD *args, int paramSize, size_t func, void *retPtr)
+void NOINLINE CallCDeclFunctionRetByRefObjFirst_impl(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func, void *retPtr)
 {
 #if defined ASM_INTEL
 
@@ -646,7 +645,7 @@ endcopy:
 #endif
 }
 
-void NOINLINE CallCDeclFunctionRetByRef_impl(const asDWORD *args, int paramSize, size_t func, void *retPtr)
+void NOINLINE CallCDeclFunctionRetByRef_impl(const asDWORD *args, int paramSize, asFUNCTION_t func, void *retPtr)
 {
 #if defined ASM_INTEL
 
@@ -745,7 +744,7 @@ endcopy:
 #endif
 }
 
-void NOINLINE CallCDeclFunctionRetByRefObjLast_impl(const void *obj, const asDWORD *args, int paramSize, size_t func, void *retPtr)
+void NOINLINE CallCDeclFunctionRetByRefObjLast_impl(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func, void *retPtr)
 {
 #if defined ASM_INTEL
 
@@ -851,7 +850,7 @@ endcopy:
 #endif
 }
 
-void NOINLINE CallSTDCallFunction(const asDWORD *args, int paramSize, size_t func)
+void NOINLINE CallSTDCallFunction(const asDWORD *args, int paramSize, asFUNCTION_t func)
 {
 #if defined ASM_INTEL
 
@@ -938,7 +937,7 @@ endcopy:
 }
 
 
-void NOINLINE CallThisCallFunction(const void *obj, const asDWORD *args, int paramSize, size_t func)
+void NOINLINE CallThisCallFunction(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func)
 {
 #if defined ASM_INTEL
 
@@ -1044,7 +1043,7 @@ endcopy:
 #endif
 }
 
-void NOINLINE CallThisCallFunctionRetByRef_impl(const void *obj, const asDWORD *args, int paramSize, size_t func, void *retPtr)
+void NOINLINE CallThisCallFunctionRetByRef_impl(const void *obj, const asDWORD *args, int paramSize, asFUNCTION_t func, void *retPtr)
 {
 #if defined ASM_INTEL
 

+ 1 - 3
ThirdParty/AngelScript/source/as_callfunc_xenon.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -735,7 +735,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 		}
 	}
 
-	context->isCallingSystemFunction = true;
 	switch( callConv )
 	{
 	case ICC_CDECL:
@@ -765,7 +764,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr,
 	default:
 		context->SetInternalException( TXT_INVALID_CALLING_CONVENTION );
 	}
-	context->isCallingSystemFunction = false;
 
 	// If the return is a float value we need to get the value from the FP register
 	if( sysFunc->hostReturnFloat )

+ 56 - 70
ThirdParty/AngelScript/source/as_compiler.cpp

@@ -39,6 +39,9 @@
 #include <math.h> // fmodf()
 
 #include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_compiler.h"
 #include "as_tokendef.h"
 #include "as_tokenizer.h"
@@ -101,7 +104,6 @@ void asCCompiler::Reset(asCBuilder *builder, asCScriptCode *script, asCScriptFun
 	byteCode.ClearAll();
 }
 
-#ifndef AS_NO_COMPILER
 int asCCompiler::CompileDefaultConstructor(asCBuilder *builder, asCScriptCode *script, asCScriptNode *node, asCScriptFunction *outFunc)
 {
 	Reset(builder, script, outFunc);
@@ -197,28 +199,42 @@ int asCCompiler::CompileFactory(asCBuilder *builder, asCScriptCode *script, asCS
 */
 	return 0;
 }
-#endif
 
-// Entry
-int asCCompiler::CompileTemplateFactoryStub(asCBuilder *builder, int trueFactoryId, asCObjectType *objType, asCScriptFunction *outFunc)
+void asCCompiler::FinalizeFunction()
 {
-	Reset(builder, 0, outFunc);
+	asUINT n;
 
-	asCScriptFunction *descr = builder->GetFunctionDescription(trueFactoryId);
+	// Tell the bytecode which variables are temporary
+	for( n = 0; n < variableIsTemporary.GetLength(); n++ )
+	{
+		if( variableIsTemporary[n] )
+			byteCode.DefineTemporaryVariable(GetVariableOffset(n));
+	}
 
-	byteCode.InstrPTR(asBC_OBJTYPE, objType);
-	byteCode.Call(asBC_CALLSYS, trueFactoryId, descr->GetSpaceNeededForArguments());
-	byteCode.Ret(outFunc->GetSpaceNeededForArguments());
+	// Finalize the bytecode
+	byteCode.Finalize();
 
-	FinalizeFunction();
+	byteCode.ExtractObjectVariableInfo(outFunc);
 
-	// Tell the virtual machine not to clean up the object on exception
-	outFunc->dontCleanUpOnException = true;
+	// Compile the list of object variables for the exception handler
+	for( n = 0; n < variableAllocations.GetLength(); n++ )
+	{
+		if( variableAllocations[n].IsObject() && !variableAllocations[n].IsReference() )
+		{
+			outFunc->objVariableTypes.PushLast(variableAllocations[n].GetObjectType());
+			outFunc->objVariablePos.PushLast(GetVariableOffset(n));
+			outFunc->objVariableIsOnHeap.PushLast(variableIsOnHeap[n]);
+		}
+	}
 
-	return 0;
+	// Copy byte code to the function
+	outFunc->byteCode.SetLength(byteCode.GetSize());
+	byteCode.Output(outFunc->byteCode.AddressOf());
+	outFunc->AddReferences();
+	outFunc->stackNeeded = byteCode.largestStackUsed;
+	outFunc->lineNumbers = byteCode.lineNumbers;
 }
 
-#ifndef AS_NO_COMPILER
 // Entry
 int asCCompiler::CompileFunction(asCBuilder *builder, asCScriptCode *script, sExplicitSignature *signature, asCScriptNode *func, asCScriptFunction *outFunc)
 {
@@ -318,8 +334,14 @@ int asCCompiler::CompileFunction(asCBuilder *builder, asCScriptCode *script, sEx
 			if( (type.IsReference() && inoutFlag != asTM_INOUTREF && !type.CanBeInstanciated()) ||
 				(!type.IsReference() && !type.CanBeInstanciated()) )
 			{
+				asCString parm = type.Format();
+				if( inoutFlag == asTM_INREF )
+					parm += "in";
+				else if( inoutFlag == asTM_OUTREF )
+					parm += "out";
+
 				asCString str;
-				str.Format(TXT_PARAMETER_CANT_BE_s, type.Format().AddressOf());
+				str.Format(TXT_PARAMETER_CANT_BE_s, parm.AddressOf());
 				Error(str.AddressOf(), node);
 			}
 
@@ -533,7 +555,6 @@ int asCCompiler::CompileFunction(asCBuilder *builder, asCScriptCode *script, sEx
 
 	return 0;
 }
-#endif
 
 int asCCompiler::CallCopyConstructor(asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc, asSExprContext *arg, asCScriptNode *node, bool isGlobalVar, bool derefDest)
 {
@@ -848,7 +869,6 @@ void asCCompiler::CompileStatementBlock(asCScriptNode *block, bool ownVariableSc
 	}
 }
 
-#ifndef AS_NO_COMPILER
 // Entry
 int asCCompiler::CompileGlobalVariable(asCBuilder *builder, asCScriptCode *script, asCScriptNode *node, sGlobalVariableDescription *gvar, asCScriptFunction *outFunc)
 {
@@ -1120,42 +1140,6 @@ int asCCompiler::CompileGlobalVariable(asCBuilder *builder, asCScriptCode *scrip
 
 	return 0;
 }
-#endif
-
-void asCCompiler::FinalizeFunction()
-{
-	asUINT n;
-
-	// Tell the bytecode which variables are temporary
-	for( n = 0; n < variableIsTemporary.GetLength(); n++ )
-	{
-		if( variableIsTemporary[n] )
-			byteCode.DefineTemporaryVariable(GetVariableOffset(n));
-	}
-
-	// Finalize the bytecode
-	byteCode.Finalize();
-
-	byteCode.ExtractObjectVariableInfo(outFunc);
-
-	// Compile the list of object variables for the exception handler
-	for( n = 0; n < variableAllocations.GetLength(); n++ )
-	{
-		if( variableAllocations[n].IsObject() && !variableAllocations[n].IsReference() )
-		{
-			outFunc->objVariableTypes.PushLast(variableAllocations[n].GetObjectType());
-			outFunc->objVariablePos.PushLast(GetVariableOffset(n));
-			outFunc->objVariableIsOnHeap.PushLast(variableIsOnHeap[n]);
-		}
-	}
-
-	// Copy byte code to the function
-	outFunc->byteCode.SetLength(byteCode.GetSize());
-	byteCode.Output(outFunc->byteCode.AddressOf());
-	outFunc->AddReferences();
-	outFunc->stackNeeded = byteCode.largestStackUsed;
-	outFunc->lineNumbers = byteCode.lineNumbers;
-}
 
 void asCCompiler::PrepareArgument(asCDataType *paramType, asSExprContext *ctx, asCScriptNode *node, bool isFunction, int refType, bool isMakingCopy)
 {
@@ -1344,8 +1328,9 @@ void asCCompiler::PrepareArgument(asCDataType *paramType, asSExprContext *ctx, a
 				!ctx->type.isVariable &&
 				ctx->type.dataType.IsObject() &&
 				!ctx->type.dataType.IsObjectHandle() &&
-				ctx->type.dataType.GetBehaviour()->addref &&
-				ctx->type.dataType.GetBehaviour()->release )
+				((ctx->type.dataType.GetBehaviour()->addref &&
+				  ctx->type.dataType.GetBehaviour()->release) || 
+				 (ctx->type.dataType.GetObjectType()->flags & asOBJ_NOCOUNT)) )
 			{
 				// Store a handle to the object as local variable
 				asSExprContext tmp(engine);
@@ -1517,6 +1502,7 @@ void asCCompiler::MoveArgsToStack(int funcId, asCByteCode *bc, asCArray<asSExprC
 	if( descr->DoesReturnOnStack() )
 		offset += AS_PTR_SIZE;
 
+#ifdef AS_DEBUG
 	// If the function being called is the opAssign or copy constructor for the same type
 	// as the argument, then we should avoid making temporary copy of the argument
 	bool makingCopy = false;
@@ -1525,6 +1511,7 @@ void asCCompiler::MoveArgsToStack(int funcId, asCByteCode *bc, asCArray<asSExprC
 		((descr->name == "opAssign" && descr->objectType && descr->objectType == args[0]->type.dataType.GetObjectType()) ||
 		 (args[0]->type.dataType.GetObjectType() && descr->name == args[0]->type.dataType.GetObjectType()->name)) )
 		makingCopy = true;
+#endif
 
 	// Move the objects that are sent by value to the stack just before the call
 	for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
@@ -1535,7 +1522,9 @@ void asCCompiler::MoveArgsToStack(int funcId, asCByteCode *bc, asCArray<asSExprC
 			{
 				if( descr->inOutFlags[n] != asTM_INOUTREF )
 				{
+#ifdef AS_DEBUG
 					asASSERT( args[n]->type.isVariable || args[n]->type.isTemporary || makingCopy );
+#endif
 
 					if( (args[n]->type.isVariable || args[n]->type.isTemporary) )
 					{
@@ -3603,6 +3592,7 @@ int asCCompiler::GetVariableOffset(int varIndex)
 	return varOffset;
 }
 
+
 int asCCompiler::GetVariableSlot(int offset)
 {
 	int varOffset = 1;
@@ -3714,7 +3704,6 @@ void asCCompiler::Dereference(asSExprContext *ctx, bool generateCode)
 	}
 }
 
-
 bool asCCompiler::IsVariableInitialized(asCTypeInfo *type, asCScriptNode *node)
 {
 	// Temporary variables are assumed to be initialized
@@ -4150,7 +4139,6 @@ bool asCCompiler::CompileRefCast(asSExprContext *ctx, const asCDataType &to, boo
 	return conversionDone;
 }
 
-
 asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asSExprContext *ctx, const asCDataType &toOrig, asCScriptNode *node, EImplicitConv convType, bool generateCode)
 {
 	asCDataType to = toOrig;
@@ -6154,7 +6142,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asSExprContext *ctx)
 				ctx->bc.Label((short)afterLabel);
 
 				// Make sure both expressions have the same type
-				if( le.type.dataType != re.type.dataType )
+				if( !le.type.dataType.IsEqualExceptConst(re.type.dataType) )
 					Error(TXT_BOTH_MUST_BE_SAME, expr);
 
 				// Set the temporary variable as output
@@ -7450,8 +7438,9 @@ void asCCompiler::ProcessDeferredParams(asSExprContext *ctx)
 			else if( !outParam.argType.isVariable )
 			{
 				if( outParam.argType.dataType.IsObject() &&
-					outParam.argType.dataType.GetBehaviour()->addref &&
-					outParam.argType.dataType.GetBehaviour()->release )
+					((outParam.argType.dataType.GetBehaviour()->addref &&
+					  outParam.argType.dataType.GetBehaviour()->release) ||
+					 (outParam.argType.dataType.GetObjectType()->flags & asOBJ_NOCOUNT)) )
 				{
 					// Release the object handle that was taken to guarantee the reference
 					ReleaseTemporaryVariable(outParam.argType, &ctx->bc);
@@ -7886,7 +7875,7 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asSExprContext *ctx
 		// Verify that the type allow its handle to be taken
 		if( ctx->type.isExplicitHandle ||
 			!ctx->type.dataType.IsObject() ||
-			!((ctx->type.dataType.GetObjectType()->beh.addref && ctx->type.dataType.GetObjectType()->beh.release) || 
+			!(((ctx->type.dataType.GetObjectType()->beh.addref && ctx->type.dataType.GetObjectType()->beh.release) || (ctx->type.dataType.GetObjectType()->flags & asOBJ_NOCOUNT)) || 
 			  (ctx->type.dataType.GetObjectType()->flags & asOBJ_ASHANDLE)) )
 		{
 			Error(TXT_OBJECT_HANDLE_NOT_SUPPORTED, node);
@@ -9366,11 +9355,6 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char
 				// Make sure the method is accessible by the module
 				if( builder->module->accessMask & func->accessMask )
 				{
-#ifdef AS_DEPRECATED
-					// deprecated since 2011-10-04
-					asCConfigGroup *group = engine->FindConfigGroupForFunction(func->id);
-					if( !group || group->HasModuleAccess(builder->module->name.AddressOf()) )
-#endif
 					funcs.PushLast(func->id);
 				}
 			}
@@ -10349,28 +10333,28 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asSExprContext
 		{
 			if( !lctx->type.isConstant )
 				signMismatch = true;
-			else if( lctx->type.qwordValue & (I64(1)<<63) )
+			else if( lctx->type.qwordValue & (asQWORD(1)<<63) )
 				signMismatch = true;
 		}
 		if( lctx->type.dataType.GetTokenType() == ttUInt )
 		{
 			if( !lctx->type.isConstant )
 				signMismatch = true;
-			else if( lctx->type.dwordValue & (1<<31) )
+			else if( lctx->type.dwordValue & (asDWORD(1)<<31) )
 				signMismatch = true;
 		}
 		if( rctx->type.dataType.GetTokenType() == ttUInt64 )
 		{
 			if( !rctx->type.isConstant )
 				signMismatch = true;
-			else if( rctx->type.qwordValue & (I64(1)<<63) )
+			else if( rctx->type.qwordValue & (asQWORD(1)<<63) )
 				signMismatch = true;
 		}
 		if( rctx->type.dataType.GetTokenType() == ttUInt )
 		{
 			if( !rctx->type.isConstant )
 				signMismatch = true;
-			else if( rctx->type.dwordValue & (1<<31) )
+			else if( rctx->type.dwordValue & (asDWORD(1)<<31) )
 				signMismatch = true;
 		}
 	}
@@ -11241,5 +11225,7 @@ void asCCompiler::FilterConst(asCArray<int> &funcs)
 
 END_AS_NAMESPACE
 
+#endif // AS_NO_COMPILER
+
 
 

+ 5 - 7
ThirdParty/AngelScript/source/as_compiler.h

@@ -41,6 +41,9 @@
 #define AS_COMPILER_H
 
 #include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_builder.h"
 #include "as_scriptfunction.h"
 #include "as_variablescope.h"
@@ -121,14 +124,10 @@ public:
 	asCCompiler(asCScriptEngine *engine);
 	~asCCompiler();
 
-#ifndef AS_NO_COMPILER
 	int CompileFunction(asCBuilder *builder, asCScriptCode *script, sExplicitSignature *signature, asCScriptNode *func, asCScriptFunction *outFunc);
 	int CompileDefaultConstructor(asCBuilder *builder, asCScriptCode *script, asCScriptNode *node, asCScriptFunction *outFunc);
 	int CompileFactory(asCBuilder *builder, asCScriptCode *script, asCScriptFunction *outFunc);
 	int CompileGlobalVariable(asCBuilder *builder, asCScriptCode *script, asCScriptNode *expr, sGlobalVariableDescription *gvar, asCScriptFunction *outFunc);
-#endif
-
-	int CompileTemplateFactoryStub(asCBuilder *builder, int trueFactoryId, asCObjectType *objType, asCScriptFunction *outFunc);
 
 protected:
 	friend class asCBuilder;
@@ -231,15 +230,12 @@ protected:
 	asUINT ProcessStringConstant(asCString &str, asCScriptNode *node, bool processEscapeSequences = true);
 	void ProcessHeredocStringConstant(asCString &str, asCScriptNode *node);
 	int  GetPrecedence(asCScriptNode *op);
-
 	void Error(const char *msg, asCScriptNode *node);
 	void Warning(const char *msg, asCScriptNode *node);
 	void Information(const char *msg, asCScriptNode *node);
 	void PrintMatchingFuncs(asCArray<int> &funcs, asCScriptNode *node);
-
 	void AddVariableScope(bool isBreakScope = false, bool isContinueScope = false);
 	void RemoveVariableScope();
-
 	void FinalizeFunction();
 
 	asCByteCode byteCode;
@@ -283,4 +279,6 @@ protected:
 
 END_AS_NAMESPACE
 
+#endif // AS_NO_COMPILER
+
 #endif

+ 61 - 46
ThirdParty/AngelScript/source/as_config.h

@@ -63,6 +63,11 @@
 // This flag can be defined to make the library write some extra output when
 // compiling and executing scripts.
 
+// AS_DEBUG_STATS
+// This flag, combined with AS_DEBUG, make the library write out statistics
+// from the VM, for example how many times each bytecode instruction is executed,
+// etc. It is used to help identify potential code for optimizations.
+
 // AS_DEPRECATED
 // If this flag is defined then some backwards compatibility is maintained.
 // There is no guarantee for how well deprecated functionality will work though
@@ -219,22 +224,23 @@
 // compiler is the same for both, when this is so these flags are used to produce the
 // right code.
 
-// AS_WIN     - Microsoft Windows
-// AS_LINUX   - Linux
-// AS_MAC     - Apple Macintosh
-// AS_BSD     - BSD based OS (FreeBSD, DragonFly, OpenBSD, etc)
-// AS_XBOX    - Microsoft XBox
-// AS_XBOX360 - Microsoft XBox 360
-// AS_PSP     - Sony Playstation Portable
-// AS_PS2     - Sony Playstation 2
-// AS_PS3     - Sony Playstation 3
-// AS_DC      - Sega Dreamcast
-// AS_GC      - Nintendo GameCube
-// AS_WII     - Nintendo Wii
-// AS_IPHONE  - Apple IPhone
-// AS_ANDROID - Android
-// AS_HAIKU   - Haiku
-// AS_ILLUMOS - Illumos like (OpenSolaris, OpenIndiana, NCP, etc)
+// AS_WIN       - Microsoft Windows
+// AS_LINUX     - Linux
+// AS_MAC       - Apple Macintosh
+// AS_BSD       - BSD based OS (FreeBSD, DragonFly, OpenBSD, etc)
+// AS_XBOX      - Microsoft XBox
+// AS_XBOX360   - Microsoft XBox 360
+// AS_PSP       - Sony Playstation Portable
+// AS_PS2       - Sony Playstation 2
+// AS_PS3       - Sony Playstation 3
+// AS_DC        - Sega Dreamcast
+// AS_GC        - Nintendo GameCube
+// AS_WII       - Nintendo Wii
+// AS_IPHONE    - Apple IPhone
+// AS_ANDROID   - Android
+// AS_HAIKU     - Haiku
+// AS_ILLUMOS   - Illumos like (OpenSolaris, OpenIndiana, NCP, etc)
+// AS_MARMALADE - Marmalade cross platform SDK (a layer on top of the OS)
 
 
 
@@ -282,7 +288,6 @@
 // CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE
 // Specifies the minimum size in dwords a class/struct needs to be to be passed in memory
 
-
 // CALLEE_POPS_HIDDEN_RETURN_POINTER
 // This constant should be defined if the callee pops the hidden return pointer,
 // used when returning an object in memory.
@@ -369,8 +374,6 @@
 	#define AS_X86
 	#define ASM_INTEL
 
-	#define I64(x) x##ll
-
 	#define asVSNPRINTF(a, b, c, d) _vsnprintf(a, b, c, d)
 
 	#define fmodf(a,b) fmod(a,b)
@@ -390,15 +393,33 @@
 	#define HAVE_VIRTUAL_BASE_OFFSET
 	#define THISCALL_RETURN_SIMPLE_IN_MEMORY
 	#define THISCALL_PASS_OBJECT_POINTER_IN_ECX
-	#if _MSC_VER < 1500 // MSVC++ 9 (aka MSVC++ .NET 2008)
-		#define asVSNPRINTF(a, b, c, d) _vsnprintf(a, b, c, d)
+
+	// There doesn't seem to be a standard define to identify Marmalade, so we'll 
+	// look for one of these defines that have to be given by the project settings
+	// http://www.madewithmarmalade.com/
+	#if defined(AS_MARMALADE) || defined (MARMALADE)
+		#ifndef AS_MARMALADE
+			// From now on we'll use the below define
+			#define AS_MARMALADE
+		#endif
+
+		// Marmalade doesn't use the Windows libraries
+		#define asVSNPRINTF(a, b, c, d) vsnprintf(a, b, c, d)
+		#define AS_POSIX_THREADS
+		#define AS_NO_ATOMIC
 	#else
-		#define asVSNPRINTF(a, b, c, d) vsnprintf_s(a, b, _TRUNCATE, c, d)
+		#if _MSC_VER < 1500  // MSVC++ 9 (aka MSVC++ .NET 2008)
+			#define asVSNPRINTF(a, b, c, d) _vsnprintf(a, b, c, d)
+		#else
+			#define asVSNPRINTF(a, b, c, d) vsnprintf_s(a, b, _TRUNCATE, c, d)
+		#endif
+
+		#define AS_WINDOWS_THREADS
 	#endif
+
 	#define THISCALL_CALLEE_POPS_ARGUMENTS
 	#define STDCALL __stdcall
 	#define AS_SIZEOF_BOOL 1
-	#define AS_WINDOWS_THREADS
 
 	#define ASM_INTEL  // Intel style for inline assembly on microsoft compilers
 
@@ -425,12 +446,6 @@
 		#endif
 	#endif
 
-	#if _MSC_VER <= 1300 // MSVC++ 7.0 and lower
-		#define I64(x) x##l
-	#else // MSVC++ 7.1 and higher
-		#define I64(x) x##ll
-	#endif
-
 	#ifdef _ARM_
 		#define AS_ALIGN
 		#define AS_ARM
@@ -474,16 +489,10 @@
 		#define ASM_INTEL  // Intel style for inline assembly
 	#endif
 
-	#if _MSC_VER <= 1300 // MSVC++ 7.0 and lower
-		#define I64(x) x##l
-	#else // MSVC++ 7.1 and higher
-		#define I64(x) x##ll
-	#endif
-
 	#define UNREACHABLE_RETURN
 #endif
 
-// SN Systems ProDG (also experimental, let me know if something isn't working)
+// SN Systems ProDG 
 #if defined(__SNC__) || defined(SNSYS)
 	#define GNU_STYLE_VIRTUAL_METHOD
 	#define MULTI_BASE_OFFSET(x) (*((asDWORD*)(&x)+1))
@@ -515,11 +524,13 @@
 		// Support native calling conventions on PS3
 		#define AS_PS3
 		#define AS_PPC_64
+	// PSP
+	#elif defined(__psp__)
+		#define AS_NO_MEMORY_H
+		#define AS_MIPS
+		#define AS_PSP
 	#endif
 
-
-	#define I64(x) x##ll
-
 	#define UNREACHABLE_RETURN
 #endif
 
@@ -620,6 +631,10 @@
 			#define COMPLEX_MASK asOBJ_APP_CLASS_DESTRUCTOR
 			#undef COMPLEX_RETURN_MASK
 			#define COMPLEX_RETURN_MASK asOBJ_APP_CLASS_DESTRUCTOR
+			
+			// STDCALL is not available on ARM
+			#undef STDCALL
+			#define STDCALL
 		#else
 			// Unknown CPU type
 			#define AS_MAX_PORTABILITY
@@ -793,6 +808,10 @@
 		#define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 2
 
 		#if (defined(_ARM_) || defined(__arm__))
+			// The stdcall calling convention is not used on the arm cpu
+			#undef STDCALL
+			#define STDCALL
+
 			#define AS_ARM
 			#define AS_CALLEE_DESTROY_OBJ_BY_VAL
 			#define AS_ALIGN
@@ -847,8 +866,6 @@
 		#endif
 	#endif
 
-	#define I64(x) x##ll
-
 	#define UNREACHABLE_RETURN
 #endif
 
@@ -878,7 +895,7 @@
 		#define AS_USE_DOUBLE_AS_FLOAT
 	#endif
 	// XBox 360
-	#if (_XBOX_VER >= 200 )
+	#if (_XBOX_VER >= 200)
 		#define AS_ALIGN
 	#endif
 	// PS3
@@ -964,13 +981,11 @@
 
 #ifdef AS_64BIT_PTR
 	#define AS_PTR_SIZE  2
-	#define asPTRWORD    asQWORD
 #else
 	#define AS_PTR_SIZE  1
-	#define asPTRWORD    asDWORD
 #endif
-#define ARG_PTR(b)   ((asPTRWORD*)&b)
-#define BCARG_PTR(b) ((asPTRWORD*)&(b)[1])
+#define ARG_PTR(b)   ((asPWORD*)&b)
+#define BCARG_PTR(b) ((asPWORD*)&(b)[1])
 
 // This macro is used to avoid warnings about unused variables.
 // Usually where the variables are only used in debug mode.

+ 1 - 42
ThirdParty/AngelScript/source/as_configgroup.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2010 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -46,10 +46,6 @@ BEGIN_AS_NAMESPACE
 asCConfigGroup::asCConfigGroup()
 {
 	refCount = 0;
-#ifdef AS_DEPRECATED
-	// Deprecated since 2011-10-04
-	defaultAccess = true;
-#endif
 }
 
 asCConfigGroup::~asCConfigGroup()
@@ -210,41 +206,4 @@ void asCConfigGroup::ValidateNoUsage(asCScriptEngine *engine, asCObjectType *typ
 }
 #endif
 
-#ifdef AS_DEPRECATED
-// deprecated since 2011-10-04
-int asCConfigGroup::SetModuleAccess(const char *module, bool hasAccess)
-{
-	if( module == asALL_MODULES )
-	{
-		// Set default module access
-		defaultAccess = hasAccess;
-	}
-	else
-	{
-		asCString mod(module ? module : "");
-		asSMapNode<asCString,bool> *cursor = 0;
-		if( moduleAccess.MoveTo(&cursor, mod) )
-		{
-			moduleAccess.GetValue(cursor) = hasAccess;
-		}
-		else
-		{
-			moduleAccess.Insert(mod, hasAccess);
-		}
-	}
-
-	return 0;
-}
-
-bool asCConfigGroup::HasModuleAccess(const char *module)
-{
-	asCString mod(module ? module : "");
-	asSMapNode<asCString,bool> *cursor = 0;
-	if( moduleAccess.MoveTo(&cursor, mod) )
-		return moduleAccess.GetValue(cursor);
-	
-	return defaultAccess;
-}
-#endif
-
 END_AS_NAMESPACE

+ 1 - 18
ThirdParty/AngelScript/source/as_configgroup.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -44,10 +44,6 @@
 #include "as_string.h"
 #include "as_array.h"
 #include "as_objecttype.h"
-#ifdef AS_DEPRECATED
-// deprecated since 2011-10-04
-#include "as_map.h"
-#endif
 
 BEGIN_AS_NAMESPACE
 
@@ -67,12 +63,6 @@ public:
 	bool HasLiveObjects();
 	void RemoveConfiguration(asCScriptEngine *engine, bool notUsed = false);
 
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-04
-	int SetModuleAccess(const char *module, bool hasAccess);
-	bool HasModuleAccess(const char *module);
-#endif
-
 #ifdef AS_DEBUG
 	void ValidateNoUsage(asCScriptEngine *engine, asCObjectType *type);
 #endif
@@ -85,13 +75,6 @@ public:
 	asCArray<asCGlobalProperty*> globalProps;
 	asCArray<asCConfigGroup*>    referencedConfigGroups;
 	asCArray<asCScriptFunction*> funcDefs;
-
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-04
-	// Module access
-	bool defaultAccess;
-	asCMap<asCString, bool> moduleAccess;
-#endif
 };
 
 END_AS_NAMESPACE

+ 177 - 148
ThirdParty/AngelScript/source/as_context.cpp

@@ -62,7 +62,7 @@ const int RESERVE_STACK = 2*AS_PTR_SIZE;
 const int CALLSTACK_FRAME_SIZE = 5;
 
 
-#ifdef AS_DEBUG
+#if defined(AS_DEBUG) && defined(AS_DEBUG_STATS)
 // Instruction statistics
 int instrCount[256];
 
@@ -79,33 +79,36 @@ public:
 
 	~asCDebugStats()
 	{
-/*
 		// This code writes out some statistics for the VM. 
 		// It's useful for determining what needs to be optimized.
 
 		_mkdir("AS_DEBUG");
-		FILE *f = fopen("AS_DEBUG/total.txt", "at");
+		#if _MSC_VER >= 1500 
+			FILE *f;
+			fopen_s(&f, "AS_DEBUG/total.txt", "at");
+		#else
+			FILE *f = fopen("AS_DEBUG/total.txt", "at");
+		#endif
 		if( f )
 		{
 			// Output instruction statistics
 			fprintf(f, "\nTotal count\n");
 			int n;
-			for( n = 0; n < BC_MAXBYTECODE; n++ )
+			for( n = 0; n < asBC_MAXBYTECODE; n++ )
 			{
-				if( bcName[n].name && instrCount[n] > 0 )
-					fprintf(f, "%-10.10s : %.0f\n", bcName[n].name, instrCount[n]);
+				if( asBCInfo[n].name && instrCount[n] > 0 )
+					fprintf(f, "%-10.10s : %.0f\n", asBCInfo[n].name, instrCount[n]);
 			}
 
 			fprintf(f, "\nNever executed\n");
-			for( n = 0; n < BC_MAXBYTECODE; n++ )
+			for( n = 0; n < asBC_MAXBYTECODE; n++ )
 			{
-				if( bcName[n].name && instrCount[n] == 0 )
-					fprintf(f, "%-10.10s\n", bcName[n].name);
+				if( asBCInfo[n].name && instrCount[n] == 0 )
+					fprintf(f, "%-10.10s\n", asBCInfo[n].name);
 			}
 
 			fclose(f);
 		}
-*/
 	}
 
 	double instrCount[256];
@@ -142,7 +145,7 @@ void asPopActiveContext(asIScriptContext *ctx)
 
 asCContext::asCContext(asCScriptEngine *engine, bool holdRef)
 {
-#ifdef AS_DEBUG
+#if defined(AS_DEBUG) && defined(AS_DEBUG_STATS)
 	memset(instrCount, 0, sizeof(instrCount));
 
 	memset(instrCount2, 0, sizeof(instrCount2));
@@ -162,6 +165,7 @@ asCContext::asCContext(asCScriptEngine *engine, bool holdRef)
 	isStackMemoryNotAllocated = false;
 
 	currentFunction = 0;
+	callingSystemFunction = 0;
 	regs.objectRegister = 0;
 	initialFunction = 0;
 
@@ -262,6 +266,12 @@ int asCContext::Prepare(int funcId)
 	return Prepare(engine->GetFunctionById(funcId));
 }
 
+// interface
+asIScriptFunction *asCContext::GetSystemFunction()
+{
+	return callingSystemFunction;
+}
+
 // interface
 int asCContext::Prepare(asIScriptFunction *func)
 {
@@ -336,7 +346,6 @@ int asCContext::Prepare(asIScriptFunction *func)
 	{
 		exceptionLine           = -1;
 		exceptionFunction       = 0;
-		isCallingSystemFunction = false;
 		doAbort                 = false;
 		doSuspend               = false;
 		regs.doProcessSuspend   = lineCallback;
@@ -372,7 +381,7 @@ int asCContext::Prepare(asIScriptFunction *func)
 			if( !currentFunction->objVariableIsOnHeap[n] ) continue;
 
 			int pos = currentFunction->objVariablePos[n];
-			*(size_t*)&regs.stackFramePointer[-pos] = 0;
+			*(asPWORD*)&regs.stackFramePointer[-pos] = 0;
 		}
 	}
 	else
@@ -509,7 +518,7 @@ void *asCContext::GetReturnObject()
 	if( !dt->IsObject() ) return 0;
 
 	if( dt->IsReference() )
-		return *(void**)(size_t)regs.valueRegister;
+		return *(void**)(asPWORD)regs.valueRegister;
 	else
 	{
 		if( initialFunction->DoesReturnOnStack() )
@@ -554,7 +563,7 @@ int asCContext::SetObject(void *obj)
 		return asERROR;
 	}
 
-	*(size_t*)&regs.stackFramePointer[0] = (size_t)obj;
+	*(asPWORD*)&regs.stackFramePointer[0] = (asPWORD)obj;
 
 	return 0;
 }
@@ -849,7 +858,7 @@ int asCContext::SetArgAddress(asUINT arg, void *value)
 		offset += initialFunction->parameterTypes[n].GetSizeOnStackDWords();
 
 	// Set the value
-	*(size_t*)(&regs.stackFramePointer[offset]) = (size_t)value;
+	*(asPWORD*)(&regs.stackFramePointer[offset]) = (asPWORD)value;
 
 	return 0;
 }
@@ -902,7 +911,7 @@ int asCContext::SetArgObject(asUINT arg, void *obj)
 		offset += initialFunction->parameterTypes[n].GetSizeOnStackDWords();
 
 	// Set the value
-	*(size_t*)(&regs.stackFramePointer[offset]) = (size_t)obj;
+	*(asPWORD*)(&regs.stackFramePointer[offset]) = (asPWORD)obj;
 
 	return 0;
 }
@@ -941,10 +950,10 @@ void *asCContext::GetAddressOfArg(asUINT arg)
 
 int asCContext::Abort()
 {
-	// TODO: multithread: Make thread safe
-
 	if( engine == 0 ) return asERROR;
 
+	// TODO: multithread: Make thread safe. There is a chance that the status
+	//                    changes to something else after being set to ABORTED here.
 	if( status == asEXECUTION_SUSPENDED )
 		status = asEXECUTION_ABORTED;
 
@@ -992,7 +1001,7 @@ int asCContext::Execute()
 			// The currentFunction is a virtual method
 
 			// Determine the true function from the object
-			asCScriptObject *obj = *(asCScriptObject**)(size_t*)regs.stackFramePointer;
+			asCScriptObject *obj = *(asCScriptObject**)(asPWORD*)regs.stackFramePointer;
 			if( obj == 0 )
 			{
 				SetInternalException(TXT_NULL_POINTER_ACCESS);
@@ -1041,7 +1050,7 @@ int asCContext::Execute()
 						for( asUINT n = 0; n < currentFunction->objVariablePos.GetLength(); n++ )
 						{
 							int pos = currentFunction->objVariablePos[n];
-							*(size_t*)&regs.stackFramePointer[-pos] = 0;
+							*(asPWORD*)&regs.stackFramePointer[-pos] = 0;
 						}
 					}
 				}
@@ -1076,20 +1085,24 @@ int asCContext::Execute()
 	asPopActiveContext((asIScriptContext *)this);
 
 
-#ifdef AS_DEBUG
-/*
+#if defined(AS_DEBUG) && defined(AS_DEBUG_STATS)
 	// Output instruction statistics
 	// This is useful for determining what needs to be optimized.
 
 	_mkdir("AS_DEBUG");
-	FILE *f = fopen("AS_DEBUG/stats.txt", "at");
+	#if _MSC_VER >= 1500 
+		FILE *f;
+		fopen_s(&f, "AS_DEBUG/stats.txt", "at");
+	#else
+		FILE *f = fopen("AS_DEBUG/stats.txt", "at");
+	#endif
 	fprintf(f, "\n");
 	asQWORD total = 0;
 	int n;
 	for( n = 0; n < 256; n++ )
 	{
-		if( bcName[n].name && instrCount[n] )
-			fprintf(f, "%-10.10s : %d\n", bcName[n].name, instrCount[n]);
+		if( asBCInfo[n].name && instrCount[n] )
+			fprintf(f, "%-10.10s : %d\n", asBCInfo[n].name, instrCount[n]);
 
 		total += instrCount[n];
 	}
@@ -1099,17 +1112,16 @@ int asCContext::Execute()
 	fprintf(f, "\n");
 	for( n = 0; n < 256; n++ )
 	{
-		if( bcName[n].name )
+		if( asBCInfo[n].name )
 		{
 			for( int m = 0; m < 256; m++ )
 			{
 				if( instrCount2[n][m] )
-					fprintf(f, "%-10.10s, %-10.10s : %d\n", bcName[n].name, bcName[m].name, instrCount2[n][m]);
+					fprintf(f, "%-10.10s, %-10.10s : %d\n", asBCInfo[n].name, asBCInfo[m].name, instrCount2[n][m]);
 			}
 		}
 	}
 	fclose(f);
-*/
 #endif
 
 	if( status == asEXECUTION_FINISHED )
@@ -1146,14 +1158,14 @@ void asCContext::PushCallState()
     // for all the compiler knows. So introducing the local variable s, which is never referred to by
     // its address we avoid this issue.
 
-	size_t s[5];
-	s[0] = (size_t)regs.stackFramePointer;
-	s[1] = (size_t)currentFunction;
-	s[2] = (size_t)regs.programPointer;
-	s[3] = (size_t)regs.stackPointer;
+	asPWORD s[5];
+	s[0] = (asPWORD)regs.stackFramePointer;
+	s[1] = (asPWORD)currentFunction;
+	s[2] = (asPWORD)regs.programPointer;
+	s[3] = (asPWORD)regs.stackPointer;
 	s[4] = stackIndex;
 
-	size_t *tmp = callStack.AddressOf() + callStack.GetLength() - CALLSTACK_FRAME_SIZE;
+	asPWORD *tmp = callStack.AddressOf() + callStack.GetLength() - CALLSTACK_FRAME_SIZE;
 	tmp[0] = s[0];
 	tmp[1] = s[1];
 	tmp[2] = s[2];
@@ -1164,8 +1176,8 @@ void asCContext::PushCallState()
 void asCContext::PopCallState()
 {
 	// See comments in PushCallState about pointer aliasing and data cache trashing
-	size_t *tmp = callStack.AddressOf() + callStack.GetLength() - CALLSTACK_FRAME_SIZE;
-	size_t s[5];
+	asPWORD *tmp = callStack.AddressOf() + callStack.GetLength() - CALLSTACK_FRAME_SIZE;
+	asPWORD s[5];
 	s[0] = tmp[0];
 	s[1] = tmp[1];
 	s[2] = tmp[2];
@@ -1197,7 +1209,7 @@ asIScriptFunction *asCContext::GetFunction(asUINT stackLevel)
 
 	if( stackLevel == 0 ) return currentFunction;
 
-	size_t *s = callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1)*CALLSTACK_FRAME_SIZE;
+	asPWORD *s = callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1)*CALLSTACK_FRAME_SIZE;
 	asCScriptFunction *func = (asCScriptFunction*)s[1];
 
 	return func;
@@ -1217,7 +1229,7 @@ int asCContext::GetLineNumber(asUINT stackLevel, int *column, const char **secti
 	}
 	else
 	{
-		size_t *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
+		asPWORD *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
 		func = (asCScriptFunction*)s[1];
 		bytePos = (asDWORD*)s[2];
 	}
@@ -1291,14 +1303,14 @@ void asCContext::CallScriptFunction(asCScriptFunction *func)
 		if( !currentFunction->objVariableIsOnHeap[n] ) continue;
 
 		int pos = currentFunction->objVariablePos[n];
-		*(size_t*)&regs.stackFramePointer[-pos] = 0;
+		*(asPWORD*)&regs.stackFramePointer[-pos] = 0;
 	}
 }
 
 void asCContext::CallInterfaceMethod(asCScriptFunction *func)
 {
 	// Resolve the interface method using the current script type
-	asCScriptObject *obj = *(asCScriptObject**)(size_t*)regs.stackPointer;
+	asCScriptObject *obj = *(asCScriptObject**)(asPWORD*)regs.stackPointer;
 	if( obj == 0 )
 	{
 		SetInternalException(TXT_NULL_POINTER_ACCESS);
@@ -1358,13 +1370,14 @@ void asCContext::ExecuteNext()
 	{
 
 #ifdef AS_DEBUG
+#ifdef AS_DEBUG_STATS
 	++stats.instrCount[*(asBYTE*)l_bc];
 
 	++instrCount[*(asBYTE*)l_bc];
 
 	++instrCount2[lastBC][*(asBYTE*)l_bc];
 	lastBC = *(asBYTE*)l_bc;
-
+#endif
 	// Used to verify that the size of the instructions are correct
 	asDWORD *old = l_bc;
 #endif
@@ -1409,16 +1422,16 @@ void asCContext::ExecuteNext()
 	// Push the address of a variable on the stack
 	case asBC_PSF:
 		l_sp -= AS_PTR_SIZE;
-		*(asPTRWORD*)l_sp = (asPTRWORD)size_t(l_fp - asBC_SWORDARG0(l_bc));
+		*(asPWORD*)l_sp = asPWORD(l_fp - asBC_SWORDARG0(l_bc));
 		l_bc++;
 		break;
 
 	// Swap the top 2 pointers on the stack
 	case asBC_SwapPtr:
 		{
-			asPTRWORD p = (asPTRWORD)*l_sp;
-			*(asPTRWORD*)l_sp = *(asPTRWORD*)(l_sp+AS_PTR_SIZE);
-			*(asDWORD*)(l_sp+AS_PTR_SIZE) = p;
+			asPWORD p = (asPWORD)*l_sp;
+			*(asPWORD*)l_sp = *(asPWORD*)(l_sp+AS_PTR_SIZE);
+			*(asPWORD*)(l_sp+AS_PTR_SIZE) = p;
 			l_bc++;
 		}
 		break;
@@ -1448,14 +1461,14 @@ void asCContext::ExecuteNext()
 	// Push the dword value of a global variable on the stack
 	case asBC_PshG4:
 		--l_sp;
-		*l_sp = *(asDWORD*)(size_t)asBC_PTRARG(l_bc);
+		*l_sp = *(asDWORD*)asBC_PTRARG(l_bc);
 		l_bc += 1 + AS_PTR_SIZE;
 		break;
 
 	// Load the address of a global variable in the register, then  
 	// copy the value of the global variable into a local variable
 	case asBC_LdGRdR4:
-		*(void**)&regs.valueRegister = (void*)(size_t)asBC_PTRARG(l_bc);
+		*(void**)&regs.valueRegister = (void*)asBC_PTRARG(l_bc);
 		*(l_fp - asBC_SWORDARG0(l_bc)) = **(asDWORD**)&regs.valueRegister;
 		l_bc += 1+AS_PTR_SIZE;
 		break;
@@ -1877,8 +1890,8 @@ void asCContext::ExecuteNext()
 
 	case asBC_COPY:
 		{
-			void *d = (void*)*(size_t*)l_sp; l_sp += AS_PTR_SIZE;
-			void *s = (void*)*(size_t*)l_sp;
+			void *d = (void*)*(asPWORD*)l_sp; l_sp += AS_PTR_SIZE;
+			void *s = (void*)*(asPWORD*)l_sp;
 			if( s == 0 || d == 0 )
 			{
 				// Need to move the values back to the context
@@ -1893,7 +1906,7 @@ void asCContext::ExecuteNext()
 			memcpy(d, s, asBC_WORDARG0(l_bc)*4);
 
 			// replace the pointer on the stack with the lvalue
-			*(size_t**)l_sp = (size_t*)d;
+			*(asPWORD**)l_sp = (asPWORD*)d;
 		}
 		l_bc += 2;
 		break;
@@ -1906,13 +1919,13 @@ void asCContext::ExecuteNext()
 
 	case asBC_PshVPtr:
 		l_sp -= AS_PTR_SIZE;
-		*(asPTRWORD*)l_sp = *(asPTRWORD*)(l_fp - asBC_SWORDARG0(l_bc));
+		*(asPWORD*)l_sp = *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc));
 		l_bc++;
 		break;
 
 	case asBC_RDSPtr:
 		// Pop an address from the stack, read a pointer from that address and push it on the stack
-		*(asPTRWORD*)l_sp = *(asPTRWORD*)*(size_t*)l_sp;
+		*(asPWORD*)l_sp = *(asPWORD*)*(asPWORD*)l_sp;
 		l_bc++;
 		break;
 
@@ -1997,14 +2010,14 @@ void asCContext::ExecuteNext()
 		break;
 
 	case asBC_PopRPtr:
-		*(asPTRWORD*)&regs.valueRegister = *(asPTRWORD*)l_sp;
+		*(asPWORD*)&regs.valueRegister = *(asPWORD*)l_sp;
 		l_sp += AS_PTR_SIZE;
 		l_bc++;
 		break;
 
 	case asBC_PshRPtr:
 		l_sp -= AS_PTR_SIZE;
-		*(asPTRWORD*)l_sp = *(asPTRWORD*)&regs.valueRegister;
+		*(asPWORD*)l_sp = *(asPWORD*)&regs.valueRegister;
 		l_bc++;
 		break;
 
@@ -2015,7 +2028,7 @@ void asCContext::ExecuteNext()
 			// Push the string pointer on the stack
 			const asCString &b = engine->GetConstantString(w);
 			l_sp -= AS_PTR_SIZE;
-			*(asPTRWORD*)l_sp = (asPTRWORD)(size_t)b.AddressOf();
+			*(asPWORD*)l_sp = (asPWORD)b.AddressOf();
 			// Push the string length on the stack
 			--l_sp;
 			*l_sp = (asDWORD)b.GetLength();
@@ -2132,7 +2145,7 @@ void asCContext::ExecuteNext()
 
 	case asBC_ALLOC:
 		{
-			asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(l_bc);
+			asCObjectType *objType = (asCObjectType*)asBC_PTRARG(l_bc);
 			int func = asBC_INTARG(l_bc+AS_PTR_SIZE);
 
 			if( objType->flags & asOBJ_SCRIPT_OBJECT )
@@ -2146,12 +2159,12 @@ void asCContext::ExecuteNext()
 				// Call the constructor to initalize the memory
 				asCScriptFunction *f = engine->scriptFunctions[func];
 
-				asDWORD **a = (asDWORD**)*(size_t*)(l_sp + f->GetSpaceNeededForArguments());
+				asDWORD **a = (asDWORD**)*(asPWORD*)(l_sp + f->GetSpaceNeededForArguments());
 				if( a ) *a = mem;
 
 				// Push the object pointer on the stack
 				l_sp -= AS_PTR_SIZE;
-				*(size_t*)l_sp = (size_t)mem;
+				*(asPWORD*)l_sp = (asPWORD)mem;
 
 				l_bc += 2+AS_PTR_SIZE;
 
@@ -2188,7 +2201,7 @@ void asCContext::ExecuteNext()
 				}
 
 				// Pop the variable address from the stack
-				asDWORD **a = (asDWORD**)*(size_t*)l_sp;
+				asDWORD **a = (asDWORD**)*(asPWORD*)l_sp;
 				l_sp += AS_PTR_SIZE;
 				if( a ) *a = mem;
 
@@ -2226,10 +2239,10 @@ void asCContext::ExecuteNext()
 	case asBC_FREE:
 		{
 			// Get the variable that holds the object handle/reference
-			asPTRWORD *a = (asPTRWORD*)size_t(l_fp - asBC_SWORDARG0(l_bc));
+			asPWORD *a = (asPWORD*)asPWORD(l_fp - asBC_SWORDARG0(l_bc));
 			if( *a )
 			{
-				asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(l_bc);
+				asCObjectType *objType = (asCObjectType*)asBC_PTRARG(l_bc);
 				asSTypeBehaviour *beh = &objType->beh;
 
 				// Need to move the values back to the context as the called functions
@@ -2238,18 +2251,18 @@ void asCContext::ExecuteNext()
 				regs.stackPointer = l_sp;
 				regs.stackFramePointer = l_fp;
 
-				if( beh->release )
+				if( objType->flags & asOBJ_REF )
 				{
-					engine->CallObjectMethod((void*)(size_t)*a, beh->release);
+					asASSERT( (objType->flags & asOBJ_NOCOUNT) || beh->release );
+					if( beh->release )
+						engine->CallObjectMethod((void*)(asPWORD)*a, beh->release);
 				}
 				else
 				{
 					if( beh->destruct )
-					{
-						engine->CallObjectMethod((void*)(size_t)*a, beh->destruct);
-					}
+						engine->CallObjectMethod((void*)(asPWORD)*a, beh->destruct);
 
-					engine->CallFree((void*)(size_t)*a);
+					engine->CallFree((void*)(asPWORD)*a);
 				}
 
 				// Clear the variable
@@ -2272,7 +2285,7 @@ void asCContext::ExecuteNext()
 
 	case asBC_STOREOBJ:
 		// Move the object pointer from the object register to the object variable
-		*(size_t*)(l_fp - asBC_SWORDARG0(l_bc)) = size_t(regs.objectRegister);
+		*(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = asPWORD(regs.objectRegister);
 		regs.objectRegister = 0;
 		l_bc++;
 		break;
@@ -2280,10 +2293,10 @@ void asCContext::ExecuteNext()
 	case asBC_GETOBJ:
 		{
 			// Read variable index from location on stack
-			size_t *a = (size_t*)(l_sp + asBC_WORDARG0(l_bc));
+			asPWORD *a = (asPWORD*)(l_sp + asBC_WORDARG0(l_bc));
 			asDWORD offset = *(asDWORD*)a;
 			// Move pointer from variable to the same location on the stack
-			size_t *v = (size_t*)(l_fp - offset);
+			asPWORD *v = (asPWORD*)(l_fp - offset);
 			*a = *v;
 			// Clear variable
 			*v = 0;
@@ -2293,15 +2306,15 @@ void asCContext::ExecuteNext()
 
 	case asBC_REFCPY:
 		{
-			asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(l_bc);
+			asCObjectType *objType = (asCObjectType*)asBC_PTRARG(l_bc);
 			asSTypeBehaviour *beh = &objType->beh;
 
 			// Pop address of destination pointer from the stack
-			void **d = (void**)*(size_t*)l_sp;
+			void **d = (void**)*(asPWORD*)l_sp;
 			l_sp += AS_PTR_SIZE;
 			
 			// Read wanted pointer from the stack
-			void *s = (void*)*(size_t*)l_sp;
+			void *s = (void*)*(asPWORD*)l_sp;
 
 			// Need to move the values back to the context as the called functions
 			// may use the debug interface to inspect the registers
@@ -2309,12 +2322,15 @@ void asCContext::ExecuteNext()
 			regs.stackPointer = l_sp;
 			regs.stackFramePointer = l_fp;
 
-			// Release previous object held by destination pointer
-			if( *d != 0 )
-				engine->CallObjectMethod(*d, beh->release);
-			// Increase ref counter of wanted object
-			if( s != 0 )
-				engine->CallObjectMethod(s, beh->addref);
+			if( !(objType->flags & asOBJ_NOCOUNT) )
+			{
+				// Release previous object held by destination pointer
+				if( *d != 0 )
+					engine->CallObjectMethod(*d, beh->release);
+				// Increase ref counter of wanted object
+				if( s != 0 )
+					engine->CallObjectMethod(s, beh->addref);
+			}
 
 			// Set the new object in the destination
 			*d = s;
@@ -2326,7 +2342,7 @@ void asCContext::ExecuteNext()
 		{
 			// Verify if the pointer on the stack is null
 			// This is used when validating a pointer that an operator will work on
-			size_t a = *(size_t*)l_sp;
+			asPWORD a = *(asPWORD*)l_sp;
 			if( a == 0 )
 			{
 				regs.programPointer = l_bc;
@@ -2343,10 +2359,10 @@ void asCContext::ExecuteNext()
 	case asBC_GETOBJREF:
 		{
 			// Get the location on the stack where the reference will be placed
-			size_t *a = (size_t*)(l_sp + asBC_WORDARG0(l_bc));
+			asPWORD *a = (asPWORD*)(l_sp + asBC_WORDARG0(l_bc));
 
 			// Replace the variable index with the object handle held in the variable
-			*(size_t**)a = *(size_t**)(l_fp - *a);
+			*(asPWORD**)a = *(asPWORD**)(l_fp - *a);
 		}
 		l_bc++;
 		break;
@@ -2354,10 +2370,10 @@ void asCContext::ExecuteNext()
 	case asBC_GETREF:
 		{
 			// Get the location on the stack where the reference will be placed
-			size_t *a = (size_t*)(l_sp + asBC_WORDARG0(l_bc));
+			asPWORD *a = (asPWORD*)(l_sp + asBC_WORDARG0(l_bc));
 
 			// Replace the variable index with the address of the variable
-			*(size_t**)a = (size_t*)(l_fp - (int)*a);
+			*(asPWORD**)a = (asPWORD*)(l_fp - (int)*a);
 		}
 		l_bc++;
 		break;
@@ -2365,20 +2381,20 @@ void asCContext::ExecuteNext()
 	case asBC_PshNull:
 		// Push a null pointer on the stack
 		l_sp -= AS_PTR_SIZE;
-		*(asPTRWORD*)l_sp = 0;
+		*(asPWORD*)l_sp = 0;
 		l_bc++;
 		break;
 
 	case asBC_ClrVPtr:
 		// Clear pointer variable
-		*(asPTRWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = 0;
+		*(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = 0;
 		l_bc++;
 		break;
 
 	case asBC_OBJTYPE:
 		// Push the object type on the stack
 		l_sp -= AS_PTR_SIZE;
-		*(asPTRWORD*)l_sp = asBC_PTRARG(l_bc);
+		*(asPWORD*)l_sp = asBC_PTRARG(l_bc);
 		l_bc += 1+AS_PTR_SIZE;
 		break;
 
@@ -2400,7 +2416,7 @@ void asCContext::ExecuteNext()
 		break;
 
 	case asBC_ADDSi:
-		*(size_t*)l_sp = size_t(asPTRWORD(*(size_t*)l_sp) + asBC_SWORDARG0(l_bc));
+		*(asPWORD*)l_sp = asPWORD(*(asPWORD*)l_sp) + asBC_SWORDARG0(l_bc);
 		l_bc += 2;
 		break;
 
@@ -2425,7 +2441,7 @@ void asCContext::ExecuteNext()
 		break;
 
 	case asBC_CpyVtoG4:
-		*(asDWORD*)(size_t)asBC_PTRARG(l_bc) = *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc));
+		*(asDWORD*)asBC_PTRARG(l_bc) = *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc));
 		l_bc += 1 + AS_PTR_SIZE;
 		break;
 
@@ -2440,7 +2456,7 @@ void asCContext::ExecuteNext()
 		break;
 
 	case asBC_CpyGtoV4:
-		*(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asDWORD*)(size_t)asBC_PTRARG(l_bc);
+		*(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asDWORD*)asBC_PTRARG(l_bc);
 		l_bc += 1 + AS_PTR_SIZE;
 		break;
 
@@ -2499,7 +2515,7 @@ void asCContext::ExecuteNext()
 		break;
 
 	case asBC_LDG:
-		*(asPTRWORD*)&regs.valueRegister = asBC_PTRARG(l_bc);
+		*(asPWORD*)&regs.valueRegister = asBC_PTRARG(l_bc);
 		l_bc += 1+AS_PTR_SIZE;
 		break;
 
@@ -2510,23 +2526,26 @@ void asCContext::ExecuteNext()
 
 	case asBC_PGA:
 		l_sp -= AS_PTR_SIZE;
-		*(asPTRWORD*)l_sp = asBC_PTRARG(l_bc);
+		*(asPWORD*)l_sp = asBC_PTRARG(l_bc);
 		l_bc += 1+AS_PTR_SIZE;
 		break;
 
 	case asBC_CmpPtr:
 		{
-			asPTRWORD i = *(asPTRWORD*)(l_fp - asBC_SWORDARG0(l_bc)) - *(asPTRWORD*)(l_fp - asBC_SWORDARG1(l_bc));
-			if( i == 0 )     *(int*)&regs.valueRegister =  0;
-			else if( i < 0 ) *(int*)&regs.valueRegister = -1;
-			else             *(int*)&regs.valueRegister =  1;
+			// TODO: optimize: This instruction should really just be an equals, and return true or false.
+			//                 The instruction is only used for is and !is tests anyway.
+			asPWORD p1 = *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc));
+			asPWORD p2 = *(asPWORD*)(l_fp - asBC_SWORDARG1(l_bc));
+			if( p1 == p2 )     *(int*)&regs.valueRegister =  0;
+			else if( p1 < p2 ) *(int*)&regs.valueRegister = -1;
+			else               *(int*)&regs.valueRegister =  1;
 			l_bc += 2;
 		}
 		break;
 
 	case asBC_VAR:
 		l_sp -= AS_PTR_SIZE;
-		*(size_t*)l_sp = (size_t)asBC_SWORDARG0(l_bc);
+		*(asPWORD*)l_sp = (asPWORD)asBC_SWORDARG0(l_bc);
 		l_bc++;
 		break;
 
@@ -2805,7 +2824,7 @@ void asCContext::ExecuteNext()
 
 	//-----------------------------------
 	case asBC_SetG4:
-		*(asDWORD*)(size_t)asBC_PTRARG(l_bc) = asBC_DWORDARG(l_bc+AS_PTR_SIZE);
+		*(asDWORD*)asBC_PTRARG(l_bc) = asBC_DWORDARG(l_bc+AS_PTR_SIZE);
 		l_bc += 2 + AS_PTR_SIZE;
 		break;
 
@@ -2813,7 +2832,7 @@ void asCContext::ExecuteNext()
 		{
 			// Verify if the pointer on the stack refers to a non-null value
 			// This is used to validate a reference to a handle
-			asDWORD *a = (asDWORD*)*(size_t*)l_sp;
+			asDWORD *a = (asDWORD*)*(asPWORD*)l_sp;
 			if( *a == 0 )
 			{
 				regs.programPointer = l_bc;
@@ -2925,7 +2944,7 @@ void asCContext::ExecuteNext()
 	case asBC_Cast:
 		// Cast the handle at the top of the stack to the type in the argument
 		{
-			asDWORD **a = (asDWORD**)*(size_t*)l_sp;
+			asDWORD **a = (asDWORD**)*(asPWORD*)l_sp;
 			if( a && *a )
 			{
 				asDWORD typeId = asBC_DWORDARG(l_bc);
@@ -3161,7 +3180,7 @@ void asCContext::ExecuteNext()
 		{
 			// Verify if the pointer on the stack is null
 			// This is used for example when validating handles passed as function arguments
-			size_t a = *(size_t*)(l_sp + asBC_WORDARG0(l_bc));
+			asPWORD a = *(asPWORD*)(l_sp + asBC_WORDARG0(l_bc));
 			if( a == 0 )
 			{
 				regs.programPointer = l_bc;
@@ -3275,20 +3294,20 @@ void asCContext::ExecuteNext()
 	case asBC_FuncPtr:
 		// Push the function pointer on the stack. The pointer is in the argument
 		l_sp -= AS_PTR_SIZE;
-		*(asPTRWORD*)l_sp = asBC_PTRARG(l_bc);
+		*(asPWORD*)l_sp = asBC_PTRARG(l_bc);
 		l_bc += 1+AS_PTR_SIZE;
 		break;
 
 	case asBC_LoadThisR:
 		{
 			// PshVPtr 0
-			asPTRWORD tmp = *(asPTRWORD*)l_fp;
+			asPWORD tmp = *(asPWORD*)l_fp;
 
 			// ADDSi
 			tmp = tmp + asBC_SWORDARG0(l_bc);
 
 			// PopRPtr
-			*(asPTRWORD*)&regs.valueRegister = tmp;
+			*(asPWORD*)&regs.valueRegister = tmp;
 			l_bc += 2;
 		}
 		break;
@@ -3379,13 +3398,13 @@ void asCContext::ExecuteNext()
 	case asBC_LoadRObjR:
 		{
 			// PshVPtr x
-			asPTRWORD tmp = *(asPTRWORD*)(l_fp - asBC_SWORDARG0(l_bc)); 
+			asPWORD tmp = *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)); 
 
 			// ADDSi y
 			tmp = tmp + asBC_SWORDARG1(l_bc);
 
 			// PopRPtr
-			*(asPTRWORD*)&regs.valueRegister = tmp;
+			*(asPWORD*)&regs.valueRegister = tmp;
 			l_bc += 3;
 		}
 		break;
@@ -3393,13 +3412,13 @@ void asCContext::ExecuteNext()
 	case asBC_LoadVObjR:
 		{
 			// PSF x
-			asPTRWORD tmp = (asPTRWORD)(size_t)(l_fp - asBC_SWORDARG0(l_bc)); 
+			asPWORD tmp = (asPWORD)(l_fp - asBC_SWORDARG0(l_bc)); 
 
 			// ADDSi y
 			tmp = tmp + asBC_SWORDARG1(l_bc);
 
 			// PopRPtr
-			*(asPTRWORD*)&regs.valueRegister = tmp;
+			*(asPWORD*)&regs.valueRegister = tmp;
 			l_bc += 3;
 		}
 		break;
@@ -3480,6 +3499,7 @@ void asCContext::ExecuteNext()
 #ifdef AS_DEBUG
 	default:
 		asASSERT(false);
+		SetInternalException(TXT_UNRECOGNIZED_BYTE_CODE);
 #endif
 /*
 	default:
@@ -3500,14 +3520,12 @@ void asCContext::ExecuteNext()
 		}
 #endif
 	}
-
-	SetInternalException(TXT_UNRECOGNIZED_BYTE_CODE);
 }
 
 int asCContext::SetException(const char *descr)
 {
 	// Only allow this if we're executing a CALL byte code
-	if( !isCallingSystemFunction ) return asERROR;
+	if( callingSystemFunction == 0 ) return asERROR;
 
 	SetInternalException(descr);
 
@@ -3554,12 +3572,14 @@ void asCContext::CleanReturnObject()
 	{
 		// Call the destructor on the object
 		asSTypeBehaviour *beh = &((asCObjectType*)regs.objectType)->beh;
-		if( beh->release )
+		if( regs.objectType->GetFlags() & asOBJ_REF )
 		{
-			engine->CallObjectMethod(regs.objectRegister, beh->release);
-			regs.objectRegister = 0;
+			asASSERT( beh->release || (regs.objectType->GetFlags() & asOBJ_NOCOUNT) );
 
-			// The release method is responsible for freeing the memory
+			if( beh->release )
+				engine->CallObjectMethod(regs.objectRegister, beh->release);
+
+			regs.objectRegister = 0;
 		}
 		else
 		{
@@ -3604,7 +3624,7 @@ bool asCContext::IsVarInScope(asUINT varIndex, asUINT stackLevel)
 	}
 	else
 	{
-		size_t *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
+		asPWORD *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
 		func = (asCScriptFunction*)s[1];
 		pos = asUINT((asDWORD*)s[2] - func->byteCode.AddressOf());
 	}
@@ -3658,7 +3678,7 @@ void asCContext::DetermineLiveObjects(asCArray<int> &liveObjects, asUINT stackLe
 	}
 	else
 	{
-		size_t *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
+		asPWORD *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
 		func = (asCScriptFunction*)s[1];
 		pos = asUINT((asDWORD*)s[2] - func->byteCode.AddressOf());
 	}
@@ -3758,23 +3778,25 @@ void asCContext::CleanStackFrame()
 			if( currentFunction->objVariableIsOnHeap[n] )
 			{
 				// Check if the pointer is initialized
-				if( *(size_t*)&regs.stackFramePointer[-pos] )
+				if( *(asPWORD*)&regs.stackFramePointer[-pos] )
 				{
 					// Call the object's destructor
 					asSTypeBehaviour *beh = &currentFunction->objVariableTypes[n]->beh;
-					if( beh->release )
+					if( currentFunction->objVariableTypes[n]->flags & asOBJ_REF )
 					{
-						engine->CallObjectMethod((void*)*(size_t*)&regs.stackFramePointer[-pos], beh->release);
-						*(size_t*)&regs.stackFramePointer[-pos] = 0;
+						asASSERT( (currentFunction->objVariableTypes[n]->flags & asOBJ_NOCOUNT) || beh->release );
+						if( beh->release )
+							engine->CallObjectMethod((void*)*(asPWORD*)&regs.stackFramePointer[-pos], beh->release);
+						*(asPWORD*)&regs.stackFramePointer[-pos] = 0;
 					}
 					else
 					{
 						if( beh->destruct )
-							engine->CallObjectMethod((void*)*(size_t*)&regs.stackFramePointer[-pos], beh->destruct);
+							engine->CallObjectMethod((void*)*(asPWORD*)&regs.stackFramePointer[-pos], beh->destruct);
 
 						// Free the memory
-						engine->CallFree((void*)*(size_t*)&regs.stackFramePointer[-pos]);
-						*(size_t*)&regs.stackFramePointer[-pos] = 0;
+						engine->CallFree((void*)*(asPWORD*)&regs.stackFramePointer[-pos]);
+						*(asPWORD*)&regs.stackFramePointer[-pos] = 0;
 					}
 				}
 			}
@@ -3787,7 +3809,7 @@ void asCContext::CleanStackFrame()
 				{
 					asSTypeBehaviour *beh = &currentFunction->objVariableTypes[n]->beh;
 					if( beh->destruct )
-						engine->CallObjectMethod((void*)(size_t*)&regs.stackFramePointer[-pos], beh->destruct);
+						engine->CallObjectMethod((void*)(asPWORD*)&regs.stackFramePointer[-pos], beh->destruct);
 				}
 			}
 		}
@@ -3798,10 +3820,10 @@ void asCContext::CleanStackFrame()
 		if( currentFunction->objectType && regs.programPointer != currentFunction->byteCode.AddressOf() )
 		{
 			asSTypeBehaviour *beh = &currentFunction->objectType->beh;
-			if( beh->release && *(size_t*)&regs.stackFramePointer[0] != 0 )
+			if( beh->release && *(asPWORD*)&regs.stackFramePointer[0] != 0 )
 			{
-				engine->CallObjectMethod((void*)*(size_t*)&regs.stackFramePointer[0], beh->release);
-				*(size_t*)&regs.stackFramePointer[0] = 0;
+				engine->CallObjectMethod((void*)*(asPWORD*)&regs.stackFramePointer[0], beh->release);
+				*(asPWORD*)&regs.stackFramePointer[0] = 0;
 			}
 		}
 	}
@@ -3822,23 +3844,26 @@ void asCContext::CleanStackFrame()
 	{
 		if( currentFunction->parameterTypes[n].IsObject() && !currentFunction->parameterTypes[n].IsReference() )
 		{
-			if( *(size_t*)&regs.stackFramePointer[offset] )
+			if( *(asPWORD*)&regs.stackFramePointer[offset] )
 			{
 				// Call the object's destructor
 				asSTypeBehaviour *beh = currentFunction->parameterTypes[n].GetBehaviour();
-				if( beh->release )
+				if( currentFunction->parameterTypes[n].GetObjectType()->flags & asOBJ_REF )
 				{
-					engine->CallObjectMethod((void*)*(size_t*)&regs.stackFramePointer[offset], beh->release);
-					*(size_t*)&regs.stackFramePointer[offset] = 0;
+					asASSERT( (currentFunction->parameterTypes[n].GetObjectType()->flags & asOBJ_NOCOUNT) || beh->release );
+
+					if( beh->release )
+						engine->CallObjectMethod((void*)*(asPWORD*)&regs.stackFramePointer[offset], beh->release);
+					*(asPWORD*)&regs.stackFramePointer[offset] = 0;
 				}
 				else
 				{
 					if( beh->destruct )
-						engine->CallObjectMethod((void*)*(size_t*)&regs.stackFramePointer[offset], beh->destruct);
+						engine->CallObjectMethod((void*)*(asPWORD*)&regs.stackFramePointer[offset], beh->destruct);
 
 					// Free the memory
-					engine->CallFree((void*)*(size_t*)&regs.stackFramePointer[offset]);
-					*(size_t*)&regs.stackFramePointer[offset] = 0;
+					engine->CallFree((void*)*(asPWORD*)&regs.stackFramePointer[offset]);
+					*(asPWORD*)&regs.stackFramePointer[offset] = 0;
 				}
 			}
 		}
@@ -3860,11 +3885,11 @@ int asCContext::GetExceptionLineNumber(int *column, const char **sectionName)
 }
 
 // interface
-int asCContext::GetExceptionFunction()
+asIScriptFunction *asCContext::GetExceptionFunction()
 {
-	if( GetState() != asEXECUTION_EXCEPTION ) return asERROR;
+	if( GetState() != asEXECUTION_EXCEPTION ) return 0;
 
-	return exceptionFunction;
+	return engine->scriptFunctions[exceptionFunction];
 }
 
 // interface
@@ -3989,7 +4014,7 @@ int asCContext::CallGeneric(int id, void *objectPointer)
 			popSize += AS_PTR_SIZE;
 
 			// Check for null pointer
-			currentObject = (void*)*(size_t*)(args);
+			currentObject = (void*)*(asPWORD*)(args);
 			if( currentObject == 0 )
 			{
 				SetInternalException(TXT_NULL_POINTER_ACCESS);
@@ -3997,7 +4022,7 @@ int asCContext::CallGeneric(int id, void *objectPointer)
 			}
 
 			// Add the base offset for multiple inheritance
-			currentObject = (void*)(size_t(currentObject) + sysFunc->baseOffset);
+			currentObject = (void*)(asPWORD(currentObject) + sysFunc->baseOffset);
 
 			// Skip object pointer
 			args += AS_PTR_SIZE;
@@ -4013,9 +4038,9 @@ int asCContext::CallGeneric(int id, void *objectPointer)
 
 	asCGeneric gen(engine, sysFunction, currentObject, args);
 
-	isCallingSystemFunction = true;
+	callingSystemFunction = sysFunction;
 	func(&gen);
-	isCallingSystemFunction = false;
+	callingSystemFunction = 0;
 
 	regs.valueRegister = gen.returnVal;
 	regs.objectRegister = gen.objectRegister;
@@ -4032,8 +4057,12 @@ int asCContext::CallGeneric(int id, void *objectPointer)
 			{
 				// Release the object
 				asSTypeBehaviour *beh = &sysFunction->parameterTypes[n].GetObjectType()->beh;
-				if( beh->release )
-					engine->CallObjectMethod(obj, beh->release);
+				if( sysFunction->parameterTypes[n].GetObjectType()->flags & asOBJ_REF )
+				{
+					asASSERT( (sysFunction->parameterTypes[n].GetObjectType()->flags & asOBJ_NOCOUNT) || beh->release );
+					if( beh->release )
+						engine->CallObjectMethod(obj, beh->release);
+				}
 				else
 				{
 					// Call the destructor then free the memory
@@ -4105,7 +4134,7 @@ void *asCContext::GetAddressOfVar(asUINT varIndex, asUINT stackLevel)
 	}
 	else
 	{
-		size_t *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
+		asPWORD *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
 		func = (asCScriptFunction*)s[1];
 		sf = (asDWORD*)s[0];
 	}
@@ -4187,7 +4216,7 @@ void *asCContext::GetThisPointer(asUINT stackLevel)
 	}
 	else
 	{
-		size_t *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
+		asPWORD *s = callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
 		func = (asCScriptFunction*)s[1];
 		sf = (asDWORD*)s[0];
 	}
@@ -4198,7 +4227,7 @@ void *asCContext::GetThisPointer(asUINT stackLevel)
 	if( func->objectType == 0 )
 		return 0; // not in a method
 
-	void *thisPointer = (void*)*(size_t*)(sf);
+	void *thisPointer = (void*)*(asPWORD*)(sf);
 	if( thisPointer == 0 )
 	{
 		return 0;

+ 6 - 6
ThirdParty/AngelScript/source/as_context.h

@@ -93,11 +93,10 @@ public:
 	int  Abort();
 	int  Suspend();
 
-	int  SetException(const char *descr);
-	int  GetExceptionLineNumber(int *column, const char **sectionName);
-	// TODO: interface: GetExceptionFunction should return asIScriptFunction.
-	int  GetExceptionFunction();
-	const char *GetExceptionString();
+	int                SetException(const char *descr);
+	int                GetExceptionLineNumber(int *column, const char **sectionName);
+	asIScriptFunction *GetExceptionFunction();
+	const char *       GetExceptionString();
 
 	int  SetLineCallback(asSFuncPtr callback, void *obj, int callConv);
 	void ClearLineCallback();
@@ -115,6 +114,7 @@ public:
 	bool               IsVarInScope(asUINT varIndex, asUINT stackLevel);
 	int                GetThisTypeId(asUINT stackLevel);
     void              *GetThisPointer(asUINT stackLevel);
+	asIScriptFunction *GetSystemFunction();
 
 	void *SetUserData(void *data);
 	void *GetUserData() const;
@@ -157,9 +157,9 @@ public:
 	bool doSuspend;
 	bool doAbort;
 	bool externalSuspendRequest;
-	bool isCallingSystemFunction;
 
 	asCScriptFunction *currentFunction;
+	asCScriptFunction *callingSystemFunction;
 	bool isStackMemoryNotAllocated;
 
 	asCArray<size_t> callStack;

+ 2 - 2
ThirdParty/AngelScript/source/as_criticalsection.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -52,7 +52,7 @@ BEGIN_AS_NAMESPACE
 
 #else
 
-#define DECLARECRITICALSECTION(x)  asCThreadCriticalSection x
+#define DECLARECRITICALSECTION(x)  asCThreadCriticalSection x;
 #define ENTERCRITICALSECTION(x)    x.Enter()
 #define LEAVECRITICALSECTION(x)    x.Leave()
 #define TRYENTERCRITICALSECTION(x) x.TryEnter()

+ 12 - 27
ThirdParty/AngelScript/source/as_datatype.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -28,7 +28,6 @@
    [email protected]
 */
 
-// Modified by Lasse Öörni for Urho3D
 
 //
 // as_datatype.cpp
@@ -54,8 +53,6 @@ asCDataType::asCDataType()
 	isObjectHandle = false;
 	isConstHandle  = false;
 	funcDef        = 0;
-	// Urho3D: reset cached type ID
-	cachedTypeId   = 0;
 }
 
 asCDataType::asCDataType(const asCDataType &dt)
@@ -67,8 +64,6 @@ asCDataType::asCDataType(const asCDataType &dt)
 	isObjectHandle = dt.isObjectHandle;
 	isConstHandle  = dt.isConstHandle;
 	funcDef        = dt.funcDef;
-	// Urho3D: copy cached type ID
-	cachedTypeId   = dt.cachedTypeId;
 }
 
 asCDataType::~asCDataType()
@@ -149,7 +144,7 @@ bool asCDataType::IsNullHandle() const
 	return false;
 }
 
-asCString asCDataType::Format() const
+asCString asCDataType::Format(bool includeNamespace) const
 {
 	if( IsNullHandle() )
 		return "<null handle>";
@@ -159,13 +154,21 @@ asCString asCDataType::Format() const
 	if( isReadOnly )
 		str = "const ";
 
+	if( includeNamespace )
+	{
+		if( objectType )
+			str += objectType->nameSpace + "::";
+		else if( funcDef )
+			str += objectType->nameSpace + "::";
+	}
+
 	if( tokenType != ttIdentifier )
 	{
 		str += asCTokenizer::GetDefinition(tokenType);
 	}
 	else if( IsArrayType() && objectType && !objectType->engine->ep.expandDefaultArrayToTemplate )
 	{
-		str += objectType->templateSubType.Format();
+		str += objectType->templateSubType.Format(includeNamespace);
 		str += "[]";
 	}
 	else if( funcDef )
@@ -178,7 +181,7 @@ asCString asCDataType::Format() const
 		if( objectType->flags & asOBJ_TEMPLATE )
 		{
 			str += "<";
-			str += objectType->templateSubType.Format();
+			str += objectType->templateSubType.Format(includeNamespace);
 			str += ">";
 		}
 	}
@@ -200,7 +203,6 @@ asCString asCDataType::Format() const
 	return str;
 }
 
-
 asCDataType &asCDataType::operator =(const asCDataType &dt)
 {
 	tokenType        = dt.tokenType;
@@ -210,17 +212,12 @@ asCDataType &asCDataType::operator =(const asCDataType &dt)
 	isObjectHandle   = dt.isObjectHandle;
 	isConstHandle    = dt.isConstHandle;
 	funcDef          = dt.funcDef;
-	// Urho3D: copy cached type id
-	cachedTypeId     = dt.cachedTypeId;
 
 	return (asCDataType &)*this;
 }
 
 int asCDataType::MakeHandle(bool b, bool acceptHandleForScope)
 {
-	// Urho3D: reset cached type ID
-	cachedTypeId = 0;
-
 	if( !b )
 	{
 		isObjectHandle = b;
@@ -253,9 +250,6 @@ int asCDataType::MakeHandle(bool b, bool acceptHandleForScope)
 
 int asCDataType::MakeArray(asCScriptEngine *engine)
 {
-	// Urho3D: reset cached type ID
-	cachedTypeId = 0;
-
 	if( engine->defaultArrayObjectType == 0 )
 		return asINVALID_TYPE;
 
@@ -275,9 +269,6 @@ int asCDataType::MakeArray(asCScriptEngine *engine)
 
 int asCDataType::MakeReference(bool b)
 {
-	// Urho3D: reset cached type ID
-	cachedTypeId = 0;
-
 	isReference = b;
 
 	return 0;
@@ -285,9 +276,6 @@ int asCDataType::MakeReference(bool b)
 
 int asCDataType::MakeReadOnly(bool b)
 {
-	// Urho3D: reset cached type ID
-	cachedTypeId = 0;
-
 	if( isObjectHandle )
 	{
 		isConstHandle = b;
@@ -300,9 +288,6 @@ int asCDataType::MakeReadOnly(bool b)
 
 int asCDataType::MakeHandleToConst(bool b)
 {
-	// Urho3D: reset cached type ID
-	cachedTypeId = 0;
-
 	if( !isObjectHandle ) return -1;
 
 	isReadOnly = b;

+ 5 - 14
ThirdParty/AngelScript/source/as_datatype.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -28,7 +28,6 @@
    [email protected]
 */
 
-// Modified by Lasse Öörni for Urho3D
 
 //
 // as_datatype.h
@@ -60,7 +59,7 @@ public:
 
 	bool IsValid() const;
 
-	asCString Format() const;
+	asCString Format(bool includeNamespace = false) const;
 
 	static asCDataType CreatePrimitive(eTokenType tt, bool isConst);
 	static asCDataType CreateObject(asCObjectType *ot, bool isConst);
@@ -113,19 +112,14 @@ public:
 	int  GetSizeInMemoryBytes()  const;
 	int  GetSizeInMemoryDWords() const;
 
-	// Urho3D: reset cached type id whenever something changes
-	void SetTokenType(eTokenType tt)         { tokenType = tt; cachedTypeId = 0; }
-	void SetObjectType(asCObjectType *obj)   { objectType = obj; cachedTypeId = 0; }
-	void SetFuncDef(asCScriptFunction *func) { asASSERT(funcDef); funcDef = func; cachedTypeId = 0; }
+	void SetTokenType(eTokenType tt)         {tokenType = tt;}
+	void SetObjectType(asCObjectType *obj)   {objectType = obj;}
+	void SetFuncDef(asCScriptFunction *func) { asASSERT(funcDef); funcDef = func; }
 
 	asCDataType &operator =(const asCDataType &);
 
 	asSTypeBehaviour *GetBehaviour() const;
 
-	// Urho3D: cache the type id for repeated queries
-	void SetCachedTypeId(int id)       const {cachedTypeId = id;}
-	int GetCachedTypeId()              const {return cachedTypeId;}
-
 protected:
 	// Base object type
 	eTokenType tokenType;
@@ -134,9 +128,6 @@ protected:
 	asCObjectType *objectType;
 	asCScriptFunction *funcDef;
 
-	// Urho3D: cached type id
-	mutable int cachedTypeId;
-
 	// Top level
 	bool isReference:1;
 	bool isReadOnly:1;

+ 1 - 1
ThirdParty/AngelScript/source/as_debug.h

@@ -43,7 +43,7 @@
 // Neither does WinCE
 
 
-#if defined(__GNUC__) 
+#if defined(__GNUC__) || defined( AS_MARMALADE )
 // Define mkdir for GNUC
 #include <sys/stat.h>
 #include <sys/types.h>

+ 3 - 5
ThirdParty/AngelScript/source/as_gc.cpp

@@ -123,19 +123,18 @@ int asCGarbageCollector::GarbageCollect(asDWORD flags)
 				destroyOldState = destroyGarbage_init;
 			}
 
-			int r = 1;
 			unsigned int count = (unsigned int)(gcNewObjects.GetLength() + gcOldObjects.GetLength());
 			for(;;)
 			{
 				// Detect all garbage with cyclic references
 				if( doDetect )
-					while( (r = IdentifyGarbageWithCyclicRefs()) == 1 );
+					while( IdentifyGarbageWithCyclicRefs() == 1 ) {}
 
 				// Now destroy all known garbage
 				if( doDestroy )
 				{
-					while( (r = DestroyNewGarbage()) == 1 );
-					while( (r = DestroyOldGarbage()) == 1 );
+					while( DestroyNewGarbage() == 1 ) {}
+					while( DestroyOldGarbage() == 1 ) {}
 				}
 
 				// Run another iteration if any garbage was destroyed
@@ -770,7 +769,6 @@ int asCGarbageCollector::IdentifyGarbageWithCyclicRefs()
 				}
 			}
 		}
-		break;
 		} // switch
 	}
 

+ 2 - 2
ThirdParty/AngelScript/source/as_gc.h

@@ -127,8 +127,8 @@ protected:
 	asSMapNode<void*, asSIntTypePair> *gcMapCursor;
 
 	// Critical section for multithreaded access
-	DECLARECRITICALSECTION(gcCritical);   // Used for adding/removing objects
-	DECLARECRITICALSECTION(gcCollecting); // Used for processing
+	DECLARECRITICALSECTION(gcCritical)   // Used for adding/removing objects
+	DECLARECRITICALSECTION(gcCollecting) // Used for processing
 };
 
 END_AS_NAMESPACE

+ 3 - 12
ThirdParty/AngelScript/source/as_generic.cpp

@@ -74,15 +74,6 @@ int asCGeneric::GetFunctionId() const
 	return sysFunction->id;
 }
 
-#ifdef AS_DEPRECATED
-// deprecated since 2011-10-03
-// interface
-asIScriptFunction *asCGeneric::GetFunctionDescriptor() const
-{
-	return sysFunction;
-}
-#endif
-
 // interface
 asIScriptFunction *asCGeneric::GetFunction() const
 {
@@ -269,7 +260,7 @@ void *asCGeneric::GetArgAddress(asUINT arg)
 		offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords();
 
 	// Get the value
-	return (void*)*(size_t*)(&stackPointer[offset]);
+	return (void*)*(asPWORD*)(&stackPointer[offset]);
 }
 
 // interface
@@ -477,7 +468,7 @@ int asCGeneric::SetReturnObject(void *obj)
 		// If function returns object by value the memory is already allocated.
 		// Here we should just initialize that memory by calling the copy constructor
 		// or the default constructor followed by the assignment operator
-		void *mem = (void*)*(size_t*)&stackPointer[-AS_PTR_SIZE];
+		void *mem = (void*)*(asPWORD*)&stackPointer[-AS_PTR_SIZE];
 		engine->ConstructScriptObjectCopy(mem, obj, dt->GetObjectType());
 		return 0;
 	}
@@ -515,7 +506,7 @@ void *asCGeneric::GetAddressOfReturnLocation()
 		{
 			// The memory is already preallocated on the stack,
 			// and the pointer to the location is found before the first arg
-			return (void*)*(size_t*)&stackPointer[-AS_PTR_SIZE];
+			return (void*)*(asPWORD*)&stackPointer[-AS_PTR_SIZE];
 		}
 
 		// Reference types store the handle in the objectReference

+ 0 - 5
ThirdParty/AngelScript/source/as_generic.h

@@ -56,11 +56,6 @@ public:
 	asIScriptEngine   *GetEngine() const;
 	int                GetFunctionId() const;
 	asIScriptFunction *GetFunction() const;
-#ifdef AS_DEPRECATED
-	// TODO: interface: Remove this deprecated function
-	// deprecated since 2011-10-03
-	asIScriptFunction *GetFunctionDescriptor() const;
-#endif
 	void              *GetFunctionUserData() const;
 
 	// Object

+ 2 - 1
ThirdParty/AngelScript/source/as_globalproperty.cpp

@@ -215,7 +215,8 @@ static void GlobalProperty_ReleaseAllHandles_Generic(asIScriptGeneric *gen)
 void asCGlobalProperty::RegisterGCBehaviours(asCScriptEngine *engine)
 {
 	// Register the gc behaviours for the global properties
-	int r;
+	int r = 0;
+	UNUSED_VAR(r); // It is only used in debug mode
 	engine->globalPropertyBehaviours.engine = engine;
 	engine->globalPropertyBehaviours.flags = asOBJ_REF | asOBJ_GC;
 	engine->globalPropertyBehaviours.name = "_builtin_globalprop_";

+ 5 - 1
ThirdParty/AngelScript/source/as_memory.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2010 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -150,6 +150,8 @@ void asCMemoryMgr::FreeScriptNode(void *ptr)
 	LEAVECRITICALSECTION(cs);
 }
 
+#ifndef AS_NO_COMPILER
+
 void *asCMemoryMgr::AllocByteInstruction()
 {
 	if( byteInstructionPool.GetLength() )
@@ -171,6 +173,8 @@ void asCMemoryMgr::FreeByteInstruction(void *ptr)
 	byteInstructionPool.PushLast(ptr);
 }
 
+#endif // AS_NO_COMPILER
+
 END_AS_NAMESPACE
 
 

+ 4 - 2
ThirdParty/AngelScript/source/as_memory.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2009 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied
    warranty. In no event will the authors be held liable for any
@@ -89,11 +89,13 @@ public:
 	void *AllocScriptNode();
 	void FreeScriptNode(void *ptr);
 
+#ifndef AS_NO_COMPILER
 	void *AllocByteInstruction();
 	void FreeByteInstruction(void *ptr);
+#endif
 
 protected:
-	DECLARECRITICALSECTION(cs);
+	DECLARECRITICALSECTION(cs)
 	asCArray<void *> scriptNodePool;
 	asCArray<void *> byteInstructionPool;
 };

+ 111 - 48
ThirdParty/AngelScript/source/as_module.cpp

@@ -114,6 +114,39 @@ const char *asCModule::GetName() const
 	return name.AddressOf();
 }
 
+// interface
+int asCModule::SetDefaultNamespace(const char *nameSpace)
+{
+	// TODO: cleanup: This function is similar to asCScriptEngine::SetDefaultNamespace. Can we reuse the code?
+	if( nameSpace == 0 )
+		return asINVALID_ARG;
+
+	defaultNamespace = nameSpace;
+	if( defaultNamespace != "" )
+	{
+		// Make sure the namespace is composed of alternating identifier and ::
+		size_t pos = 0;
+		bool expectIdentifier = true;
+		size_t len;
+		eTokenType t = ttIdentifier;
+
+		for( ; pos < defaultNamespace.GetLength(); pos += len )
+		{
+			t = engine->tok.GetToken(defaultNamespace.AddressOf() + pos, defaultNamespace.GetLength() - pos, &len);
+			if( (expectIdentifier && t != ttIdentifier) || (!expectIdentifier && t != ttScope) )
+				return asINVALID_DECLARATION;
+
+			expectIdentifier = !expectIdentifier;
+		}
+
+		// If the namespace ends with :: then strip it off
+		if( t == ttScope )
+			defaultNamespace.SetLength(defaultNamespace.GetLength()-2);
+	}
+
+	return 0;
+}
+
 // interface
 int asCModule::AddScriptSection(const char *name, const char *code, size_t codeLength, int lineOffset)
 {
@@ -270,8 +303,7 @@ int asCModule::CallInit(asIScriptContext *myCtx)
 										 
 					if( r == asEXECUTION_EXCEPTION )
 					{
-						int funcId = ctx->GetExceptionFunction();
-						const asIScriptFunction *function = engine->GetFunctionById(funcId);
+						const asIScriptFunction *function = ctx->GetExceptionFunction();
 
 						msg.Format(TXT_EXCEPTION_s_IN_s, ctx->GetExceptionString(), function->GetDeclaration());
 
@@ -318,8 +350,12 @@ void asCModule::CallExit()
 			{
 				asCObjectType *ot = scriptGlobals[n]->type.GetObjectType();
 
-				if( ot->beh.release )
-					engine->CallObjectMethod(*obj, ot->beh.release);
+				if( ot->flags & asOBJ_REF )
+				{
+					asASSERT( (ot->flags & asOBJ_NOCOUNT) || ot->beh.release );
+					if( ot->beh.release )
+						engine->CallObjectMethod(*obj, ot->beh.release);
+				}
 				else
 				{
 					if( ot->beh.destruct )
@@ -412,7 +448,8 @@ int asCModule::GetFunctionIdByName(const char *name) const
 	int id = -1;
 	for( size_t n = 0; n < globalFunctions.GetLength(); n++ )
 	{
-		if( globalFunctions[n]->name == name )
+		if( globalFunctions[n]->name == name &&
+			globalFunctions[n]->nameSpace == defaultNamespace )
 		{
 			if( id == -1 )
 				id = globalFunctions[n]->id;
@@ -500,6 +537,9 @@ int asCModule::GetFunctionIdByDecl(const char *decl) const
 	if( r < 0 )
 		return asINVALID_DECLARATION;
 
+	// Use the defaultNamespace implicitly unless an explicit namespace has been provided
+	asCString ns = func.nameSpace == "" ? defaultNamespace : func.nameSpace;
+
 	// TODO: optimize: Improve linear search
 	// Search script functions for matching interface
 	int id = -1;
@@ -508,7 +548,8 @@ int asCModule::GetFunctionIdByDecl(const char *decl) const
 		if( globalFunctions[n]->objectType == 0 && 
 			func.name == globalFunctions[n]->name && 
 			func.returnType == globalFunctions[n]->returnType &&
-			func.parameterTypes.GetLength() == globalFunctions[n]->parameterTypes.GetLength() )
+			func.parameterTypes.GetLength() == globalFunctions[n]->parameterTypes.GetLength() &&
+			ns == globalFunctions[n]->nameSpace )
 		{
 			bool match = true;
 			for( size_t p = 0; p < func.parameterTypes.GetLength(); ++p )
@@ -555,7 +596,8 @@ int asCModule::GetGlobalVarIndexByName(const char *name) const
 	int id = -1;
 	for( size_t n = 0; n < scriptGlobals.GetLength(); n++ )
 	{
-		if( scriptGlobals[n]->name == name )
+		if( scriptGlobals[n]->name == name &&
+			scriptGlobals[n]->nameSpace == defaultNamespace )
 		{
 			id = (int)n;
 			break;
@@ -579,39 +621,23 @@ int asCModule::RemoveGlobalVar(asUINT index)
 	return 0;
 }
 
-#ifdef AS_DEPRECATED
-// deprecated since 2011-10-03
-// interface
-asIScriptFunction *asCModule::GetFunctionDescriptorByIndex(asUINT index) const
-{
-	if( index >= globalFunctions.GetLength() )
-		return 0;
-
-	return globalFunctions[index];
-}
-
-// interface
-asIScriptFunction *asCModule::GetFunctionDescriptorById(int funcId) const
-{
-	return engine->GetFunctionDescriptorById(funcId);
-}
-#endif
-
 // interface
 int asCModule::GetGlobalVarIndexByDecl(const char *decl) const
 {
 	asCBuilder bld(engine, const_cast<asCModule*>(this));
 
-	asCObjectProperty gvar;
-	bld.ParseVariableDeclaration(decl, &gvar);
+	asCString name, nameSpace;
+	asCDataType dt;
+	bld.ParseVariableDeclaration(decl, defaultNamespace, name, nameSpace, dt);
 
 	// TODO: optimize: Improve linear search
-	// Search script functions for matching interface
+	// Search global variables for a match
 	int id = -1;
 	for( size_t n = 0; n < scriptGlobals.GetLength(); ++n )
 	{
-		if( gvar.name == scriptGlobals[n]->name && 
-			gvar.type == scriptGlobals[n]->type )
+		if( name      == scriptGlobals[n]->name && 
+			nameSpace == scriptGlobals[n]->nameSpace &&
+			dt        == scriptGlobals[n]->type )
 		{
 			id = (int)n;
 			break;
@@ -638,7 +664,7 @@ void *asCModule::GetAddressOfGlobalVar(asUINT index)
 }
 
 // interface
-const char *asCModule::GetGlobalVarDeclaration(asUINT index) const
+const char *asCModule::GetGlobalVarDeclaration(asUINT index, bool includeNamespace) const
 {
 	if( index >= scriptGlobals.GetLength() )
 		return 0;
@@ -648,13 +674,16 @@ const char *asCModule::GetGlobalVarDeclaration(asUINT index) const
 	asASSERT(threadManager);
 	asCString *tempString = &threadManager->GetLocalData()->string;
 	*tempString = prop->type.Format();
-	*tempString += " " + prop->name;
+	*tempString += " ";
+	if( includeNamespace )
+		*tempString += prop->nameSpace + "::";
+	*tempString += prop->name;
 
 	return tempString->AddressOf();
 }
 
 // interface
-int asCModule::GetGlobalVar(asUINT index, const char **name, int *typeId, bool *isConst) const
+int asCModule::GetGlobalVar(asUINT index, const char **name, const char **nameSpace, int *typeId, bool *isConst) const
 {
 	if( index >= scriptGlobals.GetLength() )
 		return asINVALID_ARG;
@@ -663,6 +692,8 @@ int asCModule::GetGlobalVar(asUINT index, const char **name, int *typeId, bool *
 
 	if( name )
 		*name = prop->name.AddressOf();
+	if( nameSpace )
+		*nameSpace = prop->nameSpace.AddressOf();
 	if( typeId )
 		*typeId = engine->GetTypeIdFromDataType(prop->type);
 	if( isConst )
@@ -686,12 +717,26 @@ asIObjectType *asCModule::GetObjectTypeByIndex(asUINT index) const
 	return classTypes[index];
 }
 
+// interface
+asIObjectType *asCModule::GetObjectTypeByName(const char *name) const
+{
+	for( asUINT n = 0; n < classTypes.GetLength(); n++ )
+	{
+		if( classTypes[n] &&
+			classTypes[n]->name == name &&
+			classTypes[n]->nameSpace == defaultNamespace )
+			return classTypes[n];
+	}
+
+	return 0;
+}
+
 // interface
 int asCModule::GetTypeIdByDecl(const char *decl) const
 {
 	asCDataType dt;
 	asCBuilder bld(engine, const_cast<asCModule*>(this));
-	int r = bld.ParseDataType(decl, &dt);
+	int r = bld.ParseDataType(decl, &dt, defaultNamespace);
 	if( r < 0 )
 		return asINVALID_TYPE;
 
@@ -705,7 +750,7 @@ asUINT asCModule::GetEnumCount() const
 }
 
 // interface
-const char *asCModule::GetEnumByIndex(asUINT index, int *enumTypeId) const
+const char *asCModule::GetEnumByIndex(asUINT index, int *enumTypeId, const char **nameSpace) const
 {
 	if( index >= enumTypes.GetLength() )
 		return 0;
@@ -713,6 +758,9 @@ const char *asCModule::GetEnumByIndex(asUINT index, int *enumTypeId) const
 	if( enumTypeId )
 		*enumTypeId = GetTypeIdByDecl(enumTypes[index]->name.AddressOf());
 
+	if( nameSpace )
+		*nameSpace = enumTypes[index]->name.AddressOf();
+
 	return enumTypes[index]->name.AddressOf();
 }
 
@@ -751,7 +799,7 @@ asUINT asCModule::GetTypedefCount() const
 }
 
 // interface
-const char *asCModule::GetTypedefByIndex(asUINT index, int *typeId) const
+const char *asCModule::GetTypedefByIndex(asUINT index, int *typeId, const char **nameSpace) const
 {
 	if( index >= typeDefs.GetLength() )
 		return 0;
@@ -759,6 +807,9 @@ const char *asCModule::GetTypedefByIndex(asUINT index, int *typeId) const
 	if( typeId )
 		*typeId = GetTypeIdByDecl(typeDefs[index]->name.AddressOf());
 
+	if( nameSpace )
+		*nameSpace = typeDefs[index]->nameSpace.AddressOf();
+
 	return typeDefs[index]->name.AddressOf();
 }
 
@@ -1033,6 +1084,9 @@ asCGlobalProperty *asCModule::AllocateGlobalProperty(const char *name, const asC
 	return prop;
 }
 
+#ifdef AS_DEPRECATED
+	// Deprecated since 2.23.0 - 2012-01-30
+
 // internal
 void asCModule::ResolveInterfaceIds(asCArray<void*> *substitutions)
 {
@@ -1388,6 +1442,8 @@ bool asCModule::AreTypesEqual(const asCDataType &a, const asCDataType &b, asCArr
 	return true;
 }
 
+#endif // AS_DEPRECATED
+
 // interface
 int asCModule::SaveByteCode(asIBinaryStream *out) const
 {
@@ -1454,6 +1510,7 @@ int asCModule::CompileGlobalVar(const char *sectionName, const char *code, int l
 	// Compile the global variable and add it to the module scope
 	asCBuilder builder(engine, this);
 	asCString str = code;
+	// TODO: namespace: Add the global var to the default namespace
 	r = builder.CompileGlobalVar(sectionName, str.AddressOf(), lineOffset);
 
 	engine->BuildCompleted();
@@ -1522,6 +1579,7 @@ int asCModule::CompileFunction(const char *sectionName, const char *code, int li
 	asCBuilder builder(engine, this);
 	asCString str = code;
 	asCScriptFunction *func = 0;
+	// TODO: namespace: Add the function to the default namespace
 	r = builder.CompileFunction(sectionName, str.AddressOf(), lineOffset, compileFlags, &func);
 
 	engine->BuildCompleted();
@@ -1544,20 +1602,25 @@ int asCModule::CompileFunction(const char *sectionName, const char *code, int li
 // interface
 int asCModule::RemoveFunction(int funcId)
 {
-	// Find the global function
-	for( asUINT n = 0; n < globalFunctions.GetLength(); n++ )
-	{
-		if( globalFunctions[n] && globalFunctions[n]->id == funcId )
-		{
-			asCScriptFunction *func = globalFunctions[n];
-			globalFunctions.RemoveIndex(n);
-			func->Release();
+	if( funcId >= 0 && funcId < (int)engine->scriptFunctions.GetLength() )
+		return RemoveFunction(engine->scriptFunctions[funcId]);
 
-			scriptFunctions.RemoveValue(func);
-			func->Release();
+	return asNO_FUNCTION;
+}
 
-			return 0;
-		}
+// interface
+int asCModule::RemoveFunction(asIScriptFunction *func)
+{
+	// Find the global function
+	asCScriptFunction *f = static_cast<asCScriptFunction*>(func);
+	int idx = globalFunctions.IndexOf(f);
+	if( idx >= 0 )
+	{
+		globalFunctions.RemoveIndex(idx);
+		f->Release();
+		scriptFunctions.RemoveValue(f);
+		f->Release();
+		return 0;
 	}
 
 	return asNO_FUNCTION;

+ 13 - 12
ThirdParty/AngelScript/source/as_module.h

@@ -103,21 +103,20 @@ public:
 	virtual int     CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD reserved, asIScriptFunction **outFunc);
 	virtual int     CompileGlobalVar(const char *sectionName, const char *code, int lineOffset);
 	virtual asDWORD SetAccessMask(asDWORD accessMask);
+	virtual int     SetDefaultNamespace(const char *nameSpace);
 
 	// Script functions
 	virtual asUINT             GetFunctionCount() const;
+	// TODO: interface: Deprecate the functions that return the function id
 	virtual int                GetFunctionIdByIndex(asUINT index) const;
 	virtual int                GetFunctionIdByName(const char *name) const;
 	virtual int                GetFunctionIdByDecl(const char *decl) const;
 	virtual asIScriptFunction *GetFunctionByIndex(asUINT index) const;
 	virtual asIScriptFunction *GetFunctionByDecl(const char *decl) const;
 	virtual asIScriptFunction *GetFunctionByName(const char *name) const;
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-03
-	virtual asIScriptFunction *GetFunctionDescriptorByIndex(asUINT index) const;
-	virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const;
-#endif
+	// TODO: interface: Deprecate RemoveFunction(int)
 	virtual int                RemoveFunction(int funcId);
+	virtual int                RemoveFunction(asIScriptFunction *func);
 
 	// Script global variables
 	// TODO: interface: Should be called InitGlobalVars, and should have a bool to reset in case already initialized
@@ -125,28 +124,26 @@ public:
 	virtual asUINT      GetGlobalVarCount() const;
 	virtual int         GetGlobalVarIndexByName(const char *name) const;
 	virtual int         GetGlobalVarIndexByDecl(const char *decl) const;
-	// TODO: interface: Add flag to define whether or not namespace should be included in declaration
-	virtual const char *GetGlobalVarDeclaration(asUINT index) const;
-	// TODO: interface: Add namespace to the return values
-	virtual int         GetGlobalVar(asUINT index, const char **name, int *typeId, bool *isConst) const;
+	virtual const char *GetGlobalVarDeclaration(asUINT index, bool includeNamespace) const;
+	virtual int         GetGlobalVar(asUINT index, const char **name, const char **nameSpace, int *typeId, bool *isConst) const;
 	virtual void       *GetAddressOfGlobalVar(asUINT index);
 	virtual int         RemoveGlobalVar(asUINT index);
 
 	// Type identification
 	virtual asUINT         GetObjectTypeCount() const;
 	virtual asIObjectType *GetObjectTypeByIndex(asUINT index) const;
-	// TODO: interface: Should have GetObjectTypeByName
+	virtual asIObjectType *GetObjectTypeByName(const char *name) const;
 	virtual int            GetTypeIdByDecl(const char *decl) const;
 
 	// Enums
 	virtual asUINT      GetEnumCount() const;
-	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId) const;
+	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **nameSpace) const;
 	virtual int         GetEnumValueCount(int enumTypeId) const;
 	virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const;
 
 	// Typedefs
 	virtual asUINT      GetTypedefCount() const;
-	virtual const char *GetTypedefByIndex(asUINT index, int *typeId) const;
+	virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **nameSpace) const;
 
 	// Dynamic binding between modules
 	virtual asUINT      GetImportedFunctionCount() const;
@@ -193,9 +190,12 @@ public:
 
 	int  GetNextImportedFunctionId();
 
+#ifdef AS_DEPRECATED
+	// Deprecated since 2.23.0 - 2012-01-30
 	void ResolveInterfaceIds(asCArray<void*> *substitutions = 0);
 	bool AreInterfacesEqual(asCObjectType *a, asCObjectType *b, asCArray<sObjectTypePair> &equals);
 	bool AreTypesEqual(const asCDataType &a, const asCDataType &b, asCArray<sObjectTypePair> &equals);
+#endif
 
 	asCScriptFunction *GetImportedFunction(int funcId) const;
 
@@ -210,6 +210,7 @@ public:
 	asCBuilder      *builder;
 	void            *userData;
 	asDWORD          accessMask;
+	asCString        defaultNamespace;
 
 	// This array holds all functions, class members, factories, etc that were compiled with the module
 	asCArray<asCScriptFunction *>  scriptFunctions;

+ 17 - 21
ThirdParty/AngelScript/source/as_objecttype.cpp

@@ -97,7 +97,8 @@ static void ObjectType_ReleaseAllHandles_Generic(asIScriptGeneric *gen)
 void RegisterObjectTypeGCBehaviours(asCScriptEngine *engine)
 {
 	// Register the gc behaviours for the object types
-	int r;
+	int r = 0;
+	UNUSED_VAR(r); // It is only used in debug mode
 	engine->objectTypeBehaviours.engine = engine;
 	engine->objectTypeBehaviours.flags = asOBJ_REF | asOBJ_GC;
 	engine->objectTypeBehaviours.name = "_builtin_objecttype_";
@@ -272,6 +273,12 @@ const char *asCObjectType::GetName() const
 	return name.AddressOf();
 }
 
+// interface
+const char *asCObjectType::GetNamespace() const
+{
+	return nameSpace.AddressOf();
+}
+
 // interface
 asDWORD asCObjectType::GetFlags() const
 {
@@ -480,25 +487,6 @@ asIScriptFunction *asCObjectType::GetMethodByDecl(const char *decl, bool getVirt
 	return engine->GetFunctionById(GetMethodIdByDecl(decl, getVirtual));
 }
 
-#ifdef AS_DEPRECATED
-// deprecated since 2011-10-03
-// interface
-asIScriptFunction *asCObjectType::GetMethodDescriptorByIndex(asUINT index, bool getVirtual) const
-{
-	if( index >= methods.GetLength() ) 
-		return 0;
-
-	if( !getVirtual )
-	{
-		asCScriptFunction *func = engine->scriptFunctions[methods[index]];
-		if( func && func->funcType == asFUNC_VIRTUAL )
-			return virtualFunctionTable[func->vfTableIdx];
-	}
-
-	return engine->scriptFunctions[methods[index]];
-}
-#endif
-
 // interface
 asUINT asCObjectType::GetPropertyCount() const
 {
@@ -506,7 +494,7 @@ asUINT asCObjectType::GetPropertyCount() const
 }
 
 // interface
-int asCObjectType::GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, int *offset, bool *isReference) const
+int asCObjectType::GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, int *offset, bool *isReference, asDWORD *accessMask) const
 {
 	if( index >= properties.GetLength() )
 		return asINVALID_ARG;
@@ -521,6 +509,8 @@ int asCObjectType::GetProperty(asUINT index, const char **name, int *typeId, boo
 		*offset = properties[index]->byteOffset;
 	if( isReference )
 		*isReference = properties[index]->type.IsReference();
+	if( accessMask )
+		*accessMask = properties[index]->accessMask;
 
 	return 0;
 }
@@ -669,6 +659,12 @@ const char *asCObjectType::GetConfigGroup() const
 	return group->groupName.AddressOf();
 }
 
+// interface
+asDWORD asCObjectType::GetAccessMask() const
+{
+	return accessMask;
+}
+
 // internal
 asCObjectProperty *asCObjectType::AddPropertyToClass(const asCString &name, const asCDataType &dt, bool isPrivate)
 {

+ 3 - 9
ThirdParty/AngelScript/source/as_objecttype.h

@@ -135,6 +135,7 @@ public:
 //=====================================
 	asIScriptEngine *GetEngine() const;
 	const char      *GetConfigGroup() const;
+	asDWORD          GetAccessMask() const;
 
 	// Memory management
 	int AddRef() const;
@@ -142,6 +143,7 @@ public:
 
 	// Type info
 	const char      *GetName() const;
+	const char      *GetNamespace() const;
 	asIObjectType   *GetBaseType() const;
 	bool             DerivesFrom(const asIObjectType *objType) const;
 	asDWORD          GetFlags() const;
@@ -149,8 +151,6 @@ public:
 	int              GetTypeId() const;
 	int              GetSubTypeId() const;
 	asIObjectType   *GetSubType() const;
-	// TODO: interface: access: Get/Set access mask for type
-	// TODO: interface: namespace: Get namespace
 
 	// Interfaces
 	asUINT           GetInterfaceCount() const;
@@ -172,16 +172,10 @@ public:
 	asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual) const;
 	asIScriptFunction *GetMethodByName(const char *name, bool getVirtual) const;
 	asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual) const;
-#ifdef AS_DEPRECATED
-	// TODO: interface: Remove this deprecated function
-	// deprecated since 2011-10-03
-	asIScriptFunction *GetMethodDescriptorByIndex(asUINT index, bool getVirtual) const;
-#endif
 
 	// Properties
-	// TODO: access: Allow getting and setting property access mask
 	asUINT      GetPropertyCount() const;
-	int         GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, int *offset, bool *isReference) const;
+	int         GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, int *offset, bool *isReference, asDWORD *accessMask) const;
 	const char *GetPropertyDeclaration(asUINT index) const;
 
 	// Behaviours

+ 7 - 1
ThirdParty/AngelScript/source/as_outputbuffer.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2007 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -37,6 +37,9 @@
 //
 
 #include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_outputbuffer.h"
 #include "as_scriptengine.h"
 
@@ -98,3 +101,6 @@ void asCOutputBuffer::SendToCallback(asCScriptEngine *engine, asSSystemFunctionI
 }
 
 END_AS_NAMESPACE
+
+#endif // AS_NO_COMPILER
+

+ 6 - 1
ThirdParty/AngelScript/source/as_outputbuffer.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2008 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -41,6 +41,9 @@
 #define AS_OUTPUTBUFFER_H
 
 #include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_string.h"
 #include "as_array.h"
 
@@ -72,4 +75,6 @@ public:
 
 END_AS_NAMESPACE
 
+#endif // AS_NO_COMPILER
+
 #endif

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1880 - 1383
ThirdParty/AngelScript/source/as_parser.cpp


+ 45 - 83
ThirdParty/AngelScript/source/as_parser.h

@@ -37,54 +37,6 @@
 
 
 
-/*
-
-TYPEDEF       = 'typedef' REALTYPE IDENTIFIER ';'
-ENUM          = 'enum' IDENTIFIER '{' ENUMELEMENT? (',' ENUMELEMENT)* '}'
-ENUMELEMENT   = IDENTIFIER ('=' EXPRESSION)
-SCRIPT        = (FUNCTION | GLOBVAR | IMPORT | STRUCT | INTERFACE | TYPEDEF | ENUM)*
-TYPE          = 'const'? DATATYPE
-TYPEMOD       = ('&' ('in' | 'out' | 'inout')?)?
-FUNCDEF       = 'funcdef' FUNCSIG ';'
-FUNCSIG       = TYPE TYPEMOD IDENTIFIER PARAMLIST
-FUNCTION      = FUNCSIG BLOCK
-IMPORT        = 'import' FUNCSIG 'from' STRING ';'
-INTERFACE     = 'interface' IDENTIFIER '{' (FUNCSIG ';')* '}' ';'
-GLOBVAR       = TYPE IDENTIFIER ('=' (INITLIST | ASSIGNMENT))? (',' IDENTIFIER ('=' (INITLIST | ASSIGNMENT))?)* ';'
-DATATYPE      = REALTYPE | IDENTIFIER
-REALTYPE      = 'void' | 'bool' | 'float' | 'int' | 'uint' | 'bits'
-PARAMLIST     = '(' (TYPE TYPEMOD IDENTIFIER? (',' TYPE TYPEMOD IDENTIFIER?)*)? ')'
-BLOCK         = '{' (DECLARATION | STATEMENT)* '}'
-DECLARATION   = TYPE IDENTIFIER ('=' (INITLIST | ASSIGNMENT))? (',' IDENTIFIER ('=' (INITLIST | ASSIGNMENT))?)* ';'
-STATEMENT     = BLOCK | IF | WHILE | DOWHILE | RETURN | EXPRSTATEMENT | BREAK | CONTINUE
-BREAK         = 'break' ';'
-CONTINUE      = 'continue' ';'
-EXPRSTATEMENT = ASSIGNMENT? ';'
-FOR           = 'for' '(' (DECLARATION | EXPRSTATEMENT) EXPRSTATEMENT ASSIGNMENT? ')' STATEMENT
-IF            = 'if' '(' ASSIGNMENT ')' STATEMENT ('else' STATEMENT)?
-WHILE         = 'while' '(' ASSIGNMENT ')' STATEMENT
-DOWHILE       = 'do' STATEMENT 'while' '(' ASSIGNMENT ')' ';'
-RETURN        = 'return' ASSIGNMENT? ';'
-ASSIGNMENT    = CONDITION (ASSIGNOP ASSIGNMENT)?
-CONDITION     = EXPRESSION ('?' ASSIGNMENT ':' ASSIGNMENT)?
-EXPRESSION    = TERM (OP TERM)*
-TERM          = PRE* VALUE POST*
-VALUE         = '(' ASSIGNMENT ')' | CONSTANT | IDENTIFIER | FUNCTIONCALL | CONVERSION | CAST
-PRE           = '-' | '+' | 'not' | '++' | '--' | '~'
-POST          = '++' | '--' | ('.' | '->') (IDENTIFIER | FUNCTIONCALL) | '[' ASSIGNMENT ']'
-FUNCTIONCALL  = IDENTIFIER ARGLIST
-ARGLIST       = '(' (ASSIGNMENT (',' ASSIGNMENT)*)? ')'
-CONSTANT      = "abc" | 123 | 123.1 | 'true' | 'false' | 0xFFFF
-OP            = 'and' | 'or' |
-                '==' | '!=' | '<' | '<=' | '>=' | '>' |
-			    '+' | '-' | '*' | '/' | '%' | '|' | '&' | '^' | '<<' | '>>' | '>>>'
-ASSIGNOP      = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '|=' | '&=' | '^=' | '<<=' | '>>=' | '>>>='
-CONVERSION    = TYPE '(' ASSIGNMENT ')'
-INITLIST      = '{' ((INITLIST | ASSIGNMENT)? (',' (INITLIST | ASSIGNMENT)?)*)? '}'
-CAST          = 'cast' '<' TYPE '>' '(' ASSIGNMENT ')'
-
-*/
-
 #ifndef AS_PARSER_H
 #define AS_PARSER_H
 
@@ -103,16 +55,17 @@ public:
 
 	int ParseFunctionDefinition(asCScriptCode *script);
 	int ParsePropertyDeclaration(asCScriptCode *script);
-	int ParseVirtualPropertyDeclaration(asCScriptCode *script, bool asMethod);
-	int ParseDataType(asCScriptCode *script);
+	int ParseDataType(asCScriptCode *script, bool isReturnType);
 	int ParseTemplateDecl(asCScriptCode *script);
 
 #ifndef AS_NO_COMPILER
 	int ParseScript(asCScriptCode *script);
+
+	// Called from compiler
 	int ParseStatementBlock(asCScriptCode *script, asCScriptNode *block);
 	int ParseGlobalVarInit(asCScriptCode *script, asCScriptNode *init);
-#endif
 	int ParseExpression(asCScriptCode *script);
+#endif
 	
 	asCScriptNode *GetScriptNode();
 
@@ -123,22 +76,24 @@ protected:
 	void RewindTo(const sToken *token);
 	void Error(const char *text, sToken *token);
 
-	asCScriptNode *ParseImport();
 	asCScriptNode *ParseFunctionDefinition();
-#ifndef AS_NO_COMPILER
-	asCScriptNode *ParseScript(bool inBlock);
-	asCScriptNode *ParseNamespace();
-#endif
+	asCScriptNode *ParseParameterList();
+	asCScriptNode *SuperficiallyParseExpression();
 	asCScriptNode *ParseType(bool allowConst, bool allowVariableType = false);
 	asCScriptNode *ParseTypeMod(bool isParam);
-	asCScriptNode *ParseFunction(bool isMethod = false);
-	asCScriptNode *ParseFuncDef();
-	asCScriptNode *ParseGlobalVar();
-	asCScriptNode *ParseParameterList();
+	void           ParseOptionalScope(asCScriptNode *node);
+	asCScriptNode *ParseRealType();
+	asCScriptNode *ParseDataType(bool allowVariableType = false);
+	asCScriptNode *ParseIdentifier();
+
+	bool IsRealType(int tokenType);
+	bool IsDataType(const sToken &token);
+
+#ifndef AS_NO_COMPILER
+	// Statements
 	asCScriptNode *SuperficiallyParseStatementBlock();
 	asCScriptNode *SuperficiallyParseGlobalVarInit();
 	asCScriptNode *ParseStatementBlock();
-	asCScriptNode *ParseDeclaration();
 	asCScriptNode *ParseStatement();
 	asCScriptNode *ParseExpressionStatement();
 	asCScriptNode *ParseSwitch();
@@ -150,6 +105,28 @@ protected:
 	asCScriptNode *ParseReturn();
 	asCScriptNode *ParseBreak();
 	asCScriptNode *ParseContinue();
+
+	// Declarations
+	asCScriptNode *ParseDeclaration();
+	asCScriptNode *ParseImport();
+	asCScriptNode *ParseScript(bool inBlock);
+	asCScriptNode *ParseNamespace();
+	asCScriptNode *ParseFunction(bool isMethod = false);
+	asCScriptNode *ParseFuncDef();
+	asCScriptNode *ParseGlobalVar();
+	asCScriptNode *ParseClass();
+	asCScriptNode *ParseInitList();
+	asCScriptNode *ParseInterface();
+	asCScriptNode *ParseInterfaceMethod();
+	asCScriptNode *ParseVirtualPropertyDecl(bool isMethod, bool isInterface);
+	asCScriptNode *ParseEnumeration();
+	asCScriptNode *ParseTypedef();
+	void ParseMethodOverrideBehaviors(asCScriptNode *funcNode);
+	bool IsVarDecl();
+	bool IsVirtualPropertyDecl();
+	bool IsFuncDecl(bool isMethod);
+
+	// Expressions
 	asCScriptNode *ParseAssignment();
 	asCScriptNode *ParseAssignOperator();
 	asCScriptNode *ParseCondition();
@@ -160,41 +137,26 @@ protected:
 	asCScriptNode *ParseExprPostOp();
 	asCScriptNode *ParseExprValue();
 	asCScriptNode *ParseArgList();
-	asCScriptNode *ParseDataType(bool allowVariableType = false);
-	asCScriptNode *ParseRealType();
-	asCScriptNode *ParseIdentifier();
-	asCScriptNode *ParseConstant();
-	asCScriptNode *ParseStringConstant();
 	asCScriptNode *ParseFunctionCall();
 	asCScriptNode *ParseVariableAccess();
 	asCScriptNode *ParseConstructCall();
-	asCScriptNode *ParseToken(int token);
-	asCScriptNode *ParseOneOf(int *tokens, int num);
-	asCScriptNode *ParseClass();
-	asCScriptNode *ParseInitList();
-	asCScriptNode *ParseInterface();
-	asCScriptNode *ParseInterfaceMethod();
-	asCScriptNode *ParseVirtualPropertyDecl(bool isMethod, bool isInterface);
 	asCScriptNode *ParseCast();
-	asCScriptNode *ParseEnumeration();				//	Parse enumeration enum { X, Y }
-	asCScriptNode *ParseTypedef();					//	Parse named type declaration
-	void ParseMethodOverrideBehaviors(asCScriptNode *funcNode);
+	asCScriptNode *ParseConstant();
+	asCScriptNode *ParseStringConstant();
 
-	bool IsVarDecl();
-	bool IsVirtualPropertyDecl();
-	bool IsFuncDecl(bool isMethod);
-	bool IsRealType(int tokenType);
-	bool IsDataType(const sToken &token);
+	bool IsConstant(int tokenType);
 	bool IsOperator(int tokenType);
 	bool IsPreOperator(int tokenType);
 	bool IsPostOperator(int tokenType);
-	bool IsConstant(int tokenType);
 	bool IsAssignOperator(int tokenType);
 	bool IsFunctionCall();
 
 	bool IdentifierIs(const sToken &t, const char *str);
-
 	bool CheckTemplateType(sToken &t);
+#endif
+
+	asCScriptNode *ParseToken(int token);
+	asCScriptNode *ParseOneOf(int *tokens, int num);
 
 	asCString ExpectedToken(const char *token);
 	asCString ExpectedTokens(const char *token1, const char *token2);

+ 479 - 201
ThirdParty/AngelScript/source/as_restore.cpp

@@ -147,6 +147,8 @@ int asCReader::Read()
 			ReadObjectTypeDeclaration(module->classTypes[i], 2);
 	}
 
+#ifdef AS_DEPRECATED
+	// Deprecated since 2.23.0 - 2012-01-30
 	asCArray<void*> substitutions;
 	module->ResolveInterfaceIds(&substitutions);
 
@@ -168,6 +170,7 @@ int asCReader::Read()
 				savedFunctions[f] = reinterpret_cast<asCScriptFunction*>(substitutions[i+1]);
 		}
 	}
+#endif
 
 	// Read class methods and behaviours
 	for( i = 0; i < module->classTypes.GetLength(); ++i )
@@ -213,7 +216,7 @@ int asCReader::Read()
 	count = ReadEncodedUInt();
 	for( i = 0; i < count; ++i ) 
 	{
-		asUINT len = module->scriptFunctions.GetLength();
+		size_t len = module->scriptFunctions.GetLength();
 		func = ReadFunction();
 		
 		// Is the function shared and was it created now?
@@ -288,29 +291,6 @@ int asCReader::Read()
 		usedTypes.PushLast(ot);
 	}
 
-	// Read the size of the value types so we can determine if it is necessary to adjust the code
-	asUINT numValueTypes = ReadEncodedUInt();
-	for( i = 0; i < numValueTypes; ++i )
-	{
-		asUINT idx = ReadEncodedUInt();
-		asUINT size = ReadEncodedUInt();
-
-		if( idx >= usedTypes.GetLength() )
-		{
-			// TODO: Write error message to the callback
-			error = true;
-			continue;
-		}
-
-		if( usedTypes[idx] && size != usedTypes[idx]->GetSize() )
-		{
-			// Keep track of the object types that have changed size 
-			// so the bytecode can be adjusted.
-			SObjChangeSize s = { usedTypes[idx], size };
-			oldObjectSizes.PushLast(s);
-		}
-	}
-
 	// usedTypeIds[]
 	ReadUsedTypeIds();
 
@@ -547,10 +527,7 @@ asCScriptFunction *asCReader::ReadFunction(bool addToModule, bool addToEngine, b
 		if( addToGC )
 			engine->gc.AddScriptObjectToGC(func, &engine->functionBehaviours);
 		
-		count = ReadEncodedUInt();
-		func->byteCode.Allocate(count, 0);
-		ReadByteCode(func->byteCode.AddressOf(), count);
-		func->byteCode.SetLength(count);
+		ReadByteCode(func);
 
 		count = ReadEncodedUInt();
 		func->objVariablePos.Allocate(count, 0);
@@ -1279,13 +1256,26 @@ asCObjectType* asCReader::ReadObjectType()
 	return ot;
 }
 
-void asCReader::ReadByteCode(asDWORD *bc, int length)
+void asCReader::ReadByteCode(asCScriptFunction *func)
 {
-	while( length )
+	// Read number of instructions
+	asUINT numInstructions = ReadEncodedUInt();
+
+	// Reserve some space for the instructions
+	func->byteCode.Allocate(numInstructions, 0);
+
+	asUINT pos = 0;
+	while( numInstructions )
 	{
 		asBYTE b;
 		READ_NUM(b);
 
+		// Allocate the space for the instruction
+		asUINT len = asBCTypeSize[asBCInfo[b].type];
+		func->byteCode.SetLength(func->byteCode.GetLength() + len);
+		asDWORD *bc = func->byteCode.AddressOf() + pos;
+		pos += len;
+
 		switch( asBCInfo[b].type )
 		{
 		case asBCTYPE_NO_ARG:
@@ -1486,7 +1476,7 @@ void asCReader::ReadByteCode(asDWORD *bc, int length)
 			}
 		}
 
-		length -= asBCTypeSize[asBCInfo[b].type];
+		numInstructions--;
 	}
 }
 
@@ -1629,16 +1619,29 @@ void asCReader::TranslateFunction(asCScriptFunction *func)
 	// Skip this if the function is part of an pre-existing shared object
 	if( dontTranslate.MoveTo(0, func) ) return;
 
+	// Pre-compute the size of each instruction in order to translate jump offsets
 	asUINT n;
 	asDWORD *bc = func->byteCode.AddressOf();
+	asCArray<asUINT> bcSizes(func->byteCode.GetLength());
+	asCArray<asUINT> instructionNbrToPos(func->byteCode.GetLength());
 	for( n = 0; n < func->byteCode.GetLength(); )
+	{
+		int c = *(asBYTE*)&bc[n];
+		asUINT size = asBCTypeSize[asBCInfo[c].type];
+		bcSizes.PushLast(size);
+		instructionNbrToPos.PushLast(n);
+		n += size;
+	}
+
+	asUINT bcNum = 0;
+	for( n = 0; n < func->byteCode.GetLength(); bcNum++ )
 	{
 		int c = *(asBYTE*)&bc[n];
 		if( c == asBC_FREE ||
 			c == asBC_REFCPY || c == asBC_OBJTYPE )
 		{
 			// Translate the index to the true object type
-			asPTRWORD *ot = (asPTRWORD*)&bc[n+1];
+			asPWORD *ot = (asPWORD*)&bc[n+1];
 			*(asCObjectType**)ot = FindObjectType(*(int*)ot);
 		}
 		else if( c == asBC_TYPEID ||
@@ -1704,13 +1707,13 @@ void asCReader::TranslateFunction(asCScriptFunction *func)
 		else if( c == asBC_FuncPtr )
 		{
 			// Translate the index to the func pointer
-			asPTRWORD *fid = (asPTRWORD*)&bc[n+1];
-			*fid = (asPTRWORD)(size_t)FindFunction((int)*fid);
+			asPWORD *fid = (asPWORD*)&bc[n+1];
+			*fid = (asPWORD)FindFunction((int)*fid);
 		}
 		else if( c == asBC_ALLOC )
 		{
 			// Translate the index to the true object type
-			asPTRWORD *arg = (asPTRWORD*)&bc[n+1];
+			asPWORD *arg = (asPWORD*)&bc[n+1];
 			*(asCObjectType**)arg = FindObjectType(*(int*)arg);
 
 			// If the object type is a script class then the constructor id must be translated
@@ -1775,7 +1778,7 @@ void asCReader::TranslateFunction(asCScriptFunction *func)
 				 c == asBC_SetG4 )
 		{
 			// Translate the global var index to pointer
-			asPTRWORD *index = (asPTRWORD*)&bc[n+1];
+			asPWORD *index = (asPWORD*)&bc[n+1];
 			if( *(asUINT*)index < usedGlobalProperties.GetLength() )
 				*(void**)index = usedGlobalProperties[*(asUINT*)index];
 			else
@@ -1785,175 +1788,233 @@ void asCReader::TranslateFunction(asCScriptFunction *func)
 				return;
 			}
 		}
+		else if( c == asBC_JMP ||
+			     c == asBC_JZ ||
+				 c == asBC_JNZ ||
+				 c == asBC_JS ||
+				 c == asBC_JNS ||
+				 c == asBC_JP ||
+				 c == asBC_JNP ) // The JMPP instruction doesn't need modification
+		{
+			// Get the offset 
+			int offset = int(bc[n+1]);
+
+			// Count the instruction sizes to the destination instruction
+			int size = 0;
+			if( offset >= 0 )
+				// If moving ahead, then start from next instruction
+				for( asUINT num = bcNum+1; offset-- > 0; num++ )
+					size += bcSizes[num];
+			else
+				// If moving backwards, then start at current instruction
+				for( asUINT num = bcNum; offset++ < 0; num-- )
+					size -= bcSizes[num];
+
+			// The size is dword offset 
+			bc[n+1] = size;
+		}
 
 		n += asBCTypeSize[asBCInfo[c].type];
 	}
 
-	// As the bytecode may have been generated on a different platform it is necessary
-	// to adjust the bytecode in case any of the value types allocated on the stack has
-	// a different size on this platform.
-	asCArray<int> adjustments;
-	for( n = 0; n < func->objVariableTypes.GetLength(); n++ )
+	// Adjust all variable positions
+	CalculateAdjustmentByPos(func);
+	bc = func->byteCode.AddressOf();
+	for( n = 0; n < func->byteCode.GetLength(); )
 	{
-		if( func->objVariableTypes[n] &&
-			(func->objVariableTypes[n]->GetFlags() & asOBJ_VALUE) &&
-			!func->objVariableIsOnHeap[n] )
+		int c = *(asBYTE*)&bc[n];
+		switch( asBCInfo[c].type )
 		{
-			// Check if type has a different size than originally
-			for( asUINT s = 0; s < oldObjectSizes.GetLength(); s++ )
+		case asBCTYPE_wW_ARG:
+		case asBCTYPE_rW_DW_ARG:
+		case asBCTYPE_wW_QW_ARG:
+		case asBCTYPE_rW_ARG:
+		case asBCTYPE_wW_DW_ARG:
+		case asBCTYPE_wW_W_ARG:
+		case asBCTYPE_rW_QW_ARG:
+		case asBCTYPE_rW_W_DW_ARG:
 			{
-				if( oldObjectSizes[s].objType == func->objVariableTypes[n] &&
-					oldObjectSizes[s].oldSize != func->objVariableTypes[n]->GetSize() )
-				{
-					// How much needs to be adjusted? 
-					int newSize = func->objVariableTypes[n]->GetSize();
-					newSize = newSize < 4 ? 1 : newSize/4;
-					int oldSize = oldObjectSizes[s].oldSize;
-					oldSize = oldSize < 4 ? 1 : oldSize/4;
-
-					int adjust = newSize - oldSize;
-					if( adjust != 0 )
-					{
-						adjustments.PushLast(func->objVariablePos[n]);
-						adjustments.PushLast(adjust);
-					}
-				}
+				asBC_SWORDARG0(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG0(&bc[n]));
 			}
-		}
-	}
+			break;
 
-	asCArray<int> adjustByPos(func->stackNeeded);
-	if( adjustments.GetLength() )
-	{
-		adjustByPos.SetLength(func->stackNeeded);
-		memset(adjustByPos.AddressOf(), 0, adjustByPos.GetLength()*sizeof(int));
+		case asBCTYPE_wW_rW_ARG:
+		case asBCTYPE_wW_rW_DW_ARG:
+		case asBCTYPE_rW_rW_ARG:
+			{
+				asBC_SWORDARG0(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG0(&bc[n]));
+				asBC_SWORDARG1(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG1(&bc[n]));
+			}
+			break;
 
-		// Build look-up table with the adjustments for each stack position
-		for( n = 0; n < adjustments.GetLength(); n+=2 )
-		{
-			int pos    = adjustments[n];
-			int adjust = adjustments[n+1];
+		case asBCTYPE_wW_rW_rW_ARG:
+			{
+				asBC_SWORDARG0(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG0(&bc[n]));
+				asBC_SWORDARG1(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG1(&bc[n]));
+				asBC_SWORDARG2(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG2(&bc[n]));
+			}
+			break;
 
-			for( asUINT i = pos; i < adjustByPos.GetLength(); i++ )
-				adjustByPos[i] += adjust;
+		default:
+			// The other types don't treat variables so won't be modified
+			break;
 		}
 
-		// Adjust all variable positions
-		asDWORD *bc = func->byteCode.AddressOf();
-		for( n = 0; n < func->byteCode.GetLength(); )
+		if( c == asBC_PUSH )
 		{
-			int c = *(asBYTE*)&bc[n];
-			switch( asBCInfo[c].type )
-			{
-			case asBCTYPE_wW_ARG:
-			case asBCTYPE_rW_DW_ARG:
-			case asBCTYPE_wW_QW_ARG:
-			case asBCTYPE_rW_ARG:
-			case asBCTYPE_wW_DW_ARG:
-			case asBCTYPE_wW_W_ARG:
-			case asBCTYPE_rW_QW_ARG:
-			case asBCTYPE_rW_W_DW_ARG:
-				{
-					short var = asBC_SWORDARG0(&bc[n]);
-					if( var >= (int)adjustByPos.GetLength() ) 
-						error = true;
-					else if( var >= 0 ) 
-						asBC_SWORDARG0(&bc[n]) += (short)adjustByPos[var];
-				}
-				break;
+			// TODO: Maybe the push instruction should be removed, and be kept in 
+			//       the asCScriptFunction as a property instead. CallScriptFunction 
+			//       can immediately reserve the space
 
-			case asBCTYPE_wW_rW_ARG:
-			case asBCTYPE_wW_rW_DW_ARG:
-			case asBCTYPE_rW_rW_ARG:
-				{
-					short var = asBC_SWORDARG0(&bc[n]);
-					if( var >= (int)adjustByPos.GetLength() ) 
-						error = true;
-					else if( var >= 0 ) 
-						asBC_SWORDARG0(&bc[n]) += (short)adjustByPos[var];
+			// PUSH is only used to reserve stack space for variables
+			asBC_SWORDARG0(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG0(&bc[n]));
+		}
 
-					var = asBC_SWORDARG1(&bc[n]);
-					if( var >= (int)adjustByPos.GetLength() ) 
-						error = true;
-					else if( var >= 0 ) 
-						asBC_SWORDARG1(&bc[n]) += (short)adjustByPos[var];
-				}
-				break;
+		n += asBCTypeSize[asBCInfo[c].type];
+	}
 
-			case asBCTYPE_wW_rW_rW_ARG:
-				{
-					short var = asBC_SWORDARG0(&bc[n]);
-					if( var >= (int)adjustByPos.GetLength() ) 
-						error = true;
-					else if( var >= 0 ) 
-						asBC_SWORDARG0(&bc[n]) += (short)adjustByPos[var];
+	// objVariablePos
+	for( n = 0; n < func->objVariablePos.GetLength(); n++ )
+	{
+		func->objVariablePos[n] = AdjustStackPosition(func->objVariablePos[n]);
+	}
 
-					var = asBC_SWORDARG1(&bc[n]);
-					if( var >= (int)adjustByPos.GetLength() ) 
-						error = true;
-					else if( var >= 0 ) 
-						asBC_SWORDARG1(&bc[n]) += (short)adjustByPos[var];
+	// objVariableInfo[x].variableOffset  // TODO: should be an index into the objVariablePos array
+	for( n = 0; n < func->objVariableInfo.GetLength(); n++ )
+	{
+		// The program position must be adjusted as it is stored in number of instructions
+		func->objVariableInfo[n].programPos = instructionNbrToPos[func->objVariableInfo[n].programPos];
 
-					var = asBC_SWORDARG2(&bc[n]);
-					if( var >= (int)adjustByPos.GetLength() ) 
-						error = true;
-					else if( var >= 0 ) 
-						asBC_SWORDARG2(&bc[n]) += (short)adjustByPos[var];
-				}
-				break;
+		func->objVariableInfo[n].variableOffset = AdjustStackPosition(func->objVariableInfo[n].variableOffset);
+	}
 
-			default:
-				// The other types don't treat variables so won't be modified
-				break;
-			}
+	// variables[x].stackOffset
+	// TODO: The variables should also be loaded and adjusted
+/*
+	for( n = 0; n < func->variables.GetLength(); n++ )
+	{
+		func->variables[n]->stackOffset = AdjustStackPosition(func->variables[n]->stackOffset);
+	}
+*/
 
-			if( c == asBC_PUSH )
-			{
-				// TODO: Maybe the push instruction should be removed, and be kept in 
-				//       the asCScriptFunction as a property instead. CallScriptFunction 
-				//       can immediately reserve the space
+	// The program position (every even number) needs to be adjusted
+	// for the line numbers to be in number of dwords instead of number of instructions 
+	for( n = 0; n < func->lineNumbers.GetLength(); n += 2 )
+	{
+		func->lineNumbers[n] = instructionNbrToPos[func->lineNumbers[n]];
+	}
 
-				// PUSH is only used to reserve stack space for variables
-				asBC_WORDARG0(&bc[n]) += (asWORD)adjustByPos[adjustByPos.GetLength()-1];
-			}
 
-			n += asBCTypeSize[asBCInfo[c].type];
-		}
+	// The stack needed by the function will be adjusted by the highest variable shift
+	// TODO: bytecode: When bytecode is adjusted for 32/64bit it is necessary to adjust 
+	//                 also for pointers pushed on the stack as function arguments
+	func->stackNeeded = AdjustStackPosition(func->stackNeeded);
+}
 
-		// objVariablePos
-		for( n = 0; n < func->objVariablePos.GetLength(); n++ )
+void asCReader::CalculateAdjustmentByPos(asCScriptFunction *func)
+{
+	// Adjust the offset of all negative variables (parameters) as  
+	// all pointers have been stored as having a size of 1 dword
+	asUINT n;
+	asCArray<int> adjustments;
+	asUINT offset = 0;
+	if( func->objectType )
+	{
+		adjustments.PushLast(offset);
+		adjustments.PushLast(1-AS_PTR_SIZE);
+		offset += 1;
+	}
+	if( func->DoesReturnOnStack() )
+	{
+		adjustments.PushLast(offset);
+		adjustments.PushLast(1-AS_PTR_SIZE);
+		offset += 1;
+	}
+	for( n = 0; n < func->parameterTypes.GetLength(); n++ )
+	{
+		if( func->parameterTypes[n].GetObjectType() ||
+			func->parameterTypes[n].IsReference() )
 		{
-			if( func->objVariablePos[n] >= (int)adjustByPos.GetLength() )
-				error = true;
-			else if( func->objVariablePos[n] >= 0 )
-				func->objVariablePos[n] += adjustByPos[func->objVariablePos[n]];
+			adjustments.PushLast(offset);
+			adjustments.PushLast(1-AS_PTR_SIZE);
+			offset += 1;
 		}
-
-		// objVariableInfo[x].variableOffset  // TODO: should be an index into the objVariablePos array
-		for( n = 0; n < func->objVariableInfo.GetLength(); n++ )
+		else
 		{
-			if( func->objVariableInfo[n].variableOffset >= (int)adjustByPos.GetLength() )
-				error = true;
-			else if( func->objVariableInfo[n].variableOffset >= 0 )
-				func->objVariableInfo[n].variableOffset += adjustByPos[func->objVariableInfo[n].variableOffset];
+			asASSERT( func->parameterTypes[n].IsPrimitive() );
+			offset += func->parameterTypes[n].GetSizeOnStackDWords();
 		}
+	}
 
-		// variables[x].stackOffset
-		for( n = 0; n < func->variables.GetLength(); n++ )
+	// Build look-up table with the adjustments for each stack position
+	adjustNegativeStackByPos.SetLength(offset);
+	memset(adjustNegativeStackByPos.AddressOf(), 0, adjustNegativeStackByPos.GetLength()*sizeof(int));
+	for( n = 0; n < adjustments.GetLength(); n+=2 )
+	{
+		int pos    = adjustments[n];
+		int adjust = adjustments[n+1];
+
+		for( asUINT i = pos+1; i < adjustNegativeStackByPos.GetLength(); i++ )
+			adjustNegativeStackByPos[i] += adjust;
+	}
+
+	// The bytecode has been stored as if all object variables take up only 1 dword. 
+	// It is necessary to adjust to the size according to the current platform.
+	adjustments.SetLength(0);
+	for( n = 0; n < func->objVariableTypes.GetLength(); n++ )
+	{
+		if( func->objVariableTypes[n] )
 		{
-			if( func->variables[n]->stackOffset >= (int)adjustByPos.GetLength() )
-				error = true;
-			else if( func->variables[n]->stackOffset >= 0 )
-				func->variables[n]->stackOffset += adjustByPos[func->variables[n]->stackOffset];
+			// Determine the size the variable currently occupies on the stack
+			int size = AS_PTR_SIZE;
+			if( (func->objVariableTypes[n]->GetFlags() & asOBJ_VALUE) &&
+				!func->objVariableIsOnHeap[n] )
+			{
+				size = func->objVariableTypes[n]->GetSize();
+				if( size < 4 ) 
+					size = 1; 
+				else 
+					size /= 4;
+			}
+
+			// Check if type has a different size than stored
+			if( size > 1 )
+			{
+				adjustments.PushLast(func->objVariablePos[n]);
+				adjustments.PushLast(size-1);
+			}
 		}
+	}
 
-		// The stack needed by the function will be adjusted by the highest variable shift
-		// TODO: bytecode: When bytecode is adjusted for 32/64bit it is necessary to adjust 
-		//                 also for pointers pushed on the stack as function arguments
-		func->stackNeeded += adjustByPos[adjustByPos.GetLength()-1];
+	// Count position 0 too
+	adjustByPos.SetLength(func->stackNeeded+1);
+	memset(adjustByPos.AddressOf(), 0, adjustByPos.GetLength()*sizeof(int));
+
+	// Build look-up table with the adjustments for each stack position
+	for( n = 0; n < adjustments.GetLength(); n+=2 )
+	{
+		int pos    = adjustments[n];
+		int adjust = adjustments[n+1];
+
+		for( asUINT i = pos; i < adjustByPos.GetLength(); i++ )
+			adjustByPos[i] += adjust;
 	}
 }
 
+int asCReader::AdjustStackPosition(int pos)
+{
+	if( pos >= (int)adjustByPos.GetLength() ) 
+		error = true;
+	else if( pos >= 0 ) 
+		pos += (short)adjustByPos[pos];
+	else if( -pos >= (int)adjustNegativeStackByPos.GetLength() )
+		error = true;
+	else
+		pos += (short)adjustNegativeStackByPos[-pos];
+
+	return pos;
+}
+
 int asCReader::FindTypeId(int idx)
 {
 	if( idx >= 0 && idx < (int)usedTypeIds.GetLength() )
@@ -2096,27 +2157,10 @@ int asCWriter::Write()
 	}
 
 	// usedTypes[]
-	asUINT numValueTypes = 0;
 	count = (asUINT)usedTypes.GetLength();
 	WriteEncodedUInt(count);
 	for( i = 0; i < count; ++i )
-	{
-		if( usedTypes[i]->flags & asOBJ_VALUE )
-			numValueTypes++;
-
 		WriteObjectType(usedTypes[i]);
-	}
-
-	// Write the size of value types so the code can be adjusted if they are not the same when reloading the code
-	WriteEncodedUInt(numValueTypes);
-	for( i = 0; i < count; i++ )
-	{
-		if( usedTypes[i]->flags & asOBJ_VALUE )
-		{
-			WriteEncodedUInt(i);
-			WriteEncodedUInt(usedTypes[i]->GetSize());
-		}
-	}
 
 	// usedTypeIds[]
 	WriteUsedTypeIds();
@@ -2252,33 +2296,46 @@ void asCWriter::WriteFunction(asCScriptFunction* func)
 
 	if( func->funcType == asFUNC_SCRIPT )
 	{
-		count = (asUINT)func->byteCode.GetLength();
-		WriteEncodedUInt(count);
-		WriteByteCode(func->byteCode.AddressOf(), count);
+		// Calculate the adjustment by position lookup table
+		CalculateAdjustmentByPos(func);
+
+		WriteByteCode(func);
 
 		count = (asUINT)func->objVariablePos.GetLength();
 		WriteEncodedUInt(count);
 		for( i = 0; i < count; ++i )
 		{
 			WriteObjectType(func->objVariableTypes[i]);
-			WriteEncodedUInt(func->objVariablePos[i]);
+			WriteEncodedUInt(AdjustStackPosition(func->objVariablePos[i]));
 			WRITE_NUM(func->objVariableIsOnHeap[i]);
 		}
 
-		WriteEncodedUInt(func->stackNeeded);
+		// The stack needed by the function will be adjusted by the highest variable shift
+		// TODO: bytecode: When bytecode is adjusted for 32/64bit it is necessary to adjust 
+		//                 also for pointers pushed on the stack as function arguments.
+		//                 Perhaps it is easier to recalculate the stack needed at loadtime
+		WriteEncodedUInt(AdjustStackPosition(func->stackNeeded));
 
 		WriteEncodedUInt((asUINT)func->objVariableInfo.GetLength());
 		for( i = 0; i < func->objVariableInfo.GetLength(); ++i )
 		{
-			WriteEncodedUInt(func->objVariableInfo[i].programPos);
-			WriteEncodedUInt(func->objVariableInfo[i].variableOffset); // TODO: should be int
+			// The program position must be adjusted to be in number of instructions
+			WriteEncodedUInt(bytecodeNbrByPos[func->objVariableInfo[i].programPos]);
+			WriteEncodedUInt(AdjustStackPosition(func->objVariableInfo[i].variableOffset)); // TODO: should be int
 			WriteEncodedUInt(func->objVariableInfo[i].option);
 		}
 
+		// The program position (every even number) needs to be adjusted
+		// to be in number of instructions instead of DWORD offset
 		asUINT length = (asUINT)func->lineNumbers.GetLength();
 		WriteEncodedUInt(length);
 		for( i = 0; i < length; ++i )
-			WriteEncodedUInt(func->lineNumbers[i]);
+		{
+			if( (i & 1) == 0 )
+				WriteEncodedUInt(bytecodeNbrByPos[func->lineNumbers[i]]);
+			else
+				WriteEncodedUInt(func->lineNumbers[i]);
+		}
 
 		WRITE_NUM(func->isShared);
 
@@ -2307,8 +2364,21 @@ void asCWriter::WriteObjectTypeDeclaration(asCObjectType *ot, int phase)
 		WriteString(&ot->name);
 		// flags
 		WRITE_NUM(ot->flags);
+
 		// size
-		WriteEncodedUInt(ot->size);
+		if( (ot->flags & asOBJ_SCRIPT_OBJECT) & ot->size )
+		{
+			// The size for script objects may vary from platform to platform so 
+			// only store 1 to diferentiate from interfaces that have size 0.
+			WriteEncodedUInt(1); 
+		}
+		else
+		{
+			// Enums, typedefs, and interfaces have fixed sizes independently
+			// of platform so it is safe to serialize the size directly.
+			WriteEncodedUInt(ot->size);
+		}
+
 		// namespace
 		WriteString(&ot->nameSpace);
 	}
@@ -2596,8 +2666,141 @@ void asCWriter::WriteObjectType(asCObjectType* ot)
 	}
 }
 
-void asCWriter::WriteByteCode(asDWORD *bc, int length)
+void asCWriter::CalculateAdjustmentByPos(asCScriptFunction *func)
 {
+	// Adjust the offset of all negative variables (parameters) so all pointers will have a size of 1 dword
+	asUINT n;
+	asCArray<int> adjustments;
+	asUINT offset = 0;
+	if( func->objectType )
+	{
+		adjustments.PushLast(offset);
+		adjustments.PushLast(1-AS_PTR_SIZE);
+		offset += AS_PTR_SIZE;
+	}
+	if( func->DoesReturnOnStack() )
+	{
+		adjustments.PushLast(offset);
+		adjustments.PushLast(1-AS_PTR_SIZE);
+		offset += AS_PTR_SIZE;
+	}
+	for( n = 0; n < func->parameterTypes.GetLength(); n++ )
+	{
+		if( func->parameterTypes[n].GetObjectType() ||
+			func->parameterTypes[n].IsReference() )
+		{
+			adjustments.PushLast(offset);
+			adjustments.PushLast(1-AS_PTR_SIZE);
+			offset += AS_PTR_SIZE;
+		}
+		else
+		{
+			asASSERT( func->parameterTypes[n].IsPrimitive() );
+			offset += func->parameterTypes[n].GetSizeOnStackDWords();
+		}
+	}
+
+	// Build look-up table with the adjustments for each stack position
+	adjustNegativeStackByPos.SetLength(offset);
+	memset(adjustNegativeStackByPos.AddressOf(), 0, adjustNegativeStackByPos.GetLength()*sizeof(int));
+	for( n = 0; n < adjustments.GetLength(); n+=2 )
+	{
+		int pos    = adjustments[n];
+		int adjust = adjustments[n+1];
+
+		for( asUINT i = pos+1; i < adjustNegativeStackByPos.GetLength(); i++ )
+			adjustNegativeStackByPos[i] += adjust;
+	}
+
+	// Adjust the offset of all positive variables so that all object types and handles have a size of 1 dword
+	// This is similar to how the adjustment is done in the asCReader::TranslateFunction, only the reverse
+	adjustments.SetLength(0);
+	for( n = 0; n < func->objVariableTypes.GetLength(); n++ )
+	{
+		if( func->objVariableTypes[n] )
+		{
+			// Determine the size the variable currently occupies on the stack
+			int size = AS_PTR_SIZE;
+			if( (func->objVariableTypes[n]->GetFlags() & asOBJ_VALUE) &&
+				!func->objVariableIsOnHeap[n] )
+			{
+				size = func->objVariableTypes[n]->GetSize();
+				if( size < 4 ) 
+					size = 1; 
+				else 
+					size /= 4;
+			}
+
+			// If larger than 1 dword, adjust the offsets accordingly
+			if( size > 1 )
+			{
+				// How much needs to be adjusted?
+				adjustments.PushLast(func->objVariablePos[n]);
+				adjustments.PushLast(-(size-1));
+			}
+		}
+	}
+
+	// Build look-up table with the adjustments for each stack position
+	adjustStackByPos.SetLength(func->stackNeeded);
+	memset(adjustStackByPos.AddressOf(), 0, adjustStackByPos.GetLength()*sizeof(int));
+	for( n = 0; n < adjustments.GetLength(); n+=2 )
+	{
+		int pos    = adjustments[n];
+		int adjust = adjustments[n+1];
+
+		for( asUINT i = pos; i < adjustStackByPos.GetLength(); i++ )
+			adjustStackByPos[i] += adjust;
+	}
+
+	// Compute the sequence number of each bytecode instruction in order to update the jump offsets
+	asUINT length = func->byteCode.GetLength();
+	asDWORD *bc = func->byteCode.AddressOf();
+	bytecodeNbrByPos.SetLength(length);
+	asUINT num;
+	for( offset = 0, num = 0; offset < length; )
+	{
+		bytecodeNbrByPos[offset] = num;
+		offset += asBCTypeSize[asBCInfo[*(asBYTE*)(bc+offset)].type];
+		num++;
+	}
+	// The last instruction is always a BC_RET. This make it possible to query 
+	// the number of instructions by checking the last entry in bytecodeNbrByPos
+	asASSERT(*(asBYTE*)(bc+length-1) == asBC_RET);
+}
+
+int asCWriter::AdjustStackPosition(int pos)
+{
+	if( pos >= (int)adjustStackByPos.GetLength() )
+	{
+		// This happens for example if the function only have temporary variables
+		// The adjustByPos can also be empty if the function doesn't have any variables at all, but receive a handle by parameter
+		if( adjustStackByPos.GetLength() > 0 )
+			pos += adjustStackByPos[adjustStackByPos.GetLength()-1];
+	}
+	else if( pos >= 0 )
+		pos += adjustStackByPos[pos];
+	else
+	{
+		asASSERT( -pos < (int)adjustNegativeStackByPos.GetLength() );
+		pos -= (short)adjustNegativeStackByPos[-pos];
+	}
+
+	return pos;
+}
+
+
+void asCWriter::WriteByteCode(asCScriptFunction *func)
+{
+	asDWORD *bc   = func->byteCode.AddressOf();
+	asUINT length = func->byteCode.GetLength();
+
+	// The length cannot be stored, because it is platform dependent, 
+	// instead we store the number of instructions
+	asUINT count = bytecodeNbrByPos[bytecodeNbrByPos.GetLength()-1] + 1;
+	WriteEncodedUInt(count);
+
+	asDWORD *startBC = bc;
 	while( length )
 	{
 		asDWORD tmp[4]; // The biggest instructions take up 4 DWORDs
@@ -2606,6 +2809,11 @@ void asCWriter::WriteByteCode(asDWORD *bc, int length)
 		// Copy the instruction to a temp buffer so we can work on it before saving
 		memcpy(tmp, bc, asBCTypeSize[asBCInfo[c].type]*sizeof(asDWORD));
 
+		// TODO: bytecode: Must update the GETOBJ, GETREF, etc offsets as they too depend on pointer size
+		//                 The easiest way of doing this is probably by finding the actual function that is 
+		//                 being called after these instructions, and then use that to determine the size of 
+		//                 the arguments pushed on the stack.
+		
 		if( c == asBC_ALLOC ) // PTR_DW_ARG
 		{
 			// Translate the object type 
@@ -2629,7 +2837,7 @@ void asCWriter::WriteByteCode(asDWORD *bc, int length)
 			*(asPWORD*)(tmp+1) = 0;
 		}
 		else if( c == asBC_TYPEID || // DW_ARG
-			     c == asBC_Cast )   // DW_ARG
+			     c == asBC_Cast )    // DW_ARG
 		{
 			// Translate type ids into indices
 			*(int*)(tmp+1) = FindTypeIdIdx(*(int*)(tmp+1));
@@ -2656,6 +2864,9 @@ void asCWriter::WriteByteCode(asDWORD *bc, int length)
 		{
 			// Translate type ids into indices
 			*(int*)(tmp+1) = FindTypeIdIdx(*(int*)(tmp+1));
+
+			// Update the WORDARG0 to 0, as this will be recalculated on the target platform
+			asBC_WORDARG0(tmp) = 0;
 		}
 		else if( c == asBC_CALL ||     // DW_ARG
 				 c == asBC_CALLINTF || // DW_ARG
@@ -2667,7 +2878,7 @@ void asCWriter::WriteByteCode(asDWORD *bc, int length)
 		else if( c == asBC_FuncPtr ) // PTR_ARG
 		{
 			// Translate the function pointer
-			*(asPTRWORD*)(tmp+1) = FindFunctionIndex(*(asCScriptFunction**)(tmp+1));
+			*(asPWORD*)(tmp+1) = FindFunctionIndex(*(asCScriptFunction**)(tmp+1));
 		}
 		else if( c == asBC_STR ) // W_ARG
 		{
@@ -2699,7 +2910,74 @@ void asCWriter::WriteByteCode(asDWORD *bc, int length)
 			// Translate global variable pointers into indices
 			*(int*)(tmp+1) = FindGlobalPropPtrIndex(*(void**)(tmp+1));
 		}
+		else if( c == asBC_JMP ||	// DW_ARG
+			     c == asBC_JZ ||
+				 c == asBC_JNZ ||
+				 c == asBC_JS ||
+				 c == asBC_JNS ||
+				 c == asBC_JP ||
+				 c == asBC_JNP ) // The JMPP instruction doesn't need modification
+		{
+			// Get the DWORD offset from arg
+			int offset = *(int*)(tmp+1);
+
+			// Determine instruction number for next instruction and destination
+			int bcSeqNum = bytecodeNbrByPos[bc - startBC] + 1;
+			asDWORD *targetBC = bc + 2 + offset;
+			int targetBcSeqNum = bytecodeNbrByPos[targetBC - startBC];
+
+			// Set the offset in number of instructions
+			*(int*)(tmp+1) = targetBcSeqNum - bcSeqNum;
+		}
+
+		// Adjust the variable offsets
+		switch( asBCInfo[c].type )
+		{
+		case asBCTYPE_wW_ARG:
+		case asBCTYPE_rW_DW_ARG:
+		case asBCTYPE_wW_QW_ARG:
+		case asBCTYPE_rW_ARG:
+		case asBCTYPE_wW_DW_ARG:
+		case asBCTYPE_wW_W_ARG:
+		case asBCTYPE_rW_QW_ARG:
+		case asBCTYPE_rW_W_DW_ARG:
+			{
+				asBC_SWORDARG0(tmp) = (short)AdjustStackPosition(asBC_SWORDARG0(tmp));
+			}
+			break;
+
+		case asBCTYPE_wW_rW_ARG:
+		case asBCTYPE_wW_rW_DW_ARG:
+		case asBCTYPE_rW_rW_ARG:
+			{
+				asBC_SWORDARG0(tmp) = (short)AdjustStackPosition(asBC_SWORDARG0(tmp));
+				asBC_SWORDARG1(tmp) = (short)AdjustStackPosition(asBC_SWORDARG1(tmp));
+			}
+			break;
+
+		case asBCTYPE_wW_rW_rW_ARG:
+			{
+				asBC_SWORDARG0(tmp) = (short)AdjustStackPosition(asBC_SWORDARG0(tmp));
+				asBC_SWORDARG1(tmp) = (short)AdjustStackPosition(asBC_SWORDARG1(tmp));
+				asBC_SWORDARG2(tmp) = (short)AdjustStackPosition(asBC_SWORDARG2(tmp));
+			}
+			break;
+
+		default:
+			// The other types don't treat variables so won't be modified
+			break;
+		}
 
+		if( c == asBC_PUSH )
+		{
+			// TODO: Maybe the push instruction should be removed, and be kept in 
+			//       the asCScriptFunction as a property instead. CallScriptFunction 
+			//       can immediately reserve the space
+
+			// PUSH is only used to reserve stack space for variables
+			asBC_WORDARG0(tmp) = (asWORD)AdjustStackPosition(asBC_WORDARG0(tmp));
+		}
+				 
 		// Now store the instruction in the smallest possible way
 		switch( asBCInfo[c].type )
 		{
@@ -2913,7 +3191,7 @@ void asCWriter::WriteUsedGlobalProps()
 
 	for( int n = 0; n < c; n++ )
 	{
-		size_t *p = (size_t*)usedGlobalProperties[n];
+		asPWORD *p = (asPWORD*)usedGlobalProperties[n];
 		
 		// First search for the global in the module
 		char moduleProp = 0;
@@ -2972,7 +3250,7 @@ void asCWriter::WriteUsedObjectProps()
 				break;
 			}
 		}
-	}	
+	}
 }
 
 int asCWriter::FindObjectPropIndex(short offset, int typeId)

+ 16 - 11
ThirdParty/AngelScript/source/as_restore.h

@@ -67,7 +67,7 @@ protected:
 	void               ReadDataType(asCDataType *dt);
 	asCObjectType *    ReadObjectType();
 	void               ReadObjectTypeDeclaration(asCObjectType *ot, int phase);
-	void               ReadByteCode(asDWORD *bc, int length);
+	void               ReadByteCode(asCScriptFunction *func);
 	asUINT             ReadEncodedUInt();
 
 	void ReadUsedTypeIds();
@@ -83,6 +83,8 @@ protected:
 
 	// After loading, each function needs to be translated to update pointers, function ids, etc
 	void TranslateFunction(asCScriptFunction *func);
+	void CalculateAdjustmentByPos(asCScriptFunction *func);
+	int  AdjustStackPosition(int pos);
 
 	// Temporary storage for persisting variable data
 	asCArray<int>                usedTypeIds;
@@ -95,6 +97,9 @@ protected:
 	asCArray<asCDataType>         savedDataTypes;
 	asCArray<asCString>           savedStrings;
 
+	asCArray<int>                 adjustByPos;
+	asCArray<int>                 adjustNegativeStackByPos;
+
 	struct SObjProp
 	{
 		asCObjectType *objType;
@@ -102,14 +107,7 @@ protected:
 	};
 	asCArray<SObjProp> usedObjectProperties;
 
-	struct SObjChangeSize
-	{
-		asCObjectType *objType;
-		asUINT         oldSize;
-	};
-	asCArray<SObjChangeSize> oldObjectSizes;
-
-	asCMap<void*,bool> existingShared;
+	asCMap<void*,bool>              existingShared;
 	asCMap<asCScriptFunction*,bool> dontTranslate;
 };
 
@@ -137,7 +135,7 @@ protected:
 	void WriteDataType(const asCDataType *dt);
 	void WriteObjectType(asCObjectType *ot);
 	void WriteObjectTypeDeclaration(asCObjectType *ot, int phase);
-	void WriteByteCode(asDWORD *bc, int length);
+	void WriteByteCode(asCScriptFunction *func);
 	void WriteEncodedUInt(asUINT i);
 
 	// Helper functions for storing variable data
@@ -148,6 +146,10 @@ protected:
 	int FindStringConstantIndex(int id);
 	int FindObjectPropIndex(short offset, int typeId);
 
+	void CalculateAdjustmentByPos(asCScriptFunction *func);
+	int  AdjustStackPosition(int pos);
+	int  AdjustProgramPosition(int pos);
+
 	// Intermediate data used for storing that which isn't constant, function id's, pointers, etc
 	void WriteUsedTypeIds();
 	void WriteUsedFunctions();
@@ -167,6 +169,9 @@ protected:
 	asCArray<asCDataType>         savedDataTypes;
 	asCArray<asCString>           savedStrings;
 	asCMap<asCStringPointer, int> stringToIdMap;
+	asCArray<int>                 adjustStackByPos;
+	asCArray<int>                 adjustNegativeStackByPos;
+	asCArray<int>                 bytecodeNbrByPos;
 
 	struct SObjProp
 	{
@@ -180,4 +185,4 @@ protected:
 
 END_AS_NAMESPACE
 
-#endif //AS_RESTORE_H
+#endif // AS_RESTORE_H

+ 214 - 121
ThirdParty/AngelScript/source/as_scriptengine.cpp

@@ -51,6 +51,7 @@
 #include "as_generic.h"
 #include "as_scriptobject.h"
 #include "as_compiler.h"
+#include "as_bytecode.h"
 
 BEGIN_AS_NAMESPACE
 
@@ -206,10 +207,13 @@ AS_API asIScriptEngine *asCreateScriptEngine(asDWORD version)
 	// Verify endianess
 #ifdef AS_BIG_ENDIAN
 	asASSERT( *(asDWORD*)"\x00\x01\x02\x03" == 0x00010203 );
-	asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == I64(0x0001020304050607) );
+	asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == ((asQWORD(0x00010203)<<32)|asQWORD(0x04050607)) );
 #else
 	asASSERT( *(asDWORD*)"\x00\x01\x02\x03" == 0x03020100 );
-	asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == I64(0x0706050403020100) );
+	// C++ didn't have a standard way of declaring 64bit literal constants until C++11, so
+	// I'm forced to do it like this to avoid compilers warnings when compiling with the full
+	// C++ compliance.
+	asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == ((asQWORD(0x07060504)<<32)|asQWORD(0x03020100)) );
 #endif
 
 	return asNEW(asCScriptEngine)();
@@ -448,7 +452,8 @@ asCScriptEngine::asCScriptEngine()
 	scriptFunctions.PushLast(0);
 
 	// Make sure typeId for the built-in primitives are defined according to asETypeIdFlags
-	int id;
+	int id = 0;
+	UNUSED_VAR(id); // It is only used in debug mode
 	id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttVoid,   false)); asASSERT( id == asTYPEID_VOID   );
 	id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttBool,   false)); asASSERT( id == asTYPEID_BOOL   );
 	id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttInt8,   false)); asASSERT( id == asTYPEID_INT8   );
@@ -691,6 +696,38 @@ int asCScriptEngine::Release() const
 	return r;
 }
 
+// interface
+int asCScriptEngine::SetDefaultNamespace(const char *nameSpace)
+{
+	if( nameSpace == 0 )
+		return ConfigError(asINVALID_ARG, "SetDefaultNamespace", nameSpace, 0);
+
+	defaultNamespace = nameSpace;
+	if( defaultNamespace != "" )
+	{
+		// Make sure the namespace is composed of alternating identifier and ::
+		size_t pos = 0;
+		bool expectIdentifier = true;
+		size_t len;
+		eTokenType t = ttIdentifier;
+
+		for( ; pos < defaultNamespace.GetLength(); pos += len)
+		{
+			t = tok.GetToken(defaultNamespace.AddressOf() + pos, defaultNamespace.GetLength() - pos, &len);
+			if( (expectIdentifier && t != ttIdentifier) || (!expectIdentifier && t != ttScope) )
+				return ConfigError(asINVALID_DECLARATION, "SetDefaultNamespace", nameSpace, 0);
+
+			expectIdentifier = !expectIdentifier;
+		}
+
+		// If the namespace ends with :: then strip it off
+		if( t == ttScope )
+			defaultNamespace.SetLength(defaultNamespace.GetLength()-2);
+	}
+
+	return 0;
+}
+
 // interface
 void *asCScriptEngine::SetUserData(void *data)
 {
@@ -830,6 +867,7 @@ int asCScriptEngine::DiscardModule(const char *module)
 	return 0;
 }
 
+// internal
 void asCScriptEngine::ClearUnusedTypes()
 {
 	// Build a list of all types to check for
@@ -938,6 +976,7 @@ void asCScriptEngine::ClearUnusedTypes()
 	}
 }
 
+// internal
 void asCScriptEngine::RemoveTypeAndRelatedFromList(asCArray<asCObjectType*> &types, asCObjectType *ot)
 {
 	// Remove the type from the list
@@ -1037,7 +1076,7 @@ int asCScriptEngine::GetMethodIdByDecl(const asCObjectType *ot, const char *decl
 }
 
 
-// Internal
+// internal
 asCString asCScriptEngine::GetFunctionDeclaration(int funcId)
 {
 	asCString str;
@@ -1048,6 +1087,7 @@ asCString asCScriptEngine::GetFunctionDeclaration(int funcId)
 	return str;
 }
 
+// internal
 asCScriptFunction *asCScriptEngine::GetScriptFunction(int funcId) const
 {
 	if( funcId < 0 || funcId >= (int)scriptFunctions.GetLength() )
@@ -1057,7 +1097,7 @@ asCScriptFunction *asCScriptEngine::GetScriptFunction(int funcId) const
 }
 
 
-
+// interface
 asIScriptContext *asCScriptEngine::CreateContext()
 {
 	asIScriptContext *ctx = 0;
@@ -1065,6 +1105,7 @@ asIScriptContext *asCScriptEngine::CreateContext()
 	return ctx;
 }
 
+// internal
 int asCScriptEngine::CreateContext(asIScriptContext **context, bool isInternal)
 {
 	*context = asNEW(asCContext)(this, !isInternal);
@@ -1082,7 +1123,7 @@ int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declara
 	int r;
 	asCDataType dt;
 	asCBuilder bld(this, 0);
-	r = bld.ParseDataType(obj, &dt);
+	r = bld.ParseDataType(obj, &dt, defaultNamespace);
 	if( r < 0 )
 		return ConfigError(r, "RegisterObjectProperty", obj, declaration);
 
@@ -1114,6 +1155,7 @@ int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declara
 	return asSUCCESS;
 }
 
+// interface
 int asCScriptEngine::RegisterInterface(const char *name)
 {
 	if( name == 0 ) return ConfigError(asINVALID_NAME, "RegisterInterface", 0, 0);
@@ -1122,7 +1164,7 @@ int asCScriptEngine::RegisterInterface(const char *name)
 	asUINT n;
 	for( n = 0; n < objectTypes.GetLength(); n++ )
 	{
-		if( objectTypes[n] && objectTypes[n]->name == name )
+		if( objectTypes[n] && objectTypes[n]->name == name && objectTypes[n]->nameSpace == defaultNamespace )
 			return asALREADY_REGISTERED;
 	}
 
@@ -1130,7 +1172,7 @@ int asCScriptEngine::RegisterInterface(const char *name)
 	asCDataType dt;
 	asCBuilder bld(this, 0);
 	bool oldMsgCallback = msgCallback; msgCallback = false;
-	int r = bld.ParseDataType(name, &dt);
+	int r = bld.ParseDataType(name, &dt, defaultNamespace);
 	msgCallback = oldMsgCallback;
 	if( r >= 0 ) return ConfigError(asERROR, "RegisterInterface", name, 0);
 
@@ -1153,6 +1195,7 @@ int asCScriptEngine::RegisterInterface(const char *name)
 	st->flags = asOBJ_REF | asOBJ_SCRIPT_OBJECT | asOBJ_SHARED;
 	st->size = 0; // Cannot be instanciated
 	st->name = name;
+	st->nameSpace = defaultNamespace;
 
 	// Use the default script class behaviours
 	st->beh.factory = 0;
@@ -1179,7 +1222,7 @@ int asCScriptEngine::RegisterInterfaceMethod(const char *intf, const char *decla
 
 	asCDataType dt;
 	asCBuilder bld(this, 0);
-	int r = bld.ParseDataType(intf, &dt);
+	int r = bld.ParseDataType(intf, &dt, defaultNamespace);
 	if( r < 0 )
 		return ConfigError(r, "RegisterInterfaceMethod", intf, declaration);
 
@@ -1239,22 +1282,24 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
 	if( flags & asOBJ_REF )
 	{
 		// Can optionally have the asOBJ_GC, asOBJ_NOHANDLE, asOBJ_SCOPED, or asOBJ_TEMPLATE flag set, but nothing else
-		if( flags & ~(asOBJ_REF | asOBJ_GC | asOBJ_NOHANDLE | asOBJ_SCOPED | asOBJ_TEMPLATE) )
+		if( flags & ~(asOBJ_REF | asOBJ_GC | asOBJ_NOHANDLE | asOBJ_SCOPED | asOBJ_TEMPLATE | asOBJ_NOCOUNT) )
 			return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
 
 		// flags are exclusive
-		if( (flags & asOBJ_GC) && (flags & (asOBJ_NOHANDLE|asOBJ_SCOPED)) )
+		if( (flags & asOBJ_GC) && (flags & (asOBJ_NOHANDLE|asOBJ_SCOPED|asOBJ_NOCOUNT)) )
 			return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
-		if( (flags & asOBJ_NOHANDLE) && (flags & (asOBJ_GC|asOBJ_SCOPED)) )
+		if( (flags & asOBJ_NOHANDLE) && (flags & (asOBJ_GC|asOBJ_SCOPED|asOBJ_NOCOUNT)) )
 			return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
-		if( (flags & asOBJ_SCOPED) && (flags & (asOBJ_GC|asOBJ_NOHANDLE)) )
+		if( (flags & asOBJ_SCOPED) && (flags & (asOBJ_GC|asOBJ_NOHANDLE|asOBJ_NOCOUNT)) )
+			return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
+		if( (flags & asOBJ_NOCOUNT) && (flags & (asOBJ_GC|asOBJ_NOHANDLE|asOBJ_SCOPED)) )
 			return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
 	}
 	else if( flags & asOBJ_VALUE )
 	{
 		// Cannot use reference flags
 		// TODO: template: Should be possible to register a value type as template type
-		if( flags & (asOBJ_REF | asOBJ_GC | asOBJ_SCOPED | asOBJ_TEMPLATE) )
+		if( flags & (asOBJ_REF | asOBJ_GC | asOBJ_SCOPED | asOBJ_TEMPLATE | asOBJ_NOCOUNT) )
 			return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
 
 		// flags are exclusive
@@ -1336,13 +1381,14 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
 		asUINT n;
 		for( n = 0; n < objectTypes.GetLength(); n++ )
 		{
-			if( objectTypes[n] && objectTypes[n]->name == typeName )
+			if( objectTypes[n] && objectTypes[n]->name == typeName && objectTypes[n]->nameSpace == defaultNamespace )
 				// This is not an irrepairable error, as it may just be that the same type is registered twice
 				return asALREADY_REGISTERED;
 		}
 
 		asCObjectType *type = asNEW(asCObjectType)(this);
 		type->name       = typeName;
+		type->nameSpace  = defaultNamespace;
 		type->size       = byteSize;
 		type->flags      = flags;
 		type->accessMask = defaultAccessMask;
@@ -1405,7 +1451,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
 		// Use builder to parse the datatype
 		asCDataType dt;
 		bool oldMsgCallback = msgCallback; msgCallback = false;
-		r = bld.ParseDataType(name, &dt);
+		r = bld.ParseDataType(name, &dt, defaultNamespace);
 		msgCallback = oldMsgCallback;
 
 		// If the builder fails, then the type name
@@ -1429,6 +1475,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
 			// Put the data type in the list
 			asCObjectType *type = asNEW(asCObjectType)(this);
 			type->name       = typeName;
+			type->nameSpace  = defaultNamespace;
 			type->size       = byteSize;
 			type->flags      = flags;
 			type->accessMask = defaultAccessMask;
@@ -1467,6 +1514,8 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
 			// Put the data type in the list
 			asCObjectType *type = asNEW(asCObjectType)(this);
 			type->name       = dt.GetObjectType()->name;
+			// The namespace will be the same as the original template type
+			type->nameSpace  = dt.GetObjectType()->nameSpace;
 			type->templateSubType = dt.GetSubType();
 			if( type->templateSubType.GetObjectType() ) type->templateSubType.GetObjectType()->AddRef();
 			type->size       = byteSize;
@@ -1497,7 +1546,7 @@ int asCScriptEngine::RegisterObjectBehaviour(const char *datatype, asEBehaviours
 	// Determine the object type
 	asCBuilder bld(this, 0);
 	asCDataType type;
-	int r = bld.ParseDataType(datatype, &type);
+	int r = bld.ParseDataType(datatype, &type, defaultNamespace);
 	if( r < 0 )
 		return ConfigError(r, "RegisterObjectBehaviour", datatype, decl);
 
@@ -1719,7 +1768,8 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as
 		// Must be a ref type and must not have asOBJ_NOHANDLE, nor asOBJ_SCOPED
 		if( !(func.objectType->flags & asOBJ_REF) ||
 			(func.objectType->flags & asOBJ_NOHANDLE) ||
-			(func.objectType->flags & asOBJ_SCOPED) )
+			(func.objectType->flags & asOBJ_SCOPED) ||
+			(func.objectType->flags & asOBJ_NOCOUNT) )
 		{
 			WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE);
 			return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl);
@@ -1741,7 +1791,9 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as
 	else if( behaviour == asBEHAVE_RELEASE )
 	{
 		// Must be a ref type and must not have asOBJ_NOHANDLE
-		if( !(func.objectType->flags & asOBJ_REF) || (func.objectType->flags & asOBJ_NOHANDLE) )
+		if( !(func.objectType->flags & asOBJ_REF) || 
+			(func.objectType->flags & asOBJ_NOHANDLE) || 
+			(func.objectType->flags & asOBJ_NOCOUNT) )
 		{
 			WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE);
 			return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl);
@@ -1963,8 +2015,7 @@ int asCScriptEngine::RegisterGlobalProperty(const char *declaration, void *point
 
 	int r;
 	asCBuilder bld(this, 0);
-	// TODO: namespace: Use proper namespace
-	if( (r = bld.VerifyProperty(0, declaration, name, type, "")) < 0 )
+	if( (r = bld.VerifyProperty(0, declaration, name, type, defaultNamespace)) < 0 )
 		return ConfigError(r, "RegisterGlobalProperty", declaration, 0);
 
 	// Don't allow registering references as global properties
@@ -1974,6 +2025,7 @@ int asCScriptEngine::RegisterGlobalProperty(const char *declaration, void *point
 	// Store the property info
 	asCGlobalProperty *prop = AllocateGlobalProperty();
 	prop->name        = name;
+	prop->nameSpace   = defaultNamespace;
 	prop->type        = type;
 	prop->accessMask  = defaultAccessMask;
 
@@ -2032,13 +2084,15 @@ asUINT asCScriptEngine::GetGlobalPropertyCount() const
 
 // interface
 // TODO: If the typeId ever encodes the const flag, then the isConst parameter should be removed
-int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, int *typeId, bool *isConst, const char **configGroup, void **pointer) const
+int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, const char **nameSpace, int *typeId, bool *isConst, const char **configGroup, void **pointer, asDWORD *accessMask) const
 {
 	if( index >= registeredGlobalProps.GetLength() )
 		return asINVALID_ARG;
 
 	if( name )
 		*name = registeredGlobalProps[index]->name.AddressOf();
+	if( nameSpace )
+		*nameSpace = registeredGlobalProps[index]->nameSpace.AddressOf();
 
 	if( configGroup )
 	{
@@ -2058,9 +2112,61 @@ int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, i
 	if( pointer )
 		*pointer = registeredGlobalProps[index]->GetRegisteredAddress();
 
+	if( accessMask )
+		*accessMask = registeredGlobalProps[index]->accessMask;
+
 	return asSUCCESS;
 }
 
+// interface
+int asCScriptEngine::GetGlobalPropertyIndexByName(const char *name) const
+{
+	// Find the global var id
+	int id = -1;
+	for( size_t n = 0; n < registeredGlobalProps.GetLength(); n++ )
+	{
+		if( registeredGlobalProps[n]->name == name &&
+			registeredGlobalProps[n]->nameSpace == defaultNamespace )
+		{
+			id = (int)n;
+			break;
+		}
+	}
+
+	if( id == -1 ) return asNO_GLOBAL_VAR;
+
+	return id;
+}
+
+// interface
+int asCScriptEngine::GetGlobalPropertyIndexByDecl(const char *decl) const
+{
+	// This const cast is OK. The builder won't modify the engine
+	asCBuilder bld(const_cast<asCScriptEngine*>(this), 0);
+
+	asCString name, ns;
+	asCDataType dt;
+	bld.ParseVariableDeclaration(decl, defaultNamespace, name, ns, dt);
+
+	// TODO: optimize: Improve linear search
+	// Search for a match
+	int id = -1;
+	for( size_t n = 0; n < registeredGlobalProps.GetLength(); ++n )
+	{
+		if( name == registeredGlobalProps[n]->name && 
+			dt   == registeredGlobalProps[n]->type && 
+			ns   == registeredGlobalProps[n]->nameSpace )
+		{
+			id = (int)n;
+			break;
+		}
+	}
+
+	if( id == -1 ) return asNO_GLOBAL_VAR;
+
+	return id;
+}
+
 // interface
 int asCScriptEngine::RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv)
 {
@@ -2070,7 +2176,7 @@ int asCScriptEngine::RegisterObjectMethod(const char *obj, const char *declarati
 	// Determine the object type
 	asCDataType dt;
 	asCBuilder bld(this, 0);
-	int r = bld.ParseDataType(obj, &dt);
+	int r = bld.ParseDataType(obj, &dt, defaultNamespace);
 	if( r < 0 )
 		return ConfigError(r, "RegisterObjectMethod", obj, declaration);
 
@@ -2221,9 +2327,11 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu
 		return ConfigError(asINVALID_DECLARATION, "RegisterGlobalFunction", declaration, 0);
 	}
 
+	// TODO: namespace: What if the declaration defined an explicit namespace?
+	func->nameSpace = defaultNamespace;
+
 	// Check name conflicts
-	// TODO: namespace: Allow application to specify namespace. Probably with a SetDefaultNamespace
-	r = bld.CheckNameConflict(func->name.AddressOf(), 0, 0, "");
+	r = bld.CheckNameConflict(func->name.AddressOf(), 0, 0, defaultNamespace);
 	if( r < 0 )
 	{
 		asDELETE(func,asCScriptFunction);
@@ -2393,7 +2501,8 @@ void asCScriptEngine::PrepareEngine()
 			}
 			// Verify that ref types have add ref and release behaviours
 			else if( (objectTypes[n]->flags & asOBJ_REF) &&
-				     !(objectTypes[n]->flags & asOBJ_NOHANDLE) )
+				     !(objectTypes[n]->flags & asOBJ_NOHANDLE) &&
+					 !(objectTypes[n]->flags & asOBJ_NOCOUNT) )
 			{
 				if( objectTypes[n]->beh.addref  == 0 ||
 					objectTypes[n]->beh.release == 0 )
@@ -2454,7 +2563,7 @@ int asCScriptEngine::RegisterDefaultArrayType(const char *type)
 {
 	asCBuilder bld(this, 0);
 	asCDataType dt;
-	int r = bld.ParseDataType(type, &dt);
+	int r = bld.ParseDataType(type, &dt, defaultNamespace);
 	if( r < 0 ) return r;
 
 	if( dt.GetObjectType() == 0 ||
@@ -2504,7 +2613,7 @@ int asCScriptEngine::RegisterStringFactory(const char *datatype, const asSFuncPt
 	asCBuilder bld(this, 0);
 
 	asCDataType dt;
-	r = bld.ParseDataType(datatype, &dt);
+	r = bld.ParseDataType(datatype, &dt, defaultNamespace, true);
 	if( r < 0 )
 	{
 		// Set as dummy before deleting
@@ -2862,9 +2971,25 @@ asCScriptFunction *asCScriptEngine::GenerateTemplateFactoryStub(asCObjectType *t
 
 	SetScriptFunction(func);
 
-	asCBuilder builder(this, 0);
-	asCCompiler compiler(this);
-	compiler.CompileTemplateFactoryStub(&builder, factoryId, ot, func);
+	// Generate the bytecode for the factory stub
+	func->byteCode.SetLength(asBCTypeSize[asBCInfo[asBC_OBJTYPE].type] + 
+	                         asBCTypeSize[asBCInfo[asBC_CALLSYS].type] +
+	                         asBCTypeSize[asBCInfo[asBC_RET].type]);
+	asDWORD *bc = func->byteCode.AddressOf();
+	*(asBYTE*)bc = asBC_OBJTYPE;
+	*(asPWORD*)(bc+1) = (asPWORD)ot;
+	bc += asBCTypeSize[asBCInfo[asBC_OBJTYPE].type];
+	*(asBYTE*)bc = asBC_CALLSYS;
+	*(asDWORD*)(bc+1) = factoryId;
+	bc += asBCTypeSize[asBCInfo[asBC_CALLSYS].type];
+	*(asBYTE*)bc = asBC_RET;
+	*(((asWORD*)bc)+1) = (asWORD)func->GetSpaceNeededForArguments();
+
+	func->AddReferences();
+	func->stackNeeded = AS_PTR_SIZE;
+
+	// Tell the virtual machine not to clean up the object on exception
+	func->dontCleanUpOnException = true;
 
 	return func;
 }
@@ -3011,7 +3136,7 @@ void asCScriptEngine::CallObjectMethod(void *obj, asSSystemFunctionInterface *i,
 		} p;
 		p.func = (void (*)())(i->func);
 		void (asCSimpleDummy::*f)() = p.mthd;
-		obj = (void*)(size_t(obj) + i->baseOffset);
+		obj = (void*)(asPWORD(obj) + i->baseOffset);
 		(((asCSimpleDummy*)obj)->*f)();
 	}
 	else
@@ -3078,7 +3203,7 @@ bool asCScriptEngine::CallObjectMethodRetBool(void *obj, int func)
 		} p;
 		p.func = (void (*)())(i->func);
 		bool (asCSimpleDummy::*f)() = (bool (asCSimpleDummy::*)())p.mthd;
-		obj = (void*)(size_t(obj) + i->baseOffset);
+		obj = (void*)(asPWORD(obj) + i->baseOffset);
 		return (((asCSimpleDummy*)obj)->*f)();
 	}
 	else
@@ -3146,7 +3271,7 @@ int asCScriptEngine::CallObjectMethodRetInt(void *obj, int func)
 		} p;
 		p.func = (void (*)())(i->func);
 		int (asCSimpleDummy::*f)() = (int (asCSimpleDummy::*)())p.mthd;
-		obj = (void*)(size_t(obj) + i->baseOffset);
+		obj = (void*)(asPWORD(obj) + i->baseOffset);
 		return (((asCSimpleDummy*)obj)->*f)();
 	}
 	else
@@ -3259,7 +3384,7 @@ void asCScriptEngine::CallObjectMethod(void *obj, void *param, asSSystemFunction
 		} p;
 		p.func = (void (*)())(i->func);
 		void (asCSimpleDummy::*f)(void *) = (void (asCSimpleDummy::*)(void *))(p.mthd);
-		obj = (void*)(size_t(obj) + i->baseOffset);
+		obj = (void*)(asPWORD(obj) + i->baseOffset);
 		(((asCSimpleDummy*)obj)->*f)(param);
 	}
 	else
@@ -3343,10 +3468,9 @@ void asCScriptEngine::CallFree(void *obj) const
 }
 
 // interface
-void asCScriptEngine::NotifyGarbageCollectorOfNewObject(void *obj, int typeId)
+void asCScriptEngine::NotifyGarbageCollectorOfNewObject(void *obj, asIObjectType *type)
 {
-	asCObjectType *objType = GetObjectTypeFromTypeId(typeId);
-	gc.AddScriptObjectToGC(obj, objType);
+	gc.AddScriptObjectToGC(obj, static_cast<asCObjectType*>(type));
 }
 
 // interface
@@ -3369,16 +3493,10 @@ void asCScriptEngine::GCEnumCallback(void *reference)
 
 
 // TODO: multithread: The mapTypeIdToDataType must be protected with critical sections in all functions that access it
-/// Urho3D: modified for type id caching
 int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
 {
 	if( dtIn.IsNullHandle() ) return 0;
 
-	/// Urho3D: check cached type id first
-	int typeId = dtIn.GetCachedTypeId();
-	if( typeId )
-		return typeId;
-
 	// Register the base form
 	asCDataType dt(dtIn);
 	if( dt.GetObjectType() )
@@ -3391,7 +3509,7 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
 	{
 		if( mapTypeIdToDataType.GetValue(cursor)->IsEqualExceptRefAndConst(dt) )
 		{
-			typeId = mapTypeIdToDataType.GetKey(cursor);
+			int typeId = mapTypeIdToDataType.GetKey(cursor);
 			if( dtIn.GetObjectType() && !(dtIn.GetObjectType()->flags & asOBJ_ASHANDLE) )
 			{
 				// The the ASHANDLE types behave like handles, but are really 
@@ -3402,8 +3520,6 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
 					typeId |= asTYPEID_HANDLETOCONST;
 			}
 
-			// Urho3D: cache the type id for next query
-			dtIn.SetCachedTypeId(typeId);
 			return typeId;
 		}
 
@@ -3413,12 +3529,12 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
 	// The type id doesn't exist, create it
 
 	// Setup the basic type id
-	typeId = typeIdSeqNbr++;
+	int typeId = typeIdSeqNbr++;
 	if( dt.GetObjectType() )
 	{
 		if( dt.GetObjectType()->flags & asOBJ_SCRIPT_OBJECT ) typeId |= asTYPEID_SCRIPTOBJECT;
 		else if( dt.GetObjectType()->flags & asOBJ_TEMPLATE ) typeId |= asTYPEID_TEMPLATE; 
-		else if( dt.GetObjectType()->flags & asOBJ_ENUM ); // TODO: Should we have a specific bit for this?
+		else if( dt.GetObjectType()->flags & asOBJ_ENUM ) {} // TODO: Should we have a specific bit for this?
 		else typeId |= asTYPEID_APPOBJECT;
 	}
 
@@ -3481,7 +3597,7 @@ int asCScriptEngine::GetTypeIdByDecl(const char *decl) const
 	asCDataType dt;
 	// This cast is ok, because we are not changing anything in the engine
 	asCBuilder bld(const_cast<asCScriptEngine*>(this), 0);
-	int r = bld.ParseDataType(decl, &dt);
+	int r = bld.ParseDataType(decl, &dt, defaultNamespace);
 	if( r < 0 )
 		return asINVALID_TYPE;
 
@@ -3489,13 +3605,13 @@ int asCScriptEngine::GetTypeIdByDecl(const char *decl) const
 }
 
 // interface
-const char *asCScriptEngine::GetTypeDeclaration(int typeId) const
+const char *asCScriptEngine::GetTypeDeclaration(int typeId, bool includeNamespace) const
 {
 	asCDataType dt = GetDataTypeFromTypeId(typeId);
 
 	asASSERT(threadManager);
 	asCString *tempString = &threadManager->GetLocalData()->string;
-	*tempString = dt.Format();
+	*tempString = dt.Format(includeNamespace);
 
 	return tempString->AddressOf();
 }
@@ -3648,21 +3764,7 @@ void asCScriptEngine::ReleaseScriptObject(void *obj, int typeId)
 
 	asCObjectType *objType = dt.GetObjectType();
 
-	if( objType->beh.release )
-	{
-		// Call the release behaviour
-		CallObjectMethod(obj, objType->beh.release);
-	}
-	// TODO: interface: shouldn't work on non reference types
-	else
-	{
-		// Call the destructor
-		if( objType->beh.destruct )
-			CallObjectMethod(obj, objType->beh.destruct);
-
-		// Then free the memory
-		CallFree(obj);
-	}
+	ReleaseScriptObject(obj, objType);
 }
 
 // interface
@@ -3672,14 +3774,19 @@ void asCScriptEngine::ReleaseScriptObject(void *obj, const asIObjectType *type)
 	if( obj == 0 ) return;
 	
 	const asCObjectType *objType = static_cast<const asCObjectType *>(type);
-	if( objType->beh.release )
+	if( objType->flags & asOBJ_REF )
 	{
-		// Call the release behaviour
-		CallObjectMethod(obj, objType->beh.release);
+		asASSERT( (objType->flags & asOBJ_NOCOUNT) || objType->beh.release );
+		if( objType->beh.release )
+		{
+			// Call the release behaviour
+			CallObjectMethod(obj, objType->beh.release);
+		}
 	}
-	// TODO: interface: shouldn't work on non reference types
 	else
 	{
+		// TODO: interface: shouldn't work on non reference types
+
 		// Call the destructor
 		if( objType->beh.destruct )
 			CallObjectMethod(obj, objType->beh.destruct);
@@ -3838,40 +3945,18 @@ asCConfigGroup *asCScriptEngine::FindConfigGroupForObjectType(const asCObjectTyp
 	return 0;
 }
 
-asCConfigGroup *asCScriptEngine::FindConfigGroupForFuncDef(asCScriptFunction *funcDef) const
+asCConfigGroup *asCScriptEngine::FindConfigGroupForFuncDef(const asCScriptFunction *funcDef) const
 {
 	for( asUINT n = 0; n < configGroups.GetLength(); n++ )
 	{
-		if( configGroups[n]->funcDefs.Exists(funcDef) )
+		asCScriptFunction *f = const_cast<asCScriptFunction*>(funcDef);
+		if( configGroups[n]->funcDefs.Exists(f) )
 			return configGroups[n];
 	}
 
 	return 0;
 }
 
-#ifdef AS_DEPRECATED
-// deprecated since 2011-10-04
-int asCScriptEngine::SetConfigGroupModuleAccess(const char *groupName, const char *module, bool hasAccess)
-{
-	asCConfigGroup *group = 0;
-
-	// Make sure the group name doesn't already exist
-	for( asUINT n = 0; n < configGroups.GetLength(); n++ )
-	{
-		if( configGroups[n]->groupName == groupName )
-		{
-			group = configGroups[n];
-			break;
-		}
-	}
-
-	if( group == 0 )
-		return asWRONG_CONFIG_GROUP;
-
-	return group->SetModuleAccess(module, hasAccess);
-}
-#endif
-
 // interface
 asDWORD asCScriptEngine::SetDefaultAccessMask(asDWORD defaultMask)
 {
@@ -4001,20 +4086,11 @@ asUINT asCScriptEngine::GetFuncdefCount() const
 }
 
 // interface
-asIScriptFunction *asCScriptEngine::GetFuncdefByIndex(asUINT index, const char **configGroup) const
+asIScriptFunction *asCScriptEngine::GetFuncdefByIndex(asUINT index) const
 {
 	if( index >= registeredFuncDefs.GetLength() )
 		return 0;
 
-	if( configGroup )
-	{
-		asCConfigGroup *group = FindConfigGroupForFuncDef(registeredFuncDefs[index]);
-		if( group )
-			*configGroup = group->groupName.AddressOf();
-		else
-			*configGroup = 0;
-	}
-
 	return registeredFuncDefs[index];
 }
 
@@ -4028,7 +4104,7 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl)
 	asUINT n;
 	for( n = 0; n < objectTypes.GetLength(); n++ )
 	{
-		if( objectTypes[n] && objectTypes[n]->name == type )
+		if( objectTypes[n] && objectTypes[n]->name == type && objectTypes[n]->nameSpace == defaultNamespace )
 			// Let the application recover from this error, for example if the same typedef is registered twice
 			return asALREADY_REGISTERED;
 	}
@@ -4070,7 +4146,6 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl)
 	if( token != ttIdentifier || strlen(type) != tokenLen )
 		return ConfigError(asINVALID_NAME, "RegisterTypedef", type, decl);
 
-	// TODO: namespace: Allow application to specify namespace. Probably with a SetDefaultNamespace
 	asCBuilder bld(this, 0);
 	int r = bld.CheckNameConflict(type, 0, 0, "");
 	if( r < 0 )
@@ -4101,7 +4176,7 @@ asUINT asCScriptEngine::GetTypedefCount() const
 }
 
 // interface
-const char *asCScriptEngine::GetTypedefByIndex(asUINT index, int *typeId, const char **configGroup) const
+const char *asCScriptEngine::GetTypedefByIndex(asUINT index, int *typeId, const char **nameSpace, const char **configGroup, asDWORD *accessMask) const
 {
 	if( index >= registeredTypeDefs.GetLength() )
 		return 0;
@@ -4118,6 +4193,12 @@ const char *asCScriptEngine::GetTypedefByIndex(asUINT index, int *typeId, const
 			*configGroup = 0;
 	}
 
+	if( accessMask )
+		*accessMask = registeredTypeDefs[index]->accessMask;
+
+	if( nameSpace )
+		*nameSpace = registeredTypeDefs[index]->nameSpace.AddressOf();
+
 	return registeredTypeDefs[index]->name.AddressOf();
 }
 
@@ -4131,14 +4212,14 @@ int asCScriptEngine::RegisterEnum(const char *name)
 	// Verify if the name has been registered as a type already
 	asUINT n;
 	for( n = 0; n < objectTypes.GetLength(); n++ )
-		if( objectTypes[n] && objectTypes[n]->name == name )
+		if( objectTypes[n] && objectTypes[n]->name == name && objectTypes[n]->nameSpace == defaultNamespace )
 			return asALREADY_REGISTERED;
 
 	// Use builder to parse the datatype
 	asCDataType dt;
 	asCBuilder bld(this, 0);
 	bool oldMsgCallback = msgCallback; msgCallback = false;
-	int r = bld.ParseDataType(name, &dt);
+	int r = bld.ParseDataType(name, &dt, defaultNamespace);
 	msgCallback = oldMsgCallback;
 	if( r >= 0 )
 		return ConfigError(asERROR, "RegisterEnum", name, 0);
@@ -4162,6 +4243,7 @@ int asCScriptEngine::RegisterEnum(const char *name)
 	st->flags = asOBJ_ENUM | asOBJ_SHARED;
 	st->size = 4;
 	st->name = name;
+	st->nameSpace = defaultNamespace;
 
 	objectTypes.PushLast(st);
 	registeredEnums.PushLast(st);
@@ -4181,7 +4263,7 @@ int asCScriptEngine::RegisterEnumValue(const char *typeName, const char *valueNa
 	asCDataType dt;
 	int r;
 	asCBuilder bld(this, 0);
-	r = bld.ParseDataType(typeName, &dt);
+	r = bld.ParseDataType(typeName, &dt, defaultNamespace);
 	if( r < 0 )
 		return ConfigError(r, "RegisterEnumValue", typeName, valueName);
 
@@ -4220,7 +4302,7 @@ asUINT asCScriptEngine::GetEnumCount() const
 }
 
 // interface
-const char *asCScriptEngine::GetEnumByIndex(asUINT index, int *enumTypeId, const char **configGroup) const
+const char *asCScriptEngine::GetEnumByIndex(asUINT index, int *enumTypeId, const char **nameSpace, const char **configGroup, asDWORD *accessMask) const
 {
 	if( index >= registeredEnums.GetLength() )
 		return 0;
@@ -4234,9 +4316,15 @@ const char *asCScriptEngine::GetEnumByIndex(asUINT index, int *enumTypeId, const
 			*configGroup = 0;
 	}
 
+	if( accessMask )
+		*accessMask = registeredEnums[index]->accessMask;
+
 	if( enumTypeId )
 		*enumTypeId = GetTypeIdByDecl(registeredEnums[index]->name.AddressOf());
 
+	if( nameSpace )
+		*nameSpace = registeredEnums[index]->nameSpace.AddressOf();
+
 	return registeredEnums[index]->name.AddressOf();
 }
 
@@ -4284,6 +4372,19 @@ asIObjectType *asCScriptEngine::GetObjectTypeByIndex(asUINT index) const
 	return registeredObjTypes[index];
 }
 
+// interface
+asIObjectType *asCScriptEngine::GetObjectTypeByName(const char *name) const
+{
+	for( asUINT n = 0; n < registeredObjTypes.GetLength(); n++ )
+	{
+		if( registeredObjTypes[n]->name == name &&
+			registeredObjTypes[n]->nameSpace == defaultNamespace )
+			return registeredObjTypes[n];
+	}
+
+	return 0;
+}
+
 // interface
 asIObjectType *asCScriptEngine::GetObjectTypeById(int typeId) const
 {
@@ -4305,14 +4406,6 @@ asIScriptFunction *asCScriptEngine::GetFunctionById(int funcId) const
 	return GetScriptFunction(funcId);
 }
 
-#ifdef AS_DEPRECATED
-// deprecated since 2011-10-03
-asIScriptFunction *asCScriptEngine::GetFunctionDescriptorById(int funcId) const
-{
-	return GetScriptFunction(funcId);
-}
-#endif
-
 // internal
 bool asCScriptEngine::IsTemplateType(const char *name) const
 {

+ 16 - 29
ThirdParty/AngelScript/source/as_scriptengine.h

@@ -92,8 +92,6 @@ public:
     virtual int SetJITCompiler(asIJITCompiler *compiler);
     virtual asIJITCompiler *GetJITCompiler() const;
 
-	// TODO: interface: namespace: Allow setting the current namespace for registration
-
 	// Global functions
 	virtual int                RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv);
 	virtual asUINT             GetGlobalFunctionCount() const;
@@ -104,11 +102,10 @@ public:
 	// Global properties
 	virtual int    RegisterGlobalProperty(const char *declaration, void *pointer);
 	virtual asUINT GetGlobalPropertyCount() const;
-	// TODO: interface: namespace: Return the namespace
-	// TODO: interface: access: Return the current access mask
-	virtual int    GetGlobalPropertyByIndex(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0) const;
-	// TODO: access: Allow changing the access mask
-	
+	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;
+	virtual int    GetGlobalPropertyIndexByName(const char *name) const;
+	virtual int    GetGlobalPropertyIndexByDecl(const char *decl) const;
+
 	// Type registration
 	virtual int            RegisterObjectType(const char *obj, int byteSize, asDWORD flags);
 	virtual int            RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset);
@@ -118,7 +115,8 @@ public:
 	virtual int            RegisterInterfaceMethod(const char *intf, const char *declaration);
 	virtual asUINT         GetObjectTypeCount() const;
 	virtual asIObjectType *GetObjectTypeByIndex(asUINT index) const;
-	
+	virtual asIObjectType *GetObjectTypeByName(const char *name) const;
+
 	// String factory
 	virtual int RegisterStringFactory(const char *datatype, const asSFuncPtr &factoryFunc, asDWORD callConv);
 	virtual int GetStringFactoryReturnTypeId() const;
@@ -131,33 +129,26 @@ public:
 	virtual int         RegisterEnum(const char *type);
 	virtual int         RegisterEnumValue(const char *type, const char *name, int value);
 	virtual asUINT      GetEnumCount() const;
-	// TODO: interface: namespace: Return namespace
-	// TODO: interface: access: Return access mask
-	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **configGroup = 0) const;
+	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **nameSpace, const char **configGroup = 0, asDWORD *accessMask = 0) const;
 	virtual int         GetEnumValueCount(int enumTypeId) const;
 	virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const;
 
 	// Funcdefs
 	virtual int                RegisterFuncdef(const char *decl);
 	virtual asUINT             GetFuncdefCount() const;
-	virtual asIScriptFunction *GetFuncdefByIndex(asUINT index, const char **configGroup = 0) const;
+	virtual asIScriptFunction *GetFuncdefByIndex(asUINT index) const;
 
 	// Typedefs
-	// TODO: interface: namespace: Return namespace
 	virtual int         RegisterTypedef(const char *type, const char *decl);
 	virtual asUINT      GetTypedefCount() const;
-	virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **configGroup = 0) const;
+	virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **nameSpace, const char **configGroup = 0, asDWORD *accessMask = 0) const;
 
 	// Configuration groups
 	virtual int     BeginConfigGroup(const char *groupName);
 	virtual int     EndConfigGroup();
 	virtual int     RemoveConfigGroup(const char *groupName);
 	virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask);
-#ifdef AS_DEPRECATED
-	// TODO: interface: Remove this deprecated function
-	// deprecated since 2011-10-04
-	virtual int SetConfigGroupModuleAccess(const char *groupName, const char *module, bool hasAccess);
-#endif
+	virtual int     SetDefaultNamespace(const char *nameSpace);
 
 	// Script modules
 	virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag);
@@ -165,16 +156,11 @@ public:
 
 	// Script functions
 	virtual asIScriptFunction *GetFunctionById(int funcId) const;
-#ifdef AS_DEPRECATED
-	// deprecated since 2011-10-03
-	virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const;
-#endif
 
 	// Type identification
 	virtual asIObjectType *GetObjectTypeById(int typeId) const;
 	virtual int            GetTypeIdByDecl(const char *decl) const;
-	// TODO: interface: namespace: Add flag to allow including namespace or not in declaration
-	virtual const char    *GetTypeDeclaration(int typeId) const;
+	virtual const char    *GetTypeDeclaration(int typeId, bool includeNamespace = false) const;
 	virtual int            GetSizeOfPrimitiveType(int typeId) const;
 
 	// Script execution
@@ -194,8 +180,7 @@ public:
 	// Garbage collection
 	virtual int  GarbageCollect(asDWORD flags = asGC_FULL_CYCLE);
 	virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed, asUINT *totalDetected, asUINT *newObjects, asUINT *totalNewDestroyed) const;
-	// TODO: interface: Should have a version that takes the asIObjectType pointer
-	virtual void NotifyGarbageCollectorOfNewObject(void *obj, int typeId);
+	virtual void NotifyGarbageCollectorOfNewObject(void *obj, asIObjectType *type);
 	virtual void GCEnumCallback(void *reference);
 
 	// User data
@@ -231,6 +216,7 @@ public:
 
 	void *CallAlloc(asCObjectType *objType) const;
 	void  CallFree(void *obj) const;
+
 	void *CallGlobalFunctionRetPtr(int func);
 	void *CallGlobalFunctionRetPtr(int func, void *param1);
 	void *CallGlobalFunctionRetPtr(asSSystemFunctionInterface *func, asCScriptFunction *desc);
@@ -253,7 +239,7 @@ public:
 	asCConfigGroup *FindConfigGroupForFunction(int funcId) const;
 	asCConfigGroup *FindConfigGroupForGlobalVar(int gvarId) const;
 	asCConfigGroup *FindConfigGroupForObjectType(const asCObjectType *type) const;
-	asCConfigGroup *FindConfigGroupForFuncDef(asCScriptFunction *funcDef) const;
+	asCConfigGroup *FindConfigGroupForFuncDef(const asCScriptFunction *funcDef) const;
 
 	int  RequestBuild();
 	void BuildCompleted();
@@ -380,6 +366,7 @@ public:
 	asCArray<asCConfigGroup*>  configGroups;
 	asCConfigGroup            *currentGroup;
 	asDWORD                    defaultAccessMask;
+	asCString                  defaultNamespace;
 
 	// Message callback
 	bool                        msgCallback;
@@ -401,7 +388,7 @@ public:
 	asCLEANOBJECTTYPEFUNC_t cleanObjectTypeFunc;
 
 	// Critical sections for threads
-	DECLARECRITICALSECTION(engineCritical);
+	DECLARECRITICALSECTION(engineCritical)
 
 	// Engine properties
 	struct

+ 46 - 21
ThirdParty/AngelScript/source/as_scriptfunction.cpp

@@ -99,7 +99,8 @@ static void ScriptFunction_ReleaseAllHandles_Generic(asIScriptGeneric *gen)
 void RegisterScriptFunction(asCScriptEngine *engine)
 {
 	// Register the gc behaviours for the script functions
-	int r;
+	int r = 0;
+	UNUSED_VAR(r); // It is only used in debug mode
 	engine->functionBehaviours.engine = engine;
 	engine->functionBehaviours.flags = asOBJ_REF | asOBJ_GC;
 	engine->functionBehaviours.name = "_builtin_function_";
@@ -268,6 +269,12 @@ const char *asCScriptFunction::GetName() const
 	return name.AddressOf();
 }
 
+// interface
+const char *asCScriptFunction::GetNamespace() const
+{
+	return nameSpace.AddressOf();
+}
+
 // interface
 bool asCScriptFunction::IsReadOnly() const
 {
@@ -309,7 +316,7 @@ bool asCScriptFunction::DoesReturnOnStack() const
 }
 
 // internal
-asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName) const
+asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName, bool includeNamespace) const
 {
 	asCString str;
 
@@ -325,11 +332,18 @@ asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName) const
 	}
 	if( objectType && includeObjectName )
 	{
+		if( includeNamespace )
+			str += objectType->nameSpace + "::";
+			
 		if( objectType->name != "" )
 			str += objectType->name + "::";
 		else
 			str += "_unnamed_type_::";
 	}
+	else if( includeNamespace )
+	{
+		str += nameSpace + "::";
+	}
 	if( name == "" )
 		str += "_unnamed_function_(";
 	else
@@ -584,7 +598,7 @@ void asCScriptFunction::AddReferences()
 		case asBC_FREE:
 		case asBC_REFCPY:
 			{
-                asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+                asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				objType->AddRef();
 			}
 			break;
@@ -592,7 +606,7 @@ void asCScriptFunction::AddReferences()
 		// Object type and function
 		case asBC_ALLOC:
 			{
-				asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				objType->AddRef();
 
 				int func = asBC_INTARG(&byteCode[n]+AS_PTR_SIZE);
@@ -611,7 +625,7 @@ void asCScriptFunction::AddReferences()
 		case asBC_SetG4:
 			// Need to increase the reference for each global variable
 			{
-				void *gvarPtr = (void*)(size_t)asBC_PTRARG(&byteCode[n]);
+				void *gvarPtr = (void*)asBC_PTRARG(&byteCode[n]);
 				if( !gvarPtr ) break;
 				asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr);
 				if( !prop ) break;
@@ -651,7 +665,7 @@ void asCScriptFunction::AddReferences()
 		// Function pointers
 		case asBC_FuncPtr:
 			{
-				asCScriptFunction *func = (asCScriptFunction*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCScriptFunction *func = (asCScriptFunction*)asBC_PTRARG(&byteCode[n]);
 				func->AddRef();
 			}
 			break;
@@ -691,7 +705,7 @@ void asCScriptFunction::ReleaseReferences()
 		case asBC_FREE:
 		case asBC_REFCPY:
 			{
-				asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				if( objType ) 
 					objType->Release();
 			}
@@ -700,7 +714,7 @@ void asCScriptFunction::ReleaseReferences()
 		// Object type and function
 		case asBC_ALLOC:
 			{
-				asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				if( objType )
 					objType->Release();
 
@@ -730,7 +744,7 @@ void asCScriptFunction::ReleaseReferences()
 		case asBC_SetG4:
 			// Need to increase the reference for each global variable
 			{
-				void *gvarPtr = (void*)(size_t)asBC_PTRARG(&byteCode[n]);
+				void *gvarPtr = (void*)asBC_PTRARG(&byteCode[n]);
 				if( !gvarPtr ) break;
 				asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr);
 				if( !prop ) break;
@@ -782,7 +796,7 @@ void asCScriptFunction::ReleaseReferences()
 		// Function pointers
 		case asBC_FuncPtr:
 			{
-				asCScriptFunction *func = (asCScriptFunction*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCScriptFunction *func = (asCScriptFunction*)asBC_PTRARG(&byteCode[n]);
 				if( func )
 					func->Release();
 			}
@@ -827,11 +841,11 @@ asIScriptEngine *asCScriptFunction::GetEngine() const
 }
 
 // interface
-const char *asCScriptFunction::GetDeclaration(bool includeObjectName) const
+const char *asCScriptFunction::GetDeclaration(bool includeObjectName, bool includeNamespace) const
 {
 	asASSERT(threadManager);
 	asCString *tempString = &threadManager->GetLocalData()->string;
-	*tempString = GetDeclarationStr(includeObjectName);
+	*tempString = GetDeclarationStr(includeObjectName, includeNamespace);
 	return tempString->AddressOf();
 }
 
@@ -847,13 +861,24 @@ const char *asCScriptFunction::GetScriptSectionName() const
 // interface
 const char *asCScriptFunction::GetConfigGroup() const
 {
-	asCConfigGroup *group = engine->FindConfigGroupForFunction(id);
+	asCConfigGroup *group = 0;
+	if( funcType != asFUNC_FUNCDEF )
+		group = engine->FindConfigGroupForFunction(id);
+	else
+		group = engine->FindConfigGroupForFuncDef(this);
+
 	if( group == 0 )
 		return 0;
 
 	return group->groupName.AddressOf();
 }
 
+// interface
+asDWORD asCScriptFunction::GetAccessMask() const
+{
+	return accessMask;
+}
+
 // internal
 void asCScriptFunction::JITCompile()
 {
@@ -955,14 +980,14 @@ void asCScriptFunction::EnumReferences(asIScriptEngine *)
 		case asBC_FREE:
 		case asBC_REFCPY:
 			{
-                asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+                asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				engine->GCEnumCallback(objType);
 			}
 			break;
 
 		case asBC_ALLOC:
 			{
-				asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				engine->GCEnumCallback(objType);
 
 				int func = asBC_INTARG(&byteCode[n]+AS_PTR_SIZE);
@@ -983,7 +1008,7 @@ void asCScriptFunction::EnumReferences(asIScriptEngine *)
 		// Function pointers
 		case asBC_FuncPtr:
 			{
-				asCScriptFunction *func = (asCScriptFunction*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCScriptFunction *func = (asCScriptFunction*)asBC_PTRARG(&byteCode[n]);
 				if( func )
 					engine->GCEnumCallback(func);
 			}
@@ -1000,7 +1025,7 @@ void asCScriptFunction::EnumReferences(asIScriptEngine *)
 			// Need to enumerate the reference for each global variable
 			{
 				// TODO: optimize: Keep an array of accessed global properties
-				void *gvarPtr = (void*)(size_t)asBC_PTRARG(&byteCode[n]);
+				void *gvarPtr = (void*)asBC_PTRARG(&byteCode[n]);
 				asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr);
 
 				engine->GCEnumCallback(prop);
@@ -1044,7 +1069,7 @@ void asCScriptFunction::ReleaseAllHandles(asIScriptEngine *)
 		case asBC_FREE:
 		case asBC_REFCPY:
 			{
-				asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				if( objType )
 				{
 					objType->Release();
@@ -1055,7 +1080,7 @@ void asCScriptFunction::ReleaseAllHandles(asIScriptEngine *)
 
 		case asBC_ALLOC:
 			{
-				asCObjectType *objType = (asCObjectType*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&byteCode[n]);
 				if( objType )
 				{
 					objType->Release();
@@ -1086,11 +1111,11 @@ void asCScriptFunction::ReleaseAllHandles(asIScriptEngine *)
 		// Function pointers
 		case asBC_FuncPtr:
 			{
-				asCScriptFunction *func = (asCScriptFunction*)(size_t)asBC_PTRARG(&byteCode[n]);
+				asCScriptFunction *func = (asCScriptFunction*)asBC_PTRARG(&byteCode[n]);
 				if( func )
 				{
 					func->Release();
-					*(size_t*)&byteCode[n+1] = 0;
+					*(asPWORD*)&byteCode[n+1] = 0;
 				}
 			}
 			break;

+ 7 - 9
ThirdParty/AngelScript/source/as_scriptfunction.h

@@ -109,15 +109,16 @@ public:
 	asIObjectType       *GetObjectType() const;
 	const char          *GetObjectName() const;
 	const char          *GetName() const;
-	// TODO: interface: Allow inclusion of namespace or not in declaration
-	const char          *GetDeclaration(bool includeObjectName = true) const;
+	const char          *GetNamespace() const;
+	const char          *GetDeclaration(bool includeObjectName = true, bool includeNamespace = false) const;
 	const char          *GetScriptSectionName() const;
 	const char          *GetConfigGroup() const;
+	asDWORD              GetAccessMask() const;
 	bool                 IsReadOnly() const;
 	bool                 IsPrivate() const;
-	// TODO: interface: Add IsFinal() and IsOverride() as public methods
-	// TODO: interface: access: Get/Set access mask for function
-	// TODO: interface: namespace: Get namespace
+	bool                 IsFinal() const;
+	bool                 IsOverride() const;
+	bool                 IsShared() const;
 
 	asUINT               GetParamCount() const;
 	int                  GetParamTypeId(asUINT index, asDWORD *flags = 0) const;
@@ -149,7 +150,7 @@ public:
 
 	int       GetSpaceNeededForArguments();
 	int       GetSpaceNeededForReturnValue();
-	asCString GetDeclarationStr(bool includeObjectName = true) const;
+	asCString GetDeclarationStr(bool includeObjectName = true, bool includeNamespace = false) const;
 	int       GetLineNumber(int programPosition);
 	void      ComputeSignatureId();
 	bool      IsSignatureEqual(const asCScriptFunction *func) const;
@@ -164,9 +165,6 @@ public:
 	void      AddReferences();
 	void      ReleaseReferences();
 
-	bool      IsShared() const;
-	bool      IsFinal() const;
-	bool      IsOverride() const;
 
 	asCGlobalProperty *GetPropertyByGlobalVarPtr(void *gvarPtr);
 

+ 15 - 10
ThirdParty/AngelScript/source/as_scriptobject.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2011 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -125,7 +125,8 @@ static void ScriptObject_ReleaseAllHandles_Generic(asIScriptGeneric *gen)
 void RegisterScriptObject(asCScriptEngine *engine)
 {
 	// Register the default script class behaviours
-	int r;
+	int r = 0;
+	UNUSED_VAR(r); // It is only used in debug mode
 	engine->scriptTypeBehaviours.engine = engine;
 	engine->scriptTypeBehaviours.flags = asOBJ_SCRIPT_OBJECT | asOBJ_REF | asOBJ_GC;
 	engine->scriptTypeBehaviours.name = "_builtin_object_";
@@ -187,14 +188,14 @@ asCScriptObject::asCScriptObject(asCObjectType *ot)
 		asCObjectProperty *prop = objType->properties[n];
 		if( prop->type.IsObject() )
 		{
-			size_t *ptr = (size_t*)(((char*)this) + prop->byteOffset);
+			asPWORD *ptr = (asPWORD*)(((char*)this) + prop->byteOffset);
 
 			if( prop->type.IsObjectHandle() )
 				*ptr = 0;
 			else
 			{
 				// Allocate the object and call it's constructor
-				*ptr = (size_t)AllocateObject(prop->type.GetObjectType(), engine);
+				*ptr = (asPWORD)AllocateObject(prop->type.GetObjectType(), engine);
 			}
 		}
 	}
@@ -398,7 +399,9 @@ void asCScriptObject::ReleaseAllHandles(asIScriptEngine *engine)
 			void **ptr = (void**)(((char*)this) + prop->byteOffset);
 			if( *ptr )
 			{
-				((asCScriptEngine*)engine)->CallObjectMethod(*ptr, prop->type.GetBehaviour()->release);
+				asASSERT( (prop->type.GetObjectType()->flags & asOBJ_NOCOUNT) || prop->type.GetBehaviour()->release );
+				if( prop->type.GetBehaviour()->release )
+					((asCScriptEngine*)engine)->CallObjectMethod(*ptr, prop->type.GetBehaviour()->release);
 				*ptr = 0;
 			}
 		}
@@ -496,17 +499,19 @@ void *asCScriptObject::AllocateObject(asCObjectType *objType, asCScriptEngine *e
 
 void asCScriptObject::FreeObject(void *ptr, asCObjectType *objType, asCScriptEngine *engine)
 {
-	if( !objType->beh.release )
+	if( objType->flags & asOBJ_REF )
+	{
+		asASSERT( (objType->flags & asOBJ_NOCOUNT) || objType->beh.release );
+		if( objType->beh.release )
+			engine->CallObjectMethod(ptr, objType->beh.release);
+	}
+	else
 	{
 		if( objType->beh.destruct )
 			engine->CallObjectMethod(ptr, objType->beh.destruct);
 
 		engine->CallFree(ptr);
 	}
-	else
-	{
-		engine->CallObjectMethod(ptr, objType->beh.release);
-	}
 }
 
 void asCScriptObject::CopyObject(void *src, void *dst, asCObjectType *objType, asCScriptEngine *engine)

+ 2 - 2
ThirdParty/AngelScript/source/as_string.cpp

@@ -312,11 +312,11 @@ int asCString::FindLast(const char *str) const
 	// and then only on quite short strings anyway.
 	const char *last = 0;
 	const char *curr = AddressOf()-1;
-	while( (curr = strstr(curr+1, str)) )
+	while( (curr = strstr(curr+1, str)) != 0 )
 		last = curr;
 
 	if( last )
-		return last-AddressOf();
+		return int(last - AddressOf());
 
 	return -1;
 }

+ 12 - 11
ThirdParty/AngelScript/source/as_texts.h

@@ -119,9 +119,9 @@
 #define TXT_INVALID_UNICODE_VALUE               "Invalid unicode code point"
 #define TXT_INVALID_UNICODE_SEQUENCE_IN_SRC     "Invalid unicode sequence in source"
 
-#define TXT_METHOD_CANNOT_OVERRIDE_s      "Method '%s' declared as final and cannot be overridden"
+#define TXT_METHOD_CANNOT_OVERRIDE_s                "Method '%s' declared as final and cannot be overridden"
 #define TXT_METHOD_CANT_HAVE_NAME_OF_CLASS          "The method cannot be named with the class name"
-#define TXT_METHOD_s_DOES_NOT_OVERRIDE    "Method '%s' marked as override but does not replace any base class or interface method"
+#define TXT_METHOD_s_DOES_NOT_OVERRIDE              "Method '%s' marked as override but does not replace any base class or interface method"
 #define TXT_MISSING_IMPLEMENTATION_OF_s             "Missing implementation of '%s'"
 #define TXT_MORE_THAN_ONE_MATCHING_OP               "Found more than one matching operator"
 #define TXT_MULTIPLE_MATCHING_SIGNATURES_TO_s       "Multiple matching signatures to '%s'"
@@ -169,16 +169,16 @@
 #define TXT_ONLY_ONE_FUNCTION_ALLOWED      "The code must contain one and only one function"
 #define TXT_ONLY_ONE_VARIABLE_ALLOWED      "The code must contain one and only one global variable"
 
-#define TXT_PARAMETER_ALREADY_DECLARED    "Parameter already declared"
-#define TXT_PARAMETER_CANT_BE_s           "Parameter type can't be '%s'"
-#define TXT_POSSIBLE_LOSS_OF_PRECISION    "Conversion from double to float, possible loss of precision"
-#define TXT_PRIVATE_METHOD_CALL_s         "Illegal call to private method '%s'"
-#define TXT_PRIVATE_PROP_ACCESS_s         "Illegal access to private property '%s'"
-#define TXT_PROPERTY_ACCESSOR_DISABLED    "Property accessors have been disabled by the application"
+#define TXT_PARAMETER_ALREADY_DECLARED            "Parameter already declared"
+#define TXT_PARAMETER_CANT_BE_s                   "Parameter type can't be '%s', because the type cannot be instanciated."
+#define TXT_POSSIBLE_LOSS_OF_PRECISION            "Conversion from double to float, possible loss of precision"
+#define TXT_PRIVATE_METHOD_CALL_s                 "Illegal call to private method '%s'"
+#define TXT_PRIVATE_PROP_ACCESS_s                 "Illegal access to private property '%s'"
+#define TXT_PROPERTY_ACCESSOR_DISABLED            "Property accessors have been disabled by the application"
 #define TXT_PROPERTY_ACCESSOR_MUST_BE_IMPLEMENTED "Property accessor must be implemented"
-#define TXT_PROPERTY_CANT_BE_CONST        "Class properties cannot be declared as const"
-#define TXT_PROPERTY_HAS_NO_GET_ACCESSOR  "The property has no get accessor"
-#define TXT_PROPERTY_HAS_NO_SET_ACCESSOR  "The property has no set accessor"
+#define TXT_PROPERTY_CANT_BE_CONST                "Class properties cannot be declared as const"
+#define TXT_PROPERTY_HAS_NO_GET_ACCESSOR          "The property has no get accessor"
+#define TXT_PROPERTY_HAS_NO_SET_ACCESSOR          "The property has no set accessor"
 
 #define TXT_REF_IS_READ_ONLY                    "Reference is read-only"
 #define TXT_REF_IS_TEMP                         "Reference is temporary"
@@ -215,6 +215,7 @@
 
 // Engine message
 
+#define TXT_AUTOHANDLE_CANNOT_BE_USED_FOR_NOCOUNT  "Autohandles cannot be used with types that have been registered with NOCOUNT"
 #define TXT_INVALID_CONFIGURATION                  "Invalid configuration. Verify the registered application interface."
 #define TXT_VALUE_TYPE_MUST_HAVE_SIZE              "A value type must be registered with a non-zero size"
 #define TXT_TYPE_s_IS_MISSING_BEHAVIOURS           "Type '%s' is missing behaviours"

+ 1 - 1
ThirdParty/AngelScript/source/as_thread.h

@@ -70,7 +70,7 @@ protected:
 	void SetLocalData(asPWORD threadId, asCThreadLocalData *tld);
 
 	asCMap<asPWORD,asCThreadLocalData*> tldMap;
-	DECLARECRITICALSECTION(criticalSection);
+	DECLARECRITICALSECTION(criticalSection)
 #else
 	asCThreadLocalData *tld;
 #endif

+ 8 - 1
ThirdParty/AngelScript/source/as_variablescope.cpp

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2010 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -37,6 +37,9 @@
 
 
 #include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_variablescope.h"
 
 BEGIN_AS_NAMESPACE
@@ -128,3 +131,7 @@ sVariable *asCVariableScope::GetVariableByOffset(int offset)
 }
 
 END_AS_NAMESPACE
+
+#endif // AS_NO_COMPILER
+
+

+ 7 - 1
ThirdParty/AngelScript/source/as_variablescope.h

@@ -1,6 +1,6 @@
 /*
    AngelCode Scripting Library
-   Copyright (c) 2003-2010 Andreas Jonsson
+   Copyright (c) 2003-2012 Andreas Jonsson
 
    This software is provided 'as-is', without any express or implied 
    warranty. In no event will the authors be held liable for any 
@@ -39,6 +39,10 @@
 #ifndef AS_VARIABLESCOPE_H
 #define AS_VARIABLESCOPE_H
 
+#include "as_config.h"
+
+#ifndef AS_NO_COMPILER
+
 #include "as_array.h"
 #include "as_string.h"
 #include "as_datatype.h"
@@ -78,4 +82,6 @@ public:
 
 END_AS_NAMESPACE
 
+#endif // AS_NO_COMPILER
+
 #endif

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott