|
46 | 46 | import com.oracle.graal.python.builtins.CoreFunctions;
|
47 | 47 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
48 | 48 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
| 49 | +import com.oracle.graal.python.builtins.objects.PNone; |
49 | 50 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
50 | 51 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
| 52 | +import com.oracle.truffle.api.dsl.Bind; |
| 53 | +import com.oracle.truffle.api.dsl.Cached; |
51 | 54 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
52 | 55 | import com.oracle.truffle.api.dsl.NodeFactory;
|
53 | 56 | import com.oracle.truffle.api.dsl.Specialization;
|
| 57 | +import com.oracle.truffle.api.frame.VirtualFrame; |
| 58 | +import com.oracle.truffle.api.nodes.Node; |
| 59 | +import com.oracle.truffle.api.profiles.InlinedConditionProfile; |
54 | 60 |
|
55 | 61 | @CoreFunctions(extendClasses = PythonBuiltinClassType.PCoroutine)
|
56 | 62 | public class CoroutineBuiltins extends PythonBuiltins {
|
57 | 63 | @Override
|
58 | 64 | protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
|
59 | 65 | return CoroutineBuiltinsFactory.getFactories();
|
60 | 66 | }
|
| 67 | + @Builtin(name = "cr_code", isGetter = true, minNumOfPositionalArgs = 1) |
| 68 | + @GenerateNodeFactory |
| 69 | + public abstract static class GetCode extends PythonUnaryBuiltinNode { |
| 70 | + @Specialization |
| 71 | + public Object getCode(PGenerator self, |
| 72 | + @Bind("this") Node inliningTarget, |
| 73 | + @Cached InlinedConditionProfile hasCodeProfile) { |
| 74 | + return self.getOrCreateCode(inliningTarget, hasCodeProfile, factory()); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + @Builtin(name = "cr_await", isGetter = true, minNumOfPositionalArgs = 1) |
| 79 | + @GenerateNodeFactory |
| 80 | + public abstract static class GetAwait extends PythonUnaryBuiltinNode { |
| 81 | + @Specialization |
| 82 | + public Object getAwait(PGenerator self) { |
| 83 | + Object yieldFrom = self.getYieldFrom(); |
| 84 | + return yieldFrom != null ? yieldFrom : PNone.NONE; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Builtin(name = "cr_frame", isGetter = true, minNumOfPositionalArgs = 1) |
| 89 | + @GenerateNodeFactory |
| 90 | + public abstract static class GetFrame extends PythonUnaryBuiltinNode { |
| 91 | + @Specialization |
| 92 | + public Object getFrame(VirtualFrame frame, PGenerator self, |
| 93 | + @Cached GeneratorBuiltins.GetFrameNode getFrame) { |
| 94 | + return getFrame.execute(frame, self); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + @Builtin(name = "cr_running", isGetter = true, minNumOfPositionalArgs = 1) |
| 99 | + @GenerateNodeFactory |
| 100 | + public abstract static class IsRunning extends PythonUnaryBuiltinNode { |
| 101 | + @Specialization |
| 102 | + public boolean isRunning(PGenerator self) { |
| 103 | + return self.isRunning(); |
| 104 | + } |
| 105 | + } |
61 | 106 |
|
62 | 107 | @Builtin(name = "__await__", minNumOfPositionalArgs = 1)
|
63 | 108 | @GenerateNodeFactory
|
|
0 commit comments