src/Reference.cpp
author David Anderson <dvander@alliedmods.net>
Sat Jul 28 16:42:38 2012 -0700 (2012-07-28)
changeset 108 9dcf58a17d32
parent 86 32ad0523b309
child 164 3bf7c007883d
permissions -rw-r--r--
Stop using ccache on OS X.
     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 "Reference.h"
    19 #include "Zone.h"
    20 #include "Array.h"
    21 #include "Heap-inl.h"
    22 
    23 using namespace ke;
    24 
    25 Reference *
    26 Reference::NewStack(Zone *zone, void *location, Heap::Tenure tenure)
    27 {
    28     Local<Reference> ref(zone, Reference::cast(zone->allocate(MapKind_Reference, sizeof(Reference), tenure)));
    29     if (!ref)
    30         return NULL;
    31 
    32     ref->location_ = location;
    33     return ref;
    34 }
    35 
    36 Reference *
    37 Reference::NewStack(Zone *zone, const LocalSlot &slot, Heap::Tenure tenure)
    38 {
    39     Local<Reference> ref(zone, Reference::cast(zone->allocate(MapKind_Reference, sizeof(Reference), tenure)));
    40     if (!ref)
    41         return NULL;
    42 
    43     ref->location_ = &ref->slot_;
    44     ref->slot_ = slot;
    45     return ref;
    46 }
    47 
    48 Reference *
    49 Reference::NewArray(Zone *zone, Handle<Array> base, size_t index, Heap::Tenure tenure)
    50 {
    51     Local<Reference> ref(zone, Reference::cast(zone->allocate(MapKind_Reference, sizeof(Reference), tenure)));
    52     if (!ref)
    53         return NULL;
    54 
    55     ref->location_ = base->slotPtr(index);
    56     ref->base_ = base;
    57     return ref;
    58 }