src/Box.cpp
author David Anderson <dvander@alliedmods.net>
Sun Nov 18 15:00:08 2012 -0800 (2012-11-18)
changeset 214 e1a6deaa6ebe
parent 169 0456a16c2a63
permissions -rw-r--r--
Fix timeout handling in the test harness.
     1 /* vim: set ts=4 sw=4 tw=99 et:
     2  *
     3  * Copyright (C) 2012 David Anderson
     4  *
     5  * This file is part of SourcePawn.
     6  *
     7  * SourcePawn 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)
    10  * any later version.
    11  * 
    12  * SourcePawn 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.
    15  *
    16  * You should have received a copy of the GNU General Public License along with
    17  * SourcePawn. If not, see http://www.gnu.org/licenses/.
    18  */
    19 #include "Box.h"
    20 #include "Zone.h"
    21 #include "Types.h"
    22 #include "Heap-inl.h"
    23 
    24 using namespace ke;
    25 
    26 Box *Box::New(Zone *zone, Handle<Type> type, int i32, Heap::Tenure tenure)
    27 {
    28     Local<Box> box(zone, Box::cast(zone->allocate(MapKind_Box, sizeof(Box), tenure)));
    29     if (!box)
    30         return NULL;
    31 
    32     assert(type->pod() == PrimitiveType_Int32);
    33     box->u.i32 = i32;
    34     box->type_ = type;
    35     return box;
    36 }
    37 
    38 Box *
    39 Box::New(Zone *zone, Handle<Type> type, float f, Heap::Tenure tenure)
    40 {
    41     Local<Box> box(zone, Box::cast(zone->allocate(MapKind_Box, sizeof(Box), tenure)));
    42     if (!box)
    43         return NULL;
    44 
    45     assert(type->pod() == PrimitiveType_Float);
    46     box->u.f = f;
    47     box->type_ = type;
    48     return box;
    49 }
    50 
    51 Box *
    52 Box::NewObj(Zone *zone, Handle<Type> type, Handle<Object> obj, Heap::Tenure tenure)
    53 {
    54     Local<Box> box(zone, Box::cast(zone->allocate(MapKind_Box, sizeof(Box), tenure)));
    55     if (!box)
    56         return NULL;
    57 
    58     assert(type->isTraceable());
    59     box->u.obj = obj;
    60     box->type_ = type;
    61     return box;
    62 }
    63