@@ -968,59 +968,54 @@ abstract static class FloatNode extends PythonBinaryBuiltinNode {
968
968
// Used for the recursive call
969
969
protected abstract double executeDouble (VirtualFrame frame , PythonBuiltinClassType cls , Object arg ) throws UnexpectedResultException ;
970
970
971
- protected final boolean isPrimitiveFloat (Node inliningTarget , Object cls , InlineIsBuiltinClassProfile isPrimitiveProfile ) {
972
- return isPrimitiveProfile .profileIsBuiltinClass (inliningTarget , cls , PythonBuiltinClassType .PFloat );
973
- }
974
-
975
971
@ Specialization (guards = "isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , limit = "1" )
976
- double floatFromDouble (@ SuppressWarnings ("unused" ) Object cls , double arg ,
977
- @ Bind ("this" ) Node inliningTarget ,
978
- @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
972
+ static double floatFromDouble (@ SuppressWarnings ("unused" ) Object cls , double arg ,
973
+ @ SuppressWarnings ( "unused" ) @ Bind ("this" ) Node inliningTarget ,
974
+ @ SuppressWarnings ( "unused" ) @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
979
975
return arg ;
980
976
}
981
977
982
978
@ Specialization (guards = "isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , limit = "1" )
983
- double floatFromInt (@ SuppressWarnings ("unused" ) Object cls , int arg ,
984
- @ Bind ("this" ) Node inliningTarget ,
985
- @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
979
+ static double floatFromInt (@ SuppressWarnings ("unused" ) Object cls , int arg ,
980
+ @ SuppressWarnings ( "unused" ) @ Bind ("this" ) Node inliningTarget ,
981
+ @ SuppressWarnings ( "unused" ) @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
986
982
return arg ;
987
983
}
988
984
989
985
@ Specialization (guards = "isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , limit = "1" )
990
- double floatFromLong (@ SuppressWarnings ("unused" ) Object cls , long arg ,
991
- @ Bind ("this" ) Node inliningTarget ,
992
- @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
986
+ static double floatFromLong (@ SuppressWarnings ("unused" ) Object cls , long arg ,
987
+ @ SuppressWarnings ( "unused" ) @ Bind ("this" ) Node inliningTarget ,
988
+ @ SuppressWarnings ( "unused" ) @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
993
989
return arg ;
994
990
}
995
991
996
992
@ Specialization (guards = "isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , limit = "1" )
997
- double floatFromBoolean (@ SuppressWarnings ("unused" ) Object cls , boolean arg ,
998
- @ Bind ("this" ) Node inliningTarget ,
999
- @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
993
+ static double floatFromBoolean (@ SuppressWarnings ("unused" ) Object cls , boolean arg ,
994
+ @ SuppressWarnings ( "unused" ) @ Bind ("this" ) Node inliningTarget ,
995
+ @ SuppressWarnings ( "unused" ) @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
1000
996
return arg ? 1d : 0d ;
1001
997
}
1002
998
1003
999
@ Specialization (guards = "isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , limit = "1" )
1004
- double floatFromString (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , TruffleString obj ,
1005
- @ Bind ("this" ) Node inliningTarget ,
1006
- @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ,
1000
+ static double floatFromString (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , TruffleString obj ,
1001
+ @ SuppressWarnings ( "unused" ) @ Bind ("this" ) Node inliningTarget ,
1002
+ @ SuppressWarnings ( "unused" ) @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ,
1007
1003
@ Shared ("fromString" ) @ Cached PyFloatFromString fromString ) {
1008
1004
return fromString .execute (frame , obj );
1009
1005
}
1010
1006
1011
1007
@ Specialization (guards = {"isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , "isNoValue(obj)" }, limit = "1" )
1012
- double floatFromNoValue (@ SuppressWarnings ("unused" ) Object cls , @ SuppressWarnings ("unused" ) PNone obj ,
1013
- @ Bind ("this" ) Node inliningTarget ,
1014
- @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
1008
+ static double floatFromNoValue (@ SuppressWarnings ("unused" ) Object cls , @ SuppressWarnings ("unused" ) PNone obj ,
1009
+ @ SuppressWarnings ( "unused" ) @ Bind ("this" ) Node inliningTarget ,
1010
+ @ SuppressWarnings ( "unused" ) @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
1015
1011
return 0.0 ;
1016
1012
}
1017
1013
1018
1014
@ Specialization (guards = {"isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , "!isNoValue(obj)" }, //
1019
1015
replaces = "floatFromString" , limit = "1" )
1020
- @ SuppressWarnings ("truffle-static-method" )
1021
- double floatFromObject (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , Object obj ,
1016
+ static double floatFromObject (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , Object obj ,
1022
1017
@ Bind ("this" ) Node inliningTarget ,
1023
- @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ,
1018
+ @ SuppressWarnings ( "unused" ) @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ,
1024
1019
@ Cached IsBuiltinObjectProfile stringProfile ,
1025
1020
@ Shared ("fromString" ) @ Cached PyFloatFromString fromString ,
1026
1021
@ Cached PyNumberFloatNode pyNumberFloat ) {
@@ -1030,7 +1025,15 @@ protected final boolean isPrimitiveFloat(Node inliningTarget, Object cls, Inline
1030
1025
return pyNumberFloat .execute (frame , obj );
1031
1026
}
1032
1027
1033
- @ Specialization (guards = {"!isNativeClass(cls)" , "!isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" }, //
1028
+ @ Specialization (guards = {"!needsNativeAllocation(cls)" , "!isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , "isNoValue(obj)" }, //
1029
+ limit = "1" )
1030
+ Object floatFromNoneManagedSubclass (Object cls , PNone obj ,
1031
+ @ Bind ("this" ) Node inliningTarget ,
1032
+ @ Shared ("isFloat" ) @ Cached InlineIsBuiltinClassProfile isPrimitiveFloatProfile ) {
1033
+ return factory ().createFloat (cls , floatFromNoValue (cls , obj , inliningTarget , isPrimitiveFloatProfile ));
1034
+ }
1035
+
1036
+ @ Specialization (guards = {"!needsNativeAllocation(cls)" , "!isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" }, //
1034
1037
limit = "1" )
1035
1038
Object floatFromObjectManagedSubclass (VirtualFrame frame , Object cls , Object obj ,
1036
1039
@ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
@@ -1046,8 +1049,13 @@ Object floatFromObjectManagedSubclass(VirtualFrame frame, Object cls, Object obj
1046
1049
// logic similar to float_subtype_new(PyTypeObject *type, PyObject *x) from CPython
1047
1050
// floatobject.c we have to first create a temporary float, then fill it into
1048
1051
// a natively allocated subtype structure
1049
- @ Specialization (guards = "isSubtypeOfFloat(frame, isSubtype, cls)" , limit = "1" )
1050
- static Object floatFromObjectNativeSubclass (VirtualFrame frame , PythonNativeClass cls , Object obj ,
1052
+ @ Specialization (guards = { //
1053
+ "needsNativeAllocation(cls)" , //
1054
+ "!isPrimitiveFloat(this, cls, isPrimitiveFloatProfile)" , //
1055
+ "isSubtypeOfFloat(frame, isSubtype, cls)" }, limit = "1" )
1056
+ static Object floatFromObjectNativeSubclass (VirtualFrame frame , Object cls , Object obj ,
1057
+ @ Bind ("this" ) @ SuppressWarnings ("unused" ) Node inliningTarget ,
1058
+ @ Shared ("isFloat" ) @ Cached @ SuppressWarnings ("unused" ) InlineIsBuiltinClassProfile isPrimitiveFloatProfile ,
1051
1059
@ Cached @ SuppressWarnings ("unused" ) IsSubtypeNode isSubtype ,
1052
1060
@ Cached CExtNodes .FloatSubtypeNew subtypeNew ,
1053
1061
@ Shared @ Cached FloatNode recursiveCallNode ) {
@@ -1058,7 +1066,11 @@ static Object floatFromObjectNativeSubclass(VirtualFrame frame, PythonNativeClas
1058
1066
}
1059
1067
}
1060
1068
1061
- protected static boolean isSubtypeOfFloat (VirtualFrame frame , IsSubtypeNode isSubtypeNode , PythonNativeClass cls ) {
1069
+ protected final boolean isPrimitiveFloat (Node inliningTarget , Object cls , InlineIsBuiltinClassProfile isPrimitiveProfile ) {
1070
+ return isPrimitiveProfile .profileIsBuiltinClass (inliningTarget , cls , PythonBuiltinClassType .PFloat );
1071
+ }
1072
+
1073
+ protected static boolean isSubtypeOfFloat (VirtualFrame frame , IsSubtypeNode isSubtypeNode , Object cls ) {
1062
1074
return isSubtypeNode .execute (frame , cls , PythonBuiltinClassType .PFloat );
1063
1075
}
1064
1076
}
0 commit comments