Skip to content

Commit 2b9debd

Browse files
author
Adam Hrbac
committed
Add missing coroutine builtins
1 parent ad0134d commit 2b9debd

File tree

1 file changed

+45
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator

1 file changed

+45
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CoroutineBuiltins.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,63 @@
4646
import com.oracle.graal.python.builtins.CoreFunctions;
4747
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4848
import com.oracle.graal.python.builtins.PythonBuiltins;
49+
import com.oracle.graal.python.builtins.objects.PNone;
4950
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5051
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;
5154
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5255
import com.oracle.truffle.api.dsl.NodeFactory;
5356
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;
5460

5561
@CoreFunctions(extendClasses = PythonBuiltinClassType.PCoroutine)
5662
public class CoroutineBuiltins extends PythonBuiltins {
5763
@Override
5864
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
5965
return CoroutineBuiltinsFactory.getFactories();
6066
}
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+
}
61106

62107
@Builtin(name = "__await__", minNumOfPositionalArgs = 1)
63108
@GenerateNodeFactory

0 commit comments

Comments
 (0)