|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.modules;
|
42 | 42 |
|
43 |
| -import static com.oracle.graal.python.nodes.SpecialAttributeNames.__CLASS__; |
44 | 43 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
|
45 | 44 |
|
46 | 45 | import java.io.IOException;
|
|
54 | 53 | import com.oracle.graal.python.builtins.CoreFunctions;
|
55 | 54 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
56 | 55 | import com.oracle.graal.python.builtins.objects.PNone;
|
57 |
| -import com.oracle.graal.python.builtins.objects.cell.PCell; |
58 | 56 | import com.oracle.graal.python.builtins.objects.exception.PBaseException;
|
59 |
| -import com.oracle.graal.python.builtins.objects.function.PArguments; |
60 |
| -import com.oracle.graal.python.builtins.objects.function.PKeyword; |
61 | 57 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
62 | 58 | import com.oracle.graal.python.builtins.objects.str.PString;
|
63 |
| -import com.oracle.graal.python.builtins.objects.type.PythonClass; |
64 |
| -import com.oracle.graal.python.nodes.argument.ReadIndexedArgumentNode; |
65 |
| -import com.oracle.graal.python.nodes.attributes.SetAttributeNode; |
66 |
| -import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode; |
67 |
| -import com.oracle.graal.python.nodes.frame.ReadLocalVariableNode; |
68 |
| -import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; |
69 | 59 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
70 | 60 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
71 |
| -import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode; |
72 | 61 | import com.oracle.graal.python.runtime.PythonContext;
|
73 | 62 | import com.oracle.graal.python.runtime.PythonCore;
|
74 | 63 | import com.oracle.graal.python.runtime.PythonOptions;
|
|
79 | 68 | import com.oracle.truffle.api.Truffle;
|
80 | 69 | import com.oracle.truffle.api.TruffleLanguage.ContextReference;
|
81 | 70 | import com.oracle.truffle.api.TruffleOptions;
|
82 |
| -import com.oracle.truffle.api.dsl.Cached; |
83 |
| -import com.oracle.truffle.api.dsl.Fallback; |
84 | 71 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
85 | 72 | import com.oracle.truffle.api.dsl.NodeFactory;
|
86 | 73 | import com.oracle.truffle.api.dsl.Specialization;
|
87 |
| -import com.oracle.truffle.api.frame.Frame; |
88 |
| -import com.oracle.truffle.api.frame.FrameSlot; |
89 |
| -import com.oracle.truffle.api.frame.FrameSlotTypeException; |
90 | 74 | import com.oracle.truffle.api.frame.VirtualFrame;
|
91 | 75 | import com.oracle.truffle.api.nodes.DirectCallNode;
|
92 | 76 | import com.oracle.truffle.api.nodes.RootNode;
|
93 |
| -import com.oracle.truffle.api.profiles.ConditionProfile; |
94 | 77 |
|
95 | 78 | @CoreFunctions(defineModule = "sys")
|
96 | 79 | public class SysModuleBuiltins extends PythonBuiltins {
|
@@ -200,143 +183,6 @@ public void initialize(PythonCore core) {
|
200 | 183 | super.initialize(core);
|
201 | 184 | }
|
202 | 185 |
|
203 |
| - @Builtin(name = "__super__init__", minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true) |
204 |
| - @GenerateNodeFactory |
205 |
| - public abstract static class SuperInitNode extends PythonVarargsBuiltinNode { |
206 |
| - |
207 |
| - @Child private SetAttributeNode setTypeAttribute = SetAttributeNode.create("__type__"); |
208 |
| - @Child private SetAttributeNode setObjAttribute = SetAttributeNode.create("__obj__"); |
209 |
| - |
210 |
| - @Override |
211 |
| - public Object varArgExecute(VirtualFrame frame, Object[] arguments, PKeyword[] keywords) throws VarargsBuiltinDirectInvocationNotSupported { |
212 |
| - if (keywords.length != 0) { |
213 |
| - throw raise(PythonErrorType.RuntimeError, "super(): unexpected keyword arguments"); |
214 |
| - } |
215 |
| - if (arguments.length == 1) { |
216 |
| - return execute(frame, arguments[0], PNone.NO_VALUE, PNone.NO_VALUE); |
217 |
| - } else if (arguments.length == 2) { |
218 |
| - return execute(frame, arguments[0], arguments[1], PNone.NO_VALUE); |
219 |
| - } else if (arguments.length == 3) { |
220 |
| - return execute(frame, arguments[0], arguments[1], arguments[2]); |
221 |
| - } else { |
222 |
| - throw raise(PythonErrorType.RuntimeError, "super(): invalid number of arguments"); |
223 |
| - } |
224 |
| - } |
225 |
| - |
226 |
| - @Override |
227 |
| - public final Object execute(VirtualFrame frame, Object self, Object[] arguments, PKeyword[] keywords) { |
228 |
| - if (keywords.length != 0) { |
229 |
| - throw raise(PythonErrorType.RuntimeError, "super(): unexpected keyword arguments"); |
230 |
| - } |
231 |
| - if (arguments.length == 0) { |
232 |
| - return execute(frame, self, PNone.NO_VALUE, PNone.NO_VALUE); |
233 |
| - } else if (arguments.length == 1) { |
234 |
| - return execute(frame, self, arguments[0], PNone.NO_VALUE); |
235 |
| - } else if (arguments.length == 2) { |
236 |
| - return execute(frame, self, arguments[0], arguments[1]); |
237 |
| - } else { |
238 |
| - throw raise(PythonErrorType.RuntimeError, "super(): too many arguments"); |
239 |
| - } |
240 |
| - } |
241 |
| - |
242 |
| - protected abstract Object execute(VirtualFrame frame, Object self, Object cls, Object obj); |
243 |
| - |
244 |
| - @Specialization(guards = {"!isNoValue(cls)", "!isNoValue(obj)"}) |
245 |
| - PNone init(Object self, Object cls, Object obj) { |
246 |
| - if (!(cls instanceof PythonClass)) { |
247 |
| - throw raise(PythonErrorType.RuntimeError, "super(): __class__ is not a type (%p)", cls); |
248 |
| - } |
249 |
| - setTypeAttribute.executeVoid(self, cls); |
250 |
| - setObjAttribute.executeVoid(self, obj); |
251 |
| - return PNone.NONE; |
252 |
| - } |
253 |
| - |
254 |
| - protected boolean isInBuiltinFunctionRoot() { |
255 |
| - return getRootNode() instanceof BuiltinFunctionRootNode; |
256 |
| - } |
257 |
| - |
258 |
| - protected ReadLocalVariableNode createRead(VirtualFrame frame) { |
259 |
| - FrameSlot slot = frame.getFrameDescriptor().findFrameSlot(__CLASS__); |
260 |
| - if (slot == null) { |
261 |
| - throw raise(PythonErrorType.RuntimeError, "super(): empty __class__ cell"); |
262 |
| - } |
263 |
| - return ReadLocalVariableNode.create(slot); |
264 |
| - } |
265 |
| - |
266 |
| - /** |
267 |
| - * Executed with the frame of the calling method - direct access to the frame. |
268 |
| - */ |
269 |
| - @Specialization(guards = {"!isInBuiltinFunctionRoot()", "isNoValue(clsArg)", "isNoValue(objArg)"}) |
270 |
| - PNone initInPlace(VirtualFrame frame, Object self, @SuppressWarnings("unused") PNone clsArg, @SuppressWarnings("unused") PNone objArg, |
271 |
| - @Cached("createRead(frame)") ReadLocalVariableNode readClass, |
272 |
| - @Cached("create(0)") ReadIndexedArgumentNode readArgument, |
273 |
| - @Cached("createBinaryProfile()") ConditionProfile isCellProfile) { |
274 |
| - Object obj = readArgument.execute(frame); |
275 |
| - if (obj == PNone.NONE) { |
276 |
| - throw raise(PythonErrorType.RuntimeError, "super(): no arguments"); |
277 |
| - } |
278 |
| - Object cls = readClass.execute(frame); |
279 |
| - if (isCellProfile.profile(cls instanceof PCell)) { |
280 |
| - cls = ((PCell) cls).getPythonRef(); |
281 |
| - } |
282 |
| - if (cls == PNone.NONE) { |
283 |
| - throw raise(PythonErrorType.RuntimeError, "super(): empty __class__ cell"); |
284 |
| - } |
285 |
| - return init(self, cls, obj); |
286 |
| - } |
287 |
| - |
288 |
| - /** |
289 |
| - * Executed within a {@link BuiltinFunctionRootNode} - indirect access to the frame. |
290 |
| - */ |
291 |
| - @Specialization(guards = {"isInBuiltinFunctionRoot()", "isNoValue(clsArg)", "isNoValue(objArg)"}) |
292 |
| - PNone init(VirtualFrame frame, Object self, @SuppressWarnings("unused") PNone clsArg, @SuppressWarnings("unused") PNone objArg, |
293 |
| - @Cached("create(0)") ReadCallerFrameNode readCaller) { |
294 |
| - Frame target = readCaller.executeWith(frame); |
295 |
| - if (target == null) { |
296 |
| - throw raise(PythonErrorType.RuntimeError, "super(): no current frame"); |
297 |
| - } |
298 |
| - Object[] arguments = target.getArguments(); |
299 |
| - if (arguments.length <= PArguments.USER_ARGUMENTS_OFFSET) { |
300 |
| - throw raise(PythonErrorType.RuntimeError, "super(): no arguments"); |
301 |
| - } |
302 |
| - Object obj = arguments[PArguments.USER_ARGUMENTS_OFFSET]; |
303 |
| - if (obj == PNone.NONE) { |
304 |
| - throw raise(PythonErrorType.RuntimeError, "super(): no arguments"); |
305 |
| - } |
306 |
| - |
307 |
| - return initFromFrame(self, target, obj); |
308 |
| - } |
309 |
| - |
310 |
| - @TruffleBoundary |
311 |
| - private PNone initFromFrame(Object self, Frame target, Object obj) { |
312 |
| - // TODO: remove me |
313 |
| - // TODO: do it properly via the python API in super.__init__ : |
314 |
| - // sys._getframe(1).f_code.co_closure? |
315 |
| - FrameSlot classSlot = target.getFrameDescriptor().findFrameSlot(__CLASS__); |
316 |
| - Object cls = PNone.NONE; |
317 |
| - if (classSlot != null) { |
318 |
| - try { |
319 |
| - cls = target.getObject(classSlot); |
320 |
| - if (cls instanceof PCell) { |
321 |
| - cls = ((PCell) cls).getPythonRef(); |
322 |
| - } |
323 |
| - } catch (FrameSlotTypeException e) { |
324 |
| - // fallthrough |
325 |
| - } |
326 |
| - } |
327 |
| - if (cls == PNone.NONE) { |
328 |
| - throw raise(PythonErrorType.RuntimeError, "super(): empty __class__ cell"); |
329 |
| - } |
330 |
| - return init(self, cls, obj); |
331 |
| - } |
332 |
| - |
333 |
| - @SuppressWarnings("unused") |
334 |
| - @Fallback |
335 |
| - PNone initFallback(Object self, Object cls, Object obj) { |
336 |
| - throw raise(PythonErrorType.RuntimeError, "super(): invalid arguments"); |
337 |
| - } |
338 |
| - } |
339 |
| - |
340 | 186 | @Builtin(name = "exc_info", fixedNumOfPositionalArgs = 0)
|
341 | 187 | @GenerateNodeFactory
|
342 | 188 | public static abstract class ExcInfoNode extends PythonBuiltinNode {
|
|
0 commit comments