diff options
author | Brandt Bucher <brandt@python.org> | 2022-01-26 20:47:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-26 20:47:45 (GMT) |
commit | 85483668647e7840c7b9a1877caaf2ef14a4443f (patch) | |
tree | 48c1ba3dc17fb6c39d100e114178e1cc9ca19e88 /Python/ceval.c | |
parent | d4a85f104bf9d2e368f25c9a567eaaa2cc39a96a (diff) | |
download | cpython-85483668647e7840c7b9a1877caaf2ef14a4443f.zip cpython-85483668647e7840c7b9a1877caaf2ef14a4443f.tar.gz cpython-85483668647e7840c7b9a1877caaf2ef14a4443f.tar.bz2 |
bpo-46528: Simplify the VM's stack manipulations (GH-30902)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 68 |
1 files changed, 9 insertions, 59 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 29ca5e3..106e408 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1434,8 +1434,6 @@ eval_frame_handle_pending(PyThreadState *tstate) #define PEEK(n) (stack_pointer[-(n)]) #define SET_TOP(v) (stack_pointer[-1] = (v)) #define SET_SECOND(v) (stack_pointer[-2] = (v)) -#define SET_THIRD(v) (stack_pointer[-3] = (v)) -#define SET_FOURTH(v) (stack_pointer[-4] = (v)) #define BASIC_STACKADJ(n) (stack_pointer += n) #define BASIC_PUSH(v) (*stack_pointer++ = (v)) #define BASIC_POP() (*--stack_pointer) @@ -1920,54 +1918,6 @@ handle_eval_breaker: DISPATCH(); } - TARGET(ROT_TWO) { - PyObject *top = TOP(); - PyObject *second = SECOND(); - SET_TOP(second); - SET_SECOND(top); - DISPATCH(); - } - - TARGET(ROT_THREE) { - PyObject *top = TOP(); - PyObject *second = SECOND(); - PyObject *third = THIRD(); - SET_TOP(second); - SET_SECOND(third); - SET_THIRD(top); - DISPATCH(); - } - - TARGET(ROT_FOUR) { - PyObject *top = TOP(); - PyObject *second = SECOND(); - PyObject *third = THIRD(); - PyObject *fourth = FOURTH(); - SET_TOP(second); - SET_SECOND(third); - SET_THIRD(fourth); - SET_FOURTH(top); - DISPATCH(); - } - - TARGET(DUP_TOP) { - PyObject *top = TOP(); - Py_INCREF(top); - PUSH(top); - DISPATCH(); - } - - TARGET(DUP_TOP_TWO) { - PyObject *top = TOP(); - PyObject *second = SECOND(); - Py_INCREF(top); - Py_INCREF(second); - STACK_GROW(2); - SET_TOP(top); - SET_SECOND(second); - DISPATCH(); - } - TARGET(UNARY_POSITIVE) { PyObject *value = TOP(); PyObject *res = PyNumber_Positive(value); @@ -5170,14 +5120,6 @@ handle_eval_breaker: DISPATCH(); } - TARGET(ROT_N) { - PyObject *top = TOP(); - memmove(&PEEK(oparg - 1), &PEEK(oparg), - sizeof(PyObject*) * (oparg - 1)); - PEEK(oparg) = top; - DISPATCH(); - } - TARGET(COPY) { assert(oparg != 0); PyObject *peek = PEEK(oparg); @@ -5221,6 +5163,14 @@ handle_eval_breaker: } } + TARGET(SWAP) { + assert(oparg != 0); + PyObject *top = TOP(); + SET_TOP(PEEK(oparg)); + PEEK(oparg) = top; + DISPATCH(); + } + TARGET(EXTENDED_ARG) { int oldoparg = oparg; NEXTOPARG(); @@ -7380,7 +7330,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop "that does not implement __await__: %.100s", type->tp_name); } - else if (prevopcode == WITH_EXCEPT_START || (prevopcode == CALL_NO_KW && prevprevopcode == DUP_TOP)) { + else if (prevopcode == WITH_EXCEPT_START || (prevopcode == CALL_NO_KW && prevprevopcode == LOAD_CONST)) { _PyErr_Format(tstate, PyExc_TypeError, "'async with' received an object from __aexit__ " "that does not implement __await__: %.100s", |