Skip to content

Commit cf7ac0e

Browse files
committed
_operator: missing index builtin
1 parent a63def1 commit cf7ac0e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
5353
import com.oracle.graal.python.builtins.objects.dict.PDict;
5454
import com.oracle.graal.python.builtins.objects.ints.PInt;
55+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5556
import com.oracle.graal.python.nodes.SpecialMethodNames;
5657
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
5758
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
@@ -70,6 +71,9 @@
7071
import com.oracle.truffle.api.dsl.Specialization;
7172
import com.oracle.truffle.api.dsl.TypeSystemReference;
7273
import com.oracle.truffle.api.frame.VirtualFrame;
74+
import com.oracle.truffle.api.library.CachedLibrary;
75+
76+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INDEX__;
7377

7478
@CoreFunctions(defineModule = OperatorModuleBuiltins.MODULE_NAME)
7579
public class OperatorModuleBuiltins extends PythonBuiltins {
@@ -224,4 +228,14 @@ public boolean doString(String arg1, String arg2) {
224228
}
225229

226230
}
231+
232+
@Builtin(name = "index", minNumOfPositionalArgs = 1)
233+
@GenerateNodeFactory
234+
abstract static class IndexNode extends PythonUnaryBuiltinNode {
235+
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
236+
Object asIndex(Object value,
237+
@CachedLibrary(value = "value") PythonObjectLibrary pol) {
238+
return pol.asIndex(value);
239+
}
240+
}
227241
}

0 commit comments

Comments
 (0)