mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
gh-101799: implement PREP_RERAISE_STAR as an intrinsic function (#101800)
This commit is contained in:
parent
3690688149
commit
81e3aa835c
13 changed files with 107 additions and 73 deletions
|
@ -501,7 +501,14 @@ dummy_func(
|
|||
inst(CALL_INTRINSIC_1, (value -- res)) {
|
||||
assert(oparg <= MAX_INTRINSIC_1);
|
||||
res = _PyIntrinsics_UnaryFunctions[oparg](tstate, value);
|
||||
Py_DECREF(value);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res == NULL, error);
|
||||
}
|
||||
|
||||
inst(CALL_INTRINSIC_2, (value2, value1 -- res)) {
|
||||
assert(oparg <= MAX_INTRINSIC_2);
|
||||
res = _PyIntrinsics_BinaryFunctions[oparg](tstate, value2, value1);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res == NULL, error);
|
||||
}
|
||||
|
||||
|
@ -788,15 +795,6 @@ dummy_func(
|
|||
goto exception_unwind;
|
||||
}
|
||||
|
||||
inst(PREP_RERAISE_STAR, (orig, excs -- val)) {
|
||||
assert(PyList_Check(excs));
|
||||
|
||||
val = _PyExc_PrepReraiseStar(orig, excs);
|
||||
DECREF_INPUTS();
|
||||
|
||||
ERROR_IF(val == NULL, error);
|
||||
}
|
||||
|
||||
inst(END_ASYNC_FOR, (awaitable, exc -- )) {
|
||||
assert(exc && PyExceptionInstance_Check(exc));
|
||||
if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
|
||||
|
@ -2383,7 +2381,7 @@ dummy_func(
|
|||
}
|
||||
|
||||
// Cache layout: counter/1, func_version/2, min_args/1
|
||||
// Neither CALL_INTRINSIC_1 nor CALL_FUNCTION_EX are members!
|
||||
// Neither CALL_INTRINSIC_1/2 nor CALL_FUNCTION_EX are members!
|
||||
family(call, INLINE_CACHE_ENTRIES_CALL) = {
|
||||
CALL,
|
||||
CALL_BOUND_METHOD_EXACT_ARGS,
|
||||
|
|
|
@ -3431,7 +3431,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
|
|||
|
||||
[orig, res, rest] Ln+1: LIST_APPEND 1 ) add unhandled exc to res (could be None)
|
||||
|
||||
[orig, res] PREP_RERAISE_STAR
|
||||
[orig, res] CALL_INTRINSIC_2 PREP_RERAISE_STAR
|
||||
[exc] COPY 1
|
||||
[exc, exc] POP_JUMP_IF_NOT_NONE RER
|
||||
[exc] POP_TOP
|
||||
|
@ -3580,7 +3580,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
|
|||
NEW_JUMP_TARGET_LABEL(c, reraise);
|
||||
|
||||
USE_LABEL(c, reraise_star);
|
||||
ADDOP(c, NO_LOCATION, PREP_RERAISE_STAR);
|
||||
ADDOP_I(c, NO_LOCATION, CALL_INTRINSIC_2, INTRINSIC_PREP_RERAISE_STAR);
|
||||
ADDOP_I(c, NO_LOCATION, COPY, 1);
|
||||
ADDOP_JUMP(c, NO_LOCATION, POP_JUMP_IF_NOT_NONE, reraise);
|
||||
|
||||
|
|
30
Python/generated_cases.c.h
generated
30
Python/generated_cases.c.h
generated
|
@ -689,6 +689,20 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_INTRINSIC_2) {
|
||||
PyObject *value1 = PEEK(1);
|
||||
PyObject *value2 = PEEK(2);
|
||||
PyObject *res;
|
||||
assert(oparg <= MAX_INTRINSIC_2);
|
||||
res = _PyIntrinsics_BinaryFunctions[oparg](tstate, value2, value1);
|
||||
Py_DECREF(value2);
|
||||
Py_DECREF(value1);
|
||||
if (res == NULL) goto pop_2_error;
|
||||
STACK_SHRINK(1);
|
||||
POKE(1, res);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(RAISE_VARARGS) {
|
||||
PyObject **args = &PEEK(oparg);
|
||||
PyObject *cause = NULL, *exc = NULL;
|
||||
|
@ -999,22 +1013,6 @@
|
|||
goto exception_unwind;
|
||||
}
|
||||
|
||||
TARGET(PREP_RERAISE_STAR) {
|
||||
PyObject *excs = PEEK(1);
|
||||
PyObject *orig = PEEK(2);
|
||||
PyObject *val;
|
||||
assert(PyList_Check(excs));
|
||||
|
||||
val = _PyExc_PrepReraiseStar(orig, excs);
|
||||
Py_DECREF(orig);
|
||||
Py_DECREF(excs);
|
||||
|
||||
if (val == NULL) goto pop_2_error;
|
||||
STACK_SHRINK(1);
|
||||
POKE(1, val);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(END_ASYNC_FOR) {
|
||||
PyObject *exc = PEEK(1);
|
||||
PyObject *awaitable = PEEK(2);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "pycore_pyerrors.h"
|
||||
|
||||
|
||||
/******** Unary functions ********/
|
||||
|
||||
static PyObject *
|
||||
no_intrinsic(PyThreadState* tstate, PyObject *unused)
|
||||
|
@ -208,3 +209,20 @@ _PyIntrinsics_UnaryFunctions[] = {
|
|||
[INTRINSIC_UNARY_POSITIVE] = unary_pos,
|
||||
[INTRINSIC_LIST_TO_TUPLE] = list_to_tuple,
|
||||
};
|
||||
|
||||
|
||||
/******** Binary functions ********/
|
||||
|
||||
|
||||
static PyObject *
|
||||
prep_reraise_star(PyThreadState* unused, PyObject *orig, PyObject *excs)
|
||||
{
|
||||
assert(PyList_Check(excs));
|
||||
return _PyExc_PrepReraiseStar(orig, excs);
|
||||
}
|
||||
|
||||
instrinsic_func2
|
||||
_PyIntrinsics_BinaryFunctions[] = {
|
||||
[INTRINSIC_PREP_RERAISE_STAR] = prep_reraise_star,
|
||||
};
|
||||
|
||||
|
|
|
@ -88,6 +88,8 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
|||
return 2;
|
||||
case CALL_INTRINSIC_1:
|
||||
return 1;
|
||||
case CALL_INTRINSIC_2:
|
||||
return 2;
|
||||
case RAISE_VARARGS:
|
||||
return oparg;
|
||||
case INTERPRETER_EXIT:
|
||||
|
@ -112,8 +114,6 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
|||
return 1;
|
||||
case RERAISE:
|
||||
return oparg + 1;
|
||||
case PREP_RERAISE_STAR:
|
||||
return 2;
|
||||
case END_ASYNC_FOR:
|
||||
return 2;
|
||||
case CLEANUP_THROW:
|
||||
|
@ -440,6 +440,8 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
|||
return 0;
|
||||
case CALL_INTRINSIC_1:
|
||||
return 1;
|
||||
case CALL_INTRINSIC_2:
|
||||
return 1;
|
||||
case RAISE_VARARGS:
|
||||
return 0;
|
||||
case INTERPRETER_EXIT:
|
||||
|
@ -464,8 +466,6 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
|||
return 0;
|
||||
case RERAISE:
|
||||
return oparg;
|
||||
case PREP_RERAISE_STAR:
|
||||
return 1;
|
||||
case END_ASYNC_FOR:
|
||||
return 0;
|
||||
case CLEANUP_THROW:
|
||||
|
@ -760,6 +760,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
|
|||
[STORE_SUBSCR_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IXC },
|
||||
[DELETE_SUBSCR] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[CALL_INTRINSIC_1] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[CALL_INTRINSIC_2] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[RAISE_VARARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[INTERPRETER_EXIT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[RETURN_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
|
@ -772,7 +773,6 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
|
|||
[YIELD_VALUE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[POP_EXCEPT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[RERAISE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
|
||||
[PREP_RERAISE_STAR] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[END_ASYNC_FOR] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[CLEANUP_THROW] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
[LOAD_ASSERTION_ERROR] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IX },
|
||||
|
|
14
Python/opcode_targets.h
generated
14
Python/opcode_targets.h
generated
|
@ -87,7 +87,7 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_SETUP_ANNOTATIONS,
|
||||
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_STORE_ATTR_SLOT,
|
||||
&&TARGET_PREP_RERAISE_STAR,
|
||||
&&TARGET_STORE_ATTR_WITH_HINT,
|
||||
&&TARGET_POP_EXCEPT,
|
||||
&&TARGET_STORE_NAME,
|
||||
&&TARGET_DELETE_NAME,
|
||||
|
@ -112,7 +112,7 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_JUMP_FORWARD,
|
||||
&&TARGET_JUMP_IF_FALSE_OR_POP,
|
||||
&&TARGET_JUMP_IF_TRUE_OR_POP,
|
||||
&&TARGET_STORE_ATTR_WITH_HINT,
|
||||
&&TARGET_STORE_FAST__LOAD_FAST,
|
||||
&&TARGET_POP_JUMP_IF_FALSE,
|
||||
&&TARGET_POP_JUMP_IF_TRUE,
|
||||
&&TARGET_LOAD_GLOBAL,
|
||||
|
@ -142,7 +142,7 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_JUMP_BACKWARD,
|
||||
&&TARGET_COMPARE_AND_BRANCH,
|
||||
&&TARGET_CALL_FUNCTION_EX,
|
||||
&&TARGET_STORE_FAST__LOAD_FAST,
|
||||
&&TARGET_STORE_FAST__STORE_FAST,
|
||||
&&TARGET_EXTENDED_ARG,
|
||||
&&TARGET_LIST_APPEND,
|
||||
&&TARGET_SET_ADD,
|
||||
|
@ -152,20 +152,20 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_YIELD_VALUE,
|
||||
&&TARGET_RESUME,
|
||||
&&TARGET_MATCH_CLASS,
|
||||
&&TARGET_STORE_FAST__STORE_FAST,
|
||||
&&TARGET_STORE_SUBSCR_DICT,
|
||||
&&TARGET_STORE_SUBSCR_LIST_INT,
|
||||
&&TARGET_FORMAT_VALUE,
|
||||
&&TARGET_BUILD_CONST_KEY_MAP,
|
||||
&&TARGET_BUILD_STRING,
|
||||
&&TARGET_STORE_SUBSCR_LIST_INT,
|
||||
&&TARGET_UNPACK_SEQUENCE_LIST,
|
||||
&&TARGET_UNPACK_SEQUENCE_TUPLE,
|
||||
&&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
|
||||
&&TARGET_SEND_GEN,
|
||||
&&TARGET_LIST_EXTEND,
|
||||
&&TARGET_SET_UPDATE,
|
||||
&&TARGET_DICT_MERGE,
|
||||
&&TARGET_DICT_UPDATE,
|
||||
&&TARGET_SEND_GEN,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
|
@ -173,7 +173,7 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_CALL,
|
||||
&&TARGET_KW_NAMES,
|
||||
&&TARGET_CALL_INTRINSIC_1,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_CALL_INTRINSIC_2,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue