Skip to content

Commit

Permalink
[Truffle] Fix lazy child allocation in ReadDeclarationVariableNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Feb 24, 2016
1 parent 5fa9781 commit 938d3c0
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public ReadDeclarationVariableNode(RubyContext context, SourceSection sourceSect

@Override
public Object execute(VirtualFrame frame) {
checkReadFrameSlotNode();
final MaterializedFrame declarationFrame = RubyArguments.getDeclarationFrame(frame, frameDepth);
return readFrameSlotNode.executeRead(declarationFrame);
return readFrameSlot(frame);
}


Expand All @@ -50,9 +48,7 @@ public Object isDefined(VirtualFrame frame) {
return coreStrings().LOCAL_VARIABLE.createInstance();

case FRAME_LOCAL_GLOBAL:
checkReadFrameSlotNode();

if (readFrameSlotNode.executeRead(frame) != nil()) {
if (readFrameSlot(frame) != nil()) {
return coreStrings().GLOBAL_VARIABLE.createInstance();
} else {
return nil();
Expand All @@ -66,11 +62,14 @@ public Object isDefined(VirtualFrame frame) {
}
}

private void checkReadFrameSlotNode() {
private Object readFrameSlot(VirtualFrame frame) {
if (readFrameSlotNode == null) {
CompilerDirectives.transferToInterpreter();
readFrameSlotNode = insert(ReadFrameSlotNodeGen.create(frameSlot));
}

final MaterializedFrame declarationFrame = RubyArguments.getDeclarationFrame(frame, frameDepth);
return readFrameSlotNode.executeRead(declarationFrame);
}

@Override
Expand Down

0 comments on commit 938d3c0

Please sign in to comment.