jitcraft/Reference.cpp
author David Anderson <dvander@alliedmods.net>
Sun Jul 01 16:36:39 2012 -0700 (2012-07-01)
changeset 22 765ab1b672a3
parent 18 ffd4ddec7b2e
child 39 158f476b92b3
permissions -rw-r--r--
Added support for fused math-assign ops (+=, etc).
     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 jc;
    24 
    25 Reference *
    26 Reference::NewStack(Zone *zone, void *location, Heap::Tenure tenure)
    27 {
    28     Object *obj = zone->allocate(MapKind_Reference, sizeof(Reference), tenure);
    29     if (!obj)
    30         return NULL;
    31 
    32     Reference *ref = Reference::cast(obj);
    33     ref->location_ = location;
    34     return ref;
    35 }
    36 
    37 Reference *
    38 Reference::NewStack(Zone *zone, const LocalSlot &slot, Heap::Tenure tenure)
    39 {
    40     Object *obj = zone->allocate(MapKind_Reference, sizeof(Reference), tenure);
    41     if (!obj)
    42         return NULL;
    43 
    44     Reference *ref = Reference::cast(obj);
    45     ref->location_ = &ref->slot_;
    46     ref->slot_ = slot;
    47     return ref;
    48 }
    49 
    50 Reference *
    51 Reference::NewArray(Zone *zone, Array *base, size_t index, Heap::Tenure tenure)
    52 {
    53     Object *obj = zone->allocate(MapKind_Reference, sizeof(Reference), tenure);
    54     if (!obj)
    55         return NULL;
    56 
    57     Reference *ref = Reference::cast(obj);
    58     ref->location_ = base->slotPtr(index);
    59     ref->base_ = base;
    60     return ref;
    61 }