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: 2255c6fcff6f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c38ac6752f60
Choose a head ref
  • 2 commits
  • 10 files changed
  • 1 contributor

Commits on Mar 8, 2015

  1. Copy the full SHA
    1f82778 View commit details
  2. Copy the full SHA
    c38ac67 View commit details
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.array.*;
import org.jruby.truffle.nodes.cast.ToSNodeFactory;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.nodes.methods.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.nodes.methods.arguments.ReadPreArgumentNode;
@@ -39,6 +38,7 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.control.RedoException;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.runtime.util.ArrayUtils;
import org.jruby.util.ByteList;
@@ -1838,7 +1838,7 @@ public MaxBlock(RubyContext context) {
frameDescriptor = new FrameDescriptor();
frameSlot = frameDescriptor.addFrameSlot("maximum_memo");

sharedMethodInfo = new SharedMethodInfo(sourceSection, null, "max", false, null, false);
sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, "max", false, null, false);

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
@@ -1951,7 +1951,7 @@ public MinBlock(RubyContext context) {
frameDescriptor = new FrameDescriptor();
frameSlot = frameDescriptor.addFrameSlot("minimum_memo");

sharedMethodInfo = new SharedMethodInfo(sourceSection, null, "min", false, null, false);
sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, "min", false, null, false);

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
Original file line number Diff line number Diff line change
@@ -135,8 +135,6 @@ private static void addMethod(RubyModule module, RubyRootNode rootNode, List<Str
private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails methodDetails, boolean needsSelf) {
final CoreSourceSection sourceSection = new CoreSourceSection(methodDetails.getClassAnnotation().name(), methodDetails.getMethodAnnotation().names()[0]);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, methodDetails.getIndicativeName(), false, null, true);

final int required = methodDetails.getMethodAnnotation().required();
final int optional;

@@ -148,6 +146,8 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails

final Arity arity = new Arity(required, optional, methodDetails.getMethodAnnotation().argumentsAsArray(), false);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, arity, methodDetails.getIndicativeName(), false, null, true);

final List<RubyNode> argumentsNodes = new ArrayList<>();

if (needsSelf) {
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public abstract static class EqualNode extends HashCoreMethodNode {
public EqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
eqlNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
}

public EqualNode(EqualNode prev) {
@@ -260,7 +260,7 @@ public abstract static class GetIndexNode extends HashCoreMethodNode {
public GetIndexNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
eqlNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
yield = new YieldDispatchHeadNode(context);
findEntryNode = new FindEntryNode(context, sourceSection);
}
Original file line number Diff line number Diff line change
@@ -408,7 +408,7 @@ public static void attrReader(Node currentNode, RubyContext context, SourceSecti

final String indicativeName = name + "(attr_reader)";

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, indicativeName, false, null, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, indicativeName, false, null, false);
final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, sharedMethodInfo, block);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = new InternalMethod(sharedMethodInfo, name, module, Visibility.PUBLIC, false, callTarget, null);
@@ -461,7 +461,7 @@ public static void attrWriter(Node currentNode, RubyContext context, SourceSecti

final String indicativeName = name + "(attr_writer)";

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, indicativeName, false, null, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.ONE_REQUIRED, indicativeName, false, null, false);
final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, sharedMethodInfo, block);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = new InternalMethod(sharedMethodInfo, name + "=", module, Visibility.PUBLIC, false, callTarget, null);
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.methods.SymbolProcNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.util.ByteList;
import org.jruby.util.ByteListHolder;
@@ -57,7 +58,7 @@ public RubyProc toProc(SourceSection sourceSection, final Node currentNode) {

final RubyContext context = getContext();

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, symbol, true, null, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.NO_ARGUMENTS, symbol, true, null, false);

final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, new FrameDescriptor(), sharedMethodInfo,
new SymbolProcNode(context, sourceSection, symbol));
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@

public class Arity {

public static final Arity NO_ARGUMENTS = new Arity(0, 0, false, false);
public static final Arity ONE_REQUIRED = new Arity(1, 0, false, false);

private final int required;
private final int optional;
private final boolean allowsMore;
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.runtime.methods;

import com.oracle.truffle.api.source.SourceSection;
import org.jruby.ast.Node;
import org.jruby.truffle.runtime.LexicalScope;

/**
@@ -20,17 +21,19 @@ public class SharedMethodInfo {

private final SourceSection sourceSection;
private final LexicalScope lexicalScope;
private final Arity arity;
private final String name;
private final boolean isBlock;
private final org.jruby.ast.Node parseTree;
private final boolean alwaysSplit;

public SharedMethodInfo(SourceSection sourceSection, LexicalScope lexicalScope, String name, boolean isBlock, org.jruby.ast.Node parseTree, boolean alwaysSplit) {
public SharedMethodInfo(SourceSection sourceSection, LexicalScope lexicalScope, Arity arity, String name, boolean isBlock, Node parseTree, boolean alwaysSplit) {
assert sourceSection != null;
assert name != null;

this.sourceSection = sourceSection;
this.lexicalScope = lexicalScope;
this.arity = arity;
this.name = name;
this.isBlock = isBlock;
this.parseTree = parseTree;
@@ -45,6 +48,10 @@ public LexicalScope getLexicalScope() {
return lexicalScope;
}

public Arity getArity() {
return arity;
}

public String getName() {
return name;
}
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.util.ByteList;
import org.jruby.util.KeyValuePair;
@@ -808,7 +809,7 @@ public RubyNode visitCaseNode(org.jruby.ast.CaseNode node) {
private RubyNode openModule(SourceSection sourceSection, RubyNode defineOrGetNode, String name, Node bodyNode) {
LexicalScope newLexicalScope = environment.pushLexicalScope();
try {
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, newLexicalScope, name, false, bodyNode, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, newLexicalScope, Arity.NO_ARGUMENTS, name, false, bodyNode, false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(context, environment, environment.getParser(),
environment.getParser().allocateReturnID(), true, true, sharedMethodInfo, name, false);
@@ -1067,7 +1068,7 @@ public RubyNode visitDefsNode(org.jruby.ast.DefsNode node) {
}

protected RubyNode translateMethodDefinition(SourceSection sourceSection, RubyNode classNode, String methodName, org.jruby.ast.Node parseTree, org.jruby.ast.ArgsNode argsNode, org.jruby.ast.Node bodyNode) {
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), methodName, false, parseTree, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), MethodTranslator.getArity(argsNode), methodName, false, parseTree, false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
context, environment, environment.getParser(), environment.getParser().allocateReturnID(), true, true, sharedMethodInfo, methodName, false);
@@ -1654,14 +1655,6 @@ public RubyNode visitIterNode(org.jruby.ast.IterNode node) {

final boolean hasOwnScope = !translatingForStatement;

// Unset this flag for any for any blocks within the for statement's body
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), currentCallMethodName, true, node, false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
context, environment, environment.getParser(), environment.getReturnID(), hasOwnScope, false, sharedMethodInfo, environment.getNamedMethodName(), true);
final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, true, source);
methodCompiler.translatingForStatement = translatingForStatement;

org.jruby.ast.ArgsNode argsNode;

if (node.getVarNode() instanceof org.jruby.ast.ArgsNode) {
@@ -1676,6 +1669,14 @@ public RubyNode visitIterNode(org.jruby.ast.IterNode node) {
throw new UnsupportedOperationException();
}

// Unset this flag for any for any blocks within the for statement's body
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), MethodTranslator.getArity(argsNode), currentCallMethodName, true, node, false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
context, environment, environment.getParser(), environment.getReturnID(), hasOwnScope, false, sharedMethodInfo, environment.getNamedMethodName(), true);
final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, true, source);
methodCompiler.translatingForStatement = translatingForStatement;

if (translatingForStatement && useClassVariablesAsIfInClass) {
methodCompiler.useClassVariablesAsIfInClass = true;
}
@@ -2744,13 +2745,6 @@ public RubyNode visitBackRefNode(org.jruby.ast.BackRefNode node) {
public RubyNode visitLambdaNode(org.jruby.ast.LambdaNode node) {
final SourceSection sourceSection = translate(node.getPosition());

// TODO(cs): code copied and modified from visitIterNode - extract common
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), "(lambda)", true, node, false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
context, environment, environment.getParser(), environment.getReturnID(), false, false, sharedMethodInfo, sharedMethodInfo.getName(), true);
final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, false, source);

org.jruby.ast.ArgsNode argsNode;

if (node.getVarNode() instanceof org.jruby.ast.ArgsNode) {
@@ -2765,6 +2759,13 @@ public RubyNode visitLambdaNode(org.jruby.ast.LambdaNode node) {
throw new UnsupportedOperationException();
}

// TODO(cs): code copied and modified from visitIterNode - extract common
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), MethodTranslator.getArity(argsNode), "(lambda)", true, node, false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
context, environment, environment.getParser(), environment.getReturnID(), false, false, sharedMethodInfo, sharedMethodInfo.getName(), true);
final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, false, source);

final RubyNode definitionNode = methodCompiler.compileFunctionNode(translate(node.getPosition()), sharedMethodInfo.getName(), argsNode, node.getBodyNode(), sharedMethodInfo);

return new LambdaNode(context, translate(node.getPosition()), definitionNode);
Original file line number Diff line number Diff line change
@@ -239,7 +239,7 @@ public RubyNode compileFunctionNode(SourceSection sourceSection, String methodNa
}
}

private static Arity getArity(org.jruby.ast.ArgsNode argsNode) {
public static Arity getArity(org.jruby.ast.ArgsNode argsNode) {
final int minimum = argsNode.getRequiredArgsCount();
final int maximum = argsNode.getMaxArgumentsCount();
return new Arity(minimum, argsNode.getOptionalArgsCount(), maximum == -1, argsNode.hasKwargs());
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyException;
import org.jruby.truffle.runtime.core.RubyFile;
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

import java.io.IOException;
@@ -49,7 +50,7 @@ public static enum ParserContext {

public RubyNode parse(RubyContext context, org.jruby.ast.Node parseTree, org.jruby.ast.ArgsNode argsNode, org.jruby.ast.Node bodyNode, Node currentNode) {
final LexicalScope lexicalScope = context.getRootLexicalScope(); // TODO(eregon): figure out how to get the lexical scope from JRuby
final SharedMethodInfo sharedMethod = new SharedMethodInfo(null, lexicalScope, "(unknown)", false, parseTree, false);
final SharedMethodInfo sharedMethod = new SharedMethodInfo(null, lexicalScope, Arity.NO_ARGUMENTS, "(unknown)", false, parseTree, false);

final TranslatorEnvironment environment = new TranslatorEnvironment(
context, environmentForFrame(context, null), this, allocateReturnID(), true, true, sharedMethod, sharedMethod.getName(), false);
@@ -123,7 +124,7 @@ public RubyRootNode parse(Node currentNode, RubyContext context, Source source,
final SourceSection sourceSection = source.createSection("<main>", 0, source.getCode().length());
// The important thing here is to reset the lexical scope.
// TODO (10 Feb. 2015): name should be "<top (required)> for the require-d/load-ed files.
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, context.getRootLexicalScope(), "<main>", false, rootNode, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, context.getRootLexicalScope(), Arity.NO_ARGUMENTS, "<main>", false, rootNode, false);

final TranslatorEnvironment environment = new TranslatorEnvironment(context, environmentForFrame(context, parentFrame), this, allocateReturnID(), ownScopeForAssignments, false, sharedMethodInfo, sharedMethodInfo.getName(), false);

@@ -218,7 +219,7 @@ private TranslatorEnvironment environmentForFrame(RubyContext context, Materiali
return null;
} else {
SourceSection sourceSection = new NullSourceSection("Unknown source section", "(unknown)");
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, context.getRootLexicalScope(), "(unknown)", false, null, false);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, context.getRootLexicalScope(), Arity.NO_ARGUMENTS, "(unknown)", false, null, false);
final MaterializedFrame parent = RubyArguments.getDeclarationFrame(frame.getArguments());
// TODO(CS): how do we know if the frame is a block or not?
return new TranslatorEnvironment(context, environmentForFrame(context, parent), frame.getFrameDescriptor(), this, allocateReturnID(), true, true, sharedMethodInfo, sharedMethodInfo.getName(), false);