|
55 | 55 | import com.oracle.graal.python.annotations.ArgumentClinic; |
56 | 56 | import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion; |
57 | 57 | import com.oracle.graal.python.annotations.ArgumentClinic.PrimitiveType; |
| 58 | +import com.oracle.graal.python.annotations.Builtin; |
58 | 59 | import com.oracle.graal.python.annotations.ClinicConverterFactory; |
59 | 60 | import com.oracle.graal.python.annotations.ClinicConverterFactory.ArgumentName; |
60 | 61 | import com.oracle.graal.python.annotations.ClinicConverterFactory.BuiltinName; |
61 | | -import com.oracle.graal.python.annotations.Builtin; |
| 62 | +import com.oracle.graal.python.annotations.PythonOS; |
62 | 63 | import com.oracle.graal.python.builtins.CoreFunctions; |
63 | 64 | import com.oracle.graal.python.builtins.Python3Core; |
64 | 65 | import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
65 | 66 | import com.oracle.graal.python.builtins.PythonBuiltins; |
66 | | -import com.oracle.graal.python.annotations.PythonOS; |
67 | 67 | import com.oracle.graal.python.builtins.modules.SysModuleBuiltins.AuditNode; |
68 | 68 | import com.oracle.graal.python.builtins.objects.PNone; |
69 | 69 | import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary; |
70 | 70 | import com.oracle.graal.python.builtins.objects.bytes.BytesNodes; |
71 | 71 | import com.oracle.graal.python.builtins.objects.bytes.PBytes; |
72 | | -import com.oracle.graal.python.builtins.objects.common.SequenceNodes.LenNode; |
73 | 72 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; |
74 | 73 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetItemNode; |
75 | 74 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ToArrayNode; |
|
128 | 127 | import com.oracle.graal.python.runtime.exception.PException; |
129 | 128 | import com.oracle.graal.python.runtime.exception.PythonExitException; |
130 | 129 | import com.oracle.graal.python.runtime.object.PFactory; |
131 | | -import com.oracle.graal.python.runtime.sequence.PSequence; |
132 | 130 | import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage; |
133 | 131 | import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; |
134 | 132 | import com.oracle.graal.python.util.OverflowException; |
@@ -2020,21 +2018,19 @@ static long[] now(VirtualFrame frame, PNone times, PNone ns) { |
2020 | 2018 | @Specialization(guards = {"isNoValue(ns)"}) |
2021 | 2019 | static long[] times(VirtualFrame frame, PTuple times, @SuppressWarnings("unused") PNone ns, |
2022 | 2020 | @Bind Node inliningTarget, |
2023 | | - @Exclusive @Cached LenNode lenNode, |
2024 | | - @Shared @Cached("createNotNormalized()") GetItemNode getItemNode, |
| 2021 | + @Shared @Cached SequenceStorageNodes.GetItemScalarNode getItemNode, |
2025 | 2022 | @Cached ObjectToTimespecNode objectToTimespecNode, |
2026 | 2023 | @Exclusive @Cached PRaiseNode raiseNode) { |
2027 | | - return convertToTimespec(frame, inliningTarget, times, lenNode, getItemNode, objectToTimespecNode, raiseNode); |
| 2024 | + return convertToTimespec(frame, inliningTarget, times, getItemNode, objectToTimespecNode, raiseNode); |
2028 | 2025 | } |
2029 | 2026 |
|
2030 | 2027 | @Specialization |
2031 | 2028 | static long[] ns(VirtualFrame frame, @SuppressWarnings("unused") PNone times, PTuple ns, |
2032 | 2029 | @Bind Node inliningTarget, |
2033 | | - @Exclusive @Cached LenNode lenNode, |
2034 | | - @Shared @Cached("createNotNormalized()") GetItemNode getItemNode, |
| 2030 | + @Shared @Cached SequenceStorageNodes.GetItemScalarNode getItemNode, |
2035 | 2031 | @Cached SplitLongToSAndNsNode splitLongToSAndNsNode, |
2036 | 2032 | @Exclusive @Cached PRaiseNode raiseNode) { |
2037 | | - return convertToTimespec(frame, inliningTarget, ns, lenNode, getItemNode, splitLongToSAndNsNode, raiseNode); |
| 2033 | + return convertToTimespec(frame, inliningTarget, ns, getItemNode, splitLongToSAndNsNode, raiseNode); |
2038 | 2034 | } |
2039 | 2035 |
|
2040 | 2036 | @Specialization(guards = {"!isPNone(times)", "!isNoValue(ns)"}) |
@@ -2066,14 +2062,15 @@ private static PException timesTupleError(Node inliningTarget, PRaiseNode raiseN |
2066 | 2062 | throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_BE_EITHER_OR, "utime", "times", "a tuple of two ints", "None"); |
2067 | 2063 | } |
2068 | 2064 |
|
2069 | | - private static long[] convertToTimespec(VirtualFrame frame, Node inliningTarget, PTuple times, LenNode lenNode, GetItemNode getItemNode, ConvertToTimespecBaseNode convertToTimespecBaseNode, |
2070 | | - PRaiseNode raiseNode) { |
2071 | | - if (lenNode.execute(inliningTarget, times) != 2) { |
| 2065 | + private static long[] convertToTimespec(VirtualFrame frame, Node inliningTarget, PTuple times, SequenceStorageNodes.GetItemScalarNode getItemNode, |
| 2066 | + ConvertToTimespecBaseNode convertToTimespecBaseNode, PRaiseNode raiseNode) { |
| 2067 | + SequenceStorage storage = times.getSequenceStorage(); |
| 2068 | + if (storage.length() != 2) { |
2072 | 2069 | throw timesTupleError(inliningTarget, raiseNode); |
2073 | 2070 | } |
2074 | 2071 | long[] timespec = new long[4]; |
2075 | | - convertToTimespecBaseNode.execute(frame, inliningTarget, getItemNode.execute(times.getSequenceStorage(), 0), timespec, 0); |
2076 | | - convertToTimespecBaseNode.execute(frame, inliningTarget, getItemNode.execute(times.getSequenceStorage(), 1), timespec, 2); |
| 2072 | + convertToTimespecBaseNode.execute(frame, inliningTarget, getItemNode.execute(inliningTarget, storage, 0), timespec, 0); |
| 2073 | + convertToTimespecBaseNode.execute(frame, inliningTarget, getItemNode.execute(inliningTarget, storage, 1), timespec, 2); |
2077 | 2074 | return timespec; |
2078 | 2075 | } |
2079 | 2076 | } |
@@ -3245,17 +3242,19 @@ static void doLong(long value, long[] timespec, int offset) { |
3245 | 3242 | @Specialization(guards = {"!isInteger(value)"}) |
3246 | 3243 | static void doGeneric(VirtualFrame frame, Node inliningTarget, Object value, long[] timespec, int offset, |
3247 | 3244 | @Cached PyNumberDivmodNode divmodNode, |
3248 | | - @Cached LenNode lenNode, |
3249 | 3245 | @Cached(value = "createNotNormalized()", inline = false) GetItemNode getItemNode, |
3250 | 3246 | @Cached PyLongAsLongNode asLongNode, |
3251 | 3247 | @Cached PRaiseNode raiseNode) { |
3252 | 3248 | Object divmod = divmodNode.execute(frame, inliningTarget, value, BILLION); |
3253 | | - if (!PGuards.isPTuple(divmod) || lenNode.execute(inliningTarget, (PSequence) divmod) != 2) { |
3254 | | - throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_RETURN_2TUPLE, value, divmod); |
| 3249 | + if (divmod instanceof PTuple tuple) { |
| 3250 | + SequenceStorage storage = tuple.getSequenceStorage(); |
| 3251 | + if (storage.length() == 2) { |
| 3252 | + timespec[offset] = asLongNode.execute(frame, inliningTarget, getItemNode.execute(storage, 0)); |
| 3253 | + timespec[offset + 1] = asLongNode.execute(frame, inliningTarget, getItemNode.execute(storage, 1)); |
| 3254 | + return; |
| 3255 | + } |
3255 | 3256 | } |
3256 | | - SequenceStorage storage = ((PTuple) divmod).getSequenceStorage(); |
3257 | | - timespec[offset] = asLongNode.execute(frame, inliningTarget, getItemNode.execute(storage, 0)); |
3258 | | - timespec[offset + 1] = asLongNode.execute(frame, inliningTarget, getItemNode.execute(storage, 1)); |
| 3257 | + throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.MUST_RETURN_2TUPLE, value, divmod); |
3259 | 3258 | } |
3260 | 3259 | } |
3261 | 3260 |
|
|
0 commit comments