Exemplo n.º 1
0
  private RubyNode composeBody(RubyNode prelude, RubyNode body) {
    final SourceSection sourceSection =
        SequenceNode.enclosing(prelude.getSourceSection(), body.getSourceSection());

    body = SequenceNode.sequence(context, sourceSection, prelude, body);

    if (environment.getFlipFlopStates().size() > 0) {
      body = SequenceNode.sequence(context, sourceSection, initFlipFlopStates(sourceSection), body);
    }

    return body;
  }
Exemplo n.º 2
0
  public RubyNode doCompileMethodBody(
      SourceSection sourceSection,
      String methodName,
      org.jruby.ast.Node bodyNode,
      SharedMethodInfo sharedMethodInfo) {
    declareArguments(sourceSection, methodName, sharedMethodInfo);
    final Arity arity = getArity(argsNode);

    final LoadArgumentsTranslator loadArgumentsTranslator =
        new LoadArgumentsTranslator(currentNode, context, source, false, this);
    final RubyNode loadArguments = argsNode.accept(loadArgumentsTranslator);

    RubyNode body;

    parentSourceSection.push(sourceSection);
    try {
      body = translateNodeOrNil(sourceSection, bodyNode);
    } finally {
      parentSourceSection.pop();
    }

    final RubyNode prelude;

    if (usesRubiniusPrimitive) {
      // Use Rubinius.primitive seems to turn off arity checking. See Time.from_array for example.
      prelude = loadArguments;
    } else {
      prelude =
          SequenceNode.sequence(
              context,
              sourceSection,
              CheckArityNode.create(context, sourceSection, arity),
              loadArguments);
    }

    body = SequenceNode.sequence(context, body.getSourceSection(), prelude, body);

    if (environment.getFlipFlopStates().size() > 0) {
      body =
          SequenceNode.sequence(
              context, body.getSourceSection(), initFlipFlopStates(sourceSection), body);
    }

    body =
        new CatchForMethodNode(context, body.getSourceSection(), body, environment.getReturnID());

    // TODO(CS, 10-Jan-15) why do we only translate exceptions in methods and not blocks?
    body = new ExceptionTranslatingNode(context, body.getSourceSection(), body);
    return body;
  }
Exemplo n.º 3
0
  public MethodDefinitionNode compileMethodNode(
      SourceSection sourceSection,
      String methodName,
      org.jruby.ast.Node bodyNode,
      SharedMethodInfo sharedMethodInfo) {
    final RubyNode body = compileMethodBody(sourceSection, methodName, bodyNode, sharedMethodInfo);
    final RubyRootNode rootNode =
        new RubyRootNode(
            context,
            considerExtendingMethodToCoverEnd(body.getSourceSection()),
            environment.getFrameDescriptor(),
            environment.getSharedMethodInfo(),
            body,
            environment.needsDeclarationFrame());

    final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    return new MethodDefinitionNode(
        context, sourceSection, methodName, environment.getSharedMethodInfo(), callTarget);
  }
Exemplo n.º 4
0
 public PassthroughNode(RubyNode child) {
   super(child.getContext(), child.getSourceSection());
   this.child = child;
 }