Пример #1
0
 void Resolver::visit(WhileExpr& expr, int dest)
 {
   Scope loopScope(this);
   
   resolve(expr.condition());
   
   // TODO(bob): Should the body get its own scope?
   numLoops_++;
   resolve(expr.body());
   numLoops_--;
   
   loopScope.end();
 }
Пример #2
0
  void ExprCompiler::visit(WhileExpr& expr, int dest)
  {
    int loopStart = startJumpBack();

    // Compile the condition.
    int condition = makeTemp();
    compile(expr.condition(), condition);
    int loopExit = startJump(expr);
    releaseTemp(); // condition

    Loop loop(this);
    compile(expr.body(), dest);

    endJumpBack(expr, loopStart);
    endJump(loopExit, OP_JUMP_IF_FALSE, condition);
    loop.end();
  }