Skip to content

Commit

Permalink
[Truffle] Adding Fixnum#+ Specialization for Complex
Browse files Browse the repository at this point in the history
Closes #2805
  • Loading branch information
bjfish committed Apr 5, 2015
1 parent c6599ea commit 704cc35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Expand Up @@ -269,6 +269,11 @@ public boolean isRational(RubyBasicObject o) {
return o.getLogicalClass() == getContext().getCoreLibrary().getRationalClass();
}

public boolean isComplex(RubyBasicObject o) {
// TODO(BF, 4-4-15) COPIED from isRational - should this be a full is_a? test? We'd need a node for that.
return o.getLogicalClass() == getContext().getCoreLibrary().getComplexClass();
}

public boolean isNaN(double value) {
return Double.isNaN(value);
}
Expand Down
Expand Up @@ -136,6 +136,11 @@ public Object add(VirtualFrame frame, int a, RubyBasicObject b) {
return rationalAdd.call(frame, b, "+", null, a);
}

@Specialization(guards = "isComplex(arguments[1])")
public Object addComplex(VirtualFrame frame, int a, RubyBasicObject b) {
return ruby(frame, "b + a", "b", b, "a", a);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long add(long a, int b) {
return ExactMath.addExact(a, b);
Expand Down Expand Up @@ -177,6 +182,11 @@ public Object add(VirtualFrame frame, long a, RubyBasicObject b) {
return rationalAdd.call(frame, b, "+", null, a);
}

@Specialization(guards = "isComplex(arguments[1])")
public Object addComplex(VirtualFrame frame, long a, RubyBasicObject b) {
return ruby(frame, "b + a", "b", b, "a", a);
}

}

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

0 comments on commit 704cc35

Please sign in to comment.