1.1 --- a/src/Types.h Mon Jul 30 22:30:38 2012 -0700
1.2 +++ b/src/Types.h Wed Aug 01 22:32:59 2012 -0700
1.3 @@ -29,11 +29,28 @@
1.4
1.5 enum PrimitiveType
1.6 {
1.7 - PrimitiveType_Bool, // 0 or 1
1.8 + // A boolean type semantically represents 0 or 1. As an optimization, its
1.9 + // internal storage type is the same as int32, and any non-zero value
1.10 + // compares positively to "true".
1.11 + PrimitiveType_Bool,
1.12 +
1.13 + // A character is an arbitrary 8-bit value. Characters are not supported
1.14 + // as a normal storage class; they may only be used for arrays. When read
1.15 + // from an array, they are immediately sign extended to 32 bits. Integers
1.16 + // stored into an char array are truncated to 8 bits.
1.17 PrimitiveType_Char, // signed, 8-bit character
1.18 - PrimitiveType_Int32, // signed, 32-bit integer
1.19 - PrimitiveType_Float, // 32-bit IEEE-754 float
1.20 - PrimitiveType_Native, // native-sized word
1.21 +
1.22 + // Enumerations and untyped variables are stored as signed, 32-bit integers.
1.23 + PrimitiveType_Int32,
1.24 +
1.25 + // Floating point values are 32-bit IEEE-754 floats. This is required ro
1.26 + // SourcePawn 1 compatibility.
1.27 + PrimitiveType_Float,
1.28 +
1.29 + // This is a native-sized integer type (32-bit on 32-bit systems, 64-bit
1.30 + // on 64-bit systems), and does not exist in language semantics.
1.31 + PrimitiveType_Native,
1.32 +
1.33 PrimitiveTypes_Total
1.34 };
1.35
1.36 @@ -45,7 +62,8 @@
1.37 REFERENCE,
1.38 FUNCTION,
1.39 NATIVE,
1.40 - VOID
1.41 + VOID,
1.42 + ENUM
1.43 };
1.44
1.45 private:
1.46 @@ -58,12 +76,12 @@
1.47 static const size_t MAX_UNSAFE_ARRAY_DEPTH = 5;
1.48
1.49 static Type *NewVoid(Zone *zone);
1.50 - static Type *NewPrimitive(Zone *zone, Handle<String> tag);
1.51 static Type *NewPrimitive(Zone *zone, PrimitiveType type);
1.52 static Type *NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst);
1.53 static Type *NewReference(Zone *zone, Handle<Type> contained, bool isConst);
1.54 static Type *NewFunction(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters);
1.55 static Type *NewNative(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters, bool isVariadic);
1.56 + static Type *NewEnum(Zone *zone, Handle<String> name);
1.57
1.58 static bool Compare(Type *left, Type *right);
1.59
1.60 @@ -98,6 +116,12 @@
1.61 assert(isPrimitive());
1.62 return primitive_;
1.63 }
1.64 + PrimitiveType pod() {
1.65 + assert(isPrimitive() || isEnum());
1.66 + return isPrimitive()
1.67 + ? primitive()
1.68 + : PrimitiveType_Int32;
1.69 + }
1.70 Type *contained() {
1.71 assert(isArray() || isReference());
1.72 return Type::cast(contained_);
1.73 @@ -110,10 +134,6 @@
1.74 assert(isArray());
1.75 return levels_;
1.76 }
1.77 - String *tag() {
1.78 - assert(isPrimitive());
1.79 - return tag_;
1.80 - }
1.81 Type *innermost() {
1.82 assert(isArray());
1.83 Type *temp = contained();
1.84 @@ -127,6 +147,9 @@
1.85 bool isInt32() {
1.86 return isPrimitive() && primitive() == PrimitiveType_Int32;
1.87 }
1.88 + bool isInt32OrEnum() {
1.89 + return isInt32() || isEnum();
1.90 + }
1.91 bool isCharArray() {
1.92 return isArray() &&
1.93 contained()->isPrimitive() &&
1.94 @@ -150,6 +173,14 @@
1.95 assert(kind() == PRIMITIVE || kind() == ARRAY || kind() == REFERENCE);
1.96 return const_;
1.97 }
1.98 + bool isEnum() {
1.99 + return kind() == ENUM;
1.100 + }
1.101 +
1.102 + String *name() {
1.103 + assert(isEnum());
1.104 + return name_;
1.105 + }
1.106
1.107 // GC Descriptor.
1.108 static inline size_t offsetOfContained() {
1.109 @@ -161,15 +192,14 @@
1.110 static inline size_t offsetOfParameters() {
1.111 return OFFSETOF(Type, parameters_);
1.112 }
1.113 - static inline size_t offsetOfTag() {
1.114 - return OFFSETOF(Type, tag_);
1.115 + static inline size_t offsetOfName() {
1.116 + return OFFSETOF(Type, name_);
1.117 }
1.118 // End GC Descriptor.
1.119
1.120 private:
1.121 Kind kind_;
1.122 PrimitiveType primitive_;
1.123 - Barriered<String> tag_;
1.124
1.125 // Primitives, arrays, and references.
1.126 bool const_;
1.127 @@ -185,6 +215,9 @@
1.128 Barriered<Type> returnType_;
1.129 Barriered<FixedArray> parameters_;
1.130 bool variadicNative_;
1.131 +
1.132 + // Enums only.
1.133 + Barriered<String> name_;
1.134 };
1.135
1.136 class BoxedPrimitive