Exemplo n.º 1
0
  void Resolver::visit(CatchExpr& expr, int dummy)
  {
    // Resolve the block body.
    Scope tryScope(this);
    resolve(expr.body());
    tryScope.end();

    // Resolve the catch handlers.
    for (int i = 0; i < expr.catches().count(); i++)
    {
      Scope caseScope(this);
      const MatchClause& clause = expr.catches()[i];
      
      // Resolve the pattern.
      scope_->resolve(*clause.pattern());
      
      // Resolve the body.
      resolve(clause.body());
      caseScope.end();
    }
  }
Exemplo n.º 2
0
  void ExprCompiler::visit(CatchExpr& expr, int dest)
  {
    // Register the catch handler.
    int enter = startJump(expr);

    // Compile the block body.
    compile(expr.body(), dest);

    // Complete the catch handler.
    write(expr, OP_EXIT_TRY);

    // Jump past it if an exception is not thrown.
    int jumpPastCatch = startJump(expr);

    endJump(enter, OP_ENTER_TRY);

    // TODO(bob): Can we use "dest" here or does it need to be a temp?
    // Write a pseudo-opcode so we know what slot to put the error in.
    write(expr, OP_MOVE, dest);

    compileMatch(expr.catches(), dest);

    endJump(jumpPastCatch, OP_JUMP, 1);
  }