Skip to content

Commit

Permalink
[Truffle] Use an execute method to not break encapsulation in #to_int…
Browse files Browse the repository at this point in the history
… coercion.
  • Loading branch information
eregon committed Apr 17, 2015
1 parent bdb27a1 commit 760d8c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Expand Up @@ -55,13 +55,12 @@ public RubyBignum coerceRubyBignum(RubyBignum value) {
}

@Specialization
public Object coerceDouble(double value) {
public Object coerceDouble(VirtualFrame frame, double value) {
if (floatToIntNode == null) {
CompilerDirectives.transferToInterpreter();
floatToIntNode = insert(FloatNodesFactory.ToINodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{}));
}

return floatToIntNode.toI(value);
return floatToIntNode.executeToI(frame, value);
}

@Specialization(guards = "!isRubyBignum")
Expand Down Expand Up @@ -92,9 +91,7 @@ public Object coerceObject(VirtualFrame frame, Object object) {
return coerced;
} else {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
getContext().getCoreLibrary().typeErrorBadCoercion(object, "Integer", "to_int", coerced, this));
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "Integer", "to_int", coerced, this));
}
}

Expand Down
Expand Up @@ -779,8 +779,10 @@ public ToINode(ToINode prev) {
fixnumOrBignum = prev.fixnumOrBignum;
}

public abstract Object executeToI(VirtualFrame frame, double value);

@Specialization
public Object toI(double value) {
Object toI(double value) {
if (Double.isInfinite(value)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().floatDomainError("Infinity", this));
Expand Down

0 comments on commit 760d8c5

Please sign in to comment.