Convert AST std::vector to PoolList.
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 "AllocatorPolicies.h"
26 Zone jc::SingleThreadedZone;
44 if (!stack_.initialize())
46 if (!heap_.initialize())
49 symbols_ = new StringPool(this);
50 if (!symbols_ || !symbols_->initialize())
53 maps_[MapKind_Meta] = heap_.metaMap();
54 if ((maps_[MapKind_Type] = allocateMap(MapKind_Type, sizeof(Map))) == NULL)
56 if ((maps_[MapKind_FixedArray] = allocateMap(MapKind_FixedArray, sizeof(Map))) == NULL)
58 if ((maps_[MapKind_ByteArray] = allocateMap(MapKind_ByteArray, sizeof(Map))) == NULL)
60 if ((maps_[MapKind_Code] = allocateMap(MapKind_Code, sizeof(Map))) == NULL)
62 if ((maps_[MapKind_Reference] = allocateMap(MapKind_Reference, sizeof(Map))) == NULL)
64 if ((maps_[MapKind_MetaArray] = allocateMap(MapKind_MetaArray, sizeof(Map))) == NULL)
66 if ((maps_[MapKind_Module] = allocateMap(MapKind_Module, sizeof(Map))) == NULL)
68 if ((maps_[MapKind_Function] = allocateMap(MapKind_Function, sizeof(Map))) == NULL)
70 if ((maps_[MapKind_String] = allocateMap(MapKind_String, sizeof(Map))) == NULL)
72 if ((maps_[MapKind_FreeRegion] = allocateMap(MapKind_FreeRegion, sizeof(Map))) == NULL)
75 types_ = new TypeManager(this);
76 if (!types_ || !types_->initialize())
83 Zone::allocateMap(MapKind kind, size_t bytes, MapKind parent)
85 assert(maps_[parent]);
86 Map *map = heap_.allocateMap(kind, bytes);
89 map->init(maps_[parent]);
94 Zone::accept(VirtualObjectVisitor *visitor)
96 for (unsigned i = 0; i < MapKinds_Total; i++)
97 visitor->visit(maps_[i].address());
98 types()->accept(visitor);
100 Local<Object> *local = lastLocalRoot_;
102 visitor->visit(local->address());
103 local = local->prev();
106 rootScopes_.accept(visitor);
108 stack_.accept(visitor);
112 Zone::makeSymbol(const char *str, size_t length)
114 return symbols_->add(str, length);
118 Zone::makeSymbol(const char *str)
120 return makeSymbol(str, strlen(str));
124 ZoneAllocatorPolicy::reportOutOfMemory()
131 ZoneAllocatorPolicy::reportAllocationOverflow()