Skip to content

Commit a7f4542

Browse files
committed
[Truffle] Implemented Bignum#==(BasicObject).
1 parent cedad15 commit a7f4542

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

spec/truffle/tags/core/bignum/equal_value_tags.txt

-2
This file was deleted.

truffle/src/main/java/org/jruby/truffle/nodes/core/BignumNodes.java

+24
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import com.oracle.truffle.api.utilities.BranchProfile;
1818
import com.oracle.truffle.api.utilities.ConditionProfile;
1919

20+
import org.jruby.truffle.nodes.cast.BooleanCastNode;
21+
import org.jruby.truffle.nodes.cast.BooleanCastNodeFactory;
2022
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
23+
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
2124
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
2225
import org.jruby.truffle.runtime.RubyContext;
2326
import org.jruby.truffle.runtime.UndefinedPlaceholder;
@@ -334,12 +337,16 @@ public boolean lessEqual(RubyBignum a, RubyBignum b) {
334337
@CoreMethod(names = {"==", "eql?"}, required = 1)
335338
public abstract static class EqualNode extends CoreMethodNode {
336339

340+
@Child private BooleanCastNode booleanCastNode;
341+
@Child private CallDispatchHeadNode reverseCallNode;
342+
337343
public EqualNode(RubyContext context, SourceSection sourceSection) {
338344
super(context, sourceSection);
339345
}
340346

341347
public EqualNode(EqualNode prev) {
342348
super(prev);
349+
reverseCallNode = prev.reverseCallNode;
343350
}
344351

345352
@Specialization
@@ -361,6 +368,23 @@ public boolean equal(RubyBignum a, double b) {
361368
public boolean equal(RubyBignum a, RubyBignum b) {
362369
return a.bigIntegerValue().equals(b.bigIntegerValue());
363370
}
371+
372+
@Specialization(guards = "!isRubyBignum(arguments[1])")
373+
public Object equal(VirtualFrame frame, RubyBignum a, RubyBasicObject b) {
374+
if (booleanCastNode == null) {
375+
CompilerDirectives.transferToInterpreter();
376+
booleanCastNode = insert(BooleanCastNodeFactory.create(getContext(), getSourceSection(), null));
377+
}
378+
379+
if (reverseCallNode == null) {
380+
CompilerDirectives.transferToInterpreter();
381+
reverseCallNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
382+
}
383+
384+
final Object reversedResult = reverseCallNode.call(frame, b, "==", null, a);
385+
386+
return booleanCastNode.executeBoolean(frame, reversedResult);
387+
}
364388
}
365389

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

0 commit comments

Comments
 (0)