diff --git a/Doc/library/token-list.inc b/Doc/library/token-list.inc index 39df2927a0b7f2..7e27b9b6874e59 100644 --- a/Doc/library/token-list.inc +++ b/Doc/library/token-list.inc @@ -205,6 +205,10 @@ Token value for ``"!"``. +.. data:: BACKTICK + + Token value for ``"`"``. + .. data:: OP .. data:: TYPE_IGNORE diff --git a/Include/internal/pycore_magic_number.h b/Include/internal/pycore_magic_number.h index a88ff2deeba941..136cd4c3ae2de2 100644 --- a/Include/internal/pycore_magic_number.h +++ b/Include/internal/pycore_magic_number.h @@ -260,6 +260,7 @@ Known values: Python 3.14a1 3606 (Specialize CALL_KW) Python 3.14a1 3607 (Add pseudo instructions JUMP_IF_TRUE/FALSE) Python 3.14a1 3608 (Add support for slices) + Python 3.14a1 3609 (GET_REPR) Python 3.15 will start with 3650 @@ -272,7 +273,7 @@ PC/launcher.c must also be updated. */ -#define PYC_MAGIC_NUMBER 3608 +#define PYC_MAGIC_NUMBER 3609 /* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes (little-endian) and then appending b'\r\n'. */ #define PYC_MAGIC_NUMBER_TOKEN \ diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h index c18423476d3962..e801670a28d81c 100644 --- a/Include/internal/pycore_opcode_metadata.h +++ b/Include/internal/pycore_opcode_metadata.h @@ -215,6 +215,8 @@ int _PyOpcode_num_popped(int opcode, int oparg) { return 1; case GET_LEN: return 1; + case GET_REPR: + return 1; case GET_YIELD_FROM_ITER: return 1; case IMPORT_FROM: @@ -674,6 +676,8 @@ int _PyOpcode_num_pushed(int opcode, int oparg) { return 1; case GET_LEN: return 2; + case GET_REPR: + return 1; case GET_YIELD_FROM_ITER: return 1; case IMPORT_FROM: @@ -1104,6 +1108,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[266] = { [GET_AWAITABLE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [GET_ITER] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [GET_LEN] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, + [GET_REPR] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [GET_YIELD_FROM_ITER] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG }, [IMPORT_FROM] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [IMPORT_NAME] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, @@ -1333,6 +1338,7 @@ _PyOpcode_macro_expansion[256] = { [GET_AWAITABLE] = { .nuops = 1, .uops = { { _GET_AWAITABLE, 0, 0 } } }, [GET_ITER] = { .nuops = 1, .uops = { { _GET_ITER, 0, 0 } } }, [GET_LEN] = { .nuops = 1, .uops = { { _GET_LEN, 0, 0 } } }, + [GET_REPR] = { .nuops = 1, .uops = { { _GET_REPR, 0, 0 } } }, [GET_YIELD_FROM_ITER] = { .nuops = 1, .uops = { { _GET_YIELD_FROM_ITER, 0, 0 } } }, [IMPORT_FROM] = { .nuops = 1, .uops = { { _IMPORT_FROM, 0, 0 } } }, [IMPORT_NAME] = { .nuops = 1, .uops = { { _IMPORT_NAME, 0, 0 } } }, @@ -1522,6 +1528,7 @@ const char *_PyOpcode_OpName[266] = { [GET_AWAITABLE] = "GET_AWAITABLE", [GET_ITER] = "GET_ITER", [GET_LEN] = "GET_LEN", + [GET_REPR] = "GET_REPR", [GET_YIELD_FROM_ITER] = "GET_YIELD_FROM_ITER", [IMPORT_FROM] = "IMPORT_FROM", [IMPORT_NAME] = "IMPORT_NAME", @@ -1778,6 +1785,7 @@ const uint8_t _PyOpcode_Deopt[256] = { [GET_AWAITABLE] = GET_AWAITABLE, [GET_ITER] = GET_ITER, [GET_LEN] = GET_LEN, + [GET_REPR] = GET_REPR, [GET_YIELD_FROM_ITER] = GET_YIELD_FROM_ITER, [IMPORT_FROM] = IMPORT_FROM, [IMPORT_NAME] = IMPORT_NAME, @@ -1907,7 +1915,6 @@ const uint8_t _PyOpcode_Deopt[256] = { #endif // NEED_OPCODE_METADATA #define EXTRA_CASES \ - case 116: \ case 117: \ case 118: \ case 119: \ diff --git a/Include/internal/pycore_token.h b/Include/internal/pycore_token.h index 571cd6249f2812..bbbaafdac92e90 100644 --- a/Include/internal/pycore_token.h +++ b/Include/internal/pycore_token.h @@ -68,17 +68,18 @@ extern "C" { #define ELLIPSIS 52 #define COLONEQUAL 53 #define EXCLAMATION 54 -#define OP 55 -#define TYPE_IGNORE 56 -#define TYPE_COMMENT 57 -#define SOFT_KEYWORD 58 -#define FSTRING_START 59 -#define FSTRING_MIDDLE 60 -#define FSTRING_END 61 -#define COMMENT 62 -#define NL 63 -#define ERRORTOKEN 64 -#define N_TOKENS 66 +#define BACKTICK 55 +#define OP 56 +#define TYPE_IGNORE 57 +#define TYPE_COMMENT 58 +#define SOFT_KEYWORD 59 +#define FSTRING_START 60 +#define FSTRING_MIDDLE 61 +#define FSTRING_END 62 +#define COMMENT 63 +#define NL 64 +#define ERRORTOKEN 65 +#define N_TOKENS 67 #define NT_OFFSET 256 /* Special definitions for cooperation with parser */ diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h index 1951c65a2871cf..2a3be30209dac7 100644 --- a/Include/internal/pycore_uop_ids.h +++ b/Include/internal/pycore_uop_ids.h @@ -116,6 +116,7 @@ extern "C" { #define _GET_AWAITABLE GET_AWAITABLE #define _GET_ITER GET_ITER #define _GET_LEN GET_LEN +#define _GET_REPR GET_REPR #define _GET_YIELD_FROM_ITER GET_YIELD_FROM_ITER #define _GUARD_BOTH_FLOAT 367 #define _GUARD_BOTH_INT 368 diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index 2f0a7fb2f6e549..1e165355f69c91 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -181,6 +181,7 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_MATCH_SEQUENCE] = 0, [_MATCH_KEYS] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_GET_ITER] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, + [_GET_REPR] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_GET_YIELD_FROM_ITER] = HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_FOR_ITER_TIER_TWO] = HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_ITER_CHECK_LIST] = HAS_EXIT_FLAG, @@ -396,6 +397,7 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = { [_GET_AWAITABLE] = "_GET_AWAITABLE", [_GET_ITER] = "_GET_ITER", [_GET_LEN] = "_GET_LEN", + [_GET_REPR] = "_GET_REPR", [_GET_YIELD_FROM_ITER] = "_GET_YIELD_FROM_ITER", [_GUARD_BOTH_FLOAT] = "_GUARD_BOTH_FLOAT", [_GUARD_BOTH_INT] = "_GUARD_BOTH_INT", @@ -888,6 +890,8 @@ int _PyUop_num_popped(int opcode, int oparg) return 2; case _GET_ITER: return 1; + case _GET_REPR: + return 1; case _GET_YIELD_FROM_ITER: return 1; case _FOR_ITER_TIER_TWO: diff --git a/Include/opcode_ids.h b/Include/opcode_ids.h index 327bdb792464a0..ed1e52fc14fc66 100644 --- a/Include/opcode_ids.h +++ b/Include/opcode_ids.h @@ -29,103 +29,104 @@ extern "C" { #define GET_ITER 16 #define RESERVED 17 #define GET_LEN 18 -#define GET_YIELD_FROM_ITER 19 -#define INTERPRETER_EXIT 20 -#define LOAD_BUILD_CLASS 21 -#define LOAD_LOCALS 22 -#define MAKE_FUNCTION 23 -#define MATCH_KEYS 24 -#define MATCH_MAPPING 25 -#define MATCH_SEQUENCE 26 -#define NOP 27 -#define POP_EXCEPT 28 -#define POP_TOP 29 -#define PUSH_EXC_INFO 30 -#define PUSH_NULL 31 -#define RETURN_GENERATOR 32 -#define RETURN_VALUE 33 -#define SETUP_ANNOTATIONS 34 -#define STORE_SLICE 35 -#define STORE_SUBSCR 36 -#define TO_BOOL 37 -#define UNARY_INVERT 38 -#define UNARY_NEGATIVE 39 -#define UNARY_NOT 40 -#define WITH_EXCEPT_START 41 -#define BINARY_OP 42 -#define BUILD_LIST 43 -#define BUILD_MAP 44 -#define BUILD_SET 45 -#define BUILD_SLICE 46 -#define BUILD_STRING 47 -#define BUILD_TUPLE 48 -#define CALL 49 -#define CALL_FUNCTION_EX 50 -#define CALL_INTRINSIC_1 51 -#define CALL_INTRINSIC_2 52 -#define CALL_KW 53 -#define COMPARE_OP 54 -#define CONTAINS_OP 55 -#define CONVERT_VALUE 56 -#define COPY 57 -#define COPY_FREE_VARS 58 -#define DELETE_ATTR 59 -#define DELETE_DEREF 60 -#define DELETE_FAST 61 -#define DELETE_GLOBAL 62 -#define DELETE_NAME 63 -#define DICT_MERGE 64 -#define DICT_UPDATE 65 -#define EXTENDED_ARG 66 -#define FOR_ITER 67 -#define GET_AWAITABLE 68 -#define IMPORT_FROM 69 -#define IMPORT_NAME 70 -#define IS_OP 71 -#define JUMP_BACKWARD 72 -#define JUMP_BACKWARD_NO_INTERRUPT 73 -#define JUMP_FORWARD 74 -#define LIST_APPEND 75 -#define LIST_EXTEND 76 -#define LOAD_ATTR 77 -#define LOAD_COMMON_CONSTANT 78 -#define LOAD_CONST 79 -#define LOAD_DEREF 80 -#define LOAD_FAST 81 -#define LOAD_FAST_AND_CLEAR 82 -#define LOAD_FAST_CHECK 83 -#define LOAD_FAST_LOAD_FAST 84 -#define LOAD_FROM_DICT_OR_DEREF 85 -#define LOAD_FROM_DICT_OR_GLOBALS 86 -#define LOAD_GLOBAL 87 -#define LOAD_NAME 88 -#define LOAD_SPECIAL 89 -#define LOAD_SUPER_ATTR 90 -#define MAKE_CELL 91 -#define MAP_ADD 92 -#define MATCH_CLASS 93 -#define POP_JUMP_IF_FALSE 94 -#define POP_JUMP_IF_NONE 95 -#define POP_JUMP_IF_NOT_NONE 96 -#define POP_JUMP_IF_TRUE 97 -#define RAISE_VARARGS 98 -#define RERAISE 99 -#define RETURN_CONST 100 -#define SEND 101 -#define SET_ADD 102 -#define SET_FUNCTION_ATTRIBUTE 103 -#define SET_UPDATE 104 -#define STORE_ATTR 105 -#define STORE_DEREF 106 -#define STORE_FAST 107 -#define STORE_FAST_LOAD_FAST 108 -#define STORE_FAST_STORE_FAST 109 -#define STORE_GLOBAL 110 -#define STORE_NAME 111 -#define SWAP 112 -#define UNPACK_EX 113 -#define UNPACK_SEQUENCE 114 -#define YIELD_VALUE 115 +#define GET_REPR 19 +#define GET_YIELD_FROM_ITER 20 +#define INTERPRETER_EXIT 21 +#define LOAD_BUILD_CLASS 22 +#define LOAD_LOCALS 23 +#define MAKE_FUNCTION 24 +#define MATCH_KEYS 25 +#define MATCH_MAPPING 26 +#define MATCH_SEQUENCE 27 +#define NOP 28 +#define POP_EXCEPT 29 +#define POP_TOP 30 +#define PUSH_EXC_INFO 31 +#define PUSH_NULL 32 +#define RETURN_GENERATOR 33 +#define RETURN_VALUE 34 +#define SETUP_ANNOTATIONS 35 +#define STORE_SLICE 36 +#define STORE_SUBSCR 37 +#define TO_BOOL 38 +#define UNARY_INVERT 39 +#define UNARY_NEGATIVE 40 +#define UNARY_NOT 41 +#define WITH_EXCEPT_START 42 +#define BINARY_OP 43 +#define BUILD_LIST 44 +#define BUILD_MAP 45 +#define BUILD_SET 46 +#define BUILD_SLICE 47 +#define BUILD_STRING 48 +#define BUILD_TUPLE 49 +#define CALL 50 +#define CALL_FUNCTION_EX 51 +#define CALL_INTRINSIC_1 52 +#define CALL_INTRINSIC_2 53 +#define CALL_KW 54 +#define COMPARE_OP 55 +#define CONTAINS_OP 56 +#define CONVERT_VALUE 57 +#define COPY 58 +#define COPY_FREE_VARS 59 +#define DELETE_ATTR 60 +#define DELETE_DEREF 61 +#define DELETE_FAST 62 +#define DELETE_GLOBAL 63 +#define DELETE_NAME 64 +#define DICT_MERGE 65 +#define DICT_UPDATE 66 +#define EXTENDED_ARG 67 +#define FOR_ITER 68 +#define GET_AWAITABLE 69 +#define IMPORT_FROM 70 +#define IMPORT_NAME 71 +#define IS_OP 72 +#define JUMP_BACKWARD 73 +#define JUMP_BACKWARD_NO_INTERRUPT 74 +#define JUMP_FORWARD 75 +#define LIST_APPEND 76 +#define LIST_EXTEND 77 +#define LOAD_ATTR 78 +#define LOAD_COMMON_CONSTANT 79 +#define LOAD_CONST 80 +#define LOAD_DEREF 81 +#define LOAD_FAST 82 +#define LOAD_FAST_AND_CLEAR 83 +#define LOAD_FAST_CHECK 84 +#define LOAD_FAST_LOAD_FAST 85 +#define LOAD_FROM_DICT_OR_DEREF 86 +#define LOAD_FROM_DICT_OR_GLOBALS 87 +#define LOAD_GLOBAL 88 +#define LOAD_NAME 89 +#define LOAD_SPECIAL 90 +#define LOAD_SUPER_ATTR 91 +#define MAKE_CELL 92 +#define MAP_ADD 93 +#define MATCH_CLASS 94 +#define POP_JUMP_IF_FALSE 95 +#define POP_JUMP_IF_NONE 96 +#define POP_JUMP_IF_NOT_NONE 97 +#define POP_JUMP_IF_TRUE 98 +#define RAISE_VARARGS 99 +#define RERAISE 100 +#define RETURN_CONST 101 +#define SEND 102 +#define SET_ADD 103 +#define SET_FUNCTION_ATTRIBUTE 104 +#define SET_UPDATE 105 +#define STORE_ATTR 106 +#define STORE_DEREF 107 +#define STORE_FAST 108 +#define STORE_FAST_LOAD_FAST 109 +#define STORE_FAST_STORE_FAST 110 +#define STORE_GLOBAL 111 +#define STORE_NAME 112 +#define SWAP 113 +#define UNPACK_EX 114 +#define UNPACK_SEQUENCE 115 +#define YIELD_VALUE 116 #define RESUME 149 #define BINARY_OP_ADD_FLOAT 150 #define BINARY_OP_ADD_INT 151 @@ -235,7 +236,7 @@ extern "C" { #define SETUP_WITH 264 #define STORE_FAST_MAYBE_NULL 265 -#define HAVE_ARGUMENT 41 +#define HAVE_ARGUMENT 42 #define MIN_SPECIALIZED_OPCODE 150 #define MIN_INSTRUMENTED_OPCODE 236 diff --git a/Lib/_opcode_metadata.py b/Lib/_opcode_metadata.py index 9a793717cf082b..939fa58d300921 100644 --- a/Lib/_opcode_metadata.py +++ b/Lib/_opcode_metadata.py @@ -218,103 +218,104 @@ 'GET_ANEXT': 15, 'GET_ITER': 16, 'GET_LEN': 18, - 'GET_YIELD_FROM_ITER': 19, - 'INTERPRETER_EXIT': 20, - 'LOAD_BUILD_CLASS': 21, - 'LOAD_LOCALS': 22, - 'MAKE_FUNCTION': 23, - 'MATCH_KEYS': 24, - 'MATCH_MAPPING': 25, - 'MATCH_SEQUENCE': 26, - 'NOP': 27, - 'POP_EXCEPT': 28, - 'POP_TOP': 29, - 'PUSH_EXC_INFO': 30, - 'PUSH_NULL': 31, - 'RETURN_GENERATOR': 32, - 'RETURN_VALUE': 33, - 'SETUP_ANNOTATIONS': 34, - 'STORE_SLICE': 35, - 'STORE_SUBSCR': 36, - 'TO_BOOL': 37, - 'UNARY_INVERT': 38, - 'UNARY_NEGATIVE': 39, - 'UNARY_NOT': 40, - 'WITH_EXCEPT_START': 41, - 'BINARY_OP': 42, - 'BUILD_LIST': 43, - 'BUILD_MAP': 44, - 'BUILD_SET': 45, - 'BUILD_SLICE': 46, - 'BUILD_STRING': 47, - 'BUILD_TUPLE': 48, - 'CALL': 49, - 'CALL_FUNCTION_EX': 50, - 'CALL_INTRINSIC_1': 51, - 'CALL_INTRINSIC_2': 52, - 'CALL_KW': 53, - 'COMPARE_OP': 54, - 'CONTAINS_OP': 55, - 'CONVERT_VALUE': 56, - 'COPY': 57, - 'COPY_FREE_VARS': 58, - 'DELETE_ATTR': 59, - 'DELETE_DEREF': 60, - 'DELETE_FAST': 61, - 'DELETE_GLOBAL': 62, - 'DELETE_NAME': 63, - 'DICT_MERGE': 64, - 'DICT_UPDATE': 65, - 'EXTENDED_ARG': 66, - 'FOR_ITER': 67, - 'GET_AWAITABLE': 68, - 'IMPORT_FROM': 69, - 'IMPORT_NAME': 70, - 'IS_OP': 71, - 'JUMP_BACKWARD': 72, - 'JUMP_BACKWARD_NO_INTERRUPT': 73, - 'JUMP_FORWARD': 74, - 'LIST_APPEND': 75, - 'LIST_EXTEND': 76, - 'LOAD_ATTR': 77, - 'LOAD_COMMON_CONSTANT': 78, - 'LOAD_CONST': 79, - 'LOAD_DEREF': 80, - 'LOAD_FAST': 81, - 'LOAD_FAST_AND_CLEAR': 82, - 'LOAD_FAST_CHECK': 83, - 'LOAD_FAST_LOAD_FAST': 84, - 'LOAD_FROM_DICT_OR_DEREF': 85, - 'LOAD_FROM_DICT_OR_GLOBALS': 86, - 'LOAD_GLOBAL': 87, - 'LOAD_NAME': 88, - 'LOAD_SPECIAL': 89, - 'LOAD_SUPER_ATTR': 90, - 'MAKE_CELL': 91, - 'MAP_ADD': 92, - 'MATCH_CLASS': 93, - 'POP_JUMP_IF_FALSE': 94, - 'POP_JUMP_IF_NONE': 95, - 'POP_JUMP_IF_NOT_NONE': 96, - 'POP_JUMP_IF_TRUE': 97, - 'RAISE_VARARGS': 98, - 'RERAISE': 99, - 'RETURN_CONST': 100, - 'SEND': 101, - 'SET_ADD': 102, - 'SET_FUNCTION_ATTRIBUTE': 103, - 'SET_UPDATE': 104, - 'STORE_ATTR': 105, - 'STORE_DEREF': 106, - 'STORE_FAST': 107, - 'STORE_FAST_LOAD_FAST': 108, - 'STORE_FAST_STORE_FAST': 109, - 'STORE_GLOBAL': 110, - 'STORE_NAME': 111, - 'SWAP': 112, - 'UNPACK_EX': 113, - 'UNPACK_SEQUENCE': 114, - 'YIELD_VALUE': 115, + 'GET_REPR': 19, + 'GET_YIELD_FROM_ITER': 20, + 'INTERPRETER_EXIT': 21, + 'LOAD_BUILD_CLASS': 22, + 'LOAD_LOCALS': 23, + 'MAKE_FUNCTION': 24, + 'MATCH_KEYS': 25, + 'MATCH_MAPPING': 26, + 'MATCH_SEQUENCE': 27, + 'NOP': 28, + 'POP_EXCEPT': 29, + 'POP_TOP': 30, + 'PUSH_EXC_INFO': 31, + 'PUSH_NULL': 32, + 'RETURN_GENERATOR': 33, + 'RETURN_VALUE': 34, + 'SETUP_ANNOTATIONS': 35, + 'STORE_SLICE': 36, + 'STORE_SUBSCR': 37, + 'TO_BOOL': 38, + 'UNARY_INVERT': 39, + 'UNARY_NEGATIVE': 40, + 'UNARY_NOT': 41, + 'WITH_EXCEPT_START': 42, + 'BINARY_OP': 43, + 'BUILD_LIST': 44, + 'BUILD_MAP': 45, + 'BUILD_SET': 46, + 'BUILD_SLICE': 47, + 'BUILD_STRING': 48, + 'BUILD_TUPLE': 49, + 'CALL': 50, + 'CALL_FUNCTION_EX': 51, + 'CALL_INTRINSIC_1': 52, + 'CALL_INTRINSIC_2': 53, + 'CALL_KW': 54, + 'COMPARE_OP': 55, + 'CONTAINS_OP': 56, + 'CONVERT_VALUE': 57, + 'COPY': 58, + 'COPY_FREE_VARS': 59, + 'DELETE_ATTR': 60, + 'DELETE_DEREF': 61, + 'DELETE_FAST': 62, + 'DELETE_GLOBAL': 63, + 'DELETE_NAME': 64, + 'DICT_MERGE': 65, + 'DICT_UPDATE': 66, + 'EXTENDED_ARG': 67, + 'FOR_ITER': 68, + 'GET_AWAITABLE': 69, + 'IMPORT_FROM': 70, + 'IMPORT_NAME': 71, + 'IS_OP': 72, + 'JUMP_BACKWARD': 73, + 'JUMP_BACKWARD_NO_INTERRUPT': 74, + 'JUMP_FORWARD': 75, + 'LIST_APPEND': 76, + 'LIST_EXTEND': 77, + 'LOAD_ATTR': 78, + 'LOAD_COMMON_CONSTANT': 79, + 'LOAD_CONST': 80, + 'LOAD_DEREF': 81, + 'LOAD_FAST': 82, + 'LOAD_FAST_AND_CLEAR': 83, + 'LOAD_FAST_CHECK': 84, + 'LOAD_FAST_LOAD_FAST': 85, + 'LOAD_FROM_DICT_OR_DEREF': 86, + 'LOAD_FROM_DICT_OR_GLOBALS': 87, + 'LOAD_GLOBAL': 88, + 'LOAD_NAME': 89, + 'LOAD_SPECIAL': 90, + 'LOAD_SUPER_ATTR': 91, + 'MAKE_CELL': 92, + 'MAP_ADD': 93, + 'MATCH_CLASS': 94, + 'POP_JUMP_IF_FALSE': 95, + 'POP_JUMP_IF_NONE': 96, + 'POP_JUMP_IF_NOT_NONE': 97, + 'POP_JUMP_IF_TRUE': 98, + 'RAISE_VARARGS': 99, + 'RERAISE': 100, + 'RETURN_CONST': 101, + 'SEND': 102, + 'SET_ADD': 103, + 'SET_FUNCTION_ATTRIBUTE': 104, + 'SET_UPDATE': 105, + 'STORE_ATTR': 106, + 'STORE_DEREF': 107, + 'STORE_FAST': 108, + 'STORE_FAST_LOAD_FAST': 109, + 'STORE_FAST_STORE_FAST': 110, + 'STORE_GLOBAL': 111, + 'STORE_NAME': 112, + 'SWAP': 113, + 'UNPACK_EX': 114, + 'UNPACK_SEQUENCE': 115, + 'YIELD_VALUE': 116, 'INSTRUMENTED_END_FOR': 236, 'INSTRUMENTED_END_SEND': 237, 'INSTRUMENTED_LOAD_SUPER_ATTR': 238, @@ -345,5 +346,5 @@ 'STORE_FAST_MAYBE_NULL': 265, } -HAVE_ARGUMENT = 41 +HAVE_ARGUMENT = 42 MIN_INSTRUMENTED_OPCODE = 236 diff --git a/Lib/token.py b/Lib/token.py index b620317106e173..7c84b9259d272d 100644 --- a/Lib/token.py +++ b/Lib/token.py @@ -58,19 +58,20 @@ ELLIPSIS = 52 COLONEQUAL = 53 EXCLAMATION = 54 -OP = 55 -TYPE_IGNORE = 56 -TYPE_COMMENT = 57 -SOFT_KEYWORD = 58 -FSTRING_START = 59 -FSTRING_MIDDLE = 60 -FSTRING_END = 61 -COMMENT = 62 -NL = 63 +BACKTICK = 55 +OP = 56 +TYPE_IGNORE = 57 +TYPE_COMMENT = 58 +SOFT_KEYWORD = 59 +FSTRING_START = 60 +FSTRING_MIDDLE = 61 +FSTRING_END = 62 +COMMENT = 63 +NL = 64 # These aren't used by the C tokenizer but are needed for tokenize.py -ERRORTOKEN = 64 -ENCODING = 65 -N_TOKENS = 66 +ERRORTOKEN = 65 +ENCODING = 66 +N_TOKENS = 67 # Special definitions for cooperation with parser NT_OFFSET = 256 @@ -123,6 +124,7 @@ ']': RSQB, '^': CIRCUMFLEX, '^=': CIRCUMFLEXEQUAL, + '`': BACKTICK, '{': LBRACE, '|': VBAR, '|=': VBAREQUAL, diff --git a/Parser/token.c b/Parser/token.c index 4f163f21609a0a..ccf9200bc58fcc 100644 --- a/Parser/token.c +++ b/Parser/token.c @@ -61,6 +61,7 @@ const char * const _PyParser_TokenNames[] = { "ELLIPSIS", "COLONEQUAL", "EXCLAMATION", + "BACKTICK", "OP", "TYPE_IGNORE", "TYPE_COMMENT", @@ -101,6 +102,7 @@ _PyToken_OneChar(int c1) case '[': return LSQB; case ']': return RSQB; case '^': return CIRCUMFLEX; + case '`': return BACKTICK; case '{': return LBRACE; case '|': return VBAR; case '}': return RBRACE; diff --git a/Python/bytecodes.c b/Python/bytecodes.c index e6525657cabc2b..a39414e736817b 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2762,6 +2762,14 @@ dummy_func( iter = PyStackRef_FromPyObjectSteal(iter_o); } + inst(GET_REPR, (value -- repr)) { + PyObject *value_o = PyStackRef_AsPyObjectBorrow(value); + PyObject *repr_o = PyObject_Repr(value_o); + DECREF_INPUTS(); + ERROR_IF(repr_o == NULL, error); + repr = PyStackRef_FromPyObjectSteal(repr_o); + } + inst(GET_YIELD_FROM_ITER, (iterable -- iter)) { /* before: [obj]; after [getiter(obj)] */ PyObject *iterable_o = PyStackRef_AsPyObjectBorrow(iterable); diff --git a/Python/codegen.c b/Python/codegen.c index 57a3c440acec34..ff1560ea0626ef 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -4884,8 +4884,8 @@ codegen_visit_expr(compiler *c, expr_ty e) VISIT(c, expr, e->v.NamedExpr.target); break; case Repr_kind: - // TODO - abort(); + VISIT(c, expr, e->v.Repr.value); + ADDOP(c, loc, GET_REPR); break; case BoolOp_kind: return codegen_boolop(c, e); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 15a6c7bc1a7966..c017e19c496d2e 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -3323,6 +3323,21 @@ break; } + case _GET_REPR: { + _PyStackRef value; + _PyStackRef repr; + value = stack_pointer[-1]; + PyObject *value_o = PyStackRef_AsPyObjectBorrow(value); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyObject *repr_o = PyObject_Repr(value_o); + stack_pointer = _PyFrame_GetStackPointer(frame); + PyStackRef_CLOSE(value); + if (repr_o == NULL) JUMP_TO_ERROR(); + repr = PyStackRef_FromPyObjectSteal(repr_o); + stack_pointer[-1] = repr; + break; + } + case _GET_YIELD_FROM_ITER: { _PyStackRef iterable; _PyStackRef iter; diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index a9290986c24f45..b24bd142cc0965 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -4272,6 +4272,24 @@ DISPATCH(); } + TARGET(GET_REPR) { + frame->instr_ptr = next_instr; + next_instr += 1; + INSTRUCTION_STATS(GET_REPR); + _PyStackRef value; + _PyStackRef repr; + value = stack_pointer[-1]; + PyObject *value_o = PyStackRef_AsPyObjectBorrow(value); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyObject *repr_o = PyObject_Repr(value_o); + stack_pointer = _PyFrame_GetStackPointer(frame); + PyStackRef_CLOSE(value); + if (repr_o == NULL) goto pop_1_error; + repr = PyStackRef_FromPyObjectSteal(repr_o); + stack_pointer[-1] = repr; + DISPATCH(); + } + TARGET(GET_YIELD_FROM_ITER) { frame->instr_ptr = next_instr; next_instr += 1; diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h index 3fc9d3118d59ad..d7f150242570a5 100644 --- a/Python/opcode_targets.h +++ b/Python/opcode_targets.h @@ -18,6 +18,7 @@ static void *opcode_targets[256] = { &&TARGET_GET_ITER, &&TARGET_RESERVED, &&TARGET_GET_LEN, + &&TARGET_GET_REPR, &&TARGET_GET_YIELD_FROM_ITER, &&TARGET_INTERPRETER_EXIT, &&TARGET_LOAD_BUILD_CLASS, @@ -147,7 +148,6 @@ static void *opcode_targets[256] = { &&_unknown_opcode, &&_unknown_opcode, &&_unknown_opcode, - &&_unknown_opcode, &&TARGET_RESUME, &&TARGET_BINARY_OP_ADD_FLOAT, &&TARGET_BINARY_OP_ADD_INT, diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 6ec9e69d1dbc44..91d3d0a7c7b62f 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -1462,6 +1462,13 @@ break; } + case _GET_REPR: { + _Py_UopsSymbol *repr; + repr = sym_new_not_null(ctx); + stack_pointer[-1] = repr; + break; + } + case _GET_YIELD_FROM_ITER: { _Py_UopsSymbol *iter; iter = sym_new_not_null(ctx);