Skip to content

Commit 973b604

Browse files
committed
IntegerCastNode is DSL inlinable node
1 parent 11e8c5c commit 973b604

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/main/java/org/truffleruby/core/cast/IntegerCastNode.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
package org.truffleruby.core.cast;
1111

12+
import com.oracle.truffle.api.dsl.GenerateCached;
13+
import com.oracle.truffle.api.dsl.GenerateInline;
14+
import com.oracle.truffle.api.nodes.Node;
1215
import org.truffleruby.language.RubyBaseNode;
1316
import org.truffleruby.language.control.RaiseException;
1417

@@ -18,31 +21,33 @@
1821

1922
/** See {@link ToIntNode} for a comparison of different integer conversion nodes. */
2023
@GenerateUncached
24+
@GenerateCached(false)
25+
@GenerateInline
2126
public abstract class IntegerCastNode extends RubyBaseNode {
2227

23-
public abstract int executeCastInt(Object value);
28+
public abstract int execute(Node node, Object value);
2429

2530
@Specialization
26-
protected int doInt(int value) {
31+
protected static int doInt(int value) {
2732
return value;
2833
}
2934

3035
@Specialization(guards = "fitsInInteger(value)")
31-
protected int doLong(long value) {
36+
protected static int doLong(long value) {
3237
return (int) value;
3338
}
3439

3540
@Specialization(guards = "!fitsInInteger(value)")
36-
protected int doLongToBig(long value) {
41+
protected static int doLongToBig(Node node, long value) {
3742
throw new RaiseException(
38-
getContext(),
39-
coreExceptions().rangeError("long too big to convert into `int'", this));
43+
getContext(node),
44+
coreExceptions(node).rangeError("long too big to convert into `int'", node));
4045
}
4146

4247
@Specialization(guards = "!isImplicitLong(value)")
43-
protected int doBasicObject(Object value) {
48+
protected static int doBasicObject(Node node, Object value) {
4449
throw new RaiseException(
45-
getContext(),
46-
coreExceptions().typeErrorIsNotA(Utils.toString(value), "Integer (fitting in int)", this));
50+
getContext(node),
51+
coreExceptions(node).typeErrorIsNotA(Utils.toString(value), "Integer (fitting in int)", node));
4752
}
4853
}

src/main/java/org/truffleruby/interop/TranslateInteropRubyExceptionNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ protected AssertionError arityExceptionClass(
143143
@Cached DispatchNode dispatch,
144144
@Cached IntegerCastNode intCastNode,
145145
@Cached @Shared LogicalClassNode logicalClassNode) throws ArityException {
146-
int minExpected = intCastNode.executeCastInt(dispatch.call(exception.getException(), "min_expected"));
147-
int maxExpected = intCastNode.executeCastInt(dispatch.call(exception.getException(), "max_expected"));
146+
int minExpected = intCastNode.execute(this, dispatch.call(exception.getException(), "min_expected"));
147+
int maxExpected = intCastNode.execute(this, dispatch.call(exception.getException(), "max_expected"));
148148
throw ArityException.create(minExpected, maxExpected, arguments.length, exception);
149149
}
150150

src/main/java/org/truffleruby/language/RubyDynamicObject.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public long getArraySize(
171171
@Cached IntegerCastNode integerCastNode,
172172
@Shared @Cached BranchProfile errorProfile,
173173
@Shared @Cached TranslateInteropRubyExceptionNode translateRubyException,
174-
@Exclusive @Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode dispatchNode)
174+
@Exclusive @Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode dispatchNode,
175+
@Bind("$node") Node node)
175176
throws UnsupportedMessageException {
176177
Object value;
177178
try {
@@ -183,7 +184,7 @@ public long getArraySize(
183184
errorProfile.enter();
184185
throw UnsupportedMessageException.create();
185186
}
186-
return integerCastNode.executeCastInt(value);
187+
return integerCastNode.execute(node, value);
187188
}
188189

189190
@ExportMessage

0 commit comments

Comments
 (0)