Added support for ISourcePawnEngine natives.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
20 #include "StringPool.h"
21 #include "TypeManager.h"
22 #include "GlobalRoots.h"
23 #include "AllocatorPolicies.h"
28 Zone *ke::SingleThreadedZone;
49 if (!stack_.initialize())
51 if (!heap_.initialize())
54 symbols_ = new StringPool(this);
55 if (!symbols_ || !symbols_->initialize())
58 globalRoots_ = new GlobalRoots(this);
59 if (!globalRoots_ || !globalRoots_->initialize())
62 maps_[MapKind_Meta] = heap_.metaMap();
63 if ((maps_[MapKind_Type] = allocateMap(MapKind_Type, sizeof(Map))) == NULL)
65 if ((maps_[MapKind_FixedArray] = allocateMap(MapKind_FixedArray, sizeof(Map))) == NULL)
67 if ((maps_[MapKind_ByteArray] = allocateMap(MapKind_ByteArray, sizeof(Map))) == NULL)
69 if ((maps_[MapKind_Code] = allocateMap(MapKind_Code, sizeof(Map))) == NULL)
71 if ((maps_[MapKind_Reference] = allocateMap(MapKind_Reference, sizeof(Map))) == NULL)
73 if ((maps_[MapKind_MetaArray] = allocateMap(MapKind_MetaArray, sizeof(Map))) == NULL)
75 if ((maps_[MapKind_Module] = allocateMap(MapKind_Module, sizeof(Map))) == NULL)
77 if ((maps_[MapKind_Function] = allocateMap(MapKind_Function, sizeof(Map))) == NULL)
79 if ((maps_[MapKind_String] = allocateMap(MapKind_String, sizeof(Map))) == NULL)
81 if ((maps_[MapKind_Native] = allocateMap(MapKind_Native, sizeof(Map))) == NULL)
83 if ((maps_[MapKind_FreeRegion] = allocateMap(MapKind_FreeRegion, sizeof(Map))) == NULL)
86 types_ = new TypeManager(this);
87 if (!types_ || !types_->initialize())
90 // Create the cached array maps for generic arrays. This is for the API
91 // version of Invoke(), which needs to make arrays very quickly from C++.
93 // Generic "cell" array (contents do not matter, just non-gc things).
94 Local<Type> type(this, types_->getPrimitive(PrimitiveType_Int32));
98 type = types_->unsafeArray(type, Type::UNKNOWN_SIZE, false);
102 Local<ArrayMap> contained(this);
103 genericArrayMap_ = ArrayMap::New(this, type, contained);
104 if (!genericArrayMap_)
107 type = types_->getPrimitive(PrimitiveType_Char);
111 type = types_->unsafeArray(type, Type::UNKNOWN_SIZE, false);
115 charArrayMap_ = ArrayMap::New(this, type, contained);
124 Zone::allocateMap(MapKind kind, size_t bytes, MapKind parent)
126 assert(maps_[parent]);
127 Map *map = heap_.allocateMap(kind, bytes);
130 map->init(maps_[parent]);
135 Zone::accept(VirtualObjectVisitor *visitor)
137 for (unsigned i = 0; i < MapKinds_Total; i++)
138 visitor->visit(maps_[i].address());
139 visitor->visit(charArrayMap_.address());
140 visitor->visit(genericArrayMap_.address());
141 types()->accept(visitor);
143 Local<Object> *local = lastLocalRoot_;
145 visitor->visit(local->address());
146 local = local->prev();
149 globalRoots_->accept(visitor);
150 rootScopes_.accept(visitor);
152 stack_.accept(visitor);
156 Zone::makeSymbol(const char *str, size_t length)
158 return symbols_->add(str, length);
162 Zone::makeSymbol(const char *str)
164 return makeSymbol(str, strlen(str));
168 ZoneAllocatorPolicy::reportOutOfMemory()
175 ZoneAllocatorPolicy::reportAllocationOverflow()