Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Add the context to the root node.
  • Loading branch information
chrisseaton committed Sep 21, 2014
1 parent 8d919e5 commit 8907691
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/truffle/nodes/RubyRootNode.java
Expand Up @@ -22,21 +22,22 @@
*/
public class RubyRootNode extends RootNode {

private final RubyContext context;
private final SharedMethodInfo sharedMethodInfo;
@Child protected RubyNode body;
private final RubyNode uninitializedBody;


public RubyRootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor, SharedMethodInfo sharedMethodInfo, RubyNode body) {
public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescriptor frameDescriptor, SharedMethodInfo sharedMethodInfo, RubyNode body) {
super(sourceSection, frameDescriptor);
assert body != null;
this.context = context;
this.body = body;
this.sharedMethodInfo = sharedMethodInfo;
uninitializedBody = NodeUtil.cloneNode(body);
}

public RubyRootNode cloneRubyRootNode() {
return new RubyRootNode(getSourceSection(), getFrameDescriptor(), sharedMethodInfo, NodeUtil.cloneNode(uninitializedBody));
return new RubyRootNode(context, getSourceSection(), getFrameDescriptor(), sharedMethodInfo, NodeUtil.cloneNode(uninitializedBody));
}

@Override
Expand Down
Expand Up @@ -2292,7 +2292,8 @@ public MaxBlock(RubyContext context) {

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

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(sourceSection, null, sharedMethodInfo,
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
ReadLevelVariableNodeFactory.create(context, sourceSection, frameSlot, 1),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
Expand Down Expand Up @@ -2404,7 +2405,8 @@ public MinBlock(RubyContext context) {

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

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(sourceSection, null, sharedMethodInfo,
callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(
context, sourceSection, null, sharedMethodInfo,
ArrayNodesFactory.MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
ReadLevelVariableNodeFactory.create(context, sourceSection, frameSlot, 1),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehaviour.RUNTIME_ERROR)
Expand Down
Expand Up @@ -207,7 +207,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
final RubyNode block = SequenceNode.sequence(context, sourceSection, checkArity, methodNode);
final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, block);

return new RubyRootNode(sourceSection, null, sharedMethodInfo, exceptionTranslatingNode);
return new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode);
}

public static class MethodDetails {
Expand Down
Expand Up @@ -231,7 +231,7 @@ public static void attrReader(RubyNode currentNode, RubyContext context, SourceS
final String indicativeName = name + "(attr_reader)";

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, indicativeName, false, null);
final RubyRootNode rootNode = new RubyRootNode(sourceSection, null, sharedMethodInfo, block);
final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, sharedMethodInfo, block);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final RubyMethod method = new RubyMethod(sharedMethodInfo, name, module, Visibility.PUBLIC, false, callTarget, null);
module.addMethod(currentNode, method);
Expand Down Expand Up @@ -284,7 +284,7 @@ public static void attrWriter(RubyNode currentNode, RubyContext context, SourceS
final String indicativeName = name + "(attr_writer)";

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, indicativeName, false, null);
final RubyRootNode rootNode = new RubyRootNode(sourceSection, null, sharedMethodInfo, block);
final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, sharedMethodInfo, block);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final RubyMethod method = new RubyMethod(sharedMethodInfo, name + "=", module, Visibility.PUBLIC, false, callTarget, null);
module.addMethod(currentNode, method);
Expand Down
Expand Up @@ -52,7 +52,7 @@ public RubyProc toProc(SourceSection sourceSection, final RubyNode currentNode)

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, symbol, true, null);

final RubyRootNode rootNode = new RubyRootNode(sourceSection, new FrameDescriptor(), sharedMethodInfo,
final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, new FrameDescriptor(), sharedMethodInfo,
new SymbolProcNode(context, sourceSection, symbol));

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
Expand Down
Expand Up @@ -166,7 +166,8 @@ public MethodDefinitionNode compileFunctionNode(SourceSection sourceSection, Str
body = new ExceptionTranslatingNode(context, sourceSection, body);
}

final RubyRootNode rootNode = new RubyRootNode(sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body);
final RubyRootNode rootNode = new RubyRootNode(
context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body);

if (isBlock) {
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
Expand All @@ -186,7 +187,9 @@ private CallTarget withoutBlockDestructureSemantics(CallTarget callTarget) {
behaveAsBlockNode.setBehaveAsBlock(false);
}

final RubyRootNode newRootNodeWithCatchReturn = new RubyRootNode(newRootNode.getSourceSection(),
final RubyRootNode newRootNodeWithCatchReturn = new RubyRootNode(
context,
newRootNode.getSourceSection(),
newRootNode.getFrameDescriptor(), newRootNode.getSharedMethodInfo(),
new CatchReturnNode(context, newRootNode.getSourceSection(), newRootNode.getBody(), getEnvironment().getReturnID()));

Expand Down
Expand Up @@ -63,7 +63,7 @@ public MethodDefinitionNode compileClassNode(ISourcePosition sourcePosition, Str

body = new CatchReturnPlaceholderNode(context, sourceSection, body, environment.getReturnID());

final RubyRootNode rootNode = new RubyRootNode(sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body);
final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body);

return new MethodDefinitionNode(context, sourceSection, environment.getSharedMethodInfo().getName(), environment.getSharedMethodInfo(), environment.needsDeclarationFrame(), rootNode, false);
}
Expand Down
Expand Up @@ -181,7 +181,7 @@ public RubyParserResult parse(RubyNode currentNode, RubyContext context, Source
truffleNode = new ShellResultNode(context, truffleNode.getSourceSection(), truffleNode);
}

final RootNode root = new RubyRootNode(truffleNode.getSourceSection(), environment.getFrameDescriptor(), environment.getSharedMethodInfo(), truffleNode);
final RootNode root = new RubyRootNode(context, truffleNode.getSourceSection(), environment.getFrameDescriptor(), environment.getSharedMethodInfo(), truffleNode);
return new RubyParserResult(root);
}

Expand Down

0 comments on commit 8907691

Please sign in to comment.