# HG changeset patch # User David Anderson # Date 1343205033 25200 # Node ID e3974e7360e9af7c7180f96fde0e28bb9f08f935 # Parent 5f44021802040478ac1d97089b8dc95ba93982c3 Add GCC/Linux support. diff -r 5f4402180204 -r e3974e7360e9 AMBuildScript --- a/AMBuildScript Wed Jul 25 00:48:08 2012 -0700 +++ b/AMBuildScript Wed Jul 25 01:30:33 2012 -0700 @@ -54,11 +54,14 @@ 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 == 'clang': + 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') + + self.compiler.AddToListVar('POSTLINKFLAGS', '-lm') elif isinstance(cxx, Cpp.MSVC): self.vendor = 'msvc' if AMBuild.options.debug == '1': diff -r 5f4402180204 -r e3974e7360e9 src/API.cpp --- a/src/API.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/API.cpp Wed Jul 25 01:30:33 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 "../include/keima.h" #include "Zone.h" #include "RootScopes.h" @@ -31,6 +32,8 @@ #include "Interpreter.h" #include "Stack.h" #include "Strings.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/BytecodeCompiler.cpp --- a/src/BytecodeCompiler.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/BytecodeCompiler.cpp Wed Jul 25 01:30:33 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 "BytecodeCompiler.h" #include "Scopes.h" #include "Modules.h" diff -r 5f4402180204 -r e3974e7360e9 src/BytecodeEmitter.cpp --- a/src/BytecodeEmitter.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/BytecodeEmitter.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -21,6 +21,8 @@ #include "Utility.h" #include "Types.h" #include "Zone.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/CompileContext.cpp --- a/src/CompileContext.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/CompileContext.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -19,6 +19,8 @@ #include "Scanner.h" #include "CompileContext.h" #include "Zone.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/Environments.cpp --- a/src/Environments.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Environments.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -15,12 +15,15 @@ * 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 "Utility.h" #include "Environments.h" #include "Structures.h" #include "FixedArray.h" #include "Zone.h" #include "NameBinding.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/GlobalRoots.cpp --- a/src/GlobalRoots.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/GlobalRoots.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -17,6 +17,8 @@ */ #include "GlobalRoots.h" #include "Zone.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/GlobalRoots.h --- a/src/GlobalRoots.h Wed Jul 25 00:48:08 2012 -0700 +++ b/src/GlobalRoots.h Wed Jul 25 01:30:33 2012 -0700 @@ -18,6 +18,7 @@ #ifndef _include_ke_global_roots_h_ #define _include_ke_global_roots_h_ +#include "Utility.h" #include "Handles.h" #include "InlineList.h" #include "VirtualObjectVisitor.h" diff -r 5f4402180204 -r e3974e7360e9 src/Handles-inl.h --- a/src/Handles-inl.h Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Handles-inl.h Wed Jul 25 01:30:33 2012 -0700 @@ -19,43 +19,10 @@ #define _include_jitcraft_rooting_inl_h_ #include "Heap.h" +#include "Zone.h" namespace ke { -template -Local::Local(Environment *env) - : zone_(env->zone()), thing_(NULL) -{ - prev_ = zone_->registerThingLocal(toRaw()); -} - -template -Local::Local(Environment *env, T *thing) - : zone_(env->zone()), thing_(thing) -{ - prev_ = zone_->registerThingLocal(toRaw()); -} - -template -Local::Local(Zone *zone) - : zone_(zone), thing_(NULL) -{ - prev_ = zone_->registerThingLocal(toRaw()); -} - -template -Local::Local(Zone *zone, T *thing) - : zone_(zone), thing_(thing) -{ - prev_ = zone_->registerThingLocal(toRaw()); -} - - -template -Local::~Local() -{ - zone_->deregisterThingLocal(toRaw(), prev_); -} } diff -r 5f4402180204 -r e3974e7360e9 src/NameBinding.cpp --- a/src/NameBinding.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/NameBinding.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -19,6 +19,8 @@ #include "Strings.h" #include "Zone.h" #include "Scopes.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/Parser.cpp --- a/src/Parser.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Parser.cpp Wed Jul 25 01:30:33 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 "Parser.h" #include "FixedArray.h" diff -r 5f4402180204 -r e3974e7360e9 src/Platform-Posix.cpp --- a/src/Platform-Posix.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Platform-Posix.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -72,7 +72,7 @@ } size_t requested = Min(amount * 2, amount + 2 * alignment); - Address address = MapMemory(amount, mode, Prot_ReadWrite); + Address address = MapMemory(requested, mode, Prot_ReadWrite); if (!address) return AlignableMapping(); @@ -87,7 +87,7 @@ if (requested - begin > amount) { // Shave off the last part of the unaligned region. - UnmapAlignedMemory(address + amount, requested - amount - begin); + UnmapAlignedMemory(aligned + amount, requested - amount - begin); } return AlignableMapping(aligned, alignment, amount); diff -r 5f4402180204 -r e3974e7360e9 src/PoolAllocator.cpp --- a/src/PoolAllocator.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/PoolAllocator.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -20,6 +20,8 @@ #include #include "PoolAllocator.h" #include "Zone.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/Scanner.cpp --- a/src/Scanner.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Scanner.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -1,4 +1,5 @@ -/* +/* vim: set ts=4 sw=4 tw=99 et: + * * Copyright (C) 2012 David Anderson * * This file is part of JITCraft. @@ -18,6 +19,8 @@ #include #include #include +#include +#include #include "Scanner.h" #include "Utility.h" @@ -263,76 +266,97 @@ return TOK_ERROR; c = char(code); } - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; } + if (!literal_.append('\0')) + return TOK_ERROR; + return TOK_STRING_LITERAL; } TokenKind Scanner::numberLiteral(char first) { - literal_ = first; + literal_.clear(); + if (!literal_.append(first)) + return TOK_ERROR; char c; for (;;) { c = getChar(); if (!IsDigit(c)) break; - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; } if (c != '.') { putChar(c); + if (!literal_.append('\0')) + return TOK_ERROR; return TOK_INTEGER_LITERAL; } - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; c = getChar(); if (!IsDigit(c)) { cc_.reportError(begin(), Message_ExpectedDigitForFloat, c); return TOK_ERROR; } - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; for (;;) { c = getChar(); if (!IsDigit(c)) break; - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; } if (c != 'e') { putChar(c); } else { - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; c = getChar(); if (c == '-') { - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; c = getChar(); } if (!IsDigit(c)) { cc_.reportError(begin(), Message_ExpectedDigitForFloat, c); return TOK_ERROR; } - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; for (;;) { c = getChar(); if (!IsDigit(c)) { putChar(c); break; } - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; } } + if (!literal_.append('\0')) + return TOK_ERROR; + return TOK_FLOAT_LITERAL; } TokenKind Scanner::identifier(char first) { - literal_ = first; + literal_.clear(); + if (!literal_.append(first)) + return TOK_ERROR; char c; for (;;) { @@ -342,36 +366,40 @@ putChar(c); break; } - literal_ += c; + if (!literal_.append(c)) + return TOK_ERROR; } - if (literal_ == "new") + if (!literal_.append('\0')) + return TOK_ERROR; + + if (!strcmp(literal(), "new")) return TOK_NEW; - if (literal_ == "for") + if (!strcmp(literal(), "for")) return TOK_FOR; - if (literal_ == "return") + if (!strcmp(literal(), "return")) return TOK_RETURN; - if (literal_ == "if") + if (!strcmp(literal(), "if")) return TOK_IF; - if (literal_ == "else") + if (!strcmp(literal(), "else")) return TOK_ELSE; - if (literal_ == "enum") + if (!strcmp(literal(), "enum")) return TOK_ENUM; - if (literal_ == "while") + if (!strcmp(literal(), "while")) return TOK_WHILE; - if (literal_ == "do") + if (!strcmp(literal(), "do")) return TOK_DO; - if (literal_ == "break") + if (!strcmp(literal(), "break")) return TOK_BREAK; - if (literal_ == "continue") + if (!strcmp(literal(), "continue")) return TOK_CONTINUE; - if (literal_ == "forward") + if (!strcmp(literal(), "forward")) return TOK_FORWARD; - if (literal_ == "public") + if (!strcmp(literal(), "public")) return TOK_PUBLIC; - if (literal_ == "const") + if (!strcmp(literal(), "const")) return TOK_CONST; - if (literal_ == "native") + if (!strcmp(literal(), "native")) return TOK_NATIVE; return (c == ':') ? TOK_LABEL : TOK_NAME; } diff -r 5f4402180204 -r e3974e7360e9 src/Scanner.h --- a/src/Scanner.h Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Scanner.h Wed Jul 25 01:30:33 2012 -0700 @@ -21,6 +21,7 @@ #include #include "Token.h" #include "CompileContext.h" +#include "Vector.h" namespace ke { @@ -32,7 +33,7 @@ bool pushed_; char saved_; const char *pos_; - std::string literal_; + Vector literal_; TokenKind lastToken_; SourcePosition last_; SourcePosition cur_; @@ -69,10 +70,10 @@ // Note: the literal may have embedded NUL characters. const char *literal() const { - return literal_.c_str(); + return literal_.buffer(); } size_t literal_length() const { - return literal_.size(); + return literal_.length() - 1; } }; diff -r 5f4402180204 -r e3974e7360e9 src/Scopes.cpp --- a/src/Scopes.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Scopes.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -23,6 +23,8 @@ #include "Strings.h" #include "CompileContext.h" #include "Environments.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/SemanticAnalysis.cpp --- a/src/SemanticAnalysis.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/SemanticAnalysis.cpp Wed Jul 25 01:30:33 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 "SemanticAnalysis.h" #include "Types.h" #include "Zone.h" @@ -560,7 +561,7 @@ cc_.reportError(expr->pos(), Message_BadArraySize); return; } - if (size >= INT_MAX / sizeof(int)) { + if (size >= int(INT_MAX / sizeof(int))) { cc_.reportError(expr->pos(), Message_ArraySizeTooBig); return; } diff -r 5f4402180204 -r e3974e7360e9 src/Spaces.cpp --- a/src/Spaces.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Spaces.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -21,6 +21,7 @@ #include "Spaces.h" #include "Platform.h" #include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/StringPool.cpp --- a/src/StringPool.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/StringPool.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -15,9 +15,12 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include "Zone.h" #include "StringPool.h" #include "Strings.h" #include "Spaces.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/Structures.cpp --- a/src/Structures.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Structures.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -18,6 +18,8 @@ */ #include "Structures.h" #include "Types.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/TypeManager.cpp --- a/src/TypeManager.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/TypeManager.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -16,11 +16,13 @@ * 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 #include "Types.h" #include "TypeManager.h" #include "Zone.h" #include "Strings.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/Types.cpp --- a/src/Types.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Types.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -15,7 +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 #include "Types.h" #include "Zone.h" #include "Strings.h" diff -r 5f4402180204 -r e3974e7360e9 src/Utility.h --- a/src/Utility.h Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Utility.h Wed Jul 25 01:30:33 2012 -0700 @@ -20,6 +20,7 @@ #define _include_jitcraft_utility_h_ #include +#include #include #ifdef _MSC_VER # include diff -r 5f4402180204 -r e3974e7360e9 src/Zone.cpp --- a/src/Zone.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/Zone.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -23,6 +23,8 @@ #include "GlobalRoots.h" #include "AllocatorPolicies.h" #include "Array.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; diff -r 5f4402180204 -r e3974e7360e9 src/main.cpp --- a/src/main.cpp Wed Jul 25 00:48:08 2012 -0700 +++ b/src/main.cpp Wed Jul 25 01:30:33 2012 -0700 @@ -27,6 +27,8 @@ #include "Modules.h" #include "RootScopes.h" #include "../include/keima.h" +#include "Spaces-inl.h" +#include "Heap-inl.h" using namespace ke; @@ -130,3 +132,31 @@ Ke::Keima::Shutdown(); } + +/* Overload a few things to prevent libstdc++ linking */ +#if defined __linux__ || defined __APPLE__ +extern "C" void __cxa_pure_virtual(void) +{ +} + +void *operator new(size_t size) +{ + return malloc(size); +} + +void *operator new[](size_t size) +{ + return malloc(size); +} + +void operator delete(void *ptr) +{ + free(ptr); +} + +void operator delete[](void * ptr) +{ + free(ptr); +} +#endif +