Skip to content

Commit

Permalink
[Truffle] Use a generated method instead of using directly the specia…
Browse files Browse the repository at this point in the history
…lization.
  • Loading branch information
eregon committed Dec 11, 2014
1 parent 89f548e commit 8467e49
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Expand Up @@ -243,12 +243,10 @@ public BindingNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public BindingNode(BindingNode prev) {
super(prev);
}
public abstract RubyBinding executeBinding(VirtualFrame frame);

@Specialization
public Object binding() {
public RubyBinding binding() {
// Materialize the caller's frame - false means don't use a slow path to get it - we want to optimize it

final MaterializedFrame callerFrame = Truffle.getRuntime().getCallerFrame()
Expand Down Expand Up @@ -482,6 +480,7 @@ public EqlNode(EqlNode prev) {
public abstract static class EvalNode extends CoreMethodNode {

@Child protected DispatchHeadNode toStr;
@Child protected BindingNode bindingNode;

public EvalNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand All @@ -493,14 +492,19 @@ public EvalNode(EvalNode prev) {
toStr = prev.toStr;
}

protected RubyBinding getCallerBinding(VirtualFrame frame) {
if (bindingNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
bindingNode = insert(KernelNodesFactory.BindingNodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{}));
}
return bindingNode.executeBinding(frame);
}

@Specialization
public Object eval(RubyString source, @SuppressWarnings("unused") UndefinedPlaceholder binding) {
public Object eval(VirtualFrame frame, RubyString source, @SuppressWarnings("unused") UndefinedPlaceholder binding) {
notDesignedForCompilation();

RubyBinding defaultBinding = (RubyBinding) KernelNodesFactory.BindingNodeFactory.create(getContext(),
getSourceSection(), new RubyNode[]{}).binding();

return eval(source, defaultBinding);
return eval(source, getCallerBinding(frame));
}

@Specialization
Expand All @@ -514,10 +518,7 @@ public Object eval(RubyString source, RubyBinding binding) {
public Object eval(VirtualFrame frame, RubyBasicObject object, @SuppressWarnings("unused") UndefinedPlaceholder binding) {
notDesignedForCompilation();

RubyBinding defaultBinding = (RubyBinding) KernelNodesFactory.BindingNodeFactory.create(getContext(),
getSourceSection(), new RubyNode[]{}).binding();

return eval(frame, object, defaultBinding);
return eval(frame, object, getCallerBinding(frame));
}

@Specialization(guards = "!isRubyString(arguments[0])")
Expand Down

0 comments on commit 8467e49

Please sign in to comment.