Пример #1
0
  private RubyNode translateLocalAssignment(
      ISourcePosition sourcePosition, String name, org.jruby.ast.Node valueNode) {
    final SourceSection sourceSection = translate(sourcePosition);

    final RubyNode readNode;

    if (valueNode instanceof org.jruby.ast.NilImplicitNode) {
      // Multiple assignment

      if (useArray()) {
        readNode =
            ArrayIndexNodeFactory.create(context, sourceSection, index, loadArray(sourceSection));
      } else {
        readNode = readArgument(sourceSection, index);
      }
    } else {
      // Optional argument
      final RubyNode defaultValue = valueNode.accept(this);
      readNode =
          new ReadOptionalArgumentNode(
              context, sourceSection, index, index + argsNode.getPostCount() + 1, defaultValue);
    }

    final FrameSlot slot =
        methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(name);
    return WriteLocalVariableNodeFactory.create(context, sourceSection, slot, readNode);
  }
Пример #2
0
 private RubyNode readArgument(SourceSection sourceSection, int index) {
   if (useArray()) {
     return ArrayIndexNodeFactory.create(context, sourceSection, index, loadArray(sourceSection));
   } else {
     if (state == State.PRE) {
       return new ReadPreArgumentNode(
           context,
           sourceSection,
           index,
           isBlock ? MissingArgumentBehaviour.NIL : MissingArgumentBehaviour.RUNTIME_ERROR);
     } else if (state == State.POST) {
       return new ReadPostArgumentNode(
           context,
           sourceSection,
           (argsNode.getPreCount() + argsNode.getOptionalArgsCount() + argsNode.getPostCount())
               - index
               - 1);
     } else {
       throw new IllegalStateException();
     }
   }
 }