mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-98831: rewrite RAISE_VARARGS in the instruction definition DSL (#101306)
This commit is contained in:
parent
6162a0e305
commit
b400219df5
4 changed files with 20 additions and 18 deletions
|
@ -505,27 +505,24 @@ dummy_func(
|
||||||
ERROR_IF(res == NULL, error);
|
ERROR_IF(res == NULL, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should remain a legacy instruction.
|
inst(RAISE_VARARGS, (args[oparg] -- )) {
|
||||||
inst(RAISE_VARARGS) {
|
|
||||||
PyObject *cause = NULL, *exc = NULL;
|
PyObject *cause = NULL, *exc = NULL;
|
||||||
switch (oparg) {
|
switch (oparg) {
|
||||||
case 2:
|
case 2:
|
||||||
cause = POP(); /* cause */
|
cause = args[1];
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 1:
|
case 1:
|
||||||
exc = POP(); /* exc */
|
exc = args[0];
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 0:
|
case 0:
|
||||||
if (do_raise(tstate, exc, cause)) {
|
ERROR_IF(do_raise(tstate, exc, cause), exception_unwind);
|
||||||
goto exception_unwind;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_PyErr_SetString(tstate, PyExc_SystemError,
|
_PyErr_SetString(tstate, PyExc_SystemError,
|
||||||
"bad RAISE_VARARGS oparg");
|
"bad RAISE_VARARGS oparg");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
goto error;
|
ERROR_IF(true, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(INTERPRETER_EXIT, (retval --)) {
|
inst(INTERPRETER_EXIT, (retval --)) {
|
||||||
|
|
11
Python/generated_cases.c.h
generated
11
Python/generated_cases.c.h
generated
|
@ -689,25 +689,24 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(RAISE_VARARGS) {
|
TARGET(RAISE_VARARGS) {
|
||||||
|
PyObject **args = &PEEK(oparg);
|
||||||
PyObject *cause = NULL, *exc = NULL;
|
PyObject *cause = NULL, *exc = NULL;
|
||||||
switch (oparg) {
|
switch (oparg) {
|
||||||
case 2:
|
case 2:
|
||||||
cause = POP(); /* cause */
|
cause = args[1];
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 1:
|
case 1:
|
||||||
exc = POP(); /* exc */
|
exc = args[0];
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 0:
|
case 0:
|
||||||
if (do_raise(tstate, exc, cause)) {
|
if (do_raise(tstate, exc, cause)) { STACK_SHRINK(oparg); goto exception_unwind; }
|
||||||
goto exception_unwind;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_PyErr_SetString(tstate, PyExc_SystemError,
|
_PyErr_SetString(tstate, PyExc_SystemError,
|
||||||
"bad RAISE_VARARGS oparg");
|
"bad RAISE_VARARGS oparg");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
goto error;
|
if (true) { STACK_SHRINK(oparg); goto error; }
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(INTERPRETER_EXIT) {
|
TARGET(INTERPRETER_EXIT) {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// from Python/bytecodes.c
|
// from Python/bytecodes.c
|
||||||
// Do not edit!
|
// Do not edit!
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
static int
|
static int
|
||||||
_PyOpcode_num_popped(int opcode, int oparg) {
|
_PyOpcode_num_popped(int opcode, int oparg) {
|
||||||
switch(opcode) {
|
switch(opcode) {
|
||||||
|
@ -86,7 +87,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
|
||||||
case CALL_INTRINSIC_1:
|
case CALL_INTRINSIC_1:
|
||||||
return 1;
|
return 1;
|
||||||
case RAISE_VARARGS:
|
case RAISE_VARARGS:
|
||||||
return -1;
|
return oparg;
|
||||||
case INTERPRETER_EXIT:
|
case INTERPRETER_EXIT:
|
||||||
return 1;
|
return 1;
|
||||||
case RETURN_VALUE:
|
case RETURN_VALUE:
|
||||||
|
@ -345,7 +346,9 @@ _PyOpcode_num_popped(int opcode, int oparg) {
|
||||||
Py_UNREACHABLE();
|
Py_UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
static int
|
static int
|
||||||
_PyOpcode_num_pushed(int opcode, int oparg) {
|
_PyOpcode_num_pushed(int opcode, int oparg) {
|
||||||
switch(opcode) {
|
switch(opcode) {
|
||||||
|
@ -430,7 +433,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
|
||||||
case CALL_INTRINSIC_1:
|
case CALL_INTRINSIC_1:
|
||||||
return 1;
|
return 1;
|
||||||
case RAISE_VARARGS:
|
case RAISE_VARARGS:
|
||||||
return -1;
|
return 0;
|
||||||
case INTERPRETER_EXIT:
|
case INTERPRETER_EXIT:
|
||||||
return 0;
|
return 0;
|
||||||
case RETURN_VALUE:
|
case RETURN_VALUE:
|
||||||
|
@ -689,6 +692,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
|
||||||
Py_UNREACHABLE();
|
Py_UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
enum Direction { DIR_NONE, DIR_READ, DIR_WRITE };
|
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 };
|
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 {
|
struct opcode_metadata {
|
||||||
|
|
|
@ -774,7 +774,8 @@ class Analyzer:
|
||||||
pushed_data.append( (instr, pushed) )
|
pushed_data.append( (instr, pushed) )
|
||||||
|
|
||||||
def write_function(direction: str, data: list[tuple[Instruction, str]]) -> None:
|
def write_function(direction: str, data: list[tuple[Instruction, str]]) -> None:
|
||||||
self.out.emit("\nstatic int");
|
self.out.emit("\n#ifndef NDEBUG");
|
||||||
|
self.out.emit("static int");
|
||||||
self.out.emit(f"_PyOpcode_num_{direction}(int opcode, int oparg) {{")
|
self.out.emit(f"_PyOpcode_num_{direction}(int opcode, int oparg) {{")
|
||||||
self.out.emit(" switch(opcode) {");
|
self.out.emit(" switch(opcode) {");
|
||||||
for instr, effect in data:
|
for instr, effect in data:
|
||||||
|
@ -784,6 +785,7 @@ class Analyzer:
|
||||||
self.out.emit(" Py_UNREACHABLE();")
|
self.out.emit(" Py_UNREACHABLE();")
|
||||||
self.out.emit(" }")
|
self.out.emit(" }")
|
||||||
self.out.emit("}")
|
self.out.emit("}")
|
||||||
|
self.out.emit("#endif");
|
||||||
|
|
||||||
write_function('popped', popped_data)
|
write_function('popped', popped_data)
|
||||||
write_function('pushed', pushed_data)
|
write_function('pushed', pushed_data)
|
||||||
|
@ -1023,7 +1025,7 @@ def always_exits(lines: list[str]) -> bool:
|
||||||
return False
|
return False
|
||||||
line = line[12:]
|
line = line[12:]
|
||||||
return line.startswith(
|
return line.startswith(
|
||||||
("goto ", "return ", "DISPATCH", "GO_TO_", "Py_UNREACHABLE()")
|
("goto ", "return ", "DISPATCH", "GO_TO_", "Py_UNREACHABLE()", "ERROR_IF(true, ")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue