Skip to content

Commit

Permalink
Showing 7 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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, sourceSection, Arrays.asList(checkArity, methodNode));
node = Translator.sequence(context, sharedMethodInfo.getName(), sourceSection, Arrays.asList(checkArity, methodNode));
node = transformResult(method, node);
}

Original file line number Diff line number Diff line change
@@ -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(), sourceSection, Arrays.asList(checkArity, accessInstanceVariable));
final RubyNode sequence = Translator.sequence(getContext(), name, 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);
Original file line number Diff line number Diff line change
@@ -111,7 +111,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(), 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(), sharedMethodInfo.getName(), 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);

Original file line number Diff line number Diff line change
@@ -634,7 +634,7 @@ private RubyNode translateCallNode(org.jruby.ast.CallNode node, boolean ignoreVi

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

final SourceSection enclosingSourceSection = enclosing(sourceSection, children.toArray(new RubyNode[children.size()]));
final SourceSection enclosingSourceSection = enclosing(getIdentifier(), 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);
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ public BlockDefinitionNode compileBlockNode(SourceSection sourceSection, String
}

// Procs
final RubyNode bodyProc = new CatchForProcNode(context, enclosing(sourceSection, body.getEncapsulatingSourceSection()), composeBody(preludeProc, NodeUtil.cloneNode(body)));
final RubyNode bodyProc = new CatchForProcNode(context, enclosing(getIdentifier(), 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(prelude.getSourceSection(), body.getSourceSection());
final SourceSection sourceSection = enclosing(getIdentifier(), prelude.getSourceSection(), body.getSourceSection());

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

Original file line number Diff line number Diff line change
@@ -46,7 +46,11 @@ public Translator(Node currentNode, RubyContext context, Source source) {
this.source = source;
}

public static RubyNode sequence(RubyContext context, SourceSection sourceSection, List<RubyNode> sequence) {
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) {
final List<RubyNode> flattened = flatten(context, sequence, true);

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

public static SourceSection enclosing(SourceSection base, SourceSection... sourceSections) {
public static SourceSection enclosing(String identifier, SourceSection base, SourceSection... sourceSections) {
for (SourceSection sourceSection : sourceSections) {
if (base == null) {
base = sourceSection;
@@ -116,14 +120,14 @@ public static SourceSection enclosing(SourceSection base, SourceSection... sourc
return base.getSource().createSection(base.getIdentifier(), index, length);
}

public static SourceSection enclosing(SourceSection base, RubyNode[] sequence) {
public static SourceSection enclosing(String identifier, 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(base, sourceSections);
return enclosing(identifier, base, sourceSections);
}

private static List<RubyNode> flatten(RubyContext context, List<RubyNode> sequence, boolean allowTrailingNil) {
Original file line number Diff line number Diff line change
@@ -135,7 +135,8 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
throw new RaiseException(context.getCoreExceptions().syntaxError(message, currentNode));
}

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

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

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

// Load flip-flop states

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

// Catch next
@@ -218,13 +219,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, sourceSection, Arrays.asList(
truffleNode = Translator.sequence(context, identifier, sourceSection, Arrays.asList(
new SetTopLevelBindingNode(context, sourceSection),
new LoadRequiredLibrariesNode(context, sourceSection),
truffleNode));

if (node.hasEndPosition()) {
truffleNode = Translator.sequence(context, sourceSection, Arrays.asList(
truffleNode = Translator.sequence(context, identifier, sourceSection, Arrays.asList(
new DataNode(context, sourceSection, node.getEndPosition()),
truffleNode));
}

0 comments on commit 68cad24

Please sign in to comment.