Handleized Type.
authorDavid Anderson <dvander@alliedmods.net>
Tue Jul 03 01:21:32 2012 -0700 (2012-07-03)
changeset 4134987baade41
parent 40 ce787d61fb71
child 42 97e089e19d7d
Handleized Type.
jitcraft/TypeManager.cpp
jitcraft/TypeManager.h
jitcraft/Types.cpp
jitcraft/Types.h
     1.1 --- a/jitcraft/TypeManager.cpp	Tue Jul 03 01:14:15 2012 -0700
     1.2 +++ b/jitcraft/TypeManager.cpp	Tue Jul 03 01:21:32 2012 -0700
     1.3 @@ -1,4 +1,5 @@
     1.4 -/*
     1.5 +/* vim: set ts=4 sw=4 tw=99 et:
     1.6 + *
     1.7   * Copyright (C) 2012 David Anderson
     1.8   *
     1.9   * This file is part of JITCraft.
    1.10 @@ -39,8 +40,10 @@
    1.11      if ((primitiveTypes_[PrimitiveType_Char] = Type::NewPrimitive(zone_, "String")) == NULL)
    1.12          return false;
    1.13  
    1.14 +    Local<Type> type(zone_);
    1.15      for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
    1.16 -        if ((referenceTypes_[i] = Type::NewReference(zone_, primitiveTypes_[i])) == NULL)
    1.17 +        type = primitiveTypes_[i];
    1.18 +        if ((referenceTypes_[i] = Type::NewReference(zone_, type)) == NULL)
    1.19              return false;
    1.20      }
    1.21  
    1.22 @@ -60,14 +63,14 @@
    1.23  }
    1.24  
    1.25  Type *
    1.26 -TypeManager::unsafeArray(Type *contained, int elements)
    1.27 +TypeManager::unsafeArray(Handle<Type> contained, int elements)
    1.28  {
    1.29      // :TODO: cache this.
    1.30      return Type::NewArray(zone_, contained, elements, false);
    1.31  }
    1.32  
    1.33  Type *
    1.34 -TypeManager::getReference(Type *type)
    1.35 +TypeManager::getReference(Handle<Type> type)
    1.36  {
    1.37      if (type->isFloat() || (type->isInt32() && !type->tag()))
    1.38          return referenceTypes_[type->primitive()];
    1.39 @@ -77,7 +80,7 @@
    1.40  }
    1.41  
    1.42  Type *
    1.43 -TypeManager::newFunction(Type *returnType, FixedArray *args)
    1.44 +TypeManager::newFunction(Handle<Type> returnType, Handle<FixedArray> args)
    1.45  {
    1.46      // :TODO: cache this.
    1.47      return Type::NewFunction(zone_, returnType, args);
     2.1 --- a/jitcraft/TypeManager.h	Tue Jul 03 01:14:15 2012 -0700
     2.2 +++ b/jitcraft/TypeManager.h	Tue Jul 03 01:21:32 2012 -0700
     2.3 @@ -40,10 +40,10 @@
     2.4      Type *getPrimitive(PrimitiveType type) {
     2.5          return primitiveTypes_[type];
     2.6      }
     2.7 -    // :TODO: use handle
     2.8 -    Type *getReference(Type *type);
     2.9 -    Type *unsafeArray(Type *contained, int elements);
    2.10 -    Type *newFunction(Type *returnType, FixedArray *args);
    2.11 +
    2.12 +    Type *getReference(Handle<Type> type);
    2.13 +    Type *unsafeArray(Handle<Type> contained, int elements);
    2.14 +    Type *newFunction(Handle<Type> returnType, Handle<FixedArray> args);
    2.15  };
    2.16  
    2.17  }
     3.1 --- a/jitcraft/Types.cpp	Tue Jul 03 01:14:15 2012 -0700
     3.2 +++ b/jitcraft/Types.cpp	Tue Jul 03 01:21:32 2012 -0700
     3.3 @@ -24,11 +24,10 @@
     3.4  Type *
     3.5  Type::NewPrimitive(Zone *zone, Name *tag)
     3.6  {
     3.7 -    Object *obj = zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old);
     3.8 -    if (!obj)
     3.9 +    Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
    3.10 +    if (!type)
    3.11          return NULL;
    3.12  
    3.13 -    Type *type = Type::cast(obj);
    3.14      type->kind_ = PRIMITIVE;
    3.15      type->tag_ = tag;
    3.16      type->contained_ = NULL;
    3.17 @@ -45,11 +44,10 @@
    3.18  Type *
    3.19  Type::NewPrimitive(Zone *zone, PrimitiveType prim)
    3.20  {
    3.21 -    Object *obj = zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old);
    3.22 -    if (!obj)
    3.23 +    Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
    3.24 +    if (!type)
    3.25          return NULL;
    3.26  
    3.27 -    Type *type = Type::cast(obj);
    3.28      type->kind_ = PRIMITIVE;
    3.29      type->tag_ = NULL;
    3.30      type->contained_ = NULL;
    3.31 @@ -58,13 +56,12 @@
    3.32  }
    3.33  
    3.34  Type *
    3.35 -Type::NewArray(Zone *zone, Type *contained, int elements, bool isConst)
    3.36 +Type::NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst)
    3.37  {
    3.38 -    Object *obj = zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old);
    3.39 -    if (!obj)
    3.40 +    Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
    3.41 +    if (!type)
    3.42          return NULL;
    3.43  
    3.44 -    Type *type = Type::cast(obj);
    3.45      type->kind_ = ARRAY;
    3.46      type->tag_ = NULL;
    3.47      type->contained_ = contained;
    3.48 @@ -78,13 +75,12 @@
    3.49  }
    3.50  
    3.51  Type *
    3.52 -Type::NewReference(Zone *zone, Type *contained)
    3.53 +Type::NewReference(Zone *zone, Handle<Type> contained)
    3.54  {
    3.55 -    Object *obj = zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old);
    3.56 -    if (!obj)
    3.57 +    Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
    3.58 +    if (!type)
    3.59          return NULL;
    3.60  
    3.61 -    Type *type = Type::cast(obj);
    3.62      type->kind_ = REFERENCE;
    3.63      type->tag_ = NULL;
    3.64      type->contained_ = contained;
    3.65 @@ -92,13 +88,12 @@
    3.66  }
    3.67  
    3.68  Type *
    3.69 -Type::NewFunction(Zone *zone, Type *returnType, FixedArray *parameters)
    3.70 +Type::NewFunction(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters)
    3.71  {
    3.72 -    Object *obj = zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old);
    3.73 -    if (!obj)
    3.74 +    Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
    3.75 +    if (!type)
    3.76          return NULL;
    3.77  
    3.78 -    Type *type = Type::cast(obj);
    3.79      type->kind_ = FUNCTION;
    3.80      type->returnType_ = returnType;
    3.81      type->parameters_ = parameters;
     4.1 --- a/jitcraft/Types.h	Tue Jul 03 01:14:15 2012 -0700
     4.2 +++ b/jitcraft/Types.h	Tue Jul 03 01:21:32 2012 -0700
     4.3 @@ -52,15 +52,14 @@
     4.4      static const int UNKNOWN_SIZE = -1;
     4.5      static const size_t MAX_UNSAFE_ARRAY_DEPTH = 5;
     4.6      
     4.7 -    // :TODO: use handles
     4.8      static Type *NewPrimitive(Zone *zone, Name *tag);
     4.9      static Type *NewPrimitive(Zone *zone, PrimitiveType type);
    4.10 -    static Type *NewArray(Zone *zone, Type *contained, int elements, bool isConst);
    4.11 -    static Type *NewReference(Zone *zone, Type *contained);
    4.12 -    static Type *NewFunction(Zone *zone, Type *returnType, FixedArray *parameters);
    4.13 +    static Type *NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst);
    4.14 +    static Type *NewReference(Zone *zone, Handle<Type> contained);
    4.15 +    static Type *NewFunction(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters);
    4.16  
    4.17      static Type *cast(Object *obj) {
    4.18 -        assert(obj->is(MapKind_Type));
    4.19 +        assert(!obj || obj->is(MapKind_Type));
    4.20          return (Type *)obj;
    4.21      }
    4.22