Added bogo "unchecked" type that will evolve later.
authorDavid Anderson <dvander@alliedmods.net>
Sun Aug 05 15:38:52 2012 -0700 (2012-08-05)
changeset 167cf82769eb136
parent 166 3ac2a36a7a0c
child 168 4d0fff61d65e
Added bogo "unchecked" type that will evolve later.
src/Parser.cpp
src/TypeManager.cpp
src/TypeManager.h
src/Types.cpp
src/Types.h
     1.1 --- a/src/Parser.cpp	Sun Aug 05 14:19:19 2012 -0700
     1.2 +++ b/src/Parser.cpp	Sun Aug 05 15:38:52 2012 -0700
     1.3 @@ -1226,16 +1226,21 @@
     1.4  }
     1.5  
     1.6  static inline bool
     1.7 -DeclareIntrinsicType(Zone *zone, Scope *scope, const char *name, PrimitiveType type)
     1.8 +DeclareIntrinsicType(Zone *zone, Scope *scope, const char *name, Handle<Type> type)
     1.9  {
    1.10      Local<String> tag(zone, zone->makeSymbol(name));
    1.11      if (!tag)
    1.12          return false;
    1.13  
    1.14 +    return !!scope->declareType(tag, type);
    1.15 +}
    1.16 +
    1.17 +static inline bool
    1.18 +DeclareIntrinsicType(Zone *zone, Scope *scope, const char *name, PrimitiveType type)
    1.19 +{
    1.20      Local<Type> primitive(zone, zone->types()->getPrimitive(type));
    1.21      assert(primitive);
    1.22 -
    1.23 -    return !!scope->declareType(tag, primitive);
    1.24 +    return DeclareIntrinsicType(zone, scope, name, primitive);
    1.25  }
    1.26  
    1.27  bool
    1.28 @@ -1249,6 +1254,11 @@
    1.29          return false;
    1.30      if (!DeclareIntrinsicType(zone_, scope_, "String", PrimitiveType_Char))
    1.31          return false;
    1.32 +
    1.33 +    Local<Type> unchecked(zone_, zone_->types()->getUnchecked());
    1.34 +    if (!DeclareIntrinsicType(zone_, scope_, "unchecked", unchecked))
    1.35 +        return false;
    1.36 +
    1.37      return true;
    1.38  }
    1.39  
     2.1 --- a/src/TypeManager.cpp	Sun Aug 05 14:19:19 2012 -0700
     2.2 +++ b/src/TypeManager.cpp	Sun Aug 05 15:38:52 2012 -0700
     2.3 @@ -39,6 +39,10 @@
     2.4      if (!voidType_)
     2.5          return false;
     2.6  
     2.7 +    uncheckedType_ = Type::NewUnchecked(zone_);
     2.8 +    if (!uncheckedType_)
     2.9 +        return false;
    2.10 +
    2.11      if ((primitiveTypes_[PrimitiveType_Int32] = Type::NewPrimitive(zone_, PrimitiveType_Int32)) == NULL)
    2.12          return false;
    2.13      if ((primitiveTypes_[PrimitiveType_Float] = Type::NewPrimitive(zone_, PrimitiveType_Float)) == NULL)
    2.14 @@ -107,6 +111,7 @@
    2.15  TypeManager::accept(VirtualObjectVisitor *visitor)
    2.16  {
    2.17      visitor->visit(voidType_.address());
    2.18 +    visitor->visit(uncheckedType_.address());
    2.19      for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
    2.20          visitor->visit(primitiveTypes_[i].address());
    2.21          visitor->visit(referenceTypes_[i].address());
     3.1 --- a/src/TypeManager.h	Sun Aug 05 14:19:19 2012 -0700
     3.2 +++ b/src/TypeManager.h	Sun Aug 05 15:38:52 2012 -0700
     3.3 @@ -1,19 +1,20 @@
     3.4 -/*
     3.5 +/* vim: set ts=4 sw=4 tw=99 et:
     3.6 + *
     3.7   * Copyright (C) 2012 David Anderson
     3.8   *
     3.9 - * This file is part of JITCraft.
    3.10 + * This file is part of SourcePawn.
    3.11   *
    3.12 - * JITCraft is free software: you can redistribute it and/or modify it under
    3.13 + * SourcePawn is free software: you can redistribute it and/or modify it under
    3.14   * the terms of the GNU General Public License as published by the Free
    3.15   * Software Foundation, either version 3 of the License, or (at your option)
    3.16   * any later version.
    3.17   * 
    3.18 - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    3.19 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    3.20   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    3.21   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    3.22   *
    3.23   * You should have received a copy of the GNU General Public License along with
    3.24 - * JITCraft. If not, see http://www.gnu.org/licenses/.
    3.25 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
    3.26   */
    3.27  #ifndef _include_jitcraft_type_manager_h_
    3.28  #define _include_jitcraft_type_manager_h_
    3.29 @@ -32,6 +33,7 @@
    3.30  
    3.31      // Primitive type cache.
    3.32      Unbarriered<Type> voidType_;
    3.33 +    Unbarriered<Type> uncheckedType_;
    3.34      Unbarriered<Type> primitiveTypes_[PrimitiveTypes_Total];
    3.35      Unbarriered<Type> referenceTypes_[PrimitiveTypes_Total];
    3.36  
    3.37 @@ -47,6 +49,9 @@
    3.38      Type *getVoid() {
    3.39          return voidType_;
    3.40      }
    3.41 +    Type *getUnchecked() {
    3.42 +        return uncheckedType_;
    3.43 +    }
    3.44      Type *getReference(Handle<Type> type, bool isConst);
    3.45      Type *unsafeArray(Handle<Type> contained, int elements, bool isConst);
    3.46      Type *newEnum(Handle<String> name);
     4.1 --- a/src/Types.cpp	Sun Aug 05 14:19:19 2012 -0700
     4.2 +++ b/src/Types.cpp	Sun Aug 05 15:38:52 2012 -0700
     4.3 @@ -42,6 +42,22 @@
     4.4  }
     4.5  
     4.6  Type *
     4.7 +Type::NewUnchecked(Zone *zone)
     4.8 +{
     4.9 +    Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
    4.10 +    if (!type)
    4.11 +        return NULL;
    4.12 +
    4.13 +    type->kind_ = UNCHECKED;
    4.14 +    type->contained_ = NULL;
    4.15 +    type->returnType_ = NULL;
    4.16 +    type->parameters_ = NULL;
    4.17 +    type->fields_ = NULL;
    4.18 +    type->newMap_ = NULL;
    4.19 +    return type;
    4.20 +}
    4.21 +
    4.22 +Type *
    4.23  Type::NewPrimitive(Zone *zone, PrimitiveType prim)
    4.24  {
    4.25      Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
     5.1 --- a/src/Types.h	Sun Aug 05 14:19:19 2012 -0700
     5.2 +++ b/src/Types.h	Sun Aug 05 15:38:52 2012 -0700
     5.3 @@ -58,14 +58,37 @@
     5.4  class Type : public Object
     5.5  {
     5.6      enum Kind {
     5.7 +        // A primitive is a plain-old-data type.
     5.8          PRIMITIVE,
     5.9 +
    5.10 +        // An array is a fixed-length vector of any other type.
    5.11          ARRAY,
    5.12 +
    5.13 +        // A reference type may only be specified on parameters, and
    5.14 +        // references may only be computed to primitives or enums.
    5.15          REFERENCE,
    5.16 +
    5.17 +        // A function type encapsulates a function signature.
    5.18          FUNCTION,
    5.19 +
    5.20 +        // A native is a limited type of function used for system calls.
    5.21          NATIVE,
    5.22 +
    5.23 +        // Void is an internal type used to specify that a function returns no
    5.24 +        // value.
    5.25          VOID,
    5.26 +
    5.27 +        // Enums are plain-old-data with int32 storage. They allow for extra
    5.28 +        // type checking that would not be possible with integers.
    5.29          ENUM,
    5.30 -        STRUCT
    5.31 +
    5.32 +        // Structs are composite records that may contain primitives, arrays,
    5.33 +        // functions, enums, and other structs.
    5.34 +        STRUCT,
    5.35 +
    5.36 +        // Unchecked is a magic type that has implicit, bitwise coercion to
    5.37 +        // int32, float, bool, or an enum.
    5.38 +        UNCHECKED
    5.39      };
    5.40  
    5.41    private:
    5.42 @@ -78,6 +101,7 @@
    5.43      static const size_t MAX_UNSAFE_ARRAY_DEPTH = 5;
    5.44      
    5.45      static Type *NewVoid(Zone *zone);
    5.46 +    static Type *NewUnchecked(Zone *zone);
    5.47      static Type *NewPrimitive(Zone *zone, PrimitiveType type);
    5.48      static Type *NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst);
    5.49      static Type *NewReference(Zone *zone, Handle<Type> contained, bool isConst);
    5.50 @@ -111,6 +135,9 @@
    5.51      bool isVoid() {
    5.52          return kind() == VOID;
    5.53      }
    5.54 +    bool isUnchecked() {
    5.55 +        return kind() == UNCHECKED;
    5.56 +    }
    5.57      bool isStruct() {
    5.58          return kind() == STRUCT;
    5.59      }