Skip to content

Commit

Permalink
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -314,9 +314,14 @@ public RubyNode visitBlockNode(org.jruby.ast.BlockNode node) {

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

final int firstLine = node.getPosition().getLine() + 1;
int lastLine = firstLine;

for (org.jruby.ast.Node child : node.children()) {
if (child.getPosition() == InvalidSourcePosition.INSTANCE) {
parentSourceSection.push(sourceSection);
} else {
lastLine = Integer.max(lastLine, child.getPosition().getLine() + 1);
}

final RubyNode translatedChild;
@@ -339,7 +344,17 @@ public RubyNode visitBlockNode(org.jruby.ast.BlockNode node) {
if (translatedChildren.size() == 1) {
ret = translatedChildren.get(0);
} else {
ret = SequenceNode.sequence(context, sourceSection, translatedChildren.toArray(new RubyNode[translatedChildren.size()]));
final int startIndex = sourceSection.getSource().getLineStartOffset(node.getPosition().getLine() + 1);

int length = 0;

for (int n = firstLine; n <= lastLine; n++) {
length += sourceSection.getSource().getLineLength(n);
}

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

ret = SequenceNode.sequence(context, sourceSection.getSource().createSection(sourceSection.getIdentifier(), startIndex, length), translatedChildren.toArray(new RubyNode[translatedChildren.size()]));
}

return addNewlineIfNeeded(node, ret);
Original file line number Diff line number Diff line change
@@ -193,23 +193,23 @@ public RubyNode doCompileMethodBody(SourceSection sourceSection, String methodNa
loadArguments);
}

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

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

body = new CatchForMethodNode(context, sourceSection, body, environment.getReturnID());
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, sourceSection, body);
body = new ExceptionTranslatingNode(context, body.getSourceSection(), 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());
context, 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);

0 comments on commit a057639

Please sign in to comment.