@@ -244,7 +244,7 @@ private static CallTarget makeGenericMethod(RubyContext context, MethodDetails m
if (!isSafe(context, method.unsafe())) {
node = new UnsafeNode(context, sourceSection);
} else {
node = Translator.sequence(context, sharedMethodInfo.getName(), sourceSection, Arrays.asList(checkArity, methodNode));
node = Translator.sequence(context, sourceSection, Arrays.asList(checkArity, methodNode));
node = transformResult(method, node);
}

@@ -391,7 +391,7 @@ private void createAccesor(DynamicObject module, String name) {
ReadPreArgumentNode readArgument = new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR);
accessInstanceVariable = new WriteInstanceVariableNode(getContext(), sourceSection, ivar, self, readArgument);
}
final RubyNode sequence = Translator.sequence(getContext(), name, sourceSection, Arrays.asList(checkArity, accessInstanceVariable));
final RubyNode sequence = Translator.sequence(getContext(), sourceSection, Arrays.asList(checkArity, accessInstanceVariable));
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, null, sharedMethodInfo, sequence, false);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = new InternalMethod(sharedMethodInfo, accessorName, module, visibility, callTarget);
@@ -24,7 +24,6 @@
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.builtins.UnaryCoreMethodNode;
import org.jruby.truffle.core.encoding.EncodingNodes;
import org.jruby.truffle.core.proc.ProcOperations;
import org.jruby.truffle.core.proc.ProcType;
import org.jruby.truffle.language.RubyRootNode;
@@ -111,7 +110,7 @@ protected DynamicObject createProc(InternalMethod method, DynamicObject symbol)

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, null, Arity.AT_LEAST_ONE, Layouts.SYMBOL.getString(symbol), true, ArgumentDescriptor.ANON_REST, false, false, false);

final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo, Translator.sequence(getContext(), sharedMethodInfo.getName(), sourceSection, Arrays.asList(Translator.createCheckArityNode(getContext(), sourceSection, Arity.AT_LEAST_ONE), new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol)))), false);
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo, Translator.sequence(getContext(), sourceSection, Arrays.asList(Translator.createCheckArityNode(getContext(), sourceSection, Arity.AT_LEAST_ONE), new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol)))), false);

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

@@ -268,14 +268,7 @@ private String formatForeign(Node callNode) {
builder.append(sourceSection.getShortDescription());

final RootNode rootNode = callNode.getRootNode();

final String identifier;

if (rootNode instanceof RubyRootNode) {
identifier = rootNode.getName();
} else {
identifier = sourceSection.getIdentifier();
}
final String identifier = rootNode.getName();

if (identifier != null && !identifier.isEmpty()) {
builder.append(":in `");
@@ -412,7 +412,7 @@ public RubyNode visitBlockNode(org.jruby.ast.BlockNode node) {

length = Math.min(length + startIndex, sourceSection.getSource().getLength()) - startIndex;

ret = sequence(context, sourceSection.getSource().createSection(getIdentifier(), startIndex, length), translatedChildren);
ret = sequence(context, sourceSection.getSource().createSection(startIndex, length), translatedChildren);
}

return addNewlineIfNeeded(node, ret);
@@ -642,7 +642,7 @@ private RubyNode translateCallNode(org.jruby.ast.CallNode node, boolean ignoreVi

children.addAll(Arrays.asList(argumentsAndBlock.getArguments()));

final SourceSection enclosingSourceSection = enclosing(getIdentifier(), sourceSection, children.toArray(new RubyNode[children.size()]));
final SourceSection enclosingSourceSection = enclosing(sourceSection, children.toArray(new RubyNode[children.size()]));
RubyNode translated = new RubyCallNode(context, enclosingSourceSection,
receiver, methodName, argumentsAndBlock.getBlock(), argumentsAndBlock.getArguments(), argumentsAndBlock.isSplatted(),
privately || ignoreVisibility, isVCall, node.isLazy(), isAttrAssign);
@@ -1248,7 +1248,7 @@ public RubyNode visitDefinedNode(org.jruby.ast.DefinedNode node) {

@Override
public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {
final SourceSection sourceSection = translate(node.getPosition(), node.getName());
final SourceSection sourceSection = translate(node.getPosition());
final RubyNode classNode = new RaiseIfFrozenNode(context, sourceSection, new GetDefaultDefineeNode(context, sourceSection));

String methodName = node.getName();
@@ -1260,7 +1260,7 @@ public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {

@Override
public RubyNode visitDefsNode(org.jruby.ast.DefsNode node) {
final SourceSection sourceSection = translate(node.getPosition(), node.getName());
final SourceSection sourceSection = translate(node.getPosition());

final RubyNode objectNode = node.getReceiverNode().accept(this);

@@ -3047,25 +3047,6 @@ public TranslatorEnvironment getEnvironment() {
return environment;
}

@Override
protected String getIdentifier() {
if (environment.isBlock()) {
TranslatorEnvironment methodParent = environment.getParent();

while (methodParent.isBlock()) {
methodParent = methodParent.getParent();
}

if (environment.getBlockDepth() > 1) {
return StringUtils.format("block (%d levels) in %s", environment.getBlockDepth(), methodParent.getNamedMethodName());
} else {
return StringUtils.format("block in %s", methodParent.getNamedMethodName());
}
} else {
return environment.getNamedMethodName();
}
}

protected String getIdentifierInNewEnvironment(boolean isBlock, String namedMethodName) {
if (isBlock) {
TranslatorEnvironment methodParent = environment;
@@ -625,9 +625,4 @@ protected RubyNode loadArray(SourceSection sourceSection) {
return new ReadLocalVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, arraySlotStack.peek().getArraySlot());
}

@Override
protected String getIdentifier() {
return methodBodyTranslator.getIdentifier();
}

}
@@ -141,7 +141,7 @@ public BlockDefinitionNode compileBlockNode(SourceSection sourceSection, String
}

// Procs
final RubyNode bodyProc = new CatchForProcNode(context, enclosing(getIdentifier(), sourceSection, body.getEncapsulatingSourceSection()), composeBody(preludeProc, NodeUtil.cloneNode(body)));
final RubyNode bodyProc = new CatchForProcNode(context, enclosing(sourceSection, body.getEncapsulatingSourceSection()), composeBody(preludeProc, NodeUtil.cloneNode(body)));

final RubyRootNode newRootNodeForProcs = new RubyRootNode(context, considerExtendingMethodToCoverEnd(bodyProc.getEncapsulatingSourceSection()), environment.getFrameDescriptor(), environment.getSharedMethodInfo(),
bodyProc, environment.needsDeclarationFrame());
@@ -193,7 +193,7 @@ private boolean shouldConsiderDestructuringArrayArg(Arity arity) {
}

private RubyNode composeBody(RubyNode prelude, RubyNode body) {
final SourceSection sourceSection = enclosing(getIdentifier(), prelude.getSourceSection(), body.getSourceSection());
final SourceSection sourceSection = enclosing(prelude.getSourceSection(), body.getSourceSection());

body = sequence(context, sourceSection, Arrays.asList(prelude, body));

@@ -418,7 +418,7 @@ private SourceSection considerExtendingMethodToCoverEnd(SourceSection sourceSect
for (;;) {
final String lineAfterString = source.getCode(lineAfter).replaceAll("\\s+$","");
if (lineAfterString.equals(indentationOnFirstLine + "end") || lineAfterString.equals(indentationOnFirstLine + "}")) {
return source.createSection(getIdentifier(), sourceSection.getCharIndex(), sourceSection.getCharLength() + 1 + source.getLineLength(lineAfter));
return source.createSection(sourceSection.getCharIndex(), sourceSection.getCharLength() + 1 + source.getLineLength(lineAfter));
}
if (++lineAfter >= source.getLineCount()) {
return sourceSection;
@@ -109,11 +109,6 @@ protected RubyNode defaultVisit(org.jruby.ast.Node node) {
return nilNode(sourceSection);
}

@Override
protected String getIdentifier() {
return methodBodyTranslator.getIdentifier();
}

public boolean isSplatted() {
return hasRestParameter;
}
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.InvalidSourcePosition;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
@@ -46,11 +47,7 @@ public Translator(Node currentNode, RubyContext context, Source source) {
this.source = source;
}

public RubyNode sequence(RubyContext context, SourceSection sourceSection, List<RubyNode> sequence) {
return sequence(context, getIdentifier(), sourceSection, sequence);
}

public static RubyNode sequence(RubyContext context, String identifier, SourceSection sourceSection, List<RubyNode> sequence) {
public static RubyNode sequence(RubyContext context, SourceSection sourceSection, List<RubyNode> sequence) {
final List<RubyNode> flattened = flatten(context, sequence, true);

if (flattened.isEmpty()) {
@@ -59,11 +56,11 @@ public static RubyNode sequence(RubyContext context, String identifier, SourceSe
return flattened.get(0);
} else {
final RubyNode[] flatSequence = flattened.toArray(new RubyNode[flattened.size()]);
return new SequenceNode(context, enclosing(identifier, sourceSection, flatSequence), flatSequence);
return new SequenceNode(context, enclosing(sourceSection, flatSequence), flatSequence);
}
}

public static SourceSection enclosing(String identifier, SourceSection base, SourceSection... sourceSections) {
public static SourceSection enclosing(SourceSection base, SourceSection... sourceSections) {
for (SourceSection sourceSection : sourceSections) {
if (base == null) {
base = sourceSection;
@@ -117,17 +114,17 @@ public static SourceSection enclosing(String identifier, SourceSection base, Sou
length = Math.min(length, base.getSource().getLength() - index);
length = Math.max(0, length);

return base.getSource().createSection(identifier, index, length);
return base.getSource().createSection(index, length);
}

public static SourceSection enclosing(String identifier, SourceSection base, RubyNode[] sequence) {
public static SourceSection enclosing(SourceSection base, RubyNode[] sequence) {
final SourceSection[] sourceSections = new SourceSection[sequence.length];

for (int n = 0; n < sequence.length; n++) {
sourceSections[n] = sequence[n].getEncapsulatingSourceSection();
}

return enclosing(identifier, base, sourceSections);
return enclosing(base, sourceSections);
}

private static List<RubyNode> flatten(RubyContext context, List<RubyNode> sequence, boolean allowTrailingNil) {
@@ -151,23 +148,19 @@ private static List<RubyNode> flatten(RubyContext context, List<RubyNode> sequen
return flattened;
}

protected SourceSection translate(org.jruby.lexer.yacc.ISourcePosition sourcePosition) {
return translate(source, sourcePosition, getIdentifier());
protected SourceSection translate(ISourcePosition sourcePosition) {
return translate(source, sourcePosition);
}

protected SourceSection translate(org.jruby.lexer.yacc.ISourcePosition sourcePosition, String identifier) {
return translate(source, sourcePosition, identifier);
}

private SourceSection translate(Source source, org.jruby.lexer.yacc.ISourcePosition sourcePosition, String identifier) {
private SourceSection translate(Source source, ISourcePosition sourcePosition) {
if (sourcePosition == InvalidSourcePosition.INSTANCE) {
if (parentSourceSection.peek() == null) {
throw new UnsupportedOperationException("Truffle doesn't want invalid positions - find a way to give me a real position!");
} else {
return parentSourceSection.peek();
}
} else {
return source.createSection(identifier, sourcePosition.getLine() + 1);
return source.createSection("(identifier)", sourcePosition.getLine() + 1);
}
}

@@ -185,8 +178,6 @@ protected RubyNode translateNodeOrNil(SourceSection sourceSection, org.jruby.ast
return rubyNode;
}

protected abstract String getIdentifier();

public static RubyNode createCheckArityNode(RubyContext context, SourceSection sourceSection, Arity arity) {
if (!arity.acceptsKeywords()) {
return new CheckArityNode(arity);
@@ -135,8 +135,7 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
throw new RaiseException(context.getCoreExceptions().syntaxError(message, currentNode));
}

final String identifier = "<main>";
final SourceSection sourceSection = source.createSection(identifier, 0, source.getCode().length());
final SourceSection sourceSection = source.createSection(0, source.getCode().length());

final InternalMethod parentMethod = parentFrame == null ? null : RubyArguments.getMethod(parentFrame);
LexicalScope lexicalScope;
@@ -195,13 +194,13 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
}

sequence.add(truffleNode);
truffleNode = Translator.sequence(context, identifier, sourceSection, sequence);
truffleNode = Translator.sequence(context, sourceSection, sequence);
}

// Load flip-flop states

if (environment.getFlipFlopStates().size() > 0) {
truffleNode = Translator.sequence(context, identifier, truffleNode.getSourceSection(), Arrays.asList(translator.initFlipFlopStates(truffleNode.getSourceSection()), truffleNode));
truffleNode = Translator.sequence(context, truffleNode.getSourceSection(), Arrays.asList(translator.initFlipFlopStates(truffleNode.getSourceSection()), truffleNode));
}

// Catch next
@@ -219,13 +218,13 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
truffleNode = new CatchRetryAsErrorNode(context, truffleNode.getSourceSection(), truffleNode);

if (parserContext == ParserContext.TOP_LEVEL_FIRST) {
truffleNode = Translator.sequence(context, identifier, sourceSection, Arrays.asList(
truffleNode = Translator.sequence(context, sourceSection, Arrays.asList(
new SetTopLevelBindingNode(context, sourceSection),
new LoadRequiredLibrariesNode(context, sourceSection),
truffleNode));

if (node.hasEndPosition()) {
truffleNode = Translator.sequence(context, identifier, sourceSection, Arrays.asList(
truffleNode = Translator.sequence(context, sourceSection, Arrays.asList(
new DataNode(context, sourceSection, node.getEndPosition()),
truffleNode));
}
@@ -93,15 +93,6 @@ public TranslatorEnvironment getParent() {
return parent;
}

public TranslatorEnvironment getParent(int level) {
assert level >= 0;
if (level == 0) {
return this;
} else {
return parent.getParent(level - 1);
}
}

public FrameSlot declareVar(String name) {
return getFrameDescriptor().findOrAddFrameSlot(name);
}
@@ -114,20 +105,6 @@ public FrameSlot declareVarWhereAllowed(String name) {
}
}

public SharedMethodInfo findMethodForLocalVar(String name) {
TranslatorEnvironment current = this;
do {
FrameSlot slot = current.getFrameDescriptor().findFrameSlot(name);
if (slot != null) {
return current.sharedMethodInfo;
}

current = current.parent;
} while (current != null);

return null;
}

public ReadLocalNode findOrAddLocalVarNodeDangerous(String name, SourceSection sourceSection) {
ReadLocalNode localVar = findLocalVarNode(name, sourceSection);