Skip to content

Commit

Permalink
[Truffle] Simplify checks by using a guard.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Jan 8, 2015
1 parent 79b8135 commit 2e2d97d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
Expand Up @@ -109,14 +109,9 @@ public Object add(int a, RubyBignum b) {
return fixnumOrBignum(bignum(a).add(b));
}

@Specialization
@Specialization(guards = "isRational(arguments[1])")
public Object add(VirtualFrame frame, int a, RubyBasicObject b) {
if (b.getLogicalClass() == getContext().getCoreLibrary().getRationalClass()) {
return rationalAdd.call(frame, b, "+", null, a);
} else {
// TODO (nirvdrum Jan. 7, 2015) Figure out what the proper exception message format is -- Symbols show the value, not the class name.
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantCoerce(b.getLogicalClass().getName(), "Fixnum", this));
}
return rationalAdd.call(frame, b, "+", null, a);
}

@Specialization(rewriteOn = ArithmeticException.class)
Expand Down Expand Up @@ -149,14 +144,13 @@ public Object add(long a, RubyBignum b) {
return fixnumOrBignum(bignum(a).add(b));
}

@Specialization
@Specialization(guards = "isRational(arguments[1])")
public Object add(VirtualFrame frame, long a, RubyBasicObject b) {
if (b.getLogicalClass() == getContext().getCoreLibrary().getRationalClass()) {
return rationalAdd.call(frame, b, "+", null, a);
} else {
// TODO (nirvdrum Jan. 7, 2015) Figure out what the proper exception message format is -- Symbols show the value, not the class name.
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantCoerce(b.getLogicalClass().getName(), "Fixnum", this));
}
return rationalAdd.call(frame, b, "+", null, a);
}

public boolean isRational(RubyBasicObject o) {
return o.getLogicalClass() == getContext().getCoreLibrary().getRationalClass();
}
}

Expand Down

0 comments on commit 2e2d97d

Please sign in to comment.