jitcraft/Zone.cpp
author David Anderson <dvander@alliedmods.net>
Sat Jun 30 19:38:53 2012 -0700 (2012-06-30)
changeset 12 75e385f68b7e
parent 11 a350c2cc736a
child 14 0784ac5cc347
permissions -rw-r--r--
Refactored Array, Code to be Objects. Removed Object tagging.
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     6  * JITCraft is free software: you can redistribute it and/or modify it under
     7  * the terms of the GNU General Public License as published by the Free
     8  * Software Foundation, either version 3 of the License, or (at your option)
     9  * any later version.
    10  * 
    11  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along with
    16  * JITCraft. If not, see http://www.gnu.org/licenses/.
    17  */
    18 #include "Zone.h"
    19 #include "TypeManager.h"
    20 
    21 using namespace jc;
    22 
    23 Zone jc::SingleThreadedZone;
    24 
    25 Zone::Zone()
    26   : heap_(this),
    27     types_(NULL)
    28 {
    29 }
    30 
    31 bool
    32 Zone::initialize()
    33 {
    34     if (!stack_.initialize())
    35         return false;
    36     if (!heap_.initialize())
    37         return false;
    38 
    39     maps_[MapKind_Meta] = heap_.metaMap();
    40     if ((maps_[MapKind_Type] = allocateMap(MapKind_Type, sizeof(Map))) == NULL)
    41         return false;
    42     if ((maps_[MapKind_FixedArray] = allocateMap(MapKind_FixedArray, sizeof(Map))) == NULL)
    43         return false;
    44     if ((maps_[MapKind_ByteArray] = allocateMap(MapKind_ByteArray, sizeof(Map))) == NULL)
    45         return false;
    46     if ((maps_[MapKind_Code] = allocateMap(MapKind_Code, sizeof(Map))) == NULL)
    47         return false;
    48     if ((maps_[MapKind_MetaArray] = allocateMap(MapKind_MetaArray, sizeof(Map))) == NULL)
    49         return false;
    50 
    51     types_ = new TypeManager(this);
    52     if (!types_ || !types_->initialize())
    53         return false;
    54 
    55     return true;
    56 }
    57 
    58 Map *
    59 Zone::allocateMap(MapKind kind, size_t bytes, MapKind parent)
    60 {
    61     assert(maps_[parent]);
    62     Map *map = heap_.allocateMap(kind, bytes);
    63     if (!map)
    64         return NULL;
    65     map->init(maps_[parent]);
    66     return map;
    67 }