|
44 | 44 | import com.oracle.graal.python.builtins.objects.PNone;
|
45 | 45 | import com.oracle.graal.python.builtins.objects.code.PCode;
|
46 | 46 | import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetObjectArrayNode;
|
| 47 | +import com.oracle.graal.python.builtins.objects.dict.PDict; |
47 | 48 | import com.oracle.graal.python.builtins.objects.exception.PBaseException;
|
48 | 49 | import com.oracle.graal.python.builtins.objects.frame.PFrame;
|
49 | 50 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
|
66 | 67 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
67 | 68 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
68 | 69 | import com.oracle.graal.python.runtime.exception.PException;
|
| 70 | +import com.oracle.graal.python.runtime.object.PythonObjectFactory; |
69 | 71 | import com.oracle.graal.python.util.PythonUtils;
|
70 | 72 | import com.oracle.truffle.api.CallTarget;
|
71 | 73 | import com.oracle.truffle.api.CompilerDirectives;
|
@@ -468,6 +470,30 @@ static Object getRunning(PGenerator self) {
|
468 | 470 | }
|
469 | 471 | }
|
470 | 472 |
|
| 473 | + @Builtin(name = "gi_frame", minNumOfPositionalArgs = 1, isGetter = true) |
| 474 | + @GenerateNodeFactory |
| 475 | + public abstract static class GetFrameNode extends PythonUnaryBuiltinNode { |
| 476 | + @Specialization |
| 477 | + static Object getFrame(PGenerator self, |
| 478 | + @Cached PythonObjectFactory factory) { |
| 479 | + if (self.isFinished()) { |
| 480 | + return PNone.NONE; |
| 481 | + } else { |
| 482 | + MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(self.getArguments()); |
| 483 | + PDict locals = PArguments.getGeneratorFrameLocals(generatorFrame); |
| 484 | + Object[] arguments = PArguments.create(); |
| 485 | + // TODO msimacek - this way, the generator will always have lineno == 1 |
| 486 | + Node location = self.getCurrentCallTarget().getRootNode(); |
| 487 | + PFrame frame = factory.createPFrame(PFrame.Reference.EMPTY, location, locals, false); |
| 488 | + PArguments.setGlobals(arguments, PArguments.getGlobals(self.getArguments())); |
| 489 | + PArguments.setClosure(arguments, PArguments.getClosure(self.getArguments())); |
| 490 | + PArguments.setGeneratorFrame(arguments, generatorFrame); |
| 491 | + frame.setArguments(arguments); |
| 492 | + return frame; |
| 493 | + } |
| 494 | + } |
| 495 | + } |
| 496 | + |
471 | 497 | @Builtin(name = __REPR__, minNumOfPositionalArgs = 1)
|
472 | 498 | @GenerateNodeFactory
|
473 | 499 | abstract static class ReprNode extends PythonUnaryBuiltinNode {
|
|
0 commit comments