diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2023-01-25 22:29:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 22:29:56 (GMT) |
commit | b400219df5f245ef2eb3c7ce0589b1f8020a1192 (patch) | |
tree | 6ce0e7cf8c039cf5c5f2f573c7f6060c329cdc35 /Python | |
parent | 6162a0e305faf82534c011ddb2fb99a94ae84d29 (diff) | |
download | cpython-b400219df5f245ef2eb3c7ce0589b1f8020a1192.zip cpython-b400219df5f245ef2eb3c7ce0589b1f8020a1192.tar.gz cpython-b400219df5f245ef2eb3c7ce0589b1f8020a1192.tar.bz2 |
gh-98831: rewrite RAISE_VARARGS in the instruction definition DSL (#101306)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bytecodes.c | 13 | ||||
-rw-r--r-- | Python/generated_cases.c.h | 11 | ||||
-rw-r--r-- | Python/opcode_metadata.h | 8 |
3 files changed, 16 insertions, 16 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index d3e242b..e5769f61 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -505,27 +505,24 @@ dummy_func( ERROR_IF(res == NULL, error); } - // This should remain a legacy instruction. - inst(RAISE_VARARGS) { + inst(RAISE_VARARGS, (args[oparg] -- )) { PyObject *cause = NULL, *exc = NULL; switch (oparg) { case 2: - cause = POP(); /* cause */ + cause = args[1]; /* fall through */ case 1: - exc = POP(); /* exc */ + exc = args[0]; /* fall through */ case 0: - if (do_raise(tstate, exc, cause)) { - goto exception_unwind; - } + ERROR_IF(do_raise(tstate, exc, cause), exception_unwind); break; default: _PyErr_SetString(tstate, PyExc_SystemError, "bad RAISE_VARARGS oparg"); break; } - goto error; + ERROR_IF(true, error); } inst(INTERPRETER_EXIT, (retval --)) { diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 7d3396a..287a1f1 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -689,25 +689,24 @@ } TARGET(RAISE_VARARGS) { + PyObject **args = &PEEK(oparg); PyObject *cause = NULL, *exc = NULL; switch (oparg) { case 2: - cause = POP(); /* cause */ + cause = args[1]; /* fall through */ case 1: - exc = POP(); /* exc */ + exc = args[0]; /* fall through */ case 0: - if (do_raise(tstate, exc, cause)) { - goto exception_unwind; - } + if (do_raise(tstate, exc, cause)) { STACK_SHRINK(oparg); goto exception_unwind; } break; default: _PyErr_SetString(tstate, PyExc_SystemError, "bad RAISE_VARARGS oparg"); break; } - goto error; + if (true) { STACK_SHRINK(oparg); goto error; } } TARGET(INTERPRETER_EXIT) { diff --git a/Python/opcode_metadata.h b/Python/opcode_metadata.h index 46fd967..cca8662 100644 --- a/Python/opcode_metadata.h +++ b/Python/opcode_metadata.h @@ -2,6 +2,7 @@ // from Python/bytecodes.c // Do not edit! +#ifndef NDEBUG static int _PyOpcode_num_popped(int opcode, int oparg) { switch(opcode) { @@ -86,7 +87,7 @@ _PyOpcode_num_popped(int opcode, int oparg) { case CALL_INTRINSIC_1: return 1; case RAISE_VARARGS: - return -1; + return oparg; case INTERPRETER_EXIT: return 1; case RETURN_VALUE: @@ -345,7 +346,9 @@ _PyOpcode_num_popped(int opcode, int oparg) { Py_UNREACHABLE(); } } +#endif +#ifndef NDEBUG static int _PyOpcode_num_pushed(int opcode, int oparg) { switch(opcode) { @@ -430,7 +433,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) { case CALL_INTRINSIC_1: return 1; case RAISE_VARARGS: - return -1; + return 0; case INTERPRETER_EXIT: return 0; case RETURN_VALUE: @@ -689,6 +692,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) { Py_UNREACHABLE(); } } +#endif enum Direction { DIR_NONE, DIR_READ, DIR_WRITE }; enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC0, INSTR_FMT_IBC000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 }; struct opcode_metadata { |