summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-27 11:24:23 (GMT)
committerGitHub <noreply@github.com>2022-06-27 11:24:23 (GMT)
commitc0453a40faaadb43d2e69767af6c9680f8689063 (patch)
treed8ab19e5244e552e5d1b371651593be9be5142e4 /Python/ceval.c
parent33fc3b5e42f241ab81cc6d115711545b4f9e271e (diff)
downloadcpython-c0453a40faaadb43d2e69767af6c9680f8689063.zip
cpython-c0453a40faaadb43d2e69767af6c9680f8689063.tar.gz
cpython-c0453a40faaadb43d2e69767af6c9680f8689063.tar.bz2
GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 47dd100..946e997 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -23,6 +23,7 @@
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_range.h" // _PyRangeIterObject
+#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
#include "pycore_sysmodule.h" // _PySys_Audit()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
@@ -2139,6 +2140,46 @@ handle_eval_breaker:
DISPATCH();
}
+ TARGET(BINARY_SLICE) {
+ PyObject *stop = POP();
+ PyObject *start = POP();
+ PyObject *container = TOP();
+
+ PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
+ if (slice == NULL) {
+ goto error;
+ }
+ PyObject *res = PyObject_GetItem(container, slice);
+ Py_DECREF(slice);
+ if (res == NULL) {
+ goto error;
+ }
+ SET_TOP(res);
+ Py_DECREF(container);
+ DISPATCH();
+ }
+
+ TARGET(STORE_SLICE) {
+ PyObject *stop = POP();
+ PyObject *start = POP();
+ PyObject *container = TOP();
+ PyObject *v = SECOND();
+
+ PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
+ if (slice == NULL) {
+ goto error;
+ }
+ int err = PyObject_SetItem(container, slice, v);
+ Py_DECREF(slice);
+ if (err) {
+ goto error;
+ }
+ STACK_SHRINK(2);
+ Py_DECREF(v);
+ Py_DECREF(container);
+ DISPATCH();
+ }
+
TARGET(BINARY_SUBSCR_ADAPTIVE) {
_PyBinarySubscrCache *cache = (_PyBinarySubscrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {