40
40
*/
41
41
package com .oracle .graal .python .nodes .util ;
42
42
43
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
43
+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .OverflowError ;
44
+
44
45
import com .oracle .graal .python .builtins .objects .ints .PInt ;
45
46
import com .oracle .graal .python .nodes .ErrorMessages ;
46
47
import com .oracle .graal .python .nodes .PRaiseNode ;
47
48
import com .oracle .graal .python .util .OverflowException ;
48
- import com .oracle .truffle .api .CompilerDirectives ;
49
+ import com .oracle .truffle .api .dsl . Cached ;
49
50
import com .oracle .truffle .api .dsl .GenerateUncached ;
50
51
import com .oracle .truffle .api .dsl .Specialization ;
51
52
@@ -64,13 +65,18 @@ public static CastToJavaLongExactNode getUncached() {
64
65
return CastToJavaLongExactNodeGen .getUncached ();
65
66
}
66
67
67
- @ Specialization
68
- protected long toLong (PInt x ) {
68
+ @ Specialization (rewriteOn = OverflowException .class )
69
+ protected static long toLongNoOverflow (PInt x ) throws OverflowException {
70
+ return x .longValueExact ();
71
+ }
72
+
73
+ @ Specialization (replaces = "toLongNoOverflow" )
74
+ protected static long toLong (PInt x ,
75
+ @ Cached PRaiseNode raiseNode ) {
69
76
try {
70
77
return x .longValueExact ();
71
78
} catch (OverflowException e ) {
72
- CompilerDirectives .transferToInterpreter ();
73
- throw PRaiseNode .getUncached ().raise (TypeError , ErrorMessages .CANNOT_BE_INTEPRETED_AS_LONG , x , x );
79
+ throw raiseNode .raise (OverflowError , ErrorMessages .PYTHON_INT_TOO_LARGE_TO_CONV_TO , "long" );
74
80
}
75
81
}
76
82
}
0 commit comments