# HG changeset patch # User David Anderson # Date 1353211358 28800 # Node ID 3c205ce501180c31b7eec142529ac7409579f52e # Parent c3d867f81d29f009ef8b715a527ff60b9360b8ec Add |while| and |do-while| support back. diff -r c3d867f81d29 -r 3c205ce50118 src/compiler/SemanticAnalysis.cpp --- a/src/compiler/SemanticAnalysis.cpp Sat Nov 17 19:48:43 2012 -0800 +++ b/src/compiler/SemanticAnalysis.cpp Sat Nov 17 20:02:38 2012 -0800 @@ -242,6 +242,32 @@ } void +SemanticAnalysis::visitWhileStatement(WhileStatement *node) +{ + PoolScope poolScope(zone_->pool()); + RootScope rootScope(zone_); + + Label header, join; + + __ bind(&header); + + LoopScope loop(scope_, &join, &header, &loop_); + if (node->token() == TOK_WHILE) { + Label body; + visitForTest(node->condition(), &body, &join, &body); + node->body()->accept(this); + __ jump(&header); + } else { + node->body()->accept(this); + visitForTest(node->condition(), &header, &join, &join); + } + + __ bind(&join); + + assert(__ stackDepth() == 0); +} + +void SemanticAnalysis::visitVariableDeclaration(VariableDeclaration *node) { PoolScope poolScope(zone_->pool()); diff -r c3d867f81d29 -r 3c205ce50118 src/compiler/SemanticAnalysis.h --- a/src/compiler/SemanticAnalysis.h Sat Nov 17 19:48:43 2012 -0800 +++ b/src/compiler/SemanticAnalysis.h Sat Nov 17 20:02:38 2012 -0800 @@ -55,6 +55,7 @@ void visitFloatLiteral(FloatLiteral *node); void visitVariableDeclaration(VariableDeclaration *node); void visitForStatement(ForStatement *node); + void visitWhileStatement(WhileStatement *node); void visitAssignment(Assignment *node); void visitBinaryExpression(BinaryExpression *node); #if 0 @@ -62,7 +63,6 @@ void visitImportStatement(ImportStatement *node); void visitExpressionStatement(ExpressionStatement *node); void visitEnumStatement(EnumStatement *node); - void visitWhileStatement(WhileStatement *node); void visitBreakStatement(BreakStatement *node); void visitContinueStatement(ContinueStatement *node); void visitStructureStatement(StructureStatement *node); diff -r c3d867f81d29 -r 3c205ce50118 tests/prototype/while.sp --- a/tests/prototype/while.sp Sat Nov 17 19:48:43 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -main() -{ - new i = 0; - while (i < 100) { - i = i + 37; - } - return i; -}