1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/Box.cpp Sun Aug 05 21:24:41 2012 -0700
1.3 @@ -0,0 +1,63 @@
1.4 +/* vim: set ts=4 sw=4 tw=99 et:
1.5 + *
1.6 + * Copyright (C) 2012 David Anderson
1.7 + *
1.8 + * This file is part of SourcePawn.
1.9 + *
1.10 + * SourcePawn is free software: you can redistribute it and/or modify it under
1.11 + * the terms of the GNU General Public License as published by the Free
1.12 + * Software Foundation, either version 3 of the License, or (at your option)
1.13 + * any later version.
1.14 + *
1.15 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
1.16 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License along with
1.20 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
1.21 + */
1.22 +#include "Box.h"
1.23 +#include "Zone.h"
1.24 +#include "Types.h"
1.25 +#include "Heap-inl.h"
1.26 +
1.27 +using namespace ke;
1.28 +
1.29 +Box *Box::New(Zone *zone, Handle<Type> type, int i32, Heap::Tenure tenure)
1.30 +{
1.31 + Local<Box> box(zone, Box::cast(zone->allocate(MapKind_Box, sizeof(Box), tenure)));
1.32 + if (!box)
1.33 + return NULL;
1.34 +
1.35 + assert(type->pod() == PrimitiveType_Int32);
1.36 + box->u.i32 = i32;
1.37 + box->type_ = type;
1.38 + return box;
1.39 +}
1.40 +
1.41 +Box *
1.42 +Box::New(Zone *zone, Handle<Type> type, float f, Heap::Tenure tenure)
1.43 +{
1.44 + Local<Box> box(zone, Box::cast(zone->allocate(MapKind_Box, sizeof(Box), tenure)));
1.45 + if (!box)
1.46 + return NULL;
1.47 +
1.48 + assert(type->pod() == PrimitiveType_Float);
1.49 + box->u.f = f;
1.50 + box->type_ = type;
1.51 + return box;
1.52 +}
1.53 +
1.54 +Box *
1.55 +Box::New(Zone *zone, Handle<Type> type, Object *obj, Heap::Tenure tenure)
1.56 +{
1.57 + Local<Box> box(zone, Box::cast(zone->allocate(MapKind_Box, sizeof(Box), tenure)));
1.58 + if (!box)
1.59 + return NULL;
1.60 +
1.61 + assert(type->isTraceable());
1.62 + box->u.obj = obj;
1.63 + box->type_ = type;
1.64 + return box;
1.65 +}
1.66 +