Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 39eaddc1934d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 677c3f6fd476
Choose a head ref
  • 4 commits
  • 1 file changed
  • 2 contributors

Commits on Aug 27, 2015

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    73224a3 View commit details
  2. Copy the full SHA
    77673b3 View commit details
  3. Copy the full SHA
    4d40c03 View commit details

Commits on Aug 28, 2015

  1. Merge pull request #3290 from bbelleville/minimal-lazy

    [Truffle] Allow for lazy parsing
    eregon committed Aug 28, 2015
    Copy the full SHA
    677c3f6 View commit details
Showing with 44 additions and 2 deletions.
  1. +44 −2 truffle/src/main/java/org/jruby/truffle/translator/MethodTranslator.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@
*/
package org.jruby.truffle.translator;

import java.util.ArrayDeque;
import java.util.Deque;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameSlot;
@@ -34,11 +37,12 @@
import org.jruby.truffle.nodes.supercall.GeneralSuperCallNode;
import org.jruby.truffle.nodes.supercall.GeneralSuperReCallNode;
import org.jruby.truffle.nodes.supercall.ZSuperOutsideMethodNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

class MethodTranslator extends BodyTranslator {
public class MethodTranslator extends BodyTranslator {

private final org.jruby.ast.ArgsNode argsNode;
private boolean isBlock;
@@ -156,7 +160,16 @@ private RubyNode wrapBody(RubyNode prelude, RubyNode body) {
return body;
}

public MethodDefinitionNode compileMethodNode(SourceSection sourceSection, String methodName, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
/*
* This method exists solely to be substituted to support lazy
* method parsing. The substitution returns a node which performs
* the parsing lazily and then calls doCompileMethodBody.
*/
public RubyNode compileMethodBody(SourceSection sourceSection, String methodName, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
return doCompileMethodBody(sourceSection, methodName, bodyNode, sharedMethodInfo);
}

public RubyNode doCompileMethodBody(SourceSection sourceSection, String methodName, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
final ParameterCollector parameterCollector = declareArguments(sourceSection, methodName, sharedMethodInfo);
final Arity arity = getArity(argsNode);

@@ -194,7 +207,11 @@ public MethodDefinitionNode compileMethodNode(SourceSection sourceSection, Strin

// TODO(CS, 10-Jan-15) why do we only translate exceptions in methods and not blocks?
body = new ExceptionTranslatingNode(context, sourceSection, body);
return body;
}

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, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body, environment.needsDeclarationFrame());

@@ -322,4 +339,29 @@ protected FlipFlopStateNode createFlipFlopState(SourceSection sourceSection, int
}
}

/*
* The following methods allow us to save and restore enough of
* the current state of the Translator to allow lazy parsing. When
* the lazy parsing is actually performed, the state is restored
* to what it would have been if the method had been parsed
* eagerly.
*/
public TranslatorState getCurrentState() {
return new TranslatorState(getEnvironment().getLexicalScope(), new ArrayDeque<SourceSection>(parentSourceSection));
}

public void restoreState(TranslatorState state) {
this.getEnvironment().getParseEnvironment().resetLexicalScope(state.scope);
this.parentSourceSection = state.parentSourceSection;
}

public static class TranslatorState {
private final LexicalScope scope;
private final Deque<SourceSection> parentSourceSection;

private TranslatorState(LexicalScope scope, Deque<SourceSection> parentSourceSection) {
this.scope = scope;
this.parentSourceSection = parentSourceSection;
}
}
}