Skip to content

Commit 96fa6f2

Browse files
committed
moved PythonCextBuiltins.PyTupleXXX to PythonCextTupleBuiltins
1 parent 401af4d commit 96fa6f2

File tree

3 files changed

+174
-137
lines changed

3 files changed

+174
-137
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
import com.oracle.graal.python.builtins.modules.cext.PythonCextUnicodeBuiltins;
128128
import com.oracle.graal.python.builtins.modules.cext.PythonCextSliceBuiltins;
129129
import com.oracle.graal.python.builtins.modules.cext.PythonCextSysBuiltins;
130+
import com.oracle.graal.python.builtins.modules.cext.PythonCextTupleBuiltins;
130131
import com.oracle.graal.python.builtins.modules.csv.CSVDialectBuiltins;
131132
import com.oracle.graal.python.builtins.modules.csv.CSVModuleBuiltins;
132133
import com.oracle.graal.python.builtins.modules.csv.CSVReaderBuiltins;
@@ -502,6 +503,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed)
502503
new PythonCextSetBuiltins(),
503504
new PythonCextSliceBuiltins(),
504505
new PythonCextSysBuiltins(),
506+
new PythonCextTupleBuiltins(),
505507
new PythonCextUnicodeBuiltins(),
506508
new WeakRefModuleBuiltins(),
507509
new ReferenceTypeBuiltins(),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 6 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,6 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules.cext;
4242

43-
<<<<<<< HEAD
44-
=======
45-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextAbstractBuiltins.PYTHON_CEXT_ABSTRACT;
46-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBytesBuiltins.PYTHON_CEXT_BYTES;
47-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextCEvalBuiltins.PYTHON_CEXT_CEVAL;
48-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextCodeBuiltins.PYTHON_CEXT_CODE;
49-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextComplexBuiltins.PYTHON_CEXT_COMPLEX;
50-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextDictBuiltins.PYTHON_CEXT_DICT;
51-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextFileBuiltins.PYTHON_CEXT_FILE;
52-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextFloatBuiltins.PYTHON_CEXT_FLOAT;
53-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextImportBuiltins.PYTHON_CEXT_IMPORT;
54-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextListBuiltins.PYTHON_CEXT_LIST;
55-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextLongBuiltins.PYTHON_CEXT_LONG;
56-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextMemoryViewBuiltins.PYTHON_CEXT_MEMORYVIEW;
57-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextNamespaceBuiltins.PYTHON_CEXT_NAMESPACE;
58-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextPythonRunBuiltins.PYTHON_CEXT_PYTHON_RUN;
59-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextSetBuiltins.PYTHON_CEXT_SET;
60-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextSliceBuiltins.PYTHON_CEXT_SLICE;
61-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextSysBuiltins.PYTHON_CEXT_SYS;
62-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextUnicodeBuiltins.PYTHON_CEXT_UNICODE;
63-
>>>>>>> intrinsified PySys_XXX
6443
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IndexError;
6544
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
6645
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
@@ -101,6 +80,7 @@
10180
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.MappingproxyNode;
10281
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
10382
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltinsFactory.CreateFunctionNodeGen;
83+
import static com.oracle.graal.python.builtins.modules.cext.PythonCextTupleBuiltins.PYTHON_CEXT_TUPLE;
10484
import com.oracle.graal.python.builtins.objects.PNone;
10585
import com.oracle.graal.python.builtins.objects.PNotImplemented;
10686
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
@@ -118,7 +98,6 @@
11898
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
11999
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsCharPointerNode;
120100
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsPythonObjectNode;
121-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsPythonObjectStealingNode;
122101
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.CastToJavaDoubleNode;
123102
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.CastToNativeLongNode;
124103
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.CextUpcallNode;
@@ -189,7 +168,12 @@
189168
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
190169
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
191170
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
171+
<<<<<<< HEAD
192172
import com.oracle.graal.python.builtins.objects.common.IndexNodes.NormalizeIndexNode;
173+
=======
174+
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterable;
175+
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterator;
176+
>>>>>>> moved PythonCextBuiltins.PyTupleXXX to PythonCextTupleBuiltins
193177
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
194178
import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
195179
import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetObjectArrayNode;
@@ -233,7 +217,6 @@
233217
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
234218
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
235219
import com.oracle.graal.python.lib.PyMemoryViewFromObject;
236-
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
237220
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
238221
import com.oracle.graal.python.lib.PyObjectLookupAttr;
239222
import com.oracle.graal.python.nodes.BuiltinNames;
@@ -362,47 +345,6 @@ public void initialize(Python3Core core) {
362345
builtinConstants.put("PyGILState_Release", new PyGILStateRelease());
363346
}
364347

365-
<<<<<<< HEAD
366-
=======
367-
@Override
368-
public void postInitialize(Python3Core core) {
369-
PythonModule cext = core.lookupBuiltinModule(PYTHON_CEXT);
370-
addModuleDict(cext, PYTHON_CEXT_ABSTRACT, core);
371-
addModuleDict(cext, PYTHON_CEXT_BYTES, core);
372-
addModuleDict(cext, PYTHON_CEXT_CEVAL, core);
373-
addModuleDict(cext, PYTHON_CEXT_CODE, core);
374-
addModuleDict(cext, PYTHON_CEXT_COMPLEX, core);
375-
addModuleDict(cext, PYTHON_CEXT_DICT, core);
376-
addModuleDict(cext, PYTHON_CEXT_FILE, core);
377-
addModuleDict(cext, PYTHON_CEXT_FLOAT, core);
378-
addModuleDict(cext, PYTHON_CEXT_IMPORT, core);
379-
addModuleDict(cext, PYTHON_CEXT_LONG, core);
380-
addModuleDict(cext, PYTHON_CEXT_LIST, core);
381-
addModuleDict(cext, PYTHON_CEXT_MEMORYVIEW, core);
382-
addModuleDict(cext, PYTHON_CEXT_NAMESPACE, core);
383-
addModuleDict(cext, PYTHON_CEXT_PYTHON_RUN, core);
384-
addModuleDict(cext, PYTHON_CEXT_SET, core);
385-
addModuleDict(cext, PYTHON_CEXT_SLICE, core);
386-
addModuleDict(cext, PYTHON_CEXT_SYS, core);
387-
addModuleDict(cext, PYTHON_CEXT_UNICODE, core);
388-
}
389-
390-
private static void addModuleDict(PythonModule cext, String module, Python3Core core) {
391-
PythonModule cext_module = core.lookupBuiltinModule(module);
392-
PDict dict = GetDictIfExistsNodeGen.getUncached().execute(cext_module);
393-
HashingStorageIterable<Object> keys = dict.keys();
394-
HashingStorageIterator<Object> it = keys.iterator();
395-
while (it.hasNext()) {
396-
Object key = it.next();
397-
Object value = dict.getItem(key);
398-
if (value instanceof PythonBuiltinObject) {
399-
assert cext.getAttribute(key) == PNone.NO_VALUE || cext.getAttribute(key) == null : "python_cext dict already contains value " + cext.getAttribute(key) + " for key " + key;
400-
cext.setAttribute(key, value);
401-
}
402-
}
403-
}
404-
405-
>>>>>>> intrinsified PySys_XXX
406348
@FunctionalInterface
407349
public interface TernaryFunction<T1, T2, T3, R> {
408350
R apply(T1 arg0, T2 arg1, T3 arg2);
@@ -659,56 +601,6 @@ Object doI(Object typeNameObject) {
659601
}
660602
}
661603

662-
@Builtin(name = "PyTuple_New", minNumOfPositionalArgs = 1)
663-
@GenerateNodeFactory
664-
abstract static class PyTuple_New extends PythonUnaryBuiltinNode {
665-
@Specialization
666-
PTuple doGeneric(VirtualFrame frame, Object size,
667-
@Cached PyNumberAsSizeNode asSizeNode) {
668-
return factory().createTuple(new Object[asSizeNode.executeExact(frame, size)]);
669-
}
670-
}
671-
672-
@Builtin(name = "PyTuple_SetItem", minNumOfPositionalArgs = 3)
673-
@GenerateNodeFactory
674-
@ImportStatic(CApiGuards.class)
675-
abstract static class PyTuple_SetItem extends PythonTernaryBuiltinNode {
676-
@Specialization
677-
static int doManaged(VirtualFrame frame, PythonNativeWrapper selfWrapper, Object position, Object elementWrapper,
678-
@Cached AsPythonObjectNode selfAsPythonObjectNode,
679-
@Cached AsPythonObjectStealingNode elementAsPythonObjectNode,
680-
@Cached("createSetItem()") SequenceStorageNodes.SetItemNode setItemNode,
681-
@Cached PRaiseNode raiseNode,
682-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
683-
try {
684-
Object self = selfAsPythonObjectNode.execute(selfWrapper);
685-
if (!PGuards.isPTuple(self) || selfWrapper.getRefCount() != 1) {
686-
throw raiseNode.raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_P, "PTuple_SetItem");
687-
}
688-
PTuple tuple = (PTuple) self;
689-
Object element = elementAsPythonObjectNode.execute(elementWrapper);
690-
setItemNode.execute(frame, tuple.getSequenceStorage(), position, element);
691-
return 0;
692-
} catch (PException e) {
693-
transformExceptionToNativeNode.execute(frame, e);
694-
return -1;
695-
}
696-
}
697-
698-
@Specialization(guards = "!isNativeWrapper(tuple)")
699-
static int doNative(Object tuple, long position, Object element,
700-
@Cached PCallCapiFunction callSetItem) {
701-
// TODO(fa): This path should be avoided since this is called from native code to do a
702-
// native operation.
703-
callSetItem.call(NativeCAPISymbol.FUN_PY_TRUFFLE_TUPLE_SET_ITEM, tuple, position, element);
704-
return 0;
705-
}
706-
707-
protected static SequenceStorageNodes.SetItemNode createSetItem() {
708-
return SequenceStorageNodes.SetItemNode.create(NormalizeIndexNode.forTupleAssign(), "invalid item for assignment");
709-
}
710-
}
711-
712604
@Builtin(name = "CreateBuiltinMethod", minNumOfPositionalArgs = 2)
713605
@GenerateNodeFactory
714606
abstract static class CreateBuiltinMethodNode extends PythonBuiltinNode {
@@ -2059,29 +1951,6 @@ int doSlow(VirtualFrame frame, Object derived, Object cls) {
20591951
}
20601952
}
20611953

2062-
@Builtin(name = "PyTuple_GetItem", minNumOfPositionalArgs = 2)
2063-
@GenerateNodeFactory
2064-
abstract static class PyTuple_GetItem extends PythonBinaryBuiltinNode {
2065-
2066-
@Specialization
2067-
Object doPTuple(VirtualFrame frame, PTuple tuple, long key,
2068-
@Cached SequenceStorageNodes.LenNode lenNode,
2069-
@Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode) {
2070-
SequenceStorage sequenceStorage = tuple.getSequenceStorage();
2071-
// we must do a bounds-check but we must not normalize the index
2072-
if (key < 0 || key >= lenNode.execute(sequenceStorage)) {
2073-
throw raise(IndexError, ErrorMessages.TUPLE_OUT_OF_BOUNDS);
2074-
}
2075-
return getItemNode.execute(frame, sequenceStorage, key);
2076-
}
2077-
2078-
@Fallback
2079-
Object doPTuple(Object tuple, @SuppressWarnings("unused") Object key) {
2080-
// TODO(fa) To be absolutely correct, we need to do a 'isinstance' check on the object.
2081-
throw raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, tuple, tuple);
2082-
}
2083-
}
2084-
20851954
@Builtin(name = "PyTruffle_Compute_Mro", minNumOfPositionalArgs = 2)
20861955
@GenerateNodeFactory
20871956
@TypeSystemReference(PythonTypes.class)

0 commit comments

Comments
 (0)