# HG changeset patch # User David Anderson # Date 1343202488 25200 # Node ID 5f44021802040478ac1d97089b8dc95ba93982c3 # Parent 3da12b433b00be090a5f5685b7777046618d859d Added clang support. A lot of the motion here is introducing a new offsetof because clang's seems broken? diff -r 3da12b433b00 -r 5f4402180204 AMBuildScript --- a/AMBuildScript Wed Jul 25 00:16:52 2012 -0700 +++ b/AMBuildScript Wed Jul 25 00:48:08 2012 -0700 @@ -46,9 +46,16 @@ self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti') self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics') + # We don't really care about these. self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor') self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual') + # The compiler is too aggressive about what what should be a valid offsetof. + self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof') + + # This would otherwise forbid ((x = y) == NULL) in clang apparently. + self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic') + if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \ (self.vendor == 'clang' and cxx.majorVersion >= 3): self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor') diff -r 3da12b433b00 -r 5f4402180204 include/keima.h --- a/include/keima.h Wed Jul 25 00:16:52 2012 -0700 +++ b/include/keima.h Wed Jul 25 00:48:08 2012 -0700 @@ -1,4 +1,5 @@ -/* +/* vim: set ts=4 sw=4 tw=99 et: + * * Copyright (C) 2004-2012 David Anderson * * This file is part of SourcePawn. @@ -100,7 +101,7 @@ template Local(Local other) : Handle(reinterpret_cast(*other)) { - typeCheck(); + this->template typeCheck(); } template Local(S *other) @@ -131,7 +132,7 @@ explicit Root(ke::HeapRoot *obj) : Handle(reinterpret_cast(obj)) { - incref(); +incref(); } static inline Root New(Handle other); @@ -142,8 +143,8 @@ Root &operator =(const Root &other) { decref(); - obj_ = other.obj_; - incref(); + this->obj_ = other.obj_; + incref(); return *this; } diff -r 3da12b433b00 -r 5f4402180204 src/AMBuild.shell --- a/src/AMBuild.shell Wed Jul 25 00:16:52 2012 -0700 +++ b/src/AMBuild.shell Wed Jul 25 00:48:08 2012 -0700 @@ -6,9 +6,11 @@ compiler.AddToListVar('CXXINCLUDES', os.path.join(AMBuild.sourceFolder, 'include')) library = osutil.StaticLibPrefix() + 'keima' + osutil.StaticLibSuffix() -compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:CONSOLE') compiler.AddToListVar('POSTLINKFLAGS', os.path.join(AMBuild.outputFolder, 'keima', library)) +if compiler.cc.name == 'msvc': + compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:CONSOLE') + job = AMBuild.AddJob('spshell') binary = Cpp.ExecutableBuilder('spshell', AMBuild, job, compiler) files = [ diff -r 3da12b433b00 -r 5f4402180204 src/Array.cpp --- a/src/Array.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Array.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include #include "Array.h" #include "Heap.h" #include "Zone.h" diff -r 3da12b433b00 -r 5f4402180204 src/Array.h --- a/src/Array.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Array.h Wed Jul 25 00:48:08 2012 -0700 @@ -123,10 +123,10 @@ // GC Descriptor. static inline size_t offsetOfType() { - return offsetof(ArrayMap, type_); + return OFFSETOF(ArrayMap, type_); } static inline size_t offsetOfContained() { - return offsetof(ArrayMap, contained_); + return OFFSETOF(ArrayMap, contained_); } // End GC Descriptor. diff -r 3da12b433b00 -r 5f4402180204 src/BytecodeCompiler.cpp --- a/src/BytecodeCompiler.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/BytecodeCompiler.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -36,9 +36,9 @@ : zone_(zone), tree_(tree), emitter_(zone->pool()), - moduleData_(module), locals_(NULL), scope_(NULL), + moduleData_(module), loop_(NULL) { } diff -r 3da12b433b00 -r 5f4402180204 src/BytecodeEmitter.h --- a/src/BytecodeEmitter.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/BytecodeEmitter.h Wed Jul 25 00:48:08 2012 -0700 @@ -31,7 +31,7 @@ class Type; class Map; -typedef PoolList> ObjectList; +typedef PoolList > ObjectList; struct OopRecord : public PoolObject { diff -r 3da12b433b00 -r 5f4402180204 src/Code.h --- a/src/Code.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Code.h Wed Jul 25 00:48:08 2012 -0700 @@ -97,22 +97,22 @@ // GC Descriptor. static inline size_t offsetOfModule() { - return offsetof(Code, module_); + return OFFSETOF(Code, module_); } static inline size_t offsetOfBytecode() { - return offsetof(Code, bytecode_); + return OFFSETOF(Code, bytecode_); } static inline size_t offsetOfLocals() { - return offsetof(Code, locals_); + return OFFSETOF(Code, locals_); } static inline size_t offsetOfObjects() { - return offsetof(Code, objects_); + return OFFSETOF(Code, objects_); } static inline size_t offsetOfSafepoints() { - return offsetof(Code, safepoints_); + return OFFSETOF(Code, safepoints_); } static inline size_t offsetOfSourceMap() { - return offsetof(Code, sourcemap_); + return OFFSETOF(Code, sourcemap_); } // End GC Descriptor. diff -r 3da12b433b00 -r 5f4402180204 src/Environments.h --- a/src/Environments.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Environments.h Wed Jul 25 00:48:08 2012 -0700 @@ -136,7 +136,7 @@ } static inline size_t offsetOfSlots() { - return offsetof(EnvironmentMap, slots_); + return OFFSETOF(EnvironmentMap, slots_); } static inline EnvironmentMap *cast(Object *obj) { diff -r 3da12b433b00 -r 5f4402180204 src/FixedArray.cpp --- a/src/FixedArray.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/FixedArray.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -16,6 +16,7 @@ * JITCraft. If not, see http://www.gnu.org/licenses/. */ #include +#include #include "FixedArray.h" #include "Zone.h" #include "Heap-inl.h" diff -r 3da12b433b00 -r 5f4402180204 src/Functions.h --- a/src/Functions.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Functions.h Wed Jul 25 00:48:08 2012 -0700 @@ -62,13 +62,13 @@ // Begin GC Descriptor. static inline size_t offsetOfCode() { - return offsetof(Function, code_); + return OFFSETOF(Function, code_); } static inline size_t offsetOfType() { - return offsetof(Function, type_); + return OFFSETOF(Function, type_); } static inline size_t offsetOfName() { - return offsetof(Function, name_); + return OFFSETOF(Function, name_); } // End GC Descriptor. @@ -104,10 +104,10 @@ // Begin GC Descriptor. static inline size_t offsetOfType() { - return offsetof(Native, type_); + return OFFSETOF(Native, type_); } static inline size_t offsetOfName() { - return offsetof(Native, name_); + return OFFSETOF(Native, name_); } // End GC Descriptor. diff -r 3da12b433b00 -r 5f4402180204 src/Heap.cpp --- a/src/Heap.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Heap.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -30,9 +30,9 @@ Heap::Heap(Zone *zone) : zone_(zone), - markStack_(NULL), + mapSpace_(zone), oldSpace_(zone), - mapSpace_(zone) + markStack_(NULL) { } diff -r 3da12b433b00 -r 5f4402180204 src/Interpreter.cpp --- a/src/Interpreter.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Interpreter.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include #include "Interpreter.h" #include "Modules.h" #include "Zone.h" diff -r 3da12b433b00 -r 5f4402180204 src/Modules.h --- a/src/Modules.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Modules.h Wed Jul 25 00:48:08 2012 -0700 @@ -89,22 +89,22 @@ // Begin GC Descriptor. static inline size_t offsetOfFunctions() { - return offsetof(Module, functions_); + return OFFSETOF(Module, functions_); } static inline size_t offsetOfPublics() { - return offsetof(Module, publics_); + return OFFSETOF(Module, publics_); } static inline size_t offsetOfNatives() { - return offsetof(Module, natives_); + return OFFSETOF(Module, natives_); } static inline size_t offsetOfFile() { - return offsetof(Module, file_); + return OFFSETOF(Module, file_); } static inline size_t offsetOfEnvironment() { - return offsetof(Module, environment_); + return OFFSETOF(Module, environment_); } static inline size_t offsetOfCode() { - return offsetof(Module, code_); + return OFFSETOF(Module, code_); } // End GC Descriptor. diff -r 3da12b433b00 -r 5f4402180204 src/Objects.h --- a/src/Objects.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Objects.h Wed Jul 25 00:48:08 2012 -0700 @@ -83,7 +83,8 @@ inline void write(Zone *zone, Object **ptr, Object *value); static inline size_t offsetOfMap() { - return offsetof(Object, map_); + // Clang doesn't accept offsetof here and it's not clear why... + return reinterpret_cast(&((Object *)NULL)->map_); } }; diff -r 3da12b433b00 -r 5f4402180204 src/Platform-Posix.cpp --- a/src/Platform-Posix.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Platform-Posix.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -19,7 +19,7 @@ #include #include "Platform.h" -using namespace jc; +using namespace ke; static inline int ToProtBits(OS::Protection prot) diff -r 3da12b433b00 -r 5f4402180204 src/PoolAllocator.h --- a/src/PoolAllocator.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/PoolAllocator.h Wed Jul 25 00:48:08 2012 -0700 @@ -126,7 +126,7 @@ { public: PoolList() - : Vector(PoolAllocationPolicy()) + : Vector(PoolAllocationPolicy()) { } }; diff -r 3da12b433b00 -r 5f4402180204 src/Spaces-inl.h --- a/src/Spaces-inl.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Spaces-inl.h Wed Jul 25 00:48:08 2012 -0700 @@ -19,6 +19,8 @@ #ifndef _include_jitcraft_spaces_inl_h_ #define _include_jitcraft_spaces_inl_h_ +#include "Objects.h" + namespace ke { inline Address @@ -54,6 +56,23 @@ return addr; } +template inline Object * +ChunkObjectIteratorBase::next() +{ + while (current_ && current_ != top_) { + Object *obj = reinterpret_cast(current_); + size_t size = evaluator_(obj, obj->map()); + current_ += size; + if (current_ == chunk_->end()) { + chunk_ = chunk_->next(); + current_ = chunk_ ? chunk_->first() : NULL; + } + if (obj->is(MapKind_FreeRegion)) + continue; + } + return NULL; +} + } #endif // _include_jitcraft_spaces_inl_h_ diff -r 3da12b433b00 -r 5f4402180204 src/Spaces.cpp --- a/src/Spaces.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Spaces.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include #include "Zone.h" #include "Spaces.h" #include "Platform.h" diff -r 3da12b433b00 -r 5f4402180204 src/Spaces.h --- a/src/Spaces.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Spaces.h Wed Jul 25 00:48:08 2012 -0700 @@ -272,20 +272,7 @@ { } - Object *next() { - while (current_ && current_ != top_) { - Object *obj = reinterpret_cast(current_); - size_t size = evaluator_(obj, obj->map()); - current_ += size; - if (current_ == chunk_->end()) { - chunk_ = chunk_->next(); - current_ = chunk_ ? chunk_->first() : NULL; - } - if (obj->is(MapKind_FreeRegion)) - continue; - } - return NULL; - } + Object *next(); }; class FreedObject diff -r 3da12b433b00 -r 5f4402180204 src/Stack.cpp --- a/src/Stack.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Stack.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -18,6 +18,7 @@ */ #include #include +#include #include "Stack.h" #include "Zone.h" #include "Strings.h" diff -r 3da12b433b00 -r 5f4402180204 src/StringPool.h --- a/src/StringPool.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/StringPool.h Wed Jul 25 00:48:08 2012 -0700 @@ -18,6 +18,7 @@ #ifndef _include_jitcraft_string_pool_h_ #define _include_jitcraft_string_pool_h_ +#include #include "AllocatorPolicies.h" #include "HashTable.h" #include "Strings.h" diff -r 3da12b433b00 -r 5f4402180204 src/Strings.cpp --- a/src/Strings.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Strings.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include #include "Strings.h" #include "Zone.h" #include "Heap-inl.h" diff -r 3da12b433b00 -r 5f4402180204 src/TypeManager.cpp --- a/src/TypeManager.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/TypeManager.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include #include "Types.h" #include "TypeManager.h" #include "Zone.h" diff -r 3da12b433b00 -r 5f4402180204 src/Types.cpp --- a/src/Types.cpp Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Types.cpp Wed Jul 25 00:48:08 2012 -0700 @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include #include "Types.h" #include "Zone.h" #include "Strings.h" diff -r 3da12b433b00 -r 5f4402180204 src/Types.h --- a/src/Types.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Types.h Wed Jul 25 00:48:08 2012 -0700 @@ -152,16 +152,16 @@ // GC Descriptor. static inline size_t offsetOfContained() { - return offsetof(Type, contained_); + return OFFSETOF(Type, contained_); } static inline size_t offsetOfReturnType() { - return offsetof(Type, returnType_); + return OFFSETOF(Type, returnType_); } static inline size_t offsetOfParameters() { - return offsetof(Type, parameters_); + return OFFSETOF(Type, parameters_); } static inline size_t offsetOfTag() { - return offsetof(Type, tag_); + return OFFSETOF(Type, tag_); } // End GC Descriptor. diff -r 3da12b433b00 -r 5f4402180204 src/Utility.h --- a/src/Utility.h Wed Jul 25 00:16:52 2012 -0700 +++ b/src/Utility.h Wed Jul 25 00:48:08 2012 -0700 @@ -238,6 +238,8 @@ return t1 < t2 ? t1 : t2; } +#define OFFSETOF(Class, Member) reinterpret_cast(&((Class *)NULL)->Member) + } #endif // _include_jitcraft_utility_h_