|
42 | 42 | import com.oracle.graal.python.builtins.objects.PNone;
|
43 | 43 | import com.oracle.graal.python.builtins.objects.code.PCode;
|
44 | 44 | import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetObjectArrayNode;
|
| 45 | +import com.oracle.graal.python.builtins.objects.dict.PDict; |
45 | 46 | import com.oracle.graal.python.builtins.objects.exception.PBaseException;
|
46 | 47 | import com.oracle.graal.python.builtins.objects.frame.PFrame;
|
47 | 48 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
|
62 | 63 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
63 | 64 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
64 | 65 | import com.oracle.graal.python.runtime.exception.PException;
|
| 66 | +import com.oracle.graal.python.runtime.object.PythonObjectFactory; |
65 | 67 | import com.oracle.graal.python.util.PythonUtils;
|
66 | 68 | import com.oracle.truffle.api.CallTarget;
|
67 | 69 | import com.oracle.truffle.api.CompilerDirectives;
|
@@ -426,6 +428,30 @@ static Object getRunning(PGenerator self) {
|
426 | 428 | }
|
427 | 429 | }
|
428 | 430 |
|
| 431 | + @Builtin(name = "gi_frame", minNumOfPositionalArgs = 1, isGetter = true) |
| 432 | + @GenerateNodeFactory |
| 433 | + public abstract static class GetFrameNode extends PythonUnaryBuiltinNode { |
| 434 | + @Specialization |
| 435 | + static Object getFrame(PGenerator self, |
| 436 | + @Cached PythonObjectFactory factory) { |
| 437 | + if (self.isFinished()) { |
| 438 | + return PNone.NONE; |
| 439 | + } else { |
| 440 | + MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(self.getArguments()); |
| 441 | + PDict locals = PArguments.getGeneratorFrameLocals(generatorFrame); |
| 442 | + Object[] arguments = PArguments.create(); |
| 443 | + // TODO msimacek - this way, the generator will always have lineno == 1 |
| 444 | + Node location = self.getCurrentCallTarget().getRootNode(); |
| 445 | + PFrame frame = factory.createPFrame(PFrame.Reference.EMPTY, location, locals, false); |
| 446 | + PArguments.setGlobals(arguments, PArguments.getGlobals(self.getArguments())); |
| 447 | + PArguments.setClosure(arguments, PArguments.getClosure(self.getArguments())); |
| 448 | + PArguments.setGeneratorFrame(arguments, generatorFrame); |
| 449 | + frame.setArguments(arguments); |
| 450 | + return frame; |
| 451 | + } |
| 452 | + } |
| 453 | + } |
| 454 | + |
429 | 455 | @Builtin(name = __REPR__, minNumOfPositionalArgs = 1)
|
430 | 456 | @GenerateNodeFactory
|
431 | 457 | abstract static class ReprNode extends PythonUnaryBuiltinNode {
|
|
0 commit comments