Skip to content

Commit

Permalink
[Truffle] Handle more instance_exec cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 16, 2015
1 parent bde6e1b commit b35f72d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/object/instance_exec_tags.txt
@@ -1,4 +1,2 @@
fails:Object#instance_exec raises a LocalJumpError unless given a block
fails:Object#instance_exec invokes Method objects without rebinding self
fails:Object#instance_exec raises a TypeError when defining methods on an immediate
fails:Object#instance_exec raises a TypeError when defining methods on numerics
Expand Up @@ -18,6 +18,7 @@
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.source.SourceSection;

import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyCallNode;
import org.jruby.truffle.nodes.RubyNode;
Expand Down Expand Up @@ -224,6 +225,8 @@ public Object instanceEval(VirtualFrame frame, Object receiver, UndefinedPlaceho
@CoreMethod(names = "instance_exec", needsBlock = true, argumentsAsArray = true)
public abstract static class InstanceExecNode extends YieldingCoreMethodNode {

private final ConditionProfile rubyMethodProfile = ConditionProfile.createBinaryProfile();

public InstanceExecNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
Expand All @@ -236,9 +239,20 @@ public InstanceExecNode(InstanceExecNode prev) {
public Object instanceExec(VirtualFrame frame, Object receiver, Object[] arguments, RubyProc block) {
notDesignedForCompilation();

if (rubyMethodProfile.profile(block.getSelfCapturedInScope() instanceof RubyMethod)) {
return yield(frame, block, arguments);
}

return yieldWithModifiedSelf(frame, block, receiver, arguments);
}

@Specialization
public Object instanceExec(Object receiver, Object[] arguments, UndefinedPlaceholder block) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(getContext().getCoreLibrary().localJumpError("no block given", this));
}

}

@CoreMethod(names = "method_missing", needsBlock = true, argumentsAsArray = true, visibility = Visibility.PRIVATE)
Expand Down

0 comments on commit b35f72d

Please sign in to comment.