# HG changeset patch # User David Anderson # Date 1353282641 28800 # Node ID c22e983b3b6e973b78d07176154da96b7d4caac0 # Parent ea63f16800975a52b6b736725a7bb59bd8ed5e08 Get preinc working again. diff -r ea63f1680097 -r c22e983b3b6e src/compiler/HIR.cpp --- a/src/compiler/HIR.cpp Sun Nov 18 15:26:12 2012 -0800 +++ b/src/compiler/HIR.cpp Sun Nov 18 15:50:41 2012 -0800 @@ -188,9 +188,11 @@ switch (kind) { case TOK_PLUS: case TOK_ASSIGN_ADD: + case TOK_INCREMENT: return OP_ADD; case TOK_MINUS: case TOK_ASSIGN_SUB: + case TOK_DECREMENT: return OP_SUB; case TOK_STAR: case TOK_ASSIGN_MUL: diff -r ea63f1680097 -r c22e983b3b6e src/compiler/NameBinding.cpp --- a/src/compiler/NameBinding.cpp Sun Nov 18 15:26:12 2012 -0800 +++ b/src/compiler/NameBinding.cpp Sun Nov 18 15:50:41 2012 -0800 @@ -335,7 +335,7 @@ void visitStringLiteral(StringLiteral *node) { } void visitIncDecExpression(IncDecExpression *node) { - assert(false); + node->expression()->accept(this); } void visitUnaryExpression(UnaryExpression *node) { assert(false); diff -r ea63f1680097 -r c22e983b3b6e src/compiler/SemanticAnalysis.cpp --- a/src/compiler/SemanticAnalysis.cpp Sun Nov 18 15:26:12 2012 -0800 +++ b/src/compiler/SemanticAnalysis.cpp Sun Nov 18 15:50:41 2012 -0800 @@ -586,6 +586,31 @@ right); } +void +SemanticAnalysis::visitIncDecExpression(IncDecExpression *node) +{ + HLValue *lval = lvalue(node->expression()); + if (!lval) + return; + + if (!lval->type()->isInt32() && !lval->type()->isFloat()) { + assert(false); + return; + } + + HIR *rval; + if (lval->type()->isInt32()) + rval = new (pool_) HInteger(lval->type(), 1); + else + rval = new (pool_) HFloat(lval->type(), 1.0); + + if (node->postfix()) { + assert(false); + } else { + hir_ = new (pool_) HStore(node->token(), lval, rval); + } +} + Type * SemanticAnalysis::coercionType(TokenKind token, HIR *left, HIR *right) { diff -r ea63f1680097 -r c22e983b3b6e src/compiler/SemanticAnalysis.h --- a/src/compiler/SemanticAnalysis.h Sun Nov 18 15:26:12 2012 -0800 +++ b/src/compiler/SemanticAnalysis.h Sun Nov 18 15:50:41 2012 -0800 @@ -62,6 +62,7 @@ void visitContinueStatement(ContinueStatement *node); void visitIfStatement(IfStatement *node); void visitIndexExpression(IndexExpression *node); + void visitIncDecExpression(IncDecExpression *node); #if 0 void visitFunctionTypeStatement(FunctionTypeStatement *node); void visitImportStatement(ImportStatement *node); @@ -73,7 +74,6 @@ void visitBinaryExpression(BinaryExpression *node); void visitCallExpression(CallExpression *node); void visitStringLiteral(StringLiteral *node); - void visitIncDecExpression(IncDecExpression *node); void visitUnaryExpression(UnaryExpression *node); void visitTernaryExpression(TernaryExpression *node); void visitBooleanLiteral(BooleanLiteral *node); diff -r ea63f1680097 -r c22e983b3b6e tests/basic/preinc-array.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/preinc-array.out Sun Nov 18 15:50:41 2012 -0800 @@ -0,0 +1,1 @@ +1 diff -r ea63f1680097 -r c22e983b3b6e tests/basic/preinc-array.sp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/preinc-array.sp Sun Nov 18 15:50:41 2012 -0800 @@ -0,0 +1,7 @@ +native PrintNum(num); + +public main() +{ + new x[5]; + PrintNum(++x[3]); +} diff -r ea63f1680097 -r c22e983b3b6e tests/basic/preinc-local.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/preinc-local.out Sun Nov 18 15:50:41 2012 -0800 @@ -0,0 +1,1 @@ +1 diff -r ea63f1680097 -r c22e983b3b6e tests/basic/preinc-local.sp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/preinc-local.sp Sun Nov 18 15:50:41 2012 -0800 @@ -0,0 +1,7 @@ +native PrintNum(num); + +public main() +{ + new i = 0; + PrintNum(++i); +} diff -r ea63f1680097 -r c22e983b3b6e tests/prototype/preinc-array.sp --- a/tests/prototype/preinc-array.sp Sun Nov 18 15:26:12 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -main() -{ - new x[5]; - return ++x[3]; -} diff -r ea63f1680097 -r c22e983b3b6e tests/prototype/preinc-local.sp --- a/tests/prototype/preinc-local.sp Sun Nov 18 15:26:12 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -main() -{ - new i = 0; - return ++i; -}