jitcraft/Types.cpp
author David Anderson <dvander@alliedmods.net>
Wed Jun 27 02:21:56 2012 -0700 (2012-06-27)
changeset 4 633176823669
parent 3 f43e399ab622
child 11 a350c2cc736a
permissions -rw-r--r--
Add support for float variables and basic math.
     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 "Types.h"
    19 
    20 using namespace jc;
    21 
    22 Type *
    23 Type::NewPrimitive(Name *tag)
    24 {
    25     Type *type = new Type;
    26     type->kind_ = PRIMITIVE;
    27     type->tag_ = tag;
    28     
    29     if (tag && strcmp(tag, "Float") == 0)
    30         type->primitive_ = PrimitiveType_Float;
    31     else
    32         type->primitive_ = PrimitiveType_Int32;
    33     return type;
    34 }
    35 
    36 Type *
    37 Type::NewPrimitive(PrimitiveType prim)
    38 {
    39     Type *type = new Type;
    40     type->kind_ = PRIMITIVE;
    41     type->tag_ = NULL;
    42     type->primitive_ = prim;
    43     return type;
    44 }
    45 
    46 Type *
    47 Type::NewUnsafeArray(Type *contained, int elements)
    48 {
    49     Type *type = new Type;
    50     type->kind_ = UNSAFE_ARRAY;
    51     type->contained_ = contained;
    52     type->elements_ = elements;
    53     if (contained->isPrimitive())
    54         type->levels_ = 1;
    55     else
    56         type->levels_ = contained->levels() + 1;
    57     return type;
    58 }