Support admin.inc again.
authorDavid Anderson <dvander@alliedmods.net>
Thu Dec 27 20:44:50 2012 -0800 (2012-12-27)
changeset 2459371f058625a
parent 244 3c57bbf22aa2
child 246 f9c4371d59d4
Support admin.inc again.
src/Interpreter.cpp
src/Messages.tbl
src/Opcodes.cpp
src/Opcodes.tbl
src/compiler/BytecodeEmitter.h
src/compiler/HIR.cpp
src/compiler/HIR.h
src/compiler/SemanticAnalysis.cpp
src/compiler/SemanticAnalysis.h
     1.1 --- a/src/Interpreter.cpp	Wed Dec 26 17:20:55 2012 -0800
     1.2 +++ b/src/Interpreter.cpp	Thu Dec 27 20:44:50 2012 -0800
     1.3 @@ -875,11 +875,9 @@
     1.4      break;
     1.5  }
     1.6  
     1.7 -case OP_BITS_I2F:
     1.8 -case OP_BITS_F2I:
     1.9 +case OP_BITCAST:
    1.10  {
    1.11 -    // Because the stack is a union, these are actually no-ops in the
    1.12 -    // interpreter.
    1.13 +    // Because the stack is a union, this is a no-ops.
    1.14      break;
    1.15  }
    1.16  
     2.1 --- a/src/Messages.tbl	Wed Dec 26 17:20:55 2012 -0800
     2.2 +++ b/src/Messages.tbl	Thu Dec 27 20:44:50 2012 -0800
     2.3 @@ -21,7 +21,6 @@
     2.4  MSG(CalleeNotFunction,              SyntaxError,            "callee is not a function")
     2.5  MSG(ArgumentCountMismatch,          SyntaxError,            "argument counts do not match")
     2.6  MSG(CannotAssignArrayToScalar,      SyntaxError,            "cannot coerce an array to a scalar")
     2.7 -MSG(UnsupportedType,                SyntaxError,            "unsupported type")
     2.8  MSG(ArrayDimensionsMismatch,        SyntaxError,            "number of array dimensions does not match")
     2.9  MSG(ExpectedArray,                  SyntaxError,            "expected array")
    2.10  MSG(ArrayDimensionSizeMismatch,     SyntaxError,            "array dimension sizes do not match (level %d)")
    2.11 @@ -39,7 +38,7 @@
    2.12  MSG(ExpectedGlobal,                 SyntaxError,            "expected global variable or function")
    2.13  MSG(ForwardNotImplemented,          SyntaxError,            "forward '%s' not implemented")
    2.14  MSG(ForwardDeclareMismatches,       SyntaxError,            "declaration does not match original forward signature")
    2.15 -MSG(ArrayCantBeReference,           SyntaxError,            "this type cannot be used with a reference")
    2.16 +MSG(ArrayCantBeReference,           TypeError,              "this type cannot be used with a reference")
    2.17  MSG(ArraySizeMustBeConstant,        SyntaxError,            "array size must be a constant integer")
    2.18  MSG(MultiArrayInNative,             SyntaxError,            "multidimensional arrays cannot be passed to natives")
    2.19  MSG(InvalidVarArgs,                 SyntaxError,            "varargs cannot be const or ref")
    2.20 @@ -82,4 +81,6 @@
    2.21  MSG(InvalidCoercion,                TypeError,              "cannot coerce type '%s' to type '%s'")
    2.22  MSG(CannotConstReference,           TypeError,              "constant outparams are not allowed")
    2.23  MSG(CannotModifyConst,              TypeError,              "cannot change constant value or structure")
    2.24 -MSG(InvalidConstOnFormal,           TypeError,              "const parameters must be arrays or structs")
    2.25 \ No newline at end of file
    2.26 +MSG(InvalidConstOnFormal,           TypeError,              "const parameters must be arrays or structs")
    2.27 +MSG(InvalidUncheckedCastFrom,       TypeError,              "cannot perform an unchecked cast on type '%s'")
    2.28 +MSG(InvalidUncheckedCastTo,         TypeError,              "cannot perform an unchecked cast to type '%s'")
    2.29 \ No newline at end of file
     3.1 --- a/src/Opcodes.cpp	Wed Dec 26 17:20:55 2012 -0800
     3.2 +++ b/src/Opcodes.cpp	Thu Dec 27 20:44:50 2012 -0800
     3.3 @@ -203,8 +203,7 @@
     3.4            case OP_NEG:
     3.5            case OP_NEG_F:
     3.6            case OP_MOD:
     3.7 -          case OP_BITS_I2F:
     3.8 -          case OP_BITS_F2I:
     3.9 +          case OP_BITCAST:
    3.10            case OP_TRUE:
    3.11            case OP_FALSE:
    3.12            case OP_SIZEOF:
     4.1 --- a/src/Opcodes.tbl	Wed Dec 26 17:20:55 2012 -0800
     4.2 +++ b/src/Opcodes.tbl	Thu Dec 27 20:44:50 2012 -0800
     4.3 @@ -216,9 +216,9 @@
     4.4  OPDEF(OP_SETGLOBAL,     "setglobal",    5,      1, 1)
     4.5  OPDEF(OP_GETGLOBAL,     "getglobal",    5,      0, 1)
     4.6  
     4.7 -// Reinterprets a 32-bit integer as a float, or vice-versa.
     4.8 -OPDEF(OP_BITS_I2F,      "bits.i2f",     1,      1, 1)
     4.9 -OPDEF(OP_BITS_F2I,      "bits.f2i",     1,      1, 1)
    4.10 +// Reinterpret casts from one 32-bit POD type to another. The new type pointer
    4.11 +// is encoded into the object table, for the JITs' type flow.
    4.12 +OPDEF(OP_BITCAST,       "BITCAST",      5,      1, 1)
    4.13  
    4.14  // Pushes a boolean value.
    4.15  OPDEF(OP_TRUE,          "true",         1,      0, 1)
     5.1 --- a/src/compiler/BytecodeEmitter.h	Wed Dec 26 17:20:55 2012 -0800
     5.2 +++ b/src/compiler/BytecodeEmitter.h	Thu Dec 27 20:44:50 2012 -0800
     5.3 @@ -627,12 +627,6 @@
     5.4      void neg_f() {
     5.5          singleByteOp(OP_NEG_F);
     5.6      }
     5.7 -    void bits_i2f() {
     5.8 -        singleByteOp(OP_BITS_I2F);
     5.9 -    }
    5.10 -    void bits_f2i() {
    5.11 -        singleByteOp(OP_BITS_F2I);
    5.12 -    }
    5.13      void true_() {
    5.14          singleByteOp(OP_TRUE);
    5.15      }
    5.16 @@ -657,6 +651,12 @@
    5.17          singleByteOp(OP_PUBLIC);
    5.18      }
    5.19  
    5.20 +    void bitcast(Type *type) {
    5.21 +        ensure(OP_BITCAST_LENGTH);
    5.22 +        writeOp(OP_BITCAST);
    5.23 +        writeObject(type);
    5.24 +    }
    5.25 +
    5.26      void tableswitch(int low, int high, Label *def, Label **labels) {
    5.27          unsigned tablesize = TableSwitchEntries(low, high);
    5.28          assert(tablesize <= MAX_TABLESWITCH_ENTRIES);
     6.1 --- a/src/compiler/HIR.cpp	Wed Dec 26 17:20:55 2012 -0800
     6.2 +++ b/src/compiler/HIR.cpp	Thu Dec 27 20:44:50 2012 -0800
     6.3 @@ -38,6 +38,7 @@
     6.4          hir->accept(this);
     6.5      }
     6.6  
     6.7 +    void visitBoolean(HBoolean *hir);
     6.8      void visitFloat(HFloat *hir);
     6.9      void visitInteger(HInteger *hir);
    6.10      void visitArray(HArray *hir);
    6.11 @@ -59,6 +60,15 @@
    6.12  #define __ emitter_.
    6.13  
    6.14  void
    6.15 +HIRTranslator::visitBoolean(HBoolean *hir)
    6.16 +{
    6.17 +    if (hir->value())
    6.18 +        __ true_();
    6.19 +    else
    6.20 +        __ false_();
    6.21 +}
    6.22 +
    6.23 +void
    6.24  HIRTranslator::visitFloat(HFloat *hir)
    6.25  {
    6.26      __ float_(hir->value());
     7.1 --- a/src/compiler/HIR.h	Wed Dec 26 17:20:55 2012 -0800
     7.2 +++ b/src/compiler/HIR.h	Thu Dec 27 20:44:50 2012 -0800
     7.3 @@ -27,6 +27,7 @@
     7.4  
     7.5  #define HIR_OPS(_)                      \
     7.6      _(Call)                             \
     7.7 +    _(Boolean)                          \
     7.8      _(Integer)                          \
     7.9      _(Float)                            \
    7.10      _(String)                           \
    7.11 @@ -127,6 +128,24 @@
    7.12          visitor->visit##name(this);             \
    7.13      }
    7.14  
    7.15 +class HBoolean : public HIR
    7.16 +{
    7.17 +  public:
    7.18 +    HBoolean(AstNode *node, Type *type, bool value)
    7.19 +      : HIR(node, type),
    7.20 +        value_(value)
    7.21 +    {
    7.22 +    }
    7.23 +
    7.24 +    DEFINE_HIR(Boolean);
    7.25 +    bool value() const {
    7.26 +        return value_;
    7.27 +    }
    7.28 +
    7.29 +  private:
    7.30 +    bool value_;
    7.31 +};
    7.32 +
    7.33  class HInteger : public HIR
    7.34  {
    7.35    public:
     8.1 --- a/src/compiler/SemanticAnalysis.cpp	Wed Dec 26 17:20:55 2012 -0800
     8.2 +++ b/src/compiler/SemanticAnalysis.cpp	Thu Dec 27 20:44:50 2012 -0800
     8.3 @@ -623,6 +623,13 @@
     8.4  }
     8.5  
     8.6  void
     8.7 +SemanticAnalysis::visitBooleanLiteral(BooleanLiteral *node)
     8.8 +{
     8.9 +    Local<Type> type(zone_, zone_->types()->getPrimitive(PrimitiveType_Bool));
    8.10 +    hir_ = new (pool_) HBoolean(node, type, node->token() == TOK_TRUE);
    8.11 +}
    8.12 +
    8.13 +void
    8.14  SemanticAnalysis::visitIntegerLiteral(IntegerLiteral *lit)
    8.15  {
    8.16      Local<Type> type(zone_, zone_->types()->getPrimitive(PrimitiveType_Int32));
    8.17 @@ -1069,6 +1076,53 @@
    8.18      }
    8.19  }
    8.20  
    8.21 +static inline bool
    8.22 +IsValidUncheckedType(Type *type)
    8.23 +{
    8.24 +    return type->isEnum() ||
    8.25 +           type->isFloat() ||
    8.26 +           type->isInt32() ||
    8.27 +           type->isChar() ||
    8.28 +           type->isUnchecked() ||
    8.29 +           type->isBool();
    8.30 +}
    8.31 +
    8.32 +void
    8.33 +SemanticAnalysis::visitUnaryExpression(UnaryExpression *node)
    8.34 +{
    8.35 +    switch (node->token()) {
    8.36 +      case TOK_LABEL:
    8.37 +      {
    8.38 +          assert(node->token() == TOK_LABEL);
    8.39 +          HIR *hir = eval(node->expression());
    8.40 +          if (!hir)
    8.41 +            return;
    8.42 +
    8.43 +          TypeSymbol *sym = node->tag()->sym()->asType();
    8.44 +          if (!sym) {
    8.45 +              cc_.reportError(node->pos(), Message_IdentifierIsNotAType,
    8.46 +                              sym->name()->chars());
    8.47 +              return;
    8.48 +          }
    8.49 +
    8.50 +          if (!IsValidUncheckedType(sym->type())) {
    8.51 +              char name[255];
    8.52 +              cc_.reportError(node->pos(), Message_InvalidUncheckedCastTo,
    8.53 +                              GetTypeName(hir->type(), name, sizeof(name)));
    8.54 +              return;
    8.55 +          }
    8.56 +          if (!IsValidUncheckedType(hir->type())) {
    8.57 +              char name[255];
    8.58 +              cc_.reportError(node->pos(), Message_InvalidUncheckedCastFrom,
    8.59 +                              GetTypeName(hir->type(), name, sizeof(name)));
    8.60 +              return;
    8.61 +          }
    8.62 +
    8.63 +          break;
    8.64 +      }
    8.65 +    }
    8.66 +}
    8.67 +
    8.68  static inline TokenKind
    8.69  ToCompare(Expression *expr)
    8.70  {
     9.1 --- a/src/compiler/SemanticAnalysis.h	Wed Dec 26 17:20:55 2012 -0800
     9.2 +++ b/src/compiler/SemanticAnalysis.h	Thu Dec 27 20:44:50 2012 -0800
     9.3 @@ -65,15 +65,15 @@
     9.4      void visitIndexExpression(IndexExpression *node);
     9.5      void visitIncDecExpression(IncDecExpression *node);
     9.6      void visitStringLiteral(StringLiteral *node);
     9.7 +    void visitUnaryExpression(UnaryExpression *node);
     9.8 +    void visitBooleanLiteral(BooleanLiteral *node);
     9.9  #if 0
    9.10      void visitFunctionTypeStatement(FunctionTypeStatement *node);
    9.11      void visitImportStatement(ImportStatement *node);
    9.12      void visitStructureStatement(StructureStatement *node);
    9.13      void visitSwitchStatement(SwitchStatement *node);
    9.14  
    9.15 -    void visitUnaryExpression(UnaryExpression *node);
    9.16      void visitTernaryExpression(TernaryExpression *node);
    9.17 -    void visitBooleanLiteral(BooleanLiteral *node);
    9.18      void visitFieldExpression(FieldExpression *node);
    9.19      void visitArrayLiteral(ArrayLiteral *node);
    9.20  #endif