Update to latest angelscript

This commit is contained in:
Marianne Gagnon
2015-05-11 19:40:43 -04:00
parent f269b44208
commit c48037984d
71 changed files with 11405 additions and 6307 deletions

View File

@@ -1,6 +1,6 @@
/*
AngelCode Scripting Library
Copyright (c) 2003-2012 Andreas Jonsson
Copyright (c) 2003-2015 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,6 +49,63 @@
BEGIN_AS_NAMESPACE
#ifdef WIP_16BYTE_ALIGN
// TODO: Add support for 16byte aligned application types (e.g. __m128). The following is a list of things that needs to be implemented:
//
// ok - The script context must make sure to always allocate the local stack memory buffer on 16byte aligned boundaries (asCContext::ReserveStackSpace)
// ok - The engine must make sure to always allocate the memory for the script objects on 16byte aligned boundaries (asCScriptEngine::CallAlloc)
// ok - The application needs to inform a new flag when registering types that require 16byte alignment, e.g. asOBJ_APP_ALIGN16 (asCScriptEngine::RegisterObjectType)
// ok - The script object type must make sure to align member properties of these types correctly (asCObjectType::AddPropertyToClass)
// ok - Script global properties must allocate memory on 16byte boundaries if holding these types (asCGlobalProperty::AllocateMemory)
// TODO - The script compiler must make sure to allocate the local variables on 16byte boundaries (asCCompiler::AllocateVariable)
// TODO - The script compiler must add pad bytes on the stack for all function calls to guarantee that the stack position is 16byte aligned on entry in the called function (asCCompiler)
// TODO - The bytecode serializer must be capable of adjusting these pad bytes to guarantee platform independent saved bytecode. Remember that the registered type may not be 16byte aligned on all platforms (asCWriter & asCReader)
// TODO - The bytecode serializer must also be prepared to adjust the position of the local variables according to the need fro 16byte alignment (asCWriter & asCReader)
// TODO - The code for the native calling conventions must be adjusted for all platforms that should support 16byte aligned types (as_callfunc...)
// ok - When the context needs to grow the local stack memory it must copy the function arguments so that the stack entry position is 16byte aligned (asCContext::CallScriptFunction)
// TODO - When the context is prepared for a new call, it must set the initial stack position so the stack entry position is 16byte aligned (asCContext::Prepare)
//
// http://www.gamedev.net/topic/650555-alignment-requirements/
// TODO: Allow user to register its own aligned memory routines
// Wrappers for aligned allocations
void *debugAlignedMalloc(size_t size, size_t align, const char *file, int line)
{
void *mem = ((asALLOCFUNCDEBUG_t)userAlloc)(size + (align-1) + sizeof(void*), file, line);
char *amem = ((char*)mem) + sizeof(void*);
if( (uintptr_t)amem & (align - 1) )
amem += align - ((uintptr_t)amem & (align - 1));
((void**)amem)[-1] = mem;
return amem;
}
void *alignedMalloc(size_t size, size_t align)
{
void *mem = userAlloc(size + (align-1) + sizeof(void*));
char *amem = ((char*)mem) + sizeof(void*);
if( (uintptr_t)amem & (align - 1) )
amem += align - ((uintptr_t)amem & (align - 1));
((void**)amem)[-1] = mem;
return amem;
}
void alignedFree(void *mem)
{
userFree( ((void**)mem)[-1] );
}
bool isAligned(const void* const pointer, asUINT alignment)
{
return (uintptr_t(pointer) % alignment) == 0;
}
#endif
// By default we'll use the standard memory management functions
// Make sure these globals are initialized first. Otherwise the
@@ -61,25 +118,47 @@ BEGIN_AS_NAMESPACE
#pragma init_seg(lib)
asALLOCFUNC_t userAlloc = malloc;
asFREEFUNC_t userFree = free;
#ifdef WIP_16BYTE_ALIGN
#ifdef AS_DEBUG
asALLOCALIGNEDFUNC_t userAllocAligned = (asALLOCALIGNEDFUNC_t)debugAlignedMalloc;
#else
asALLOCALIGNEDFUNC_t userAllocAligned = alignedMalloc;
#endif
asFREEALIGNEDFUNC_t userFreeAligned = alignedFree;
#endif
#else
// Other compilers will just have to rely on luck.
asALLOCFUNC_t userAlloc = malloc;
asFREEFUNC_t userFree = free;
#ifdef WIP_16BYTE_ALIGN
asALLOCALIGNEDFUNC_t userAllocAligned = alignedMalloc;
asFREEALIGNEDFUNC_t userFreeAligned = alignedFree;
#endif
#endif
extern "C"
{
// interface
int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc)
{
// Clean-up thread local memory before changing the allocation routines to avoid
// potential problem with trying to free memory using a different allocation
// routine than used when allocating it.
asThreadCleanup();
userAlloc = allocFunc;
userFree = freeFunc;
return 0;
}
// interface
int asResetGlobalMemoryFunctions()
{
// Clean-up thread local memory before changing the allocation routines to avoid
// potential problem with trying to free memory using a different allocation
// routine than used when allocating it.
asThreadCleanup();
userAlloc = malloc;
@@ -88,6 +167,18 @@ int asResetGlobalMemoryFunctions()
return 0;
}
// interface
void *asAllocMem(size_t size)
{
return asNEWARRAY(asBYTE, size);
}
// interface
void asFreeMem(void *mem)
{
asDELETEARRAY(mem);
}
} // extern "C"
asCMemoryMgr::asCMemoryMgr()