Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b8bdaac0117b
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 55bafc806273
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Nov 3, 2014

  1. [Truffle] Fix Kernel#=~ and Kernel#!~.

    * Remove extra {TrueClass,FalseClass}#{==,=~} which do not exist in Ruby.
    eregon committed Nov 3, 2014
    Copy the full SHA
    2983ac7 View commit details
  2. Copy the full SHA
    55bafc8 View commit details
Original file line number Diff line number Diff line change
@@ -106,22 +106,44 @@ public ReferenceEqualNode(ReferenceEqualNode prev) {
@Specialization public boolean equal(double a, double b) { return a == b; }
@Specialization public boolean equal(BigInteger a, BigInteger b) { return a == b; }

@Specialization(guards = "bothUnboxable")
@Specialization(guards = {"firstUnboxable", "secondUnboxable"})
public boolean equalUnboxable(Object a, Object b) {
return ((Unboxable) a).unbox().equals(((Unboxable) b).unbox());
}

@Specialization(guards = {"firstUnboxable", "!secondUnboxable"})
public boolean equalFirstUnboxable(Object a, Object b) {
return ((Unboxable) a).unbox().equals(b);
}

@Specialization(guards = {"!firstUnboxable", "secondUnboxable"})
public boolean equalSecondUnboxable(Object a, Object b) {
return a.equals(((Unboxable) b).unbox());
}

@Specialization
public boolean equal(Object a, Object b) {
if (a instanceof Unboxable && b instanceof Unboxable) {
return ((Unboxable) a).unbox().equals(((Unboxable) b).unbox());
if (a instanceof Unboxable) {
if (b instanceof Unboxable) {
return ((Unboxable) a).unbox().equals(((Unboxable) b).unbox());
} else {
return ((Unboxable) a).unbox().equals(b);
}
} else {
return a == b;
if (b instanceof Unboxable) {
return a.equals(((Unboxable) b).unbox());
} else {
return a == b;
}
}
}

protected boolean bothUnboxable(Object a, Object b) {
return a instanceof Unboxable && b instanceof Unboxable;
protected boolean firstUnboxable(Object a, Object b) {
return a instanceof Unboxable;
}

protected boolean secondUnboxable(Object a, Object b) {
return b instanceof Unboxable;
}

}
Original file line number Diff line number Diff line change
@@ -17,31 +17,6 @@
@CoreClass(name = "FalseClass")
public abstract class FalseClassNodes {

@CoreMethod(names = {"==", "=~"}, needsSelf = false, required = 1)
public abstract static class EqualNode extends CoreMethodNode {

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

public EqualNode(EqualNode prev) {
super(prev);
}

@Specialization
public boolean equal(boolean other) {
return !other;
}

@Specialization
public boolean equal(Object other) {
notDesignedForCompilation();

return other instanceof Boolean && !((boolean) other);
}

}

@CoreMethod(names = "^", needsSelf = false, required = 1)
public abstract static class XorNode extends CoreMethodNode {

74 changes: 9 additions & 65 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ public boolean sameOrEqual(VirtualFrame frame, Object a, Object b) {

}

@CoreMethod(names = "=~", required = 1)
@CoreMethod(names = "=~", required = 1, needsSelf = false)
public abstract static class MatchNode extends CoreMethodNode {

public MatchNode(RubyContext context, SourceSection sourceSection) {
@@ -84,86 +84,30 @@ public MatchNode(MatchNode prev) {
}

@Specialization
public boolean equal(@SuppressWarnings("unused") RubyNilClass a, @SuppressWarnings("unused") RubyNilClass b) {
return true;
}

@Specialization
public boolean equal(boolean a, boolean b) {
return a == b;
}

@Specialization
public boolean equal(int a, int b) {
return a == b;
}

@Specialization
public boolean equal(long a, long b) {
return a == b;
}

@Specialization
public boolean equal(double a, double b) {
return a == b;
}

@Specialization
public boolean equal(BigInteger a, BigInteger b) {
return a.compareTo(b) == 0;
}

@Specialization
public boolean equal(RubyBasicObject a, RubyBasicObject b) {
return a == b;
public RubyNilClass equal(Object other) {
return getContext().getCoreLibrary().getNilObject();
}

}

@CoreMethod(names = "!~", required = 1)
public abstract static class NotMatchNode extends CoreMethodNode {

@Child protected DispatchHeadNode matchNode;

public NotMatchNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
matchNode = new DispatchHeadNode(context);
}

public NotMatchNode(NotMatchNode prev) {
super(prev);
matchNode = prev.matchNode;
}

@Specialization
public boolean notMatch(@SuppressWarnings("unused") RubyNilClass a, @SuppressWarnings("unused") RubyNilClass b) {
return true;
}

@Specialization
public boolean notMatch(boolean a, boolean b) {
return a != b;
}

@Specialization
public boolean notMatch(int a, int b) {
return a != b;
}

@Specialization
public boolean notMatch(long a, long b) {
return a != b;
}

@Specialization
public boolean notMatch(double a, double b) {
return a != b;
}

@Specialization
public boolean notMatch(BigInteger a, BigInteger b) {
return a.compareTo(b) != 0;
}

@Specialization
public boolean notMatch(RubyBasicObject a, RubyBasicObject b) {
return a != b;
public boolean notMatch(VirtualFrame frame, Object self, Object other) {
return !matchNode.callIsTruthy(frame, self, "=~", null, other);
}

}
Original file line number Diff line number Diff line change
@@ -17,31 +17,6 @@
@CoreClass(name = "TrueClass")
public abstract class TrueClassNodes {

@CoreMethod(names = {"==", "=~"}, needsSelf = false, required = 1)
public abstract static class EqualNode extends CoreMethodNode {

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

public EqualNode(EqualNode prev) {
super(prev);
}

@Specialization
public boolean equal(boolean other) {
return other;
}

@Specialization
public boolean equal(Object other) {
notDesignedForCompilation();

return other instanceof Boolean && ((boolean) other);
}

}

@CoreMethod(names = "^", needsSelf = false, required = 1)
public abstract static class XorNode extends CoreMethodNode {