|
34 | 34 | import static com.oracle.graal.python.nodes.BuiltinNames.BYTEARRAY;
|
35 | 35 | import static com.oracle.graal.python.nodes.BuiltinNames.BYTES;
|
36 | 36 | import static com.oracle.graal.python.nodes.BuiltinNames.CLASSMETHOD;
|
37 |
| -import static com.oracle.graal.python.nodes.BuiltinNames.INSTANCEMETHOD; |
38 | 37 | import static com.oracle.graal.python.nodes.BuiltinNames.COMPLEX;
|
39 | 38 | import static com.oracle.graal.python.nodes.BuiltinNames.DICT;
|
40 | 39 | import static com.oracle.graal.python.nodes.BuiltinNames.DICT_ITEMITERATOR;
|
|
47 | 46 | import static com.oracle.graal.python.nodes.BuiltinNames.FLOAT;
|
48 | 47 | import static com.oracle.graal.python.nodes.BuiltinNames.FROZENSET;
|
49 | 48 | import static com.oracle.graal.python.nodes.BuiltinNames.GETSET_DESCRIPTOR;
|
| 49 | +import static com.oracle.graal.python.nodes.BuiltinNames.INSTANCEMETHOD; |
50 | 50 | import static com.oracle.graal.python.nodes.BuiltinNames.INT;
|
51 | 51 | import static com.oracle.graal.python.nodes.BuiltinNames.LIST;
|
52 | 52 | import static com.oracle.graal.python.nodes.BuiltinNames.MAP;
|
|
181 | 181 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetItemsizeNode;
|
182 | 182 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode;
|
183 | 183 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
|
184 |
| -import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode; |
185 | 184 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsAcceptableBaseNode;
|
186 | 185 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
|
187 | 186 | import com.oracle.graal.python.lib.CanBeDoubleNode;
|
|
198 | 197 | import com.oracle.graal.python.lib.PyObjectIsTrueNode;
|
199 | 198 | import com.oracle.graal.python.lib.PyObjectSizeNode;
|
200 | 199 | import com.oracle.graal.python.lib.PyObjectStrAsObjectNode;
|
| 200 | +import com.oracle.graal.python.lib.PySliceNew; |
201 | 201 | import com.oracle.graal.python.nodes.BuiltinNames;
|
202 | 202 | import com.oracle.graal.python.nodes.ErrorMessages;
|
203 | 203 | import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
|
|
239 | 239 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
240 | 240 | import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
|
241 | 241 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
242 |
| -import com.oracle.graal.python.nodes.subscript.SliceLiteralNode; |
243 | 242 | import com.oracle.graal.python.nodes.util.CannotCastException;
|
244 | 243 | import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
|
245 | 244 | import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
|
@@ -2028,59 +2027,51 @@ PZip zip(VirtualFrame frame, Object cls, Object[] args,
|
2028 | 2027 | @Builtin(name = "function", minNumOfPositionalArgs = 3, maxNumOfPositionalArgs = 6, constructsClass = PythonBuiltinClassType.PFunction, isPublic = false)
|
2029 | 2028 | @GenerateNodeFactory
|
2030 | 2029 | public abstract static class FunctionNode extends PythonBuiltinNode {
|
2031 |
| - @Child private GetNameNode getNameNode; |
2032 |
| - |
2033 | 2030 | @Specialization
|
2034 |
| - public PFunction function(Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs, @SuppressWarnings("unused") PNone closure) { |
2035 |
| - return factory().createFunction(name, getTypeName(cls), code, globals, null); |
| 2031 | + public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs, |
| 2032 | + @SuppressWarnings("unused") PNone closure) { |
| 2033 | + return factory().createFunction(name, code, globals, null); |
2036 | 2034 | }
|
2037 | 2035 |
|
2038 | 2036 | @Specialization
|
2039 |
| - public PFunction function(Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs, PTuple closure, |
| 2037 | + public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs, |
| 2038 | + PTuple closure, |
2040 | 2039 | @Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
|
2041 |
| - return factory().createFunction("<lambda>", getTypeName(cls), code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure))); |
| 2040 | + return factory().createFunction("<lambda>", code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure))); |
2042 | 2041 | }
|
2043 | 2042 |
|
2044 | 2043 | @Specialization
|
2045 |
| - public PFunction function(Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs, |
| 2044 | + public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs, |
2046 | 2045 | @SuppressWarnings("unused") PNone closure,
|
2047 | 2046 | @SuppressWarnings("unused") @Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
|
2048 |
| - return factory().createFunction("<lambda>", getTypeName(cls), code, globals, null); |
| 2047 | + return factory().createFunction("<lambda>", code, globals, null); |
2049 | 2048 | }
|
2050 | 2049 |
|
2051 | 2050 | @Specialization
|
2052 |
| - public PFunction function(Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs, PTuple closure, |
| 2051 | + public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs, PTuple closure, |
2053 | 2052 | @Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
|
2054 |
| - return factory().createFunction(name, getTypeName(cls), code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure))); |
| 2053 | + return factory().createFunction(name, code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure))); |
2055 | 2054 | }
|
2056 | 2055 |
|
2057 | 2056 | @Specialization
|
2058 |
| - public PFunction function(Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, @SuppressWarnings("unused") PNone closure, |
| 2057 | + public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, @SuppressWarnings("unused") PNone closure, |
2059 | 2058 | @Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
|
2060 | 2059 | // TODO split defaults of positional args from kwDefaults
|
2061 |
| - return factory().createFunction(name, getTypeName(cls), code, globals, getObjectArrayNode.execute(defaultArgs), null, null); |
| 2060 | + return factory().createFunction(name, code, globals, getObjectArrayNode.execute(defaultArgs), null, null); |
2062 | 2061 | }
|
2063 | 2062 |
|
2064 | 2063 | @Specialization
|
2065 |
| - public PFunction function(Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, PTuple closure, |
| 2064 | + public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, PTuple closure, |
2066 | 2065 | @Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
|
2067 | 2066 | // TODO split defaults of positional args from kwDefaults
|
2068 |
| - return factory().createFunction(name, getTypeName(cls), code, globals, getObjectArrayNode.execute(defaultArgs), null, PCell.toCellArray(getObjectArrayNode.execute(closure))); |
| 2067 | + return factory().createFunction(name, code, globals, getObjectArrayNode.execute(defaultArgs), null, PCell.toCellArray(getObjectArrayNode.execute(closure))); |
2069 | 2068 | }
|
2070 | 2069 |
|
2071 | 2070 | @Fallback
|
2072 | 2071 | @SuppressWarnings("unused")
|
2073 |
| - public PFunction function(Object cls, Object code, Object globals, Object name, Object defaultArgs, Object closure) { |
| 2072 | + public PFunction function(@SuppressWarnings("unused") Object cls, Object code, Object globals, Object name, Object defaultArgs, Object closure) { |
2074 | 2073 | throw raise(TypeError, ErrorMessages.FUNC_CONSTRUCTION_NOT_SUPPORTED, cls, code, globals, name, defaultArgs, closure);
|
2075 | 2074 | }
|
2076 |
| - |
2077 |
| - private String getTypeName(Object typeObj) { |
2078 |
| - if (getNameNode == null) { |
2079 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
2080 |
| - getNameNode = insert(TypeNodes.GetNameNode.create()); |
2081 |
| - } |
2082 |
| - return getNameNode.execute(typeObj); |
2083 |
| - } |
2084 | 2075 | }
|
2085 | 2076 |
|
2086 | 2077 | // builtin-function(method-def, self, module)
|
@@ -3253,26 +3244,25 @@ Object doGeneric(@SuppressWarnings("unused") Object clazz, Object get, Object se
|
3253 | 3244 | // slice(start, stop[, step])
|
3254 | 3245 | @Builtin(name = "slice", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4, constructsClass = PythonBuiltinClassType.PSlice)
|
3255 | 3246 | @GenerateNodeFactory
|
3256 |
| - public abstract static class CreateSliceNode extends PythonBuiltinNode { |
3257 |
| - |
3258 |
| - @Specialization(guards = {"isNoValue(second)", "isNoValue(third)"}) |
| 3247 | + abstract static class SliceNode extends PythonQuaternaryBuiltinNode { |
| 3248 | + @Specialization(guards = {"isNoValue(second)"}) |
3259 | 3249 | @SuppressWarnings("unused")
|
3260 |
| - static Object stop(VirtualFrame frame, Object cls, Object first, Object second, Object third, |
3261 |
| - @Cached SliceLiteralNode sliceNode) { |
3262 |
| - return sliceNode.execute(frame, PNone.NONE, first, PNone.NONE); |
| 3250 | + static Object singleArg(Object cls, Object first, Object second, Object third, |
| 3251 | + @Cached PySliceNew sliceNode) { |
| 3252 | + return sliceNode.execute(PNone.NONE, first, PNone.NONE); |
3263 | 3253 | }
|
3264 | 3254 |
|
3265 |
| - @Specialization(guards = {"!isNoValue(second)", "isNoValue(third)"}) |
| 3255 | + @Specialization(guards = {"!isNoValue(stop)", "isNoValue(step)"}) |
3266 | 3256 | @SuppressWarnings("unused")
|
3267 |
| - static Object startStop(VirtualFrame frame, Object cls, Object first, Object second, Object third, |
3268 |
| - @Cached SliceLiteralNode sliceNode) { |
3269 |
| - return sliceNode.execute(frame, first, second, PNone.NONE); |
| 3257 | + static Object twoArgs(Object cls, Object start, Object stop, Object step, |
| 3258 | + @Cached PySliceNew sliceNode) { |
| 3259 | + return sliceNode.execute(start, stop, PNone.NONE); |
3270 | 3260 | }
|
3271 | 3261 |
|
3272 |
| - @Specialization(guards = {"!isNoValue(second)", "!isNoValue(third)"}) |
3273 |
| - static Object slice(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object first, Object second, Object third, |
3274 |
| - @Cached SliceLiteralNode sliceNode) { |
3275 |
| - return sliceNode.execute(frame, first, second, third); |
| 3262 | + @Fallback |
| 3263 | + static Object threeArgs(@SuppressWarnings("unused") Object cls, Object start, Object stop, Object step, |
| 3264 | + @Cached PySliceNew sliceNode) { |
| 3265 | + return sliceNode.execute(start, stop, step); |
3276 | 3266 | }
|
3277 | 3267 | }
|
3278 | 3268 |
|
|
0 commit comments