Skip to content

Commit ad0134d

Browse files
author
Adam Hrbac
committed
Add aiter and anext builtins
1 parent 6e48418 commit ad0134d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@
201201
import com.oracle.graal.python.nodes.attributes.SetAttributeNode;
202202
import com.oracle.graal.python.nodes.builtins.ListNodes;
203203
import com.oracle.graal.python.nodes.builtins.ListNodes.ConstructListNode;
204+
import com.oracle.graal.python.nodes.bytecode.GetAIterNode;
205+
import com.oracle.graal.python.nodes.bytecode.GetANextNode;
204206
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
205207
import com.oracle.graal.python.nodes.call.CallDispatchNode;
206208
import com.oracle.graal.python.nodes.call.CallNode;
@@ -210,6 +212,7 @@
210212
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
211213
import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
212214
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
215+
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
213216
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
214217
import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
215218
import com.oracle.graal.python.nodes.expression.BinaryArithmetic.AddNode;
@@ -2584,4 +2587,35 @@ class InitializeBuildClass {
25842587
return cls;
25852588
}
25862589
}
2590+
2591+
@Builtin(name = "anext", minNumOfPositionalArgs = 1)
2592+
@GenerateNodeFactory
2593+
public static abstract class ANext extends PythonUnaryBuiltinNode {
2594+
@Specialization
2595+
public Object doGeneric(VirtualFrame frame, Object asyncIter,
2596+
@Bind("this") Node inliningTarget,
2597+
@Cached(parameters = "ANext") LookupSpecialMethodSlotNode getANext,
2598+
@Cached InlinedGetClassNode getAsyncIterType,
2599+
@Cached PRaiseNode raiseNoANext,
2600+
@Cached CallUnaryMethodNode callANext,
2601+
@Cached TypeNodes.GetNameNode getName) {
2602+
// TODO: two argument anext
2603+
Object type = getAsyncIterType.execute(inliningTarget, asyncIter);
2604+
Object getter = getANext.execute(frame, type, asyncIter);
2605+
if (getter == NO_VALUE) {
2606+
throw raiseNoANext.raise(PythonBuiltinClassType.TypeError, ErrorMessages.OBJECT_NOT_ASYNCGEN, getName.execute(type));
2607+
}
2608+
return callANext.executeObject(frame, getter, asyncIter);
2609+
}
2610+
}
2611+
2612+
@Builtin(name = "aiter", minNumOfPositionalArgs = 1)
2613+
@GenerateNodeFactory
2614+
public static abstract class AIter extends PythonUnaryBuiltinNode {
2615+
@Specialization
2616+
public Object doGeneric(VirtualFrame frame, Object arg,
2617+
@Cached GetAIterNode aiter) {
2618+
return aiter.execute(frame, arg);
2619+
}
2620+
}
25872621
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ContextvarsModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ protected Object copyCtx() {
8484
@Builtin(name = "ContextVar", minNumOfPositionalArgs = 2, parameterNames = {"cls", "name", "default"}, constructsClass = PythonBuiltinClassType.ContextVar)
8585
@GenerateNodeFactory
8686
public abstract static class ContextVarNode extends PythonTernaryBuiltinNode {
87-
@Specialization
87+
@Specialization(guards = "isNoValue(def)")
8888
protected Object construct(Object cls, TruffleString name, @SuppressWarnings("unused") PNone def) {
8989
return constructDef(cls, name, PContextVar.NO_DEFAULT);
9090
}
9191

92-
@Specialization(guards = "!isPNone(def)")
92+
@Specialization(guards = "!isNoValue(def)")
9393
protected Object constructDef(@SuppressWarnings("unused") Object cls, TruffleString name, Object def) {
9494
return factory().createContextVar(name, def);
9595
}

0 commit comments

Comments
 (0)