Get preinc working again.
authorDavid Anderson <dvander@alliedmods.net>
Sun Nov 18 15:50:41 2012 -0800 (2012-11-18)
changeset 217c22e983b3b6e
parent 216 ea63f1680097
child 218 ccb089827f87
Get preinc working again.
src/compiler/HIR.cpp
src/compiler/NameBinding.cpp
src/compiler/SemanticAnalysis.cpp
src/compiler/SemanticAnalysis.h
tests/basic/preinc-array.out
tests/basic/preinc-array.sp
tests/basic/preinc-local.out
tests/basic/preinc-local.sp
tests/prototype/preinc-array.sp
tests/prototype/preinc-local.sp
     1.1 --- a/src/compiler/HIR.cpp	Sun Nov 18 15:26:12 2012 -0800
     1.2 +++ b/src/compiler/HIR.cpp	Sun Nov 18 15:50:41 2012 -0800
     1.3 @@ -188,9 +188,11 @@
     1.4      switch (kind) {
     1.5        case TOK_PLUS:
     1.6        case TOK_ASSIGN_ADD:
     1.7 +      case TOK_INCREMENT:
     1.8          return OP_ADD;
     1.9        case TOK_MINUS:
    1.10        case TOK_ASSIGN_SUB:
    1.11 +      case TOK_DECREMENT:
    1.12          return OP_SUB;
    1.13        case TOK_STAR:
    1.14        case TOK_ASSIGN_MUL:
     2.1 --- a/src/compiler/NameBinding.cpp	Sun Nov 18 15:26:12 2012 -0800
     2.2 +++ b/src/compiler/NameBinding.cpp	Sun Nov 18 15:50:41 2012 -0800
     2.3 @@ -335,7 +335,7 @@
     2.4      void visitStringLiteral(StringLiteral *node) {
     2.5      }
     2.6      void visitIncDecExpression(IncDecExpression *node) {
     2.7 -        assert(false);
     2.8 +        node->expression()->accept(this);
     2.9      }
    2.10      void visitUnaryExpression(UnaryExpression *node) {
    2.11          assert(false);
     3.1 --- a/src/compiler/SemanticAnalysis.cpp	Sun Nov 18 15:26:12 2012 -0800
     3.2 +++ b/src/compiler/SemanticAnalysis.cpp	Sun Nov 18 15:50:41 2012 -0800
     3.3 @@ -586,6 +586,31 @@
     3.4                                right);
     3.5  }
     3.6  
     3.7 +void
     3.8 +SemanticAnalysis::visitIncDecExpression(IncDecExpression *node)
     3.9 +{
    3.10 +    HLValue *lval = lvalue(node->expression());
    3.11 +    if (!lval)
    3.12 +        return;
    3.13 +
    3.14 +    if (!lval->type()->isInt32() && !lval->type()->isFloat()) {
    3.15 +        assert(false);
    3.16 +        return;
    3.17 +    }
    3.18 +
    3.19 +    HIR *rval;
    3.20 +    if (lval->type()->isInt32())
    3.21 +        rval = new (pool_) HInteger(lval->type(), 1);
    3.22 +    else
    3.23 +        rval = new (pool_) HFloat(lval->type(), 1.0);
    3.24 +
    3.25 +    if (node->postfix()) {
    3.26 +        assert(false);
    3.27 +    } else {
    3.28 +        hir_ = new (pool_) HStore(node->token(), lval, rval);
    3.29 +    }
    3.30 +}
    3.31 +
    3.32  Type *
    3.33  SemanticAnalysis::coercionType(TokenKind token, HIR *left, HIR *right)
    3.34  {
     4.1 --- a/src/compiler/SemanticAnalysis.h	Sun Nov 18 15:26:12 2012 -0800
     4.2 +++ b/src/compiler/SemanticAnalysis.h	Sun Nov 18 15:50:41 2012 -0800
     4.3 @@ -62,6 +62,7 @@
     4.4      void visitContinueStatement(ContinueStatement *node);
     4.5      void visitIfStatement(IfStatement *node);
     4.6      void visitIndexExpression(IndexExpression *node);
     4.7 +    void visitIncDecExpression(IncDecExpression *node);
     4.8  #if 0
     4.9      void visitFunctionTypeStatement(FunctionTypeStatement *node);
    4.10      void visitImportStatement(ImportStatement *node);
    4.11 @@ -73,7 +74,6 @@
    4.12      void visitBinaryExpression(BinaryExpression *node);
    4.13      void visitCallExpression(CallExpression *node);
    4.14      void visitStringLiteral(StringLiteral *node);
    4.15 -    void visitIncDecExpression(IncDecExpression *node);
    4.16      void visitUnaryExpression(UnaryExpression *node);
    4.17      void visitTernaryExpression(TernaryExpression *node);
    4.18      void visitBooleanLiteral(BooleanLiteral *node);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tests/basic/preinc-array.out	Sun Nov 18 15:50:41 2012 -0800
     5.3 @@ -0,0 +1,1 @@
     5.4 +1
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tests/basic/preinc-array.sp	Sun Nov 18 15:50:41 2012 -0800
     6.3 @@ -0,0 +1,7 @@
     6.4 +native PrintNum(num);
     6.5 +
     6.6 +public main()
     6.7 +{
     6.8 +    new x[5];
     6.9 +    PrintNum(++x[3]);
    6.10 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tests/basic/preinc-local.out	Sun Nov 18 15:50:41 2012 -0800
     7.3 @@ -0,0 +1,1 @@
     7.4 +1
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tests/basic/preinc-local.sp	Sun Nov 18 15:50:41 2012 -0800
     8.3 @@ -0,0 +1,7 @@
     8.4 +native PrintNum(num);
     8.5 +
     8.6 +public main()
     8.7 +{
     8.8 +    new i = 0;
     8.9 +    PrintNum(++i);
    8.10 +}
     9.1 --- a/tests/prototype/preinc-array.sp	Sun Nov 18 15:26:12 2012 -0800
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,5 +0,0 @@
     9.4 -main()
     9.5 -{
     9.6 -    new x[5];
     9.7 -    return ++x[3];
     9.8 -}
    10.1 --- a/tests/prototype/preinc-local.sp	Sun Nov 18 15:26:12 2012 -0800
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,5 +0,0 @@
    10.4 -main()
    10.5 -{
    10.6 -    new i = 0;
    10.7 -    return ++i;
    10.8 -}