Add GCC/Linux support.
Add GCC/Linux support.
1.1 --- a/AMBuildScript Wed Jul 25 00:48:08 2012 -0700
1.2 +++ b/AMBuildScript Wed Jul 25 01:30:33 2012 -0700
1.3 @@ -54,11 +54,14 @@
1.4 self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof')
1.5
1.6 # This would otherwise forbid ((x = y) == NULL) in clang apparently.
1.7 - self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic')
1.8 + if self.vendor == 'clang':
1.9 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic')
1.10
1.11 if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
1.12 (self.vendor == 'clang' and cxx.majorVersion >= 3):
1.13 self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
1.14 +
1.15 + self.compiler.AddToListVar('POSTLINKFLAGS', '-lm')
1.16 elif isinstance(cxx, Cpp.MSVC):
1.17 self.vendor = 'msvc'
1.18 if AMBuild.options.debug == '1':
2.1 --- a/src/API.cpp Wed Jul 25 00:48:08 2012 -0700
2.2 +++ b/src/API.cpp Wed Jul 25 01:30:33 2012 -0700
2.3 @@ -16,6 +16,7 @@
2.4 * You should have received a copy of the GNU General Public License along with
2.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
2.6 */
2.7 +#include <string.h>
2.8 #include "../include/keima.h"
2.9 #include "Zone.h"
2.10 #include "RootScopes.h"
2.11 @@ -31,6 +32,8 @@
2.12 #include "Interpreter.h"
2.13 #include "Stack.h"
2.14 #include "Strings.h"
2.15 +#include "Spaces-inl.h"
2.16 +#include "Heap-inl.h"
2.17
2.18 using namespace ke;
2.19
3.1 --- a/src/BytecodeCompiler.cpp Wed Jul 25 00:48:08 2012 -0700
3.2 +++ b/src/BytecodeCompiler.cpp Wed Jul 25 01:30:33 2012 -0700
3.3 @@ -16,6 +16,7 @@
3.4 * You should have received a copy of the GNU General Public License along with
3.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
3.6 */
3.7 +#include <string.h>
3.8 #include "BytecodeCompiler.h"
3.9 #include "Scopes.h"
3.10 #include "Modules.h"
4.1 --- a/src/BytecodeEmitter.cpp Wed Jul 25 00:48:08 2012 -0700
4.2 +++ b/src/BytecodeEmitter.cpp Wed Jul 25 01:30:33 2012 -0700
4.3 @@ -21,6 +21,8 @@
4.4 #include "Utility.h"
4.5 #include "Types.h"
4.6 #include "Zone.h"
4.7 +#include "Spaces-inl.h"
4.8 +#include "Heap-inl.h"
4.9
4.10 using namespace ke;
4.11
5.1 --- a/src/CompileContext.cpp Wed Jul 25 00:48:08 2012 -0700
5.2 +++ b/src/CompileContext.cpp Wed Jul 25 01:30:33 2012 -0700
5.3 @@ -19,6 +19,8 @@
5.4 #include "Scanner.h"
5.5 #include "CompileContext.h"
5.6 #include "Zone.h"
5.7 +#include "Spaces-inl.h"
5.8 +#include "Heap-inl.h"
5.9
5.10 using namespace ke;
5.11
6.1 --- a/src/Environments.cpp Wed Jul 25 00:48:08 2012 -0700
6.2 +++ b/src/Environments.cpp Wed Jul 25 01:30:33 2012 -0700
6.3 @@ -15,12 +15,15 @@
6.4 * You should have received a copy of the GNU General Public License along with
6.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
6.6 */
6.7 +#include <string.h>
6.8 #include "Utility.h"
6.9 #include "Environments.h"
6.10 #include "Structures.h"
6.11 #include "FixedArray.h"
6.12 #include "Zone.h"
6.13 #include "NameBinding.h"
6.14 +#include "Spaces-inl.h"
6.15 +#include "Heap-inl.h"
6.16
6.17 using namespace ke;
6.18
7.1 --- a/src/GlobalRoots.cpp Wed Jul 25 00:48:08 2012 -0700
7.2 +++ b/src/GlobalRoots.cpp Wed Jul 25 01:30:33 2012 -0700
7.3 @@ -17,6 +17,8 @@
7.4 */
7.5 #include "GlobalRoots.h"
7.6 #include "Zone.h"
7.7 +#include "Spaces-inl.h"
7.8 +#include "Heap-inl.h"
7.9
7.10 using namespace ke;
7.11
8.1 --- a/src/GlobalRoots.h Wed Jul 25 00:48:08 2012 -0700
8.2 +++ b/src/GlobalRoots.h Wed Jul 25 01:30:33 2012 -0700
8.3 @@ -18,6 +18,7 @@
8.4 #ifndef _include_ke_global_roots_h_
8.5 #define _include_ke_global_roots_h_
8.6
8.7 +#include "Utility.h"
8.8 #include "Handles.h"
8.9 #include "InlineList.h"
8.10 #include "VirtualObjectVisitor.h"
9.1 --- a/src/Handles-inl.h Wed Jul 25 00:48:08 2012 -0700
9.2 +++ b/src/Handles-inl.h Wed Jul 25 01:30:33 2012 -0700
9.3 @@ -19,43 +19,10 @@
9.4 #define _include_jitcraft_rooting_inl_h_
9.5
9.6 #include "Heap.h"
9.7 +#include "Zone.h"
9.8
9.9 namespace ke {
9.10
9.11 -template <typename T>
9.12 -Local<T>::Local(Environment *env)
9.13 - : zone_(env->zone()), thing_(NULL)
9.14 -{
9.15 - prev_ = zone_->registerThingLocal(toRaw());
9.16 -}
9.17 -
9.18 -template <typename T>
9.19 -Local<T>::Local(Environment *env, T *thing)
9.20 - : zone_(env->zone()), thing_(thing)
9.21 -{
9.22 - prev_ = zone_->registerThingLocal(toRaw());
9.23 -}
9.24 -
9.25 -template <typename T>
9.26 -Local<T>::Local(Zone *zone)
9.27 - : zone_(zone), thing_(NULL)
9.28 -{
9.29 - prev_ = zone_->registerThingLocal(toRaw());
9.30 -}
9.31 -
9.32 -template <typename T>
9.33 -Local<T>::Local(Zone *zone, T *thing)
9.34 - : zone_(zone), thing_(thing)
9.35 -{
9.36 - prev_ = zone_->registerThingLocal(toRaw());
9.37 -}
9.38 -
9.39 -
9.40 -template <typename T>
9.41 -Local<T>::~Local()
9.42 -{
9.43 - zone_->deregisterThingLocal(toRaw(), prev_);
9.44 -}
9.45
9.46 }
9.47
10.1 --- a/src/NameBinding.cpp Wed Jul 25 00:48:08 2012 -0700
10.2 +++ b/src/NameBinding.cpp Wed Jul 25 01:30:33 2012 -0700
10.3 @@ -19,6 +19,8 @@
10.4 #include "Strings.h"
10.5 #include "Zone.h"
10.6 #include "Scopes.h"
10.7 +#include "Spaces-inl.h"
10.8 +#include "Heap-inl.h"
10.9
10.10 using namespace ke;
10.11
11.1 --- a/src/Parser.cpp Wed Jul 25 00:48:08 2012 -0700
11.2 +++ b/src/Parser.cpp Wed Jul 25 01:30:33 2012 -0700
11.3 @@ -16,6 +16,7 @@
11.4 * You should have received a copy of the GNU General Public License along with
11.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
11.6 */
11.7 +#include <string.h>
11.8 #include "Zone.h"
11.9 #include "Parser.h"
11.10 #include "FixedArray.h"
12.1 --- a/src/Platform-Posix.cpp Wed Jul 25 00:48:08 2012 -0700
12.2 +++ b/src/Platform-Posix.cpp Wed Jul 25 01:30:33 2012 -0700
12.3 @@ -72,7 +72,7 @@
12.4 }
12.5
12.6 size_t requested = Min(amount * 2, amount + 2 * alignment);
12.7 - Address address = MapMemory(amount, mode, Prot_ReadWrite);
12.8 + Address address = MapMemory(requested, mode, Prot_ReadWrite);
12.9 if (!address)
12.10 return AlignableMapping();
12.11
12.12 @@ -87,7 +87,7 @@
12.13
12.14 if (requested - begin > amount) {
12.15 // Shave off the last part of the unaligned region.
12.16 - UnmapAlignedMemory(address + amount, requested - amount - begin);
12.17 + UnmapAlignedMemory(aligned + amount, requested - amount - begin);
12.18 }
12.19
12.20 return AlignableMapping(aligned, alignment, amount);
13.1 --- a/src/PoolAllocator.cpp Wed Jul 25 00:48:08 2012 -0700
13.2 +++ b/src/PoolAllocator.cpp Wed Jul 25 01:30:33 2012 -0700
13.3 @@ -20,6 +20,8 @@
13.4 #include <new>
13.5 #include "PoolAllocator.h"
13.6 #include "Zone.h"
13.7 +#include "Spaces-inl.h"
13.8 +#include "Heap-inl.h"
13.9
13.10 using namespace ke;
13.11
14.1 --- a/src/Scanner.cpp Wed Jul 25 00:48:08 2012 -0700
14.2 +++ b/src/Scanner.cpp Wed Jul 25 01:30:33 2012 -0700
14.3 @@ -1,4 +1,5 @@
14.4 -/*
14.5 +/* vim: set ts=4 sw=4 tw=99 et:
14.6 + *
14.7 * Copyright (C) 2012 David Anderson
14.8 *
14.9 * This file is part of JITCraft.
14.10 @@ -18,6 +19,8 @@
14.11 #include <assert.h>
14.12 #include <ctype.h>
14.13 #include <math.h>
14.14 +#include <limits.h>
14.15 +#include <string.h>
14.16 #include "Scanner.h"
14.17 #include "Utility.h"
14.18
14.19 @@ -263,76 +266,97 @@
14.20 return TOK_ERROR;
14.21 c = char(code);
14.22 }
14.23 - literal_ += c;
14.24 + if (!literal_.append(c))
14.25 + return TOK_ERROR;
14.26 }
14.27
14.28 + if (!literal_.append('\0'))
14.29 + return TOK_ERROR;
14.30 +
14.31 return TOK_STRING_LITERAL;
14.32 }
14.33
14.34 TokenKind
14.35 Scanner::numberLiteral(char first)
14.36 {
14.37 - literal_ = first;
14.38 + literal_.clear();
14.39 + if (!literal_.append(first))
14.40 + return TOK_ERROR;
14.41
14.42 char c;
14.43 for (;;) {
14.44 c = getChar();
14.45 if (!IsDigit(c))
14.46 break;
14.47 - literal_ += c;
14.48 + if (!literal_.append(c))
14.49 + return TOK_ERROR;
14.50 }
14.51
14.52 if (c != '.') {
14.53 putChar(c);
14.54 + if (!literal_.append('\0'))
14.55 + return TOK_ERROR;
14.56 return TOK_INTEGER_LITERAL;
14.57 }
14.58 - literal_ += c;
14.59 + if (!literal_.append(c))
14.60 + return TOK_ERROR;
14.61
14.62 c = getChar();
14.63 if (!IsDigit(c)) {
14.64 cc_.reportError(begin(), Message_ExpectedDigitForFloat, c);
14.65 return TOK_ERROR;
14.66 }
14.67 - literal_ += c;
14.68 + if (!literal_.append(c))
14.69 + return TOK_ERROR;
14.70
14.71 for (;;) {
14.72 c = getChar();
14.73 if (!IsDigit(c))
14.74 break;
14.75 - literal_ += c;
14.76 + if (!literal_.append(c))
14.77 + return TOK_ERROR;
14.78 }
14.79
14.80 if (c != 'e') {
14.81 putChar(c);
14.82 } else {
14.83 - literal_ += c;
14.84 + if (!literal_.append(c))
14.85 + return TOK_ERROR;
14.86 c = getChar();
14.87 if (c == '-') {
14.88 - literal_ += c;
14.89 + if (!literal_.append(c))
14.90 + return TOK_ERROR;
14.91 c = getChar();
14.92 }
14.93 if (!IsDigit(c)) {
14.94 cc_.reportError(begin(), Message_ExpectedDigitForFloat, c);
14.95 return TOK_ERROR;
14.96 }
14.97 - literal_ += c;
14.98 + if (!literal_.append(c))
14.99 + return TOK_ERROR;
14.100 for (;;) {
14.101 c = getChar();
14.102 if (!IsDigit(c)) {
14.103 putChar(c);
14.104 break;
14.105 }
14.106 - literal_ += c;
14.107 + if (!literal_.append(c))
14.108 + return TOK_ERROR;
14.109 }
14.110 }
14.111
14.112 + if (!literal_.append('\0'))
14.113 + return TOK_ERROR;
14.114 +
14.115 return TOK_FLOAT_LITERAL;
14.116 }
14.117
14.118 TokenKind
14.119 Scanner::identifier(char first)
14.120 {
14.121 - literal_ = first;
14.122 + literal_.clear();
14.123 + if (!literal_.append(first))
14.124 + return TOK_ERROR;
14.125
14.126 char c;
14.127 for (;;) {
14.128 @@ -342,36 +366,40 @@
14.129 putChar(c);
14.130 break;
14.131 }
14.132 - literal_ += c;
14.133 + if (!literal_.append(c))
14.134 + return TOK_ERROR;
14.135 }
14.136
14.137 - if (literal_ == "new")
14.138 + if (!literal_.append('\0'))
14.139 + return TOK_ERROR;
14.140 +
14.141 + if (!strcmp(literal(), "new"))
14.142 return TOK_NEW;
14.143 - if (literal_ == "for")
14.144 + if (!strcmp(literal(), "for"))
14.145 return TOK_FOR;
14.146 - if (literal_ == "return")
14.147 + if (!strcmp(literal(), "return"))
14.148 return TOK_RETURN;
14.149 - if (literal_ == "if")
14.150 + if (!strcmp(literal(), "if"))
14.151 return TOK_IF;
14.152 - if (literal_ == "else")
14.153 + if (!strcmp(literal(), "else"))
14.154 return TOK_ELSE;
14.155 - if (literal_ == "enum")
14.156 + if (!strcmp(literal(), "enum"))
14.157 return TOK_ENUM;
14.158 - if (literal_ == "while")
14.159 + if (!strcmp(literal(), "while"))
14.160 return TOK_WHILE;
14.161 - if (literal_ == "do")
14.162 + if (!strcmp(literal(), "do"))
14.163 return TOK_DO;
14.164 - if (literal_ == "break")
14.165 + if (!strcmp(literal(), "break"))
14.166 return TOK_BREAK;
14.167 - if (literal_ == "continue")
14.168 + if (!strcmp(literal(), "continue"))
14.169 return TOK_CONTINUE;
14.170 - if (literal_ == "forward")
14.171 + if (!strcmp(literal(), "forward"))
14.172 return TOK_FORWARD;
14.173 - if (literal_ == "public")
14.174 + if (!strcmp(literal(), "public"))
14.175 return TOK_PUBLIC;
14.176 - if (literal_ == "const")
14.177 + if (!strcmp(literal(), "const"))
14.178 return TOK_CONST;
14.179 - if (literal_ == "native")
14.180 + if (!strcmp(literal(), "native"))
14.181 return TOK_NATIVE;
14.182 return (c == ':') ? TOK_LABEL : TOK_NAME;
14.183 }
15.1 --- a/src/Scanner.h Wed Jul 25 00:48:08 2012 -0700
15.2 +++ b/src/Scanner.h Wed Jul 25 01:30:33 2012 -0700
15.3 @@ -21,6 +21,7 @@
15.4 #include <string>
15.5 #include "Token.h"
15.6 #include "CompileContext.h"
15.7 +#include "Vector.h"
15.8
15.9 namespace ke {
15.10
15.11 @@ -32,7 +33,7 @@
15.12 bool pushed_;
15.13 char saved_;
15.14 const char *pos_;
15.15 - std::string literal_;
15.16 + Vector<char> literal_;
15.17 TokenKind lastToken_;
15.18 SourcePosition last_;
15.19 SourcePosition cur_;
15.20 @@ -69,10 +70,10 @@
15.21
15.22 // Note: the literal may have embedded NUL characters.
15.23 const char *literal() const {
15.24 - return literal_.c_str();
15.25 + return literal_.buffer();
15.26 }
15.27 size_t literal_length() const {
15.28 - return literal_.size();
15.29 + return literal_.length() - 1;
15.30 }
15.31 };
15.32
16.1 --- a/src/Scopes.cpp Wed Jul 25 00:48:08 2012 -0700
16.2 +++ b/src/Scopes.cpp Wed Jul 25 01:30:33 2012 -0700
16.3 @@ -23,6 +23,8 @@
16.4 #include "Strings.h"
16.5 #include "CompileContext.h"
16.6 #include "Environments.h"
16.7 +#include "Spaces-inl.h"
16.8 +#include "Heap-inl.h"
16.9
16.10 using namespace ke;
16.11
17.1 --- a/src/SemanticAnalysis.cpp Wed Jul 25 00:48:08 2012 -0700
17.2 +++ b/src/SemanticAnalysis.cpp Wed Jul 25 01:30:33 2012 -0700
17.3 @@ -16,6 +16,7 @@
17.4 * You should have received a copy of the GNU General Public License along with
17.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
17.6 */
17.7 +#include <string.h>
17.8 #include "SemanticAnalysis.h"
17.9 #include "Types.h"
17.10 #include "Zone.h"
17.11 @@ -560,7 +561,7 @@
17.12 cc_.reportError(expr->pos(), Message_BadArraySize);
17.13 return;
17.14 }
17.15 - if (size >= INT_MAX / sizeof(int)) {
17.16 + if (size >= int(INT_MAX / sizeof(int))) {
17.17 cc_.reportError(expr->pos(), Message_ArraySizeTooBig);
17.18 return;
17.19 }
18.1 --- a/src/Spaces.cpp Wed Jul 25 00:48:08 2012 -0700
18.2 +++ b/src/Spaces.cpp Wed Jul 25 01:30:33 2012 -0700
18.3 @@ -21,6 +21,7 @@
18.4 #include "Spaces.h"
18.5 #include "Platform.h"
18.6 #include "Spaces-inl.h"
18.7 +#include "Heap-inl.h"
18.8
18.9 using namespace ke;
18.10
19.1 --- a/src/StringPool.cpp Wed Jul 25 00:48:08 2012 -0700
19.2 +++ b/src/StringPool.cpp Wed Jul 25 01:30:33 2012 -0700
19.3 @@ -15,9 +15,12 @@
19.4 * You should have received a copy of the GNU General Public License along with
19.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
19.6 */
19.7 +#include "Zone.h"
19.8 #include "StringPool.h"
19.9 #include "Strings.h"
19.10 #include "Spaces.h"
19.11 +#include "Spaces-inl.h"
19.12 +#include "Heap-inl.h"
19.13
19.14 using namespace ke;
19.15
20.1 --- a/src/Structures.cpp Wed Jul 25 00:48:08 2012 -0700
20.2 +++ b/src/Structures.cpp Wed Jul 25 01:30:33 2012 -0700
20.3 @@ -18,6 +18,8 @@
20.4 */
20.5 #include "Structures.h"
20.6 #include "Types.h"
20.7 +#include "Spaces-inl.h"
20.8 +#include "Heap-inl.h"
20.9
20.10 using namespace ke;
20.11
21.1 --- a/src/TypeManager.cpp Wed Jul 25 00:48:08 2012 -0700
21.2 +++ b/src/TypeManager.cpp Wed Jul 25 01:30:33 2012 -0700
21.3 @@ -16,11 +16,13 @@
21.4 * You should have received a copy of the GNU General Public License along with
21.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
21.6 */
21.7 -#include <strings.h>
21.8 +#include <string.h>
21.9 #include "Types.h"
21.10 #include "TypeManager.h"
21.11 #include "Zone.h"
21.12 #include "Strings.h"
21.13 +#include "Spaces-inl.h"
21.14 +#include "Heap-inl.h"
21.15
21.16 using namespace ke;
21.17
22.1 --- a/src/Types.cpp Wed Jul 25 00:48:08 2012 -0700
22.2 +++ b/src/Types.cpp Wed Jul 25 01:30:33 2012 -0700
22.3 @@ -15,7 +15,7 @@
22.4 * You should have received a copy of the GNU General Public License along with
22.5 * JITCraft. If not, see http://www.gnu.org/licenses/.
22.6 */
22.7 -#include <strings.h>
22.8 +#include <string.h>
22.9 #include "Types.h"
22.10 #include "Zone.h"
22.11 #include "Strings.h"
23.1 --- a/src/Utility.h Wed Jul 25 00:48:08 2012 -0700
23.2 +++ b/src/Utility.h Wed Jul 25 01:30:33 2012 -0700
23.3 @@ -20,6 +20,7 @@
23.4 #define _include_jitcraft_utility_h_
23.5
23.6 #include <assert.h>
23.7 +#include <stddef.h>
23.8 #include <stdint.h>
23.9 #ifdef _MSC_VER
23.10 # include <intrin.h>
24.1 --- a/src/Zone.cpp Wed Jul 25 00:48:08 2012 -0700
24.2 +++ b/src/Zone.cpp Wed Jul 25 01:30:33 2012 -0700
24.3 @@ -23,6 +23,8 @@
24.4 #include "GlobalRoots.h"
24.5 #include "AllocatorPolicies.h"
24.6 #include "Array.h"
24.7 +#include "Spaces-inl.h"
24.8 +#include "Heap-inl.h"
24.9
24.10 using namespace ke;
24.11
25.1 --- a/src/main.cpp Wed Jul 25 00:48:08 2012 -0700
25.2 +++ b/src/main.cpp Wed Jul 25 01:30:33 2012 -0700
25.3 @@ -27,6 +27,8 @@
25.4 #include "Modules.h"
25.5 #include "RootScopes.h"
25.6 #include "../include/keima.h"
25.7 +#include "Spaces-inl.h"
25.8 +#include "Heap-inl.h"
25.9
25.10 using namespace ke;
25.11
25.12 @@ -130,3 +132,31 @@
25.13
25.14 Ke::Keima::Shutdown();
25.15 }
25.16 +
25.17 +/* Overload a few things to prevent libstdc++ linking */
25.18 +#if defined __linux__ || defined __APPLE__
25.19 +extern "C" void __cxa_pure_virtual(void)
25.20 +{
25.21 +}
25.22 +
25.23 +void *operator new(size_t size)
25.24 +{
25.25 + return malloc(size);
25.26 +}
25.27 +
25.28 +void *operator new[](size_t size)
25.29 +{
25.30 + return malloc(size);
25.31 +}
25.32 +
25.33 +void operator delete(void *ptr)
25.34 +{
25.35 + free(ptr);
25.36 +}
25.37 +
25.38 +void operator delete[](void * ptr)
25.39 +{
25.40 + free(ptr);
25.41 +}
25.42 +#endif
25.43 +