|
10 | 10 |
|
11 | 11 | package org.truffleruby.core.cast;
|
12 | 12 |
|
| 13 | +import com.oracle.truffle.api.dsl.Cached; |
| 14 | +import com.oracle.truffle.api.dsl.Specialization; |
13 | 15 | import org.truffleruby.core.numeric.BigIntegerOps;
|
14 | 16 | import org.truffleruby.core.numeric.RubyBignum;
|
15 | 17 | import org.truffleruby.language.RubyBaseNode;
|
16 |
| -import org.truffleruby.language.control.RaiseException; |
17 | 18 | import org.truffleruby.language.dispatch.DispatchNode;
|
18 | 19 |
|
19 |
| -import com.oracle.truffle.api.CompilerDirectives; |
20 |
| -import com.oracle.truffle.api.dsl.Cached; |
21 |
| -import com.oracle.truffle.api.dsl.Specialization; |
22 |
| -import com.oracle.truffle.api.profiles.BranchProfile; |
23 |
| - |
24 | 20 | public abstract class ToFNode extends RubyBaseNode {
|
25 | 21 |
|
26 | 22 | @Child private DispatchNode toFNode;
|
@@ -53,34 +49,12 @@ protected double coerceRubyBignum(RubyBignum value) {
|
53 | 49 |
|
54 | 50 | @Specialization(guards = { "!isRubyBignum(object)", "!isImplicitLongOrDouble(object)" })
|
55 | 51 | protected double coerceObject(Object object,
|
56 |
| - @Cached BranchProfile errorProfile) { |
57 |
| - if (toFNode == null) { |
58 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
59 |
| - toFNode = insert(DispatchNode.create()); |
60 |
| - } |
61 |
| - |
62 |
| - final Object coerced; |
63 |
| - try { |
64 |
| - coerced = toFNode.call(object, "to_f"); |
65 |
| - } catch (RaiseException e) { |
66 |
| - if (e.getException().getLogicalClass() == coreLibrary().noMethodErrorClass) { |
67 |
| - errorProfile.enter(); |
68 |
| - throw new RaiseException( |
69 |
| - getContext(), |
70 |
| - coreExceptions().typeErrorNoImplicitConversion(object, "Float", this)); |
71 |
| - } else { |
72 |
| - throw e; |
73 |
| - } |
74 |
| - } |
75 |
| - |
76 |
| - if (coerced instanceof Double) { |
77 |
| - return (double) coerced; |
78 |
| - } else { |
79 |
| - errorProfile.enter(); |
80 |
| - throw new RaiseException( |
81 |
| - getContext(), |
82 |
| - coreExceptions().typeErrorBadCoercion(object, "Float", "to_f", coerced, this)); |
83 |
| - } |
| 52 | + @Cached DispatchNode toFNode) { |
| 53 | + return (double) toFNode.call( |
| 54 | + coreLibrary().truffleTypeModule, |
| 55 | + "rb_convert_type", |
| 56 | + object, |
| 57 | + coreLibrary().floatClass, |
| 58 | + coreSymbols().TO_F); |
84 | 59 | }
|
85 |
| - |
86 | 60 | }
|
0 commit comments