156
156
import com .oracle .graal .python .builtins .objects .range .RangeNodes ;
157
157
import com .oracle .graal .python .builtins .objects .set .PFrozenSet ;
158
158
import com .oracle .graal .python .builtins .objects .set .PSet ;
159
- import com .oracle .graal .python .builtins .objects .set .SetNodes ;
160
159
import com .oracle .graal .python .builtins .objects .str .PString ;
161
160
import com .oracle .graal .python .builtins .objects .superobject .SuperObject ;
162
161
import com .oracle .graal .python .builtins .objects .traceback .PTraceback ;
@@ -1026,7 +1025,7 @@ Object doPythonObject(VirtualFrame frame, Object cls, Object obj,
1026
1025
// floatobject.c we have to first create a temporary float, then fill it into
1027
1026
// a natively allocated subtype structure
1028
1027
@ Specialization (guards = "isSubtypeOfFloat(frame, isSubtype, cls)" , limit = "1" )
1029
- Object doPythonObject (VirtualFrame frame , PythonNativeClass cls , Object obj ,
1028
+ static Object doPythonObject (VirtualFrame frame , PythonNativeClass cls , Object obj ,
1030
1029
@ Cached @ SuppressWarnings ("unused" ) IsSubtypeNode isSubtype ,
1031
1030
@ Cached CExtNodes .FloatSubtypeNew subtypeNew ,
1032
1031
@ Cached FloatNode recursiveCallNode ) {
@@ -1076,46 +1075,28 @@ private boolean isNaN(double d) {
1076
1075
@ GenerateNodeFactory
1077
1076
public abstract static class FrozenSetNode extends PythonBuiltinNode {
1078
1077
1079
- @ Child private HashingCollectionNodes .SetItemNode setItemNode ;
1080
-
1081
1078
@ Specialization (guards = "isNoValue(arg)" )
1082
1079
public PFrozenSet frozensetEmpty (Object cls , @ SuppressWarnings ("unused" ) PNone arg ) {
1083
1080
return factory ().createFrozenSet (cls );
1084
1081
}
1085
1082
1086
- @ Specialization
1087
- public PFrozenSet frozenset (VirtualFrame frame , Object cls , String arg ) {
1088
- PFrozenSet frozenSet = factory ().createFrozenSet (cls );
1089
- for (int i = 0 ; i < PString .length (arg ); i ++) {
1090
- getSetItemNode ().execute (frame , frozenSet , PString .valueOf (PString .charAt (arg , i )), PNone .NONE );
1091
- }
1092
- return frozenSet ;
1083
+ @ Specialization (guards = "isBuiltinClass.profileIsAnyBuiltinClass(cls)" )
1084
+ public static PFrozenSet frozensetIdentity (@ SuppressWarnings ("unused" ) Object cls , PFrozenSet arg ,
1085
+ @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile isBuiltinClass ) {
1086
+ return arg ;
1093
1087
}
1094
1088
1095
- @ Specialization (guards = "!isNoValue(iterable)" )
1096
- public PFrozenSet frozensetIterable (VirtualFrame frame , Object cls , Object iterable ,
1097
- @ Cached ("create()" ) GetIteratorNode getIterator ,
1098
- @ Cached ("create()" ) GetNextNode next ,
1099
- @ Cached ("create()" ) IsBuiltinClassProfile errorProfile ) {
1100
-
1101
- Object iterator = getIterator .executeWith (frame , iterable );
1102
- PFrozenSet frozenSet = factory ().createFrozenSet (cls );
1103
- while (true ) {
1104
- try {
1105
- getSetItemNode ().execute (frame , frozenSet , next .execute (frame , iterator ), PNone .NONE );
1106
- } catch (PException e ) {
1107
- e .expectStopIteration (errorProfile );
1108
- return frozenSet ;
1109
- }
1110
- }
1089
+ @ Specialization (guards = "!isBuiltinClass.profileIsAnyBuiltinClass(cls)" )
1090
+ public PFrozenSet subFrozensetIdentity (Object cls , PFrozenSet arg ,
1091
+ @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile isBuiltinClass ) {
1092
+ return factory ().createFrozenSet (cls , arg .getDictStorage ());
1111
1093
}
1112
1094
1113
- private HashingCollectionNodes .SetItemNode getSetItemNode () {
1114
- if (setItemNode == null ) {
1115
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1116
- setItemNode = insert (HashingCollectionNodes .SetItemNode .create ());
1117
- }
1118
- return setItemNode ;
1095
+ @ Specialization (guards = {"!isNoValue(iterable)" , "!isPFrozenSet(iterable)" })
1096
+ public PFrozenSet frozensetIterable (VirtualFrame frame , Object cls , Object iterable ,
1097
+ @ Cached HashingCollectionNodes .GetClonedHashingStorageNode getHashingStorageNode ) {
1098
+ HashingStorage storage = getHashingStorageNode .doNoValue (frame , iterable );
1099
+ return factory ().createFrozenSet (cls , storage );
1119
1100
}
1120
1101
}
1121
1102
@@ -1593,7 +1574,7 @@ private static String toString(byte[] barr) {
1593
1574
@ ReportPolymorphism
1594
1575
public abstract static class BoolNode extends PythonBinaryBuiltinNode {
1595
1576
@ Specialization (limit = "getCallSiteInlineCacheMaxDepth()" )
1596
- public boolean bool (VirtualFrame frame , Object cls , Object obj ,
1577
+ public static boolean bool (VirtualFrame frame , Object cls , Object obj ,
1597
1578
@ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
1598
1579
@ CachedLibrary ("obj" ) PythonObjectLibrary lib ) {
1599
1580
if (hasFrame .profile (frame != null )) {
@@ -1854,35 +1835,29 @@ Object doGeneric(@SuppressWarnings("unused") Object cls, Object start, Object st
1854
1835
}
1855
1836
}
1856
1837
1857
- protected boolean isStop (Object start , Object stop , Object step ) {
1838
+ protected static boolean isStop (Object start , Object stop , Object step ) {
1858
1839
return isNoValue (start ) && !isNoValue (stop ) && isNoValue (step );
1859
1840
}
1860
1841
1861
- protected boolean isStartStop (Object start , Object stop , Object step ) {
1842
+ protected static boolean isStartStop (Object start , Object stop , Object step ) {
1862
1843
return !isNoValue (start ) && !isNoValue (stop ) && isNoValue (step );
1863
1844
}
1864
1845
1865
- protected boolean isStartStopStep (Object start , Object stop , Object step ) {
1846
+ protected static boolean isStartStopStep (Object start , Object stop , Object step ) {
1866
1847
return !isNoValue (start ) && !isNoValue (stop ) && !isNoValue (step );
1867
1848
}
1868
1849
}
1869
1850
1870
1851
// set([iterable])
1871
- @ Builtin (name = SET , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , constructsClass = PythonBuiltinClassType .PSet )
1852
+ @ Builtin (name = SET , minNumOfPositionalArgs = 1 , takesVarArgs = true , takesVarKeywordArgs = true , constructsClass = PythonBuiltinClassType .PSet )
1872
1853
@ GenerateNodeFactory
1873
1854
public abstract static class SetNode extends PythonBuiltinNode {
1874
1855
1875
- @ Specialization (guards = "lib.isLazyPythonClass(cls)" )
1876
- protected PSet constructSet (VirtualFrame frame , Object cls , Object value ,
1877
- @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
1878
- @ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
1879
- return constructSetNode .execute (frame , cls , value );
1856
+ @ Specialization
1857
+ public PSet setEmpty (Object cls , @ SuppressWarnings ("unused" ) Object arg ) {
1858
+ return factory ().createSet (cls );
1880
1859
}
1881
1860
1882
- @ Fallback
1883
- public PSet listObject (@ SuppressWarnings ("unused" ) Object cls , Object arg ) {
1884
- throw raise (TypeError , ErrorMessages .SET_DOES_NOT_SUPPORT_ITERABLE_OBJ , arg );
1885
- }
1886
1861
}
1887
1862
1888
1863
// str(object='')
@@ -1952,7 +1927,7 @@ private Object decodeBytes(VirtualFrame frame, Object strClass, PBytes obj, Obje
1952
1927
* into a natively allocated subtype structure
1953
1928
*/
1954
1929
@ Specialization (guards = {"isNativeClass(cls)" , "isSubtypeOfString(frame, isSubtype, cls)" , "isNoValue(encoding)" , "isNoValue(errors)" })
1955
- Object doNativeSubclass (@ SuppressWarnings ("unused" ) VirtualFrame frame , Object cls , Object obj , @ SuppressWarnings ("unused" ) Object encoding ,
1930
+ static Object doNativeSubclass (@ SuppressWarnings ("unused" ) VirtualFrame frame , Object cls , Object obj , @ SuppressWarnings ("unused" ) Object encoding ,
1956
1931
@ SuppressWarnings ("unused" ) Object errors ,
1957
1932
@ Cached @ SuppressWarnings ("unused" ) IsSubtypeNode isSubtype ,
1958
1933
@ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ,
@@ -2003,14 +1978,14 @@ private ConditionProfile getIsPStringProfile() {
2003
1978
public abstract static class TupleNode extends PythonBinaryBuiltinNode {
2004
1979
2005
1980
@ Specialization (guards = "!isNativeClass(cls)" )
2006
- protected PTuple constructTuple (VirtualFrame frame , Object cls , Object iterable ,
1981
+ protected static PTuple constructTuple (VirtualFrame frame , Object cls , Object iterable ,
2007
1982
@ Cached ("create()" ) TupleNodes .ConstructTupleNode constructTupleNode ) {
2008
1983
return constructTupleNode .execute (frame , cls , iterable );
2009
1984
}
2010
1985
2011
1986
// delegate to tuple_subtype_new(PyTypeObject *type, PyObject *x)
2012
1987
@ Specialization (guards = {"isNativeClass(cls)" , "isSubtypeOfTuple(frame, isSubtype, cls)" }, limit = "1" )
2013
- Object doNative (@ SuppressWarnings ("unused" ) VirtualFrame frame , Object cls , Object iterable ,
1988
+ static Object doNative (@ SuppressWarnings ("unused" ) VirtualFrame frame , Object cls , Object iterable ,
2014
1989
@ Cached @ SuppressWarnings ("unused" ) IsSubtypeNode isSubtype ,
2015
1990
@ Cached CExtNodes .TupleSubtypeNew subtypeNew ) {
2016
1991
return subtypeNew .call (cls , iterable );
@@ -2154,7 +2129,7 @@ public abstract static class TypeNode extends PythonBuiltinNode {
2154
2129
2155
2130
@ Specialization (guards = {"isNoValue(bases)" , "isNoValue(dict)" })
2156
2131
@ SuppressWarnings ("unused" )
2157
- Object type (Object cls , Object obj , PNone bases , PNone dict , PKeyword [] kwds ,
2132
+ static Object type (Object cls , Object obj , PNone bases , PNone dict , PKeyword [] kwds ,
2158
2133
@ Cached GetClassNode getClass ) {
2159
2134
return getClass .execute (obj );
2160
2135
}
@@ -2553,6 +2528,7 @@ private void addNativeSlots(PythonManagedClass pythonClass, PTuple slots) {
2553
2528
if (callAddNativeSlotsNode == null ) {
2554
2529
CompilerDirectives .transferToInterpreterAndInvalidate ();
2555
2530
callAddNativeSlotsNode = insert (CExtNodes .PCallCapiFunction .create ());
2531
+ toSulongNode = insert (CExtNodes .ToSulongNode .create ());
2556
2532
}
2557
2533
callAddNativeSlotsNode .call (FUN_ADD_NATIVE_SLOTS , toSulongNode .execute (pythonClass ), toSulongNode .execute (slots ));
2558
2534
}
@@ -2743,7 +2719,7 @@ Object doNative(PythonAbstractNativeObject self, Object[] varargs, PKeyword[] kw
2743
2719
public abstract static class NotImplementedTypeNode extends PythonBuiltinNode {
2744
2720
@ SuppressWarnings ("unused" )
2745
2721
@ Specialization
2746
- public PNotImplemented module (Object cls ) {
2722
+ public static PNotImplemented module (Object cls ) {
2747
2723
return PNotImplemented .NOT_IMPLEMENTED ;
2748
2724
}
2749
2725
}
@@ -2753,7 +2729,7 @@ public PNotImplemented module(Object cls) {
2753
2729
public abstract static class EllipsisTypeNode extends PythonBuiltinNode {
2754
2730
@ SuppressWarnings ("unused" )
2755
2731
@ Specialization
2756
- public PEllipsis call (Object cls ) {
2732
+ public static PEllipsis call (Object cls ) {
2757
2733
return PEllipsis .INSTANCE ;
2758
2734
}
2759
2735
}
@@ -2763,7 +2739,7 @@ public PEllipsis call(Object cls) {
2763
2739
public abstract static class NoneTypeNode extends PythonBuiltinNode {
2764
2740
@ SuppressWarnings ("unused" )
2765
2741
@ Specialization
2766
- public PNone module (Object cls ) {
2742
+ public static PNone module (Object cls ) {
2767
2743
return PNone .NONE ;
2768
2744
}
2769
2745
}
@@ -2934,15 +2910,15 @@ Object call() {
2934
2910
@ GenerateNodeFactory
2935
2911
public abstract static class TracebackTypeNode extends PythonBuiltinNode {
2936
2912
@ Specialization (limit = "1" )
2937
- Object createTraceback (@ SuppressWarnings ("unused" ) Object cls , PTraceback next , PFrame frame , Object lasti , Object lineno ,
2913
+ static Object createTraceback (@ SuppressWarnings ("unused" ) Object cls , PTraceback next , PFrame frame , Object lasti , Object lineno ,
2938
2914
@ CachedLibrary ("lasti" ) PythonObjectLibrary lastiLib ,
2939
2915
@ CachedLibrary ("lineno" ) PythonObjectLibrary linenoLib ,
2940
2916
@ Cached PythonObjectFactory factory ) {
2941
2917
return factory .createTraceback (frame , linenoLib .asSize (lineno ), lastiLib .asSize (lasti ), next );
2942
2918
}
2943
2919
2944
2920
@ Specialization (limit = "1" )
2945
- Object createTraceback (@ SuppressWarnings ("unused" ) Object cls , @ SuppressWarnings ("unused" ) PNone next , PFrame frame , Object lasti , Object lineno ,
2921
+ static Object createTraceback (@ SuppressWarnings ("unused" ) Object cls , @ SuppressWarnings ("unused" ) PNone next , PFrame frame , Object lasti , Object lineno ,
2946
2922
@ CachedLibrary ("lasti" ) PythonObjectLibrary lastiLib ,
2947
2923
@ CachedLibrary ("lineno" ) PythonObjectLibrary linenoLib ,
2948
2924
@ Cached PythonObjectFactory factory ) {
@@ -3102,7 +3078,7 @@ Object doInvalid(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnin
3102
3078
throw raise (TypeError , ErrorMessages .ARG_MUST_BE_S_NOT_P , "mappingproxy()" , "mapping" , obj );
3103
3079
}
3104
3080
3105
- protected boolean isBuiltinMapping (Object o ) {
3081
+ protected static boolean isBuiltinMapping (Object o ) {
3106
3082
return o instanceof PHashingCollection ;
3107
3083
}
3108
3084
@@ -3158,20 +3134,20 @@ public abstract static class CreateSliceNode extends PythonBuiltinNode {
3158
3134
3159
3135
@ Specialization (guards = {"isNoValue(second)" , "isNoValue(third)" })
3160
3136
@ SuppressWarnings ("unused" )
3161
- Object stop (VirtualFrame frame , Object cls , Object first , Object second , Object third ,
3137
+ static Object stop (VirtualFrame frame , Object cls , Object first , Object second , Object third ,
3162
3138
@ Cached ("create()" ) SliceLiteralNode sliceNode ) {
3163
3139
return sliceNode .execute (frame , PNone .NONE , first , PNone .NONE );
3164
3140
}
3165
3141
3166
3142
@ Specialization (guards = {"!isNoValue(second)" , "isNoValue(third)" })
3167
3143
@ SuppressWarnings ("unused" )
3168
- Object startStop (VirtualFrame frame , Object cls , Object first , Object second , Object third ,
3144
+ static Object startStop (VirtualFrame frame , Object cls , Object first , Object second , Object third ,
3169
3145
@ Cached ("create()" ) SliceLiteralNode sliceNode ) {
3170
3146
return sliceNode .execute (frame , first , second , PNone .NONE );
3171
3147
}
3172
3148
3173
3149
@ Specialization (guards = {"!isNoValue(second)" , "!isNoValue(third)" })
3174
- Object slice (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , Object first , Object second , Object third ,
3150
+ static Object slice (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , Object first , Object second , Object third ,
3175
3151
@ Cached ("create()" ) SliceLiteralNode sliceNode ) {
3176
3152
return sliceNode .execute (frame , first , second , third );
3177
3153
}
0 commit comments