Index: configure.in
===================================================================
--- configure.in	(revision 1964)
+++ configure.in	(arbetskopia)
@@ -25,7 +25,7 @@
 dnl Checks for header files.
 AC_HEADER_DIRENT
 AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h sys/param.h unistd.h])
+AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h sys/param.h unistd.h malloc.h])
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_HEADER_STDBOOL
Index: src/sdk/as/source/as_gcobject.cpp
===================================================================
--- src/sdk/as/source/as_gcobject.cpp	(revision 1964)
+++ src/sdk/as/source/as_gcobject.cpp	(arbetskopia)
@@ -29,9 +29,14 @@
 */
 
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <assert.h>
 #include <new>
+#if defined(WIN32) || defined(HAVE_MALLOC_H)
 #include <malloc.h>
+#endif
 
 #include "as_config.h"
 #include "as_scriptengine.h"
Index: src/sdk/as/source/as_scriptengine.cpp
===================================================================
--- src/sdk/as/source/as_scriptengine.cpp	(revision 1964)
+++ src/sdk/as/source/as_scriptengine.cpp	(arbetskopia)
@@ -36,7 +36,12 @@
 //
 
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#if defined(WIN32) || defined(HAVE_MALLOC_H)
 #include <malloc.h>
+#endif
 
 #include "as_config.h"
 #include "as_scriptengine.h"
Index: src/sdk/as/source/as_arrayobject.cpp
===================================================================
--- src/sdk/as/source/as_arrayobject.cpp	(revision 1964)
+++ src/sdk/as/source/as_arrayobject.cpp	(arbetskopia)
@@ -28,10 +28,14 @@
    andreas@angelcode.com
 */
 
-
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <assert.h>
 #include <new>
+#if defined(WIN32) || defined(HAVE_MALLOC_H)
 #include <malloc.h>
+#endif
 
 #include "as_config.h"
 #include "as_arrayobject.h"
Index: src/sdk/as/source/as_config.h
===================================================================
--- src/sdk/as/source/as_config.h	(revision 1964)
+++ src/sdk/as/source/as_config.h	(arbetskopia)
@@ -165,6 +165,9 @@
 // AS_X86
 // Use assembler code for the x86 CPU family
 
+// AS_PPC
+// Use assembler code for the PPC CPU family
+
 // AS_SH4
 // Use assembler code for the SH4 CPU family
 
@@ -276,9 +279,21 @@
 		#define CDECL_RETURN_SIMPLE_IN_MEMORY
 		#define STDCALL_RETURN_SIMPLE_IN_MEMORY
 	#endif
+	#if defined(__APPLE__) && defined(__MACH__)
+		// Mach-O
+	#endif
 	#ifdef i386
 		#define AS_X86
 	#endif
+	#ifdef __i386__
+		#define AS_X86
+	#endif
+	#ifdef __ppc__
+		#define AS_PPC
+	#endif
+	#ifdef __powerpc__
+		#define AS_PPC
+	#endif
 #endif
 
 // Dreamcast console
Index: src/sdk/as/Makefile.am
===================================================================
--- src/sdk/as/Makefile.am	(revision 1964)
+++ src/sdk/as/Makefile.am	(arbetskopia)
@@ -21,6 +21,7 @@
 $(srcdir)/source/as_c.cpp \
 $(srcdir)/source/as_callfunc.cpp \
 $(srcdir)/source/as_callfunc_sh4.cpp \
+$(srcdir)/source/as_callfunc_ppc.cpp \
 $(srcdir)/source/as_callfunc_x86.cpp \
 $(srcdir)/source/as_compiler.cpp \
 $(srcdir)/source/as_configgroup.cpp \
Index: src/sdk/as/source/as_callfunc_ppc.cpp
===================================================================
--- /dev/null	Tue Feb  7 23:24:08 2006
+++ src/sdk/as/source/as_callfunc_ppc.cpp	Tue Feb  7 00:12:40 2006
@@ -0,0 +1,239 @@
+/*
+   AngelCode Scripting Library
+   Copyright (c) 2003-2006 Andreas Jönsson
+   Copyright (c) 2005-2006 Anders F Björklund
+
+   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.
+
+*/
+
+
+//
+// as_callfunc.cpp
+//
+// These functions handle the actual calling of system functions
+//
+
+
+
+#include "as_config.h"
+
+#ifndef AS_MAX_PORTABILITY
+#ifdef AS_PPC
+
+#include "as_callfunc.h"
+#include "as_scriptengine.h"
+#include "as_texts.h"
+#include "as_tokendef.h"
+
+BEGIN_AS_NAMESPACE
+
+int DetectCallingConvention(bool isMethod, const asUPtr &ptr, int callConv, asSSystemFunctionInterface *internal)
+{
+	memset(internal, 0, sizeof(asSSystemFunctionInterface));
+
+	internal->func = (asDWORD)ptr.f.func;
+
+	int base = callConv;
+	if( !isMethod )
+	{
+		if( base == asCALL_CDECL )
+			internal->callConv = ICC_CDECL;
+		else if( base == asCALL_STDCALL )
+			internal->callConv = ICC_STDCALL;
+		else if( base == asCALL_GENERIC )
+			internal->callConv = ICC_GENERIC_FUNC;
+		else
+			return asNOT_SUPPORTED;
+	}
+	else
+	{
+#ifndef AS_NO_CLASS_METHODS
+		if( base == asCALL_THISCALL )
+		{
+			internal->callConv = ICC_THISCALL;
+		}
+		else
+#endif
+		if( base == asCALL_CDECL_OBJLAST )
+			internal->callConv = ICC_CDECL_OBJLAST;
+		else if( base == asCALL_CDECL_OBJFIRST )
+			internal->callConv = ICC_CDECL_OBJFIRST;
+		else if( base == asCALL_GENERIC )
+			internal->callConv = ICC_GENERIC_METHOD;
+		else
+			return asNOT_SUPPORTED;
+	}
+
+	return 0;
+}
+
+// This function should prepare system functions so that it will be faster to call them
+int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine *engine)
+{
+	// References are always returned as primitive data
+	if( func->returnType.IsReference() || func->returnType.IsObjectHandle() )
+	{
+		internal->hostReturnInMemory = false;
+		internal->hostReturnSize = 1;
+		internal->hostReturnFloat = false;
+	}
+	// Registered types have special flags that determine how they are returned
+	else if( func->returnType.IsObject() )
+	{
+		asDWORD objType = func->returnType.GetObjectType()->flags;
+		if( objType & asOBJ_CLASS )
+		{
+			if( objType & COMPLEX_MASK )
+			{
+				internal->hostReturnInMemory = true;
+				internal->hostReturnSize = 1;
+				internal->hostReturnFloat = false;
+			}
+			else
+			{
+				internal->hostReturnFloat = false;
+				if( func->returnType.GetSizeInMemoryDWords() > 2 )
+				{
+					internal->hostReturnInMemory = true;
+					internal->hostReturnSize = 1;
+				}
+				else
+				{
+					internal->hostReturnInMemory = false;
+					internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords();
+				}
+
+				if( internal->callConv == ICC_THISCALL ||
+					internal->callConv == ICC_VIRTUAL_THISCALL )
+				{
+					internal->hostReturnInMemory = true;
+					internal->hostReturnSize = 1;
+				}
+
+				if( internal->callConv == ICC_CDECL ||
+					internal->callConv == ICC_CDECL_OBJLAST ||
+					internal->callConv == ICC_CDECL_OBJFIRST )
+				{
+					internal->hostReturnInMemory = true;
+					internal->hostReturnSize = 1;
+				}
+
+				if( internal->callConv == ICC_STDCALL )
+				{
+					internal->hostReturnInMemory = true;
+					internal->hostReturnSize = 1;
+				}
+			}
+		}
+		else if( objType == asOBJ_PRIMITIVE )
+		{
+			internal->hostReturnInMemory = false;
+			internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords();
+			internal->hostReturnFloat = false;
+		}
+		else if( objType == asOBJ_FLOAT )
+		{
+			internal->hostReturnInMemory = false;
+			internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords();
+			internal->hostReturnFloat = true;
+		}
+	}
+	// Primitive types can easily be determined
+	else if( func->returnType.GetSizeInMemoryDWords() > 2 )
+	{
+		// Shouldn't be possible to get here
+		assert(false);
+
+		internal->hostReturnInMemory = true;
+		internal->hostReturnSize = 1; 
+		internal->hostReturnFloat = false;
+	}
+	else if( func->returnType.GetSizeInMemoryDWords() == 2 )
+	{
+		internal->hostReturnInMemory = false;
+		internal->hostReturnSize = 2;
+		internal->hostReturnFloat = func->returnType.IsEqualExceptConst(asCDataType::CreatePrimitive(ttDouble, true));
+	}
+	else if( func->returnType.GetSizeInMemoryDWords() == 1 )
+	{
+		internal->hostReturnInMemory = false;
+		internal->hostReturnSize = 1;
+		internal->hostReturnFloat = func->returnType.IsEqualExceptConst(asCDataType::CreatePrimitive(ttFloat, true));
+	}
+	else
+	{
+		internal->hostReturnInMemory = false;
+		internal->hostReturnSize = 0;
+		internal->hostReturnFloat = false;
+	}
+
+	// Calculate the size needed for the parameters
+	internal->paramSize = func->GetSpaceNeededForArguments();
+
+	// Verify if the function takes any objects by value
+	asUINT n;
+	internal->takesObjByVal = false;
+	for( n = 0; n < func->parameterTypes.GetLength(); n++ )
+	{
+		if( func->parameterTypes[n].IsObject() && !func->parameterTypes[n].IsObjectHandle() && !func->parameterTypes[n].IsReference() )
+		{
+			internal->takesObjByVal = true;
+			break;
+		}
+	}
+
+	// Verify if the function has any registered autohandles
+	internal->hasAutoHandles = false;
+	for( n = 0; n < internal->paramAutoHandles.GetLength(); n++ )
+	{
+		if( internal->paramAutoHandles[n] )
+		{
+			internal->hasAutoHandles = true;
+			break;
+		}
+	}
+
+	return 0;
+}
+
+int CallSystemFunction(int id, asCContext *context, void *objectPointer)
+{
+	id = -id - 1;
+
+	asCScriptEngine *engine = context->engine;
+	asSSystemFunctionInterface *sysFunc = engine->systemFunctionInterfaces[id];
+	int callConv = sysFunc->callConv;
+	if( callConv == ICC_GENERIC_FUNC || callConv == ICC_GENERIC_METHOD )
+		return context->CallGeneric(-id-1, objectPointer);
+
+	context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
+
+	return 0;
+}
+
+END_AS_NAMESPACE
+
+#endif // AS_PPC
+#endif // AS_MAX_PORTABILITY
+
+
+
+
