mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
gh-98831: rewrite COPY and SWAP in the instruction definition DSL (#101620)
This commit is contained in:
parent
949c58f945
commit
38752760c9
3 changed files with 21 additions and 22 deletions
|
@ -3098,11 +3098,9 @@ dummy_func(
|
||||||
PUSH(result);
|
PUSH(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack effect: ( -- __0)
|
inst(COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {
|
||||||
inst(COPY) {
|
assert(oparg > 0);
|
||||||
assert(oparg != 0);
|
top = Py_NewRef(bottom);
|
||||||
PyObject *peek = PEEK(oparg);
|
|
||||||
PUSH(Py_NewRef(peek));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(BINARY_OP, (unused/1, lhs, rhs -- res)) {
|
inst(BINARY_OP, (unused/1, lhs, rhs -- res)) {
|
||||||
|
@ -3126,12 +3124,9 @@ dummy_func(
|
||||||
ERROR_IF(res == NULL, error);
|
ERROR_IF(res == NULL, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack effect: ( -- )
|
inst(SWAP, (bottom, unused[oparg-2], top --
|
||||||
inst(SWAP) {
|
top, unused[oparg-2], bottom)) {
|
||||||
assert(oparg != 0);
|
assert(oparg >= 2);
|
||||||
PyObject *top = TOP();
|
|
||||||
SET_TOP(PEEK(oparg));
|
|
||||||
PEEK(oparg) = top;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(EXTENDED_ARG, (--)) {
|
inst(EXTENDED_ARG, (--)) {
|
||||||
|
|
18
Python/generated_cases.c.h
generated
18
Python/generated_cases.c.h
generated
|
@ -3723,9 +3723,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(COPY) {
|
TARGET(COPY) {
|
||||||
assert(oparg != 0);
|
PyObject *bottom = PEEK(1 + (oparg-1));
|
||||||
PyObject *peek = PEEK(oparg);
|
PyObject *top;
|
||||||
PUSH(Py_NewRef(peek));
|
assert(oparg > 0);
|
||||||
|
top = Py_NewRef(bottom);
|
||||||
|
STACK_GROW(1);
|
||||||
|
POKE(1, top);
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3760,10 +3763,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(SWAP) {
|
TARGET(SWAP) {
|
||||||
assert(oparg != 0);
|
PyObject *top = PEEK(1);
|
||||||
PyObject *top = TOP();
|
PyObject *bottom = PEEK(2 + (oparg-2));
|
||||||
SET_TOP(PEEK(oparg));
|
assert(oparg >= 2);
|
||||||
PEEK(oparg) = top;
|
POKE(1, bottom);
|
||||||
|
POKE(2 + (oparg-2), top);
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -333,11 +333,11 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
||||||
case FORMAT_VALUE:
|
case FORMAT_VALUE:
|
||||||
return -1;
|
return -1;
|
||||||
case COPY:
|
case COPY:
|
||||||
return -1;
|
return (oparg-1) + 1;
|
||||||
case BINARY_OP:
|
case BINARY_OP:
|
||||||
return 2;
|
return 2;
|
||||||
case SWAP:
|
case SWAP:
|
||||||
return -1;
|
return (oparg-2) + 2;
|
||||||
case EXTENDED_ARG:
|
case EXTENDED_ARG:
|
||||||
return 0;
|
return 0;
|
||||||
case CACHE:
|
case CACHE:
|
||||||
|
@ -679,11 +679,11 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
||||||
case FORMAT_VALUE:
|
case FORMAT_VALUE:
|
||||||
return -1;
|
return -1;
|
||||||
case COPY:
|
case COPY:
|
||||||
return -1;
|
return (oparg-1) + 2;
|
||||||
case BINARY_OP:
|
case BINARY_OP:
|
||||||
return 1;
|
return 1;
|
||||||
case SWAP:
|
case SWAP:
|
||||||
return -1;
|
return (oparg-2) + 2;
|
||||||
case EXTENDED_ARG:
|
case EXTENDED_ARG:
|
||||||
return 0;
|
return 0;
|
||||||
case CACHE:
|
case CACHE:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue