Esempio n. 1
0
  private Object handleException(VirtualFrame frame, RuntimeException exception) {
    CompilerAsserts.neverPartOfCompilation();

    final RubyContext context = getContext();

    final RubyBasicObject rubyException =
        ExceptionTranslator.translateException(context, exception);

    context.getCoreLibrary().getGlobalVariablesObject().setInstanceVariable("$!", rubyException);

    for (RescueNode rescue : rescueParts) {
      if (rescue.canHandle(frame, rubyException)) {
        return rescue.execute(frame);
      }
    }

    throw exception;
  }
Esempio n. 2
0
 public TryNode(
     RubyContext context,
     SourceSection sourceSection,
     ExceptionTranslatingNode tryPart,
     RescueNode[] rescueParts,
     RubyNode elsePart) {
   super(context, sourceSection);
   this.tryPart = tryPart;
   this.rescueParts = rescueParts;
   this.elsePart = elsePart;
   clearExceptionVariableNode =
       new WriteInstanceVariableNode(
           context,
           sourceSection,
           "$!",
           new ObjectLiteralNode(
               context, sourceSection, context.getCoreLibrary().getGlobalVariablesObject()),
           new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject()),
           true);
 }
Esempio n. 3
0
  public static RubyNode sequence(
      RubyContext context, SourceSection sourceSection, List<RubyNode> sequence) {
    final List<RubyNode> flattened = flatten(sequence, true);

    if (flattened.isEmpty()) {
      return new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject());
    } else if (flattened.size() == 1) {
      return flattened.get(0);
    } else {
      return new SequenceNode(
          context, sourceSection, flattened.toArray(new RubyNode[flattened.size()]));
    }
  }