Skip to content

Commit

Permalink
[Truffle] Implemented Bignum#==(BasicObject).
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Apr 29, 2015
1 parent cedad15 commit a7f4542
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/bignum/equal_value_tags.txt

This file was deleted.

Expand Up @@ -17,7 +17,10 @@
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeFactory;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
Expand Down Expand Up @@ -334,12 +337,16 @@ public boolean lessEqual(RubyBignum a, RubyBignum b) {
@CoreMethod(names = {"==", "eql?"}, required = 1)
public abstract static class EqualNode extends CoreMethodNode {

@Child private BooleanCastNode booleanCastNode;
@Child private CallDispatchHeadNode reverseCallNode;

public EqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public EqualNode(EqualNode prev) {
super(prev);
reverseCallNode = prev.reverseCallNode;
}

@Specialization
Expand All @@ -361,6 +368,23 @@ public boolean equal(RubyBignum a, double b) {
public boolean equal(RubyBignum a, RubyBignum b) {
return a.bigIntegerValue().equals(b.bigIntegerValue());
}

@Specialization(guards = "!isRubyBignum(arguments[1])")
public Object equal(VirtualFrame frame, RubyBignum a, RubyBasicObject b) {
if (booleanCastNode == null) {
CompilerDirectives.transferToInterpreter();
booleanCastNode = insert(BooleanCastNodeFactory.create(getContext(), getSourceSection(), null));
}

if (reverseCallNode == null) {
CompilerDirectives.transferToInterpreter();
reverseCallNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object reversedResult = reverseCallNode.call(frame, b, "==", null, a);

return booleanCastNode.executeBoolean(frame, reversedResult);
}
}

@CoreMethod(names = "<=>", required = 1)
Expand Down

0 comments on commit a7f4542

Please sign in to comment.