src/Types.h
author David Anderson <dvander@alliedmods.net>
Sun Jan 06 13:52:21 2013 -0800 (2013-01-06)
changeset 256 3c184218462d
parent 247 7721042bdb67
child 258 241d082d6d89
permissions -rw-r--r--
Initial implementation of module imports.
[email protected]
     1
/* vim: set ts=4 sw=4 tw=99 et:
[email protected]
     2
 *
[email protected]
     3
 * Copyright (C) 2012 David Anderson
[email protected]
     4
 *
[email protected]
     5
 * This file is part of JITCraft.
[email protected]
     6
 *
[email protected]
     7
 * JITCraft is free software: you can redistribute it and/or modify it under
[email protected]
     8
 * the terms of the GNU General Public License as published by the Free
[email protected]
     9
 * Software Foundation, either version 3 of the License, or (at your option)
[email protected]
    10
 * any later version.
[email protected]
    11
 * 
[email protected]
    12
 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
[email protected]
    13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
[email protected]
    14
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
[email protected]
    15
 *
[email protected]
    16
 * You should have received a copy of the GNU General Public License along with
[email protected]
    17
 * JITCraft. If not, see http://www.gnu.org/licenses/.
[email protected]
    18
 */
[email protected]
    19
#ifndef _include_jc_types_h_
[email protected]
    20
#define _include_jc_types_h_
[email protected]
    21
[email protected]
    22
#include "Heap.h"
[email protected]
    23
#include "Barriers.h"
[email protected]
    24
#include "FixedArray.h"
[email protected]
    25
#include "compiler/Token.h"
[email protected]
    26
[email protected]
    27
namespace ke {
[email protected]
    28
[email protected]
    29
class String;
[email protected]
    30
class Descriptor;
[email protected]
    31
class StructMap;
[email protected]
    32
class ArrayMap;
[email protected]
    33
[email protected]
    34
#define MAX_ARRAY_DEPTH     5
[email protected]
    35
[email protected]
    36
enum PrimitiveType
[email protected]
    37
{
[email protected]
    38
    // A boolean type semantically represents 0 or 1. As an optimization, its
[email protected]
    39
    // internal storage type is the same as int32, and any non-zero value
[email protected]
    40
    // compares positively to "true".
[email protected]
    41
    PrimitiveType_Bool,
[email protected]
    42
[email protected]
    43
    // A character is an arbitrary 8-bit value. Characters are not supported
[email protected]
    44
    // as a normal storage class; they may only be used for arrays. When read
[email protected]
    45
    // from an array, they are immediately sign extended to 32 bits. Integers
[email protected]
    46
    // stored into an char array are truncated to 8 bits.
[email protected]
    47
    PrimitiveType_Char,         // signed, 8-bit character
[email protected]
    48
[email protected]
    49
    // Enumerations and untyped variables are stored as signed, 32-bit integers.
[email protected]
    50
    PrimitiveType_Int32,
[email protected]
    51
[email protected]
    52
    // Floating point values are 32-bit IEEE-754 floats. This is required ro
[email protected]
    53
    // SourcePawn 1 compatibility.
[email protected]
    54
    PrimitiveType_Float,
[email protected]
    55
[email protected]
    56
    // This is a native-sized integer type (32-bit on 32-bit systems, 64-bit
[email protected]
    57
    // on 64-bit systems), and does not exist in language semantics.
[email protected]
    58
    PrimitiveType_Native,
[email protected]
    59
[email protected]
    60
    PrimitiveTypes_Total
[email protected]
    61
};
[email protected]
    62
[email protected]
    63
enum TypeQualifiers
[email protected]
    64
{
[email protected]
    65
    TypeQual_None           = 0,
[email protected]
    66
[email protected]
    67
    // Values of this type cannot be modified.
[email protected]
    68
    TypeQual_Const       = (1 << 2)
[email protected]
    69
};
[email protected]
    70
[email protected]
    71
class Type : public Object
[email protected]
    72
{
[email protected]
    73
  protected:
[email protected]
    74
    enum Kind {
[email protected]
    75
        // A primitive is a plain-old-data type.
[email protected]
    76
        PRIMITIVE,
[email protected]
    77
[email protected]
    78
        // Void is an internal type used to specify that a function returns no
[email protected]
    79
        // value.
[email protected]
    80
        VOID,
[email protected]
    81
[email protected]
    82
        // Enums are plain-old-data with int32 storage. They allow for extra
[email protected]
    83
        // type checking that would not be possible with integers.
[email protected]
    84
        ENUM,
[email protected]
    85
[email protected]
    86
        // Unchecked is a magic type that has implicit, bitwise coercion to
[email protected]
    87
        // int32, float, bool, or an enum.
[email protected]
    88
        UNCHECKED,
[email protected]
    89
[email protected]
    90
        // Contains type qualifiers, and a back pointer to the actual
[email protected]
    91
        // unqualified type.
[email protected]
    92
        QUALTYPE,
[email protected]
    93
[email protected]
    94
        // ------ Add traceable types below (STRING FIRST!) -------
[email protected]
    95
[email protected]
    96
        // An immutable type that is a primitive in terms of language
[email protected]
    97
        // semantics, but gets a special type here to make internal
[email protected]
    98
        // logic easier.
[email protected]
    99
        STRING,
[email protected]
   100
[email protected]
   101
        // An array is a fixed-length vector of any other type.
[email protected]
   102
        ARRAY,
[email protected]
   103
        EXTERNAL_ARRAY,
[email protected]
   104
[email protected]
   105
        // A reference type may only be specified on parameters, and
[email protected]
   106
        // references may only be computed to primitives or enums.
[email protected]
   107
        REFERENCE,
[email protected]
   108
[email protected]
   109
        // A function type encapsulates a function signature.
[email protected]
   110
        FUNCTION,
[email protected]
   111
[email protected]
   112
        // Structs are composite records that may contain primitives, arrays,
[email protected]
   113
        // functions, enums, and other structs.
[email protected]
   114
        STRUCT,
[email protected]
   115
[email protected]
   116
        // Importable types are mainly used during the compilation process
[email protected]
   117
        // to distinguish between normal names and static imports.
[email protected]
   118
        IMPORTABLE
[email protected]
   119
    };
[email protected]
   120
[email protected]
   121
    void init(Kind kind, Type *root = NULL);
[email protected]
   122
[email protected]
   123
  private:
[email protected]
   124
    Kind kind() {
[email protected]
   125
        return root_->kind_;
[email protected]
   126
    }
[email protected]
   127
[email protected]
   128
  public:   
[email protected]
   129
    static Type *NewVoid(Zone *zone);
[email protected]
   130
    static Type *NewUnchecked(Zone *zone);
[email protected]
   131
    static Type *NewPrimitive(Zone *zone, PrimitiveType type);
[email protected]
   132
    static Type *NewString(Zone *zone);
[email protected]
   133
    static Type *NewQualified(Zone *zone, TypeQualifiers qual, Handle<Type> type);
[email protected]
   134
    static Type *NewImportable(Zone *zone);
[email protected]
   135
[email protected]
   136
    static Type *cast(Object *obj) {
[email protected]
   137
        assert(!obj ||
[email protected]
   138
               obj->is(MapKind_Type) ||
[email protected]
   139
               obj->is(MapKind_FunctionType) ||
[email protected]
   140
               obj->is(MapKind_StructType) ||
[email protected]
   141
               obj->is(MapKind_ArrayType) ||
[email protected]
   142
               obj->is(MapKind_ReferenceType) ||
[email protected]
   143
               obj->is(MapKind_EnumType));
[email protected]
   144
        return (Type *)obj;
[email protected]
   145
    }
[email protected]
   146
[email protected]
   147
    bool isPrimitive() {
[email protected]
   148
        return kind() == PRIMITIVE;
[email protected]
   149
    }
[email protected]
   150
    bool isArray() {
[email protected]
   151
        return kind() == ARRAY || kind() == EXTERNAL_ARRAY;
[email protected]
   152
    }
[email protected]
   153
    bool isReference() {
[email protected]
   154
        return kind() == REFERENCE;
[email protected]
   155
    }
[email protected]
   156
    bool isFunction() {
[email protected]
   157
        return kind() == FUNCTION;
[email protected]
   158
    }
[email protected]
   159
    bool isVoid() {
[email protected]
   160
        return kind() == VOID;
[email protected]
   161
    }
[email protected]
   162
    bool isUnchecked() {
[email protected]
   163
        return kind() == UNCHECKED;
[email protected]
   164
    }
[email protected]
   165
    bool isStruct() {
[email protected]
   166
        return kind() == STRUCT;
[email protected]
   167
    }
[email protected]
   168
    bool isImportable() {
[email protected]
   169
        return kind() == IMPORTABLE;
[email protected]
   170
    }
[email protected]
   171
    PrimitiveType primitive() {
[email protected]
   172
        assert(isPrimitive());
[email protected]
   173
        return root_->primitive_;
[email protected]
   174
    }
[email protected]
   175
    bool isPod() {
[email protected]
   176
        return (isPrimitive() && !isString()) || isEnum() || isUnchecked();
[email protected]
   177
    }
[email protected]
   178
    PrimitiveType pod() {
[email protected]
   179
        assert(isPod());
[email protected]
   180
        return isPrimitive()
[email protected]
   181
               ? (primitive() == PrimitiveType_Bool)
[email protected]
   182
                 ? PrimitiveType_Int32
[email protected]
   183
                 : primitive()
[email protected]
   184
               : PrimitiveType_Int32;
[email protected]
   185
    }
[email protected]
   186
    bool isChar() {
[email protected]
   187
        return isPrimitive() && primitive() == PrimitiveType_Char;
[email protected]
   188
    }
[email protected]
   189
    bool isFloat() {
[email protected]
   190
        return isPrimitive() && primitive() == PrimitiveType_Float;
[email protected]
   191
    }
[email protected]
   192
    bool isInt32() {
[email protected]
   193
        return isPrimitive() && primitive() == PrimitiveType_Int32;
[email protected]
   194
    }
[email protected]
   195
    bool isInt32OrEnum() {
[email protected]
   196
        return isInt32() || isEnum();
[email protected]
   197
    }
[email protected]
   198
    bool isBool() {
[email protected]
   199
        return isPrimitive() && primitive() == PrimitiveType_Bool;
[email protected]
   200
    }
[email protected]
   201
    bool isString() {
[email protected]
   202
        return kind() == STRING;
[email protected]
   203
    }
[email protected]
   204
    bool isExternalArray() {
[email protected]
   205
        return kind() == EXTERNAL_ARRAY;
[email protected]
   206
    }
[email protected]
   207
    bool isTraceable() {
[email protected]
   208
        return kind() >= STRING;
[email protected]
   209
    }
[email protected]
   210
    bool isEnum() {
[email protected]
   211
        return kind() == ENUM;
[email protected]
   212
    }
[email protected]
   213
    bool hasTypeQualifiers() {
[email protected]
   214
        return kind_ == QUALTYPE;
[email protected]
   215
    }
[email protected]
   216
[email protected]
   217
    TypeQualifiers quals() {
[email protected]
   218
        if (!hasTypeQualifiers())
[email protected]
   219
            return TypeQual_None;
[email protected]
   220
        return quals_;
[email protected]
   221
    }
[email protected]
   222
    Type *unqualified() {
[email protected]
   223
        return root_;
[email protected]
   224
    }
[email protected]
   225
[email protected]
   226
    // GC Descriptor.
[email protected]
   227
    static inline size_t offsetOfRoot() {
[email protected]
   228
        return OFFSETOF(Type, root_);
[email protected]
   229
    }
[email protected]
   230
    // End GC Descriptor.
[email protected]
   231
[email protected]
   232
  protected:
[email protected]
   233
    Kind kind_;
[email protected]
   234
    PrimitiveType primitive_;
[email protected]
   235
    TypeQualifiers quals_;
[email protected]
   236
[email protected]
   237
    // For unqualified types, this points to |this|. For qualified types, it
[email protected]
   238
    // points to the unqualified original type.
[email protected]
   239
    Barriered<Type> root_;
[email protected]
   240
};
[email protected]
   241
[email protected]
   242
class EnumType : public Type
[email protected]
   243
{
[email protected]
   244
  public:
[email protected]
   245
    static EnumType *New(Zone *Zone, Handle<String> name);
[email protected]
   246
[email protected]
   247
    String *name() {
[email protected]
   248
        return name_;
[email protected]
   249
    }
[email protected]
   250
[email protected]
   251
    // GC Descriptor.
[email protected]
   252
    static inline size_t offsetOfName() {
[email protected]
   253
        return OFFSETOF(EnumType, name_);
[email protected]
   254
    }
[email protected]
   255
    // End GC Descriptor.
[email protected]
   256
[email protected]
   257
    static EnumType *cast(Object *obj) {
[email protected]
   258
        assert(!obj || obj->is(MapKind_EnumType));
[email protected]
   259
        return (EnumType *)obj;
[email protected]
   260
    }
[email protected]
   261
[email protected]
   262
  private:
[email protected]
   263
    Barriered<String> name_;
[email protected]
   264
};
[email protected]
   265
[email protected]
   266
class ReferenceType : public Type
[email protected]
   267
{
[email protected]
   268
  public:
[email protected]
   269
    static ReferenceType *New(Zone *zone, Handle<Type> contained);
[email protected]
   270
    
[email protected]
   271
    Type *contained() {
[email protected]
   272
        return contained_;
[email protected]
   273
    }
[email protected]
   274
[email protected]
   275
    // GC Descriptor.
[email protected]
   276
    static inline size_t offsetOfContained() {
[email protected]
   277
        return OFFSETOF(ReferenceType, contained_);
[email protected]
   278
    }
[email protected]
   279
    // End GC Descriptor.
[email protected]
   280
[email protected]
   281
    static ReferenceType *cast(Type *obj) {
[email protected]
   282
        if (!obj)
[email protected]
   283
            return NULL;
[email protected]
   284
        obj = obj->unqualified();
[email protected]
   285
        assert(obj->is(MapKind_ReferenceType));
[email protected]
   286
        return (ReferenceType *)obj;
[email protected]
   287
    }
[email protected]
   288
[email protected]
   289
  private:
[email protected]
   290
    Barriered<Type> contained_;
[email protected]
   291
};
[email protected]
   292
[email protected]
   293
class ArrayType : public Type
[email protected]
   294
{
[email protected]
   295
  public:
[email protected]
   296
    static const int DYNAMIC_ARRAY_SIZE = -1;
[email protected]
   297
[email protected]
   298
    static ArrayType *New(Zone *zone, Handle<Type> contained, int elements);
[email protected]
   299
    static ArrayType *NewExternal(Zone *zone, Handle<Type> contained);
[email protected]
   300
[email protected]
   301
    Type *innermost() {
[email protected]
   302
        Type *temp = contained();
[email protected]
   303
        while (temp->isArray())
[email protected]
   304
            temp = ArrayType::cast(temp)->contained();
[email protected]
   305
        return temp;
[email protected]
   306
    }
[email protected]
   307
[email protected]
   308
    bool isDynamic() {
[email protected]
   309
        return elements_ == DYNAMIC_ARRAY_SIZE;
[email protected]
   310
    }
[email protected]
   311
    bool isExtensible() {
[email protected]
   312
        return isDynamic() && !(quals_ & TypeQual_Const);
[email protected]
   313
    }
[email protected]
   314
    Type *contained() {
[email protected]
   315
        return contained_;
[email protected]
   316
    }
[email protected]
   317
    bool isFixedLength() {
[email protected]
   318
        return elements_ > 0;
[email protected]
   319
    }
[email protected]
   320
    bool isCharArray() {
[email protected]
   321
        return contained()->isPrimitive() &&
[email protected]
   322
               contained()->primitive() == PrimitiveType_Char;
[email protected]
   323
    }
[email protected]
   324
    unsigned fixedLength() {
[email protected]
   325
        assert(isFixedLength());
[email protected]
   326
        return elements_;
[email protected]
   327
    }
[email protected]
   328
    unsigned levels() {
[email protected]
   329
        return levels_;
[email protected]
   330
    }
[email protected]
   331
    bool hasInlineElements() {
[email protected]
   332
        // We don't allocate traceable elements inline, since there's no
[email protected]
   333
        // point to the optimization; we're going to be allocating lots of
[email protected]
   334
        // objects anyway (in theory).
[email protected]
   335
        return isFixedLength() && !contained()->isTraceable();
[email protected]
   336
    }
[email protected]
   337
[email protected]
   338
    // Arrays of this type can be created with this cached map.
[email protected]
   339
    ArrayMap *newMap() {
[email protected]
   340
        return newMap_;
[email protected]
   341
    }
[email protected]
   342
    void setNewMap(ArrayMap *map) {
[email protected]
   343
        assert(!newMap());
[email protected]
   344
        newMap_ = map;
[email protected]
   345
    }
[email protected]
   346
[email protected]
   347
    // GC Descriptor.
[email protected]
   348
    static inline size_t offsetOfContained() {
[email protected]
   349
        return OFFSETOF(ArrayType, contained_);
[email protected]
   350
    }
[email protected]
   351
    static inline size_t offsetOfNewMap() {
[email protected]
   352
        return OFFSETOF(ArrayType, newMap_);
[email protected]
   353
    }
[email protected]
   354
    // End GC Descriptor.
[email protected]
   355
[email protected]
   356
    static ArrayType *cast(Type *obj) {
[email protected]
   357
        if (!obj)
[email protected]
   358
            return NULL;
[email protected]
   359
        obj = obj->unqualified();
[email protected]
   360
        assert(obj->is(MapKind_ArrayType));
[email protected]
   361
        return (ArrayType *)obj;
[email protected]
   362
    }
[email protected]
   363
[email protected]
   364
  private:
[email protected]
   365
    int32 elements_;
[email protected]
   366
    unsigned levels_;
[email protected]
   367
    Barriered<Type> contained_;
[email protected]
   368
    Barriered<ArrayMap> newMap_;
[email protected]
   369
};
[email protected]
   370
[email protected]
   371
class StructType : public Type
[email protected]
   372
{
[email protected]
   373
  public:
[email protected]
   374
    static StructType *New(Zone *zone, Handle<String> name, Handle<FixedArray> fields);
[email protected]
   375
[email protected]
   376
    FixedArray *fields() {
[email protected]
   377
        assert(isStruct());
[email protected]
   378
        return fields_;
[email protected]
   379
    }
[email protected]
   380
    Descriptor *lookupField(Handle<String> name, unsigned *index = NULL);
[email protected]
   381
[email protected]
   382
    // Objects of this type can be created with this cached map.
[email protected]
   383
    StructMap *newMap() {
[email protected]
   384
        return newMap_;
[email protected]
   385
    }
[email protected]
   386
    void setNewMap(StructMap *map) {
[email protected]
   387
        assert(!newMap());
[email protected]
   388
        newMap_ = map;
[email protected]
   389
    }
[email protected]
   390
[email protected]
   391
    String *name() {
[email protected]
   392
        return name_;
[email protected]
   393
    }
[email protected]
   394
[email protected]
   395
    // GC Descriptor.
[email protected]
   396
    static inline size_t offsetOfFields() {
[email protected]
   397
        return OFFSETOF(StructType, fields_);
[email protected]
   398
    }
[email protected]
   399
    static inline size_t offsetOfNewMap() {
[email protected]
   400
        return OFFSETOF(StructType, newMap_);
[email protected]
   401
    }
[email protected]
   402
    static inline size_t offsetOfName() {
[email protected]
   403
        return OFFSETOF(StructType, name_);
[email protected]
   404
    }
[email protected]
   405
    // End GC Descriptor.
[email protected]
   406
[email protected]
   407
    static StructType *cast(Type *obj) {
[email protected]
   408
        if (!obj)
[email protected]
   409
            return NULL;
[email protected]
   410
        obj = obj->unqualified();
[email protected]
   411
        assert(obj->is(MapKind_StructType));
[email protected]
   412
        return (StructType *)obj;
[email protected]
   413
    }
[email protected]
   414
[email protected]
   415
  private:
[email protected]
   416
    // Structs only.
[email protected]
   417
    Barriered<FixedArray> fields_;
[email protected]
   418
    Barriered<StructMap> newMap_;
[email protected]
   419
    Barriered<String> name_;
[email protected]
   420
};
[email protected]
   421
[email protected]
   422
class FunctionType : public Type
[email protected]
   423
{
[email protected]
   424
  public:
[email protected]
   425
    static FunctionType *New(Zone *zone, Handle<String> name, TokenKind kind);
[email protected]
   426
[email protected]
   427
    Type *parameterAt(size_t i) {
[email protected]
   428
        return Type::cast(parameters()->at(i));
[email protected]
   429
    }
[email protected]
   430
    Type *returnType() {
[email protected]
   431
        assert(isFunction());
[email protected]
   432
        return returnType_;
[email protected]
   433
    }
[email protected]
   434
    FixedArray *parameters() {
[email protected]
   435
        assert(isFunction());
[email protected]
   436
        return parameters_;
[email protected]
   437
    }
[email protected]
   438
    FixedArray *defaults() {
[email protected]
   439
        assert(isFunction());
[email protected]
   440
        return defaults_;
[email protected]
   441
    }
[email protected]
   442
    bool isNative() {
[email protected]
   443
        return token_ == TOK_NATIVE;
[email protected]
   444
    }
[email protected]
   445
    bool isForward() {
[email protected]
   446
        return token_ == TOK_FORWARD;
[email protected]
   447
    }
[email protected]
   448
    bool isNativeVariadic() {
[email protected]
   449
        assert(isNative());
[email protected]
   450
        return variadicNative_;
[email protected]
   451
    }
[email protected]
   452
    void setVariadic() {
[email protected]
   453
        assert(isNative());
[email protected]
   454
        variadicNative_ = true;
[email protected]
   455
    }
[email protected]
   456
    void setReturnType(Handle<Type> returnType) {
[email protected]
   457
        assert(!returnType_);
[email protected]
   458
        returnType_ = returnType;
[email protected]
   459
    }
[email protected]
   460
    void setParameterTypes(Handle<FixedArray> types) {
[email protected]
   461
        assert(!parameters_);
[email protected]
   462
        parameters_ = types;
[email protected]
   463
    }
[email protected]
   464
    TokenKind token() {
[email protected]
   465
        return token_;
[email protected]
   466
    }
[email protected]
   467
    String *name() {
[email protected]
   468
        return name_;
[email protected]
   469
    }
[email protected]
   470
[email protected]
   471
    // GC Descriptor.
[email protected]
   472
    static inline size_t offsetOfReturnType() {
[email protected]
   473
        return OFFSETOF(FunctionType, returnType_);
[email protected]
   474
    }
[email protected]
   475
    static inline size_t offsetOfParameters() {
[email protected]
   476
        return OFFSETOF(FunctionType, parameters_);
[email protected]
   477
    }
[email protected]
   478
    static inline size_t offsetOfDefaults() {
[email protected]
   479
        return OFFSETOF(FunctionType, defaults_);
[email protected]
   480
    }
[email protected]
   481
    static inline size_t offsetOfName() {
[email protected]
   482
        return OFFSETOF(FunctionType, name_);
[email protected]
   483
    }
[email protected]
   484
    // End GC Descriptor.
[email protected]
   485
[email protected]
   486
    static FunctionType *cast(Type *obj) {
[email protected]
   487
        if (!obj)
[email protected]
   488
            return NULL;
[email protected]
   489
        obj = obj->unqualified();
[email protected]
   490
        assert(obj->is(MapKind_FunctionType));
[email protected]
   491
        return (FunctionType *)obj;
[email protected]
   492
    }
[email protected]
   493
[email protected]
   494
  private:
[email protected]
   495
    // Functions only.
[email protected]
   496
    Barriered<Type> returnType_;
[email protected]
   497
    Barriered<FixedArray> parameters_;
[email protected]
   498
    Barriered<FixedArray> defaults_;
[email protected]
   499
    Barriered<String> name_;
[email protected]
   500
    TokenKind token_;
[email protected]
   501
    bool variadicNative_;
[email protected]
   502
};
[email protected]
   503
[email protected]
   504
class BoxedPrimitive
[email protected]
   505
{
[email protected]
   506
    PrimitiveType type_;
[email protected]
   507
    union {
[email protected]
   508
        int i_;
[email protected]
   509
        float f_;
[email protected]
   510
    };
[email protected]
   511
[email protected]
   512
  public:
[email protected]
   513
    static BoxedPrimitive Int(int i) {
[email protected]
   514
        BoxedPrimitive b;
[email protected]
   515
        b.type_ = PrimitiveType_Int32;
[email protected]
   516
        b.i_ = i;
[email protected]
   517
        return b;
[email protected]
   518
    }
[email protected]
   519
    static BoxedPrimitive Float(float f) {
[email protected]
   520
        BoxedPrimitive b;
[email protected]
   521
        b.type_ = PrimitiveType_Float;
[email protected]
   522
        b.f_ = f;
[email protected]
   523
        return b;
[email protected]
   524
    }
[email protected]
   525
[email protected]
   526
    PrimitiveType type() const {
[email protected]
   527
        return type_;
[email protected]
   528
    }
[email protected]
   529
    int toInt() const {
[email protected]
   530
        assert(type() == PrimitiveType_Int32);
[email protected]
   531
        return i_;
[email protected]
   532
    }
[email protected]
   533
    float toFloat() const {
[email protected]
   534
        assert(type() == PrimitiveType_Float);
[email protected]
   535
        return f_;
[email protected]
   536
    }
[email protected]
   537
};
[email protected]
   538
[email protected]
   539
const char *GetTypeName(Type *type, char *buffer, size_t maxlen);
[email protected]
   540
[email protected]
   541
}
[email protected]
   542
[email protected]
   543
#endif // _include_jc_types_h_