bpo-46528: Simplify the VM's stack manipulations (GH-30902)

This commit is contained in:
Brandt Bucher 2022-01-26 12:47:45 -08:00 committed by GitHub
parent d4a85f104b
commit 8548366864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 288 additions and 323 deletions

View file

@ -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",