Add |while| and |do-while| support back.
authorDavid Anderson <dvander@alliedmods.net>
Sat Nov 17 20:02:38 2012 -0800 (2012-11-17)
changeset 2033c205ce50118
parent 202 c3d867f81d29
child 204 ff89b2640fba
Add |while| and |do-while| support back.
src/compiler/SemanticAnalysis.cpp
src/compiler/SemanticAnalysis.h
tests/prototype/while.sp
     1.1 --- a/src/compiler/SemanticAnalysis.cpp	Sat Nov 17 19:48:43 2012 -0800
     1.2 +++ b/src/compiler/SemanticAnalysis.cpp	Sat Nov 17 20:02:38 2012 -0800
     1.3 @@ -242,6 +242,32 @@
     1.4  }
     1.5  
     1.6  void
     1.7 +SemanticAnalysis::visitWhileStatement(WhileStatement *node)
     1.8 +{
     1.9 +    PoolScope poolScope(zone_->pool());
    1.10 +    RootScope rootScope(zone_);
    1.11 +
    1.12 +    Label header, join;
    1.13 +
    1.14 +    __ bind(&header);
    1.15 +
    1.16 +    LoopScope loop(scope_, &join, &header, &loop_);
    1.17 +    if (node->token() == TOK_WHILE) {
    1.18 +        Label body;
    1.19 +        visitForTest(node->condition(), &body, &join, &body);
    1.20 +        node->body()->accept(this);
    1.21 +        __ jump(&header);
    1.22 +    } else {
    1.23 +        node->body()->accept(this);
    1.24 +        visitForTest(node->condition(), &header, &join, &join);
    1.25 +    }
    1.26 +
    1.27 +    __ bind(&join);
    1.28 +
    1.29 +    assert(__ stackDepth() == 0);
    1.30 +}
    1.31 +
    1.32 +void
    1.33  SemanticAnalysis::visitVariableDeclaration(VariableDeclaration *node)
    1.34  {
    1.35      PoolScope poolScope(zone_->pool());
     2.1 --- a/src/compiler/SemanticAnalysis.h	Sat Nov 17 19:48:43 2012 -0800
     2.2 +++ b/src/compiler/SemanticAnalysis.h	Sat Nov 17 20:02:38 2012 -0800
     2.3 @@ -55,6 +55,7 @@
     2.4      void visitFloatLiteral(FloatLiteral *node);
     2.5      void visitVariableDeclaration(VariableDeclaration *node);
     2.6      void visitForStatement(ForStatement *node);
     2.7 +    void visitWhileStatement(WhileStatement *node);
     2.8      void visitAssignment(Assignment *node);
     2.9      void visitBinaryExpression(BinaryExpression *node);
    2.10  #if 0
    2.11 @@ -62,7 +63,6 @@
    2.12      void visitImportStatement(ImportStatement *node);
    2.13      void visitExpressionStatement(ExpressionStatement *node);
    2.14      void visitEnumStatement(EnumStatement *node);
    2.15 -    void visitWhileStatement(WhileStatement *node);
    2.16      void visitBreakStatement(BreakStatement *node);
    2.17      void visitContinueStatement(ContinueStatement *node);
    2.18      void visitStructureStatement(StructureStatement *node);
     3.1 --- a/tests/prototype/while.sp	Sat Nov 17 19:48:43 2012 -0800
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,8 +0,0 @@
     3.4 -main()
     3.5 -{
     3.6 -   new i = 0;
     3.7 -   while (i < 100) {
     3.8 -      i = i + 37;
     3.9 -   }
    3.10 -   return i;
    3.11 -}