92
92
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
93
93
import com .oracle .graal .python .builtins .objects .function .PFunction ;
94
94
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
95
- import com .oracle .graal .python .builtins .objects .function .PythonCallable ;
96
95
import com .oracle .graal .python .builtins .objects .getsetdescriptor .HiddenKeyDescriptor ;
97
96
import com .oracle .graal .python .builtins .objects .ints .PInt ;
98
97
import com .oracle .graal .python .builtins .objects .iterator .PZip ;
@@ -968,12 +967,12 @@ private static BigInteger asciiToBigInteger(String str, int possibleBase, boolea
968
967
969
968
public abstract Object executeWith (Object cls , Object arg , Object keywordArg );
970
969
971
- protected boolean isPrimitiveInt (PythonClass cls ) {
970
+ protected boolean isPrimitiveInt (LazyPythonClass cls ) {
972
971
return isPrimitiveProfile .profileClass (cls , PythonBuiltinClassType .PInt );
973
972
}
974
973
975
974
@ Specialization
976
- Object parseInt (PythonClass cls , boolean arg , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
975
+ Object parseInt (LazyPythonClass cls , boolean arg , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
977
976
if (isPrimitiveInt (cls )) {
978
977
return arg ? 1 : 0 ;
979
978
} else {
@@ -982,15 +981,15 @@ Object parseInt(PythonClass cls, boolean arg, @SuppressWarnings("unused") PNone
982
981
}
983
982
984
983
@ Specialization (guards = "isNoValue(keywordArg)" )
985
- public Object createInt (PythonClass cls , int arg , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
984
+ public Object createInt (LazyPythonClass cls , int arg , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
986
985
if (isPrimitiveInt (cls )) {
987
986
return arg ;
988
987
}
989
988
return factory ().createInt (cls , arg );
990
989
}
991
990
992
991
@ Specialization (guards = "isNoValue(keywordArg)" )
993
- public Object createInt (PythonClass cls , long arg , @ SuppressWarnings ("unused" ) PNone keywordArg ,
992
+ public Object createInt (LazyPythonClass cls , long arg , @ SuppressWarnings ("unused" ) PNone keywordArg ,
994
993
@ Cached ("createBinaryProfile()" ) ConditionProfile isIntProfile ) {
995
994
if (isPrimitiveInt (cls )) {
996
995
int intValue = (int ) arg ;
@@ -1004,7 +1003,7 @@ public Object createInt(PythonClass cls, long arg, @SuppressWarnings("unused") P
1004
1003
}
1005
1004
1006
1005
@ Specialization (guards = "isNoValue(keywordArg)" )
1007
- public Object createInt (PythonClass cls , double arg , @ SuppressWarnings ("unused" ) PNone keywordArg ,
1006
+ public Object createInt (LazyPythonClass cls , double arg , @ SuppressWarnings ("unused" ) PNone keywordArg ,
1008
1007
@ Cached ("createBinaryProfile()" ) ConditionProfile isIntProfile ) {
1009
1008
if (isPrimitiveInt (cls ) && isIntProfile .profile (arg >= Integer .MIN_VALUE && arg <= Integer .MAX_VALUE )) {
1010
1009
return (int ) arg ;
@@ -1013,15 +1012,15 @@ public Object createInt(PythonClass cls, double arg, @SuppressWarnings("unused")
1013
1012
}
1014
1013
1015
1014
@ Specialization
1016
- public Object createInt (PythonClass cls , @ SuppressWarnings ("unused" ) PNone none , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
1015
+ public Object createInt (LazyPythonClass cls , @ SuppressWarnings ("unused" ) PNone none , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
1017
1016
if (isPrimitiveInt (cls )) {
1018
1017
return 0 ;
1019
1018
}
1020
1019
return factory ().createInt (cls , 0 );
1021
1020
}
1022
1021
1023
1022
@ Specialization (guards = "isNoValue(keywordArg)" )
1024
- public Object createInt (PythonClass cls , String arg , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
1023
+ public Object createInt (LazyPythonClass cls , String arg , @ SuppressWarnings ("unused" ) PNone keywordArg ) {
1025
1024
try {
1026
1025
Object value = stringToInt (arg , 10 );
1027
1026
if (isPrimitiveInt (cls )) {
@@ -1036,18 +1035,18 @@ public Object createInt(PythonClass cls, String arg, @SuppressWarnings("unused")
1036
1035
1037
1036
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1038
1037
@ TruffleBoundary
1039
- int parseInt (PythonClass cls , PIBytesLike arg , int keywordArg ) throws NumberFormatException {
1038
+ int parseInt (LazyPythonClass cls , PIBytesLike arg , int keywordArg ) throws NumberFormatException {
1040
1039
return parseInt (cls , toString (arg ), keywordArg );
1041
1040
}
1042
1041
1043
1042
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1044
1043
@ TruffleBoundary
1045
- long parseLong (PythonClass cls , PIBytesLike arg , int keywordArg ) throws NumberFormatException {
1044
+ long parseLong (LazyPythonClass cls , PIBytesLike arg , int keywordArg ) throws NumberFormatException {
1046
1045
return parseLong (cls , toString (arg ), keywordArg );
1047
1046
}
1048
1047
1049
1048
@ Specialization
1050
- Object parseBytesError (PythonClass cls , PIBytesLike arg , int base ,
1049
+ Object parseBytesError (LazyPythonClass cls , PIBytesLike arg , int base ,
1051
1050
@ Cached ("create()" ) BranchProfile errorProfile ) {
1052
1051
try {
1053
1052
return parsePInt (cls , toString (arg ), base );
@@ -1058,46 +1057,46 @@ Object parseBytesError(PythonClass cls, PIBytesLike arg, int base,
1058
1057
}
1059
1058
1060
1059
@ Specialization (guards = "isNoValue(base)" )
1061
- Object parseBytesError (PythonClass cls , PIBytesLike arg , @ SuppressWarnings ("unused" ) PNone base ,
1060
+ Object parseBytesError (LazyPythonClass cls , PIBytesLike arg , @ SuppressWarnings ("unused" ) PNone base ,
1062
1061
@ Cached ("create()" ) BranchProfile errorProfile ) {
1063
1062
return parseBytesError (cls , arg , 10 , errorProfile );
1064
1063
}
1065
1064
1066
1065
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1067
- int parseInt (PythonClass cls , PString arg , int keywordArg ) throws NumberFormatException {
1066
+ int parseInt (LazyPythonClass cls , PString arg , int keywordArg ) throws NumberFormatException {
1068
1067
return parseInt (cls , arg .getValue (), keywordArg );
1069
1068
}
1070
1069
1071
1070
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1072
1071
@ TruffleBoundary
1073
- long parseLong (PythonClass cls , PString arg , int keywordArg ) throws NumberFormatException {
1072
+ long parseLong (LazyPythonClass cls , PString arg , int keywordArg ) throws NumberFormatException {
1074
1073
return parseLong (cls , arg .getValue (), keywordArg );
1075
1074
}
1076
1075
1077
1076
@ Specialization
1078
- Object parsePInt (PythonClass cls , PString arg , int keywordArg ) {
1077
+ Object parsePInt (LazyPythonClass cls , PString arg , int keywordArg ) {
1079
1078
return parsePInt (cls , arg .getValue (), keywordArg );
1080
1079
}
1081
1080
1082
1081
@ Specialization (guards = "isNoValue(base)" )
1083
- Object parsePInt (PythonClass cls , PString arg , PNone base ) {
1082
+ Object parsePInt (LazyPythonClass cls , PString arg , PNone base ) {
1084
1083
return createInt (cls , arg .getValue (), base );
1085
1084
}
1086
1085
1087
1086
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1088
1087
@ TruffleBoundary
1089
- int parseInt (@ SuppressWarnings ("unused" ) PythonClass cls , String arg , int keywordArg ) throws NumberFormatException {
1088
+ int parseInt (@ SuppressWarnings ("unused" ) LazyPythonClass cls , String arg , int keywordArg ) throws NumberFormatException {
1090
1089
return Integer .parseInt (arg , keywordArg );
1091
1090
}
1092
1091
1093
1092
@ Specialization (guards = "isPrimitiveInt(cls)" , rewriteOn = NumberFormatException .class )
1094
1093
@ TruffleBoundary
1095
- long parseLong (@ SuppressWarnings ("unused" ) PythonClass cls , String arg , int keywordArg ) throws NumberFormatException {
1094
+ long parseLong (@ SuppressWarnings ("unused" ) LazyPythonClass cls , String arg , int keywordArg ) throws NumberFormatException {
1096
1095
return Long .parseLong (arg , keywordArg );
1097
1096
}
1098
1097
1099
1098
@ Specialization (rewriteOn = NumberFormatException .class )
1100
- Object parsePInt (PythonClass cls , String arg , int base ) {
1099
+ Object parsePInt (LazyPythonClass cls , String arg , int base ) {
1101
1100
Object int2 = toInt (arg , base );
1102
1101
if (int2 instanceof BigInteger ) {
1103
1102
return factory ().createInt (cls , (BigInteger ) int2 );
@@ -1110,7 +1109,7 @@ Object parsePInt(PythonClass cls, String arg, int base) {
1110
1109
}
1111
1110
1112
1111
@ Specialization (replaces = "parsePInt" )
1113
- Object parsePIntError (PythonClass cls , String arg , int base ) {
1112
+ Object parsePIntError (LazyPythonClass cls , String arg , int base ) {
1114
1113
try {
1115
1114
return parsePInt (cls , arg , base );
1116
1115
} catch (NumberFormatException e ) {
@@ -1119,7 +1118,7 @@ Object parsePIntError(PythonClass cls, String arg, int base) {
1119
1118
}
1120
1119
1121
1120
@ Specialization
1122
- public Object createInt (PythonClass cls , String arg , Object keywordArg ) {
1121
+ public Object createInt (LazyPythonClass cls , String arg , Object keywordArg ) {
1123
1122
if (keywordArg instanceof PNone ) {
1124
1123
Object value = toInt (arg );
1125
1124
if (value == null ) {
@@ -1139,12 +1138,12 @@ public Object createInt(PythonClass cls, String arg, Object keywordArg) {
1139
1138
1140
1139
@ SuppressWarnings ("unused" )
1141
1140
@ Specialization (guards = {"!isString(arg)" , "!isNoValue(keywordArg)" })
1142
- Object fail (PythonClass cls , Object arg , Object keywordArg ) {
1141
+ Object fail (LazyPythonClass cls , Object arg , Object keywordArg ) {
1143
1142
throw raise (TypeError , "int() can't convert non-string with explicit base" );
1144
1143
}
1145
1144
1146
1145
@ Specialization (guards = {"isNoValue(keywordArg)" , "!isNoValue(obj)" , "!isHandledType(obj)" })
1147
- public Object createInt (PythonClass cls , Object obj , PNone keywordArg ,
1146
+ public Object createInt (LazyPythonClass cls , Object obj , PNone keywordArg ,
1148
1147
@ Cached ("create(__INT__)" ) LookupAndCallUnaryNode callIntNode ,
1149
1148
@ Cached ("create(__TRUNC__)" ) LookupAndCallUnaryNode callTruncNode ,
1150
1149
@ Cached ("createBinaryProfile()" ) ConditionProfile isIntProfile ) {
@@ -2176,33 +2175,26 @@ private void denyInstantiationAfterInitialization() {
2176
2175
}
2177
2176
}
2178
2177
2179
- @ Specialization
2178
+ @ Specialization ( guards = { "!isNoValue(get)" , "!isNoValue(set)" })
2180
2179
@ TruffleBoundary
2181
- Object call (PythonClass getSetClass , PythonCallable get , PythonCallable set , String name , PythonClass owner ) {
2180
+ Object call (PythonClass getSetClass , Object get , Object set , String name , PythonClass owner ) {
2182
2181
denyInstantiationAfterInitialization ();
2183
2182
return factory ().createGetSetDescriptor (get , set , name , owner );
2184
2183
}
2185
2184
2186
- @ Specialization
2185
+ @ Specialization ( guards = { "!isNoValue(get)" , "isNoValue(set)" })
2187
2186
@ TruffleBoundary
2188
- Object call (PythonClass getSetClass , PythonCallable get , PNone set , String name , PythonClass owner ) {
2187
+ Object call (PythonClass getSetClass , Object get , PNone set , String name , PythonClass owner ) {
2189
2188
denyInstantiationAfterInitialization ();
2190
2189
return factory ().createGetSetDescriptor (get , null , name , owner );
2191
2190
}
2192
2191
2193
- @ Specialization
2192
+ @ Specialization ( guards = { "isNoValue(get)" , "isNoValue(set)" })
2194
2193
@ TruffleBoundary
2195
- Object call (PythonClass getSetClass , PNone set , PNone get , String name , PythonClass owner ) {
2194
+ Object call (PythonClass getSetClass , PNone get , PNone set , String name , PythonClass owner ) {
2196
2195
denyInstantiationAfterInitialization ();
2197
2196
return factory ().createGetSetDescriptor (null , null , name , owner );
2198
2197
}
2199
-
2200
- @ Fallback
2201
- @ TruffleBoundary
2202
- Object call (Object klsas , Object set , Object get , Object name , Object owner ) {
2203
- denyInstantiationAfterInitialization ();
2204
- throw new RuntimeException ("error in creating getset_descriptor during core initialization" );
2205
- }
2206
2198
}
2207
2199
2208
2200
// slice(stop)
0 commit comments