From 9b384ad1faae432b93b6a2157908e3a0bca0b8c3 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Thu, 9 Nov 2023 11:11:37 -0800 Subject: [PATCH] Add basic bytecode and disassembly support for Python 3.12 --- ASTree.cpp | 10 +- CMakeLists.txt | 2 +- PythonBytecode.txt | 411 +++++++++++++++------------ bytecode.cpp | 31 +- bytecode_ops.inl | 37 +++ bytes/comp_map.py | 2 +- bytes/python_312.map | 129 +++++++++ pyc_module.cpp | 8 +- pyc_module.h | 1 + pyc_string.cpp | 2 +- scripts/pymultic | 12 +- tests/compiled/simple_const.3.12.pyc | Bin 0 -> 274 bytes 12 files changed, 456 insertions(+), 189 deletions(-) create mode 100644 bytes/python_312.map create mode 100644 tests/compiled/simple_const.3.12.pyc diff --git a/ASTree.cpp b/ASTree.cpp index c2794d3f3..7f36b3df7 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1796,6 +1796,12 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } } break; + case Pyc::RETURN_CONST_A: + { + PycRef value = new ASTObject(code->getConst(operand)); + curblock->append(new ASTReturn(value.cast())); + } + break; case Pyc::ROT_TWO: { PycRef one = stack.top(); @@ -3347,7 +3353,9 @@ void decompyle(PycRef code, PycModule* mod, std::ostream& pyc_output) if (clean->nodes().back().type() == ASTNode::NODE_RETURN) { PycRef ret = clean->nodes().back().cast(); - if (ret->value() == NULL || ret->value().type() == ASTNode::NODE_LOCALS) { + PycRef retObj = ret->value().try_cast(); + if (ret->value() == NULL || ret->value().type() == ASTNode::NODE_LOCALS || + (retObj && retObj->object().type() == PycObject::TYPE_NONE)) { clean->removeLast(); // Always an extraneous return statement } } diff --git a/CMakeLists.txt b/CMakeLists.txt index c8bcf9730..12113f80b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ endif() set(PYTHON_VERSIONS 10 11 13 14 15 16 # Python 1.1 and 1.2 are marshal-identical 20 21 22 23 24 25 26 27 - 30 31 32 33 34 35 36 37 38 39 310 311 + 30 31 32 33 34 35 36 37 38 39 310 311 312 ) foreach(ver ${PYTHON_VERSIONS}) diff --git a/PythonBytecode.txt b/PythonBytecode.txt index 3f2066d62..e3f1f9b2e 100644 --- a/PythonBytecode.txt +++ b/PythonBytecode.txt @@ -12,6 +12,7 @@ Python MAGIC Python MAGIC Python MAGIC 3.9 0x0A0D0D61 3.10 0x0A0D0D6F 3.11 0x0A0D0DA7 + 3.12 0x0A0D0DCB 1.0 1.1 1.2 1.3 1.4 1.5 1.6 @@ -542,190 +543,244 @@ DICT_UPDATE [ ] [ ] [ ] [ ] [ ] [ ] [ ] . - 3.11 -CACHE [X] -POP_TOP [X] -PUSH_NULL [X] -<3> [ ] -<4> [ ] -<5> [ ] -<6> [ ] -<7> [ ] -<8> [ ] -NOP [X] -UNARY_POSITIVE [X] -UNARY_NEGATIVE [X] -UNARY_NOT [X] -<13> [ ] -<14> [ ] -UNARY_INVERT [X] -<16> [ ] -<17> [ ] -<18> [ ] -<19> [ ] -<20> [ ] -<21> [ ] -<22> [ ] -<23> [ ] -<24> [ ] -BINARY_SUBSCR [X] -<26> [ ] -<27> [ ] -<28> [ ] -<29> [ ] -GET_LEN [X] -MATCH_MAPPING [X] -MATCH_SEQUENCE [X] -MATCH_KEYS [X] -<34> [ ] -PUSH_EXC_INFO [X] -CHECK_EXC_MATCH [X] -CHECK_EG_MATCH [X] -<38> [ ] -<39> [ ] -<40> [ ] -<41> [ ] -<42> [ ] -<43> [ ] -<44> [ ] -<45> [ ] -<46> [ ] -<47> [ ] -<48> [ ] -WITH_EXCEPT_START [X] -GET_AITER [X] -GET_ANEXT [X] -BEFORE_ASYNC_WITH [X] -BEFORE_WITH [X] -END_ASYNC_FOR [X] -<55> [ ] -<56> [ ] -<57> [ ] -<58> [ ] -<59> [ ] -STORE_SUBSCR [X] -DELETE_SUBSCR [X] -<62> [ ] -<63> [ ] -<64> [ ] -<65> [ ] -<66> [ ] -<67> [ ] -GET_ITER [X] -GET_YIELD_FROM_ITER [X] -PRINT_EXPR [X] -LOAD_BUILD_CLASS [X] -<72> [ ] -<73> [ ] -LOAD_ASSERTION_ERROR [X] -RETURN_GENERATOR [X] -<76> [ ] -<77> [ ] -<78> [ ] -<79> [ ] -<80> [ ] -<81> [ ] -LIST_TO_TUPLE [X] -RETURN_VALUE [X] -IMPORT_STAR [X] -SETUP_ANNOTATIONS [X] -YIELD_VALUE [X] -ASYNC_GEN_WRAP [X] -PREP_RERAISE_STAR [X] -POP_EXCEPT [X] -STORE_NAME [X] -DELETE_NAME [X] -UNPACK_SEQUENCE [X] -FOR_ITER [X] -UNPACK_EX [X] -STORE_ATTR [X] -DELETE_ATTR [X] -STORE_GLOBAL [X] -DELETE_GLOBAL [X] -SWAP [X] -LOAD_CONST [X] -LOAD_NAME [X] -BUILD_TUPLE [X] -BUILD_LIST [X] -BUILD_SET [X] -BUILD_MAP [X] -LOAD_ATTR [X] -COMPARE_OP [X] -IMPORT_NAME [X] -IMPORT_FROM [X] -JUMP_FORWARD [X] -JUMP_IF_FALSE_OR_POP [X] -JUMP_IF_TRUE_OR_POP [X] -<113> [ ] -POP_JUMP_FORWARD_IF_FALSE [X] -POP_JUMP_FORWARD_IF_TRUE [X] -LOAD_GLOBAL [X] -IS_OP [X] -CONTAINS_OP [X] -RERAISE [X] -COPY [X] -<121> [ ] -BINARY_OP [X] -SEND [X] -LOAD_FAST [X] -STORE_FAST [X] -DELETE_FAST [X] -<127> [ ] -POP_JUMP_FORWARD_IF_NOT_NONE [X] -POP_JUMP_FORWARD_IF_NONE [X] -RAISE_VARARGS [X] -GET_AWAITABLE [X] -MAKE_FUNCTION [X] -BUILD_SLICE [X] -JUMP_BACKWARD_NO_INTERRUPT [X] -MAKE_CELL [X] -LOAD_CLOSURE [X] -LOAD_DEREF [X] -STORE_DEREF [X] -DELETE_DEREF [X] -JUMP_BACKWARD [X] -<141> [ ] -CALL_FUNCTION_EX [X] -<143> [ ] -EXTENDED_ARG [X] -LIST_APPEND [X] -SET_ADD [X] -MAP_ADD [X] -LOAD_CLASSDEREF [X] -COPY_FREE_VARS [X] -<150> [ ] -RESUME [X] -MATCH_CLASS [X] -<153> [ ] -<154> [ ] -FORMAT_VALUE [X] -BUILD_CONST_KEY_MAP [X] -BUILD_STRING [X] -<158> [ ] -<159> [ ] -LOAD_METHOD [X] -<161> [ ] -LIST_EXTEND [X] -SET_UPDATE [X] -DICT_MERGE [X] -DICT_UPDATE [X] -PRECALL [X] -<167> [ ] -<168> [ ] -<169> [ ] -<170> [ ] -CALL [X] -KW_NAMES [X] -POP_JUMP_BACKWARD_IF_NOT_NONE [X] -POP_JUMP_BACKWARD_IF_NONE [X] -POP_JUMP_BACKWARD_IF_FALSE [X] -POP_JUMP_BACKWARD_IF_TRUE [X] + 3.11 3.12 +CACHE [X] [X] +POP_TOP [X] [X] +PUSH_NULL [X] [X] +INTERPRETER_EXIT [ ] [X] +END_FOR [ ] [X] +END_SEND [ ] [X] +<6> [ ] [ ] +<7> [ ] [ ] +<8> [ ] [ ] +NOP [X] [X] +UNARY_POSITIVE [X] [ ] +UNARY_NEGATIVE [X] [X] +UNARY_NOT [X] [X] +<13> [ ] [ ] +<14> [ ] [ ] +UNARY_INVERT [X] [X] +<16> [ ] [ ] +RESERVED [ ] [X] +<18> [ ] [ ] +<19> [ ] [ ] +<20> [ ] [ ] +<21> [ ] [ ] +<22> [ ] [ ] +<23> [ ] [ ] +<24> [ ] [ ] +BINARY_SUBSCR [X] [X] +BINARY_SLICE [ ] [X] +STORE_SLICE [ ] [X] +<28> [ ] [ ] +<29> [ ] [ ] +GET_LEN [X] [X] +MATCH_MAPPING [X] [X] +MATCH_SEQUENCE [X] [X] +MATCH_KEYS [X] [X] +<34> [ ] [ ] +PUSH_EXC_INFO [X] [X] +CHECK_EXC_MATCH [X] [X] +CHECK_EG_MATCH [X] [X] +<38> [ ] [ ] +<39> [ ] [ ] +<40> [ ] [ ] +<41> [ ] [ ] +<42> [ ] [ ] +<43> [ ] [ ] +<44> [ ] [ ] +<45> [ ] [ ] +<46> [ ] [ ] +<47> [ ] [ ] +<48> [ ] [ ] +WITH_EXCEPT_START [X] [X] +GET_AITER [X] [X] +GET_ANEXT [X] [X] +BEFORE_ASYNC_WITH [X] [X] +BEFORE_WITH [X] [X] +END_ASYNC_FOR [X] [X] +CLEANUP_THROW [ ] [X] +<56> [ ] [ ] +<57> [ ] [ ] +<58> [ ] [ ] +<59> [ ] [ ] +STORE_SUBSCR [X] [X] +DELETE_SUBSCR [X] [X] +<62> [ ] [ ] +<63> [ ] [ ] +<64> [ ] [ ] +<65> [ ] [ ] +<66> [ ] [ ] +<67> [ ] [ ] +GET_ITER [X] [X] +GET_YIELD_FROM_ITER [X] [X] +PRINT_EXPR [X] [ ] +LOAD_BUILD_CLASS [X] [X] +<72> [ ] [ ] +<73> [ ] [ ] +LOAD_ASSERTION_ERROR [X] [X] +RETURN_GENERATOR [X] [X] +<76> [ ] [ ] +<77> [ ] [ ] +<78> [ ] [ ] +<79> [ ] [ ] +<80> [ ] [ ] +<81> [ ] [ ] +LIST_TO_TUPLE [X] [ ] +RETURN_VALUE [X] [X] +IMPORT_STAR [X] [ ] +SETUP_ANNOTATIONS [X] [X] +YIELD_VALUE [X] [ ] +ASYNC_GEN_WRAP ! [X] +LOAD_LOCALS ! [X] +PREP_RERAISE_STAR [X] [ ] +POP_EXCEPT [X] [X] +STORE_NAME [X] [X] +DELETE_NAME [X] [X] +UNPACK_SEQUENCE [X] [X] +FOR_ITER [X] [X] +UNPACK_EX [X] [X] +STORE_ATTR [X] [X] +DELETE_ATTR [X] [X] +STORE_GLOBAL [X] [X] +DELETE_GLOBAL [X] [X] +SWAP [X] [X] +LOAD_CONST [X] [X] +LOAD_NAME [X] [X] +BUILD_TUPLE [X] [X] +BUILD_LIST [X] [X] +BUILD_SET [X] [X] +BUILD_MAP [X] [X] +LOAD_ATTR [X] [X] +COMPARE_OP [X] [X] +IMPORT_NAME [X] [X] +IMPORT_FROM [X] [X] +JUMP_FORWARD [X] [X] +JUMP_IF_FALSE_OR_POP [X] [ ] +JUMP_IF_TRUE_OR_POP [X] [ ] +<113> [ ] [ ] +POP_JUMP_FORWARD_IF_FALSE ! [X] +POP_JUMP_IF_FALSE ! [X] +POP_JUMP_FORWARD_IF_TRUE ! [X] +POP_JUMP_IF_TRUE ! [X] +LOAD_GLOBAL [X] [X] +IS_OP [X] [X] +CONTAINS_OP [X] [X] +RERAISE [X] [X] +COPY [X] [X] +RETURN_CONST [ ] [X] +BINARY_OP [X] [X] +SEND [X] [X] +LOAD_FAST [X] [X] +STORE_FAST [X] [X] +DELETE_FAST [X] [X] +LOAD_FAST_CHECK [ ] [X] +POP_JUMP_FORWARD_IF_NOT_NONE ! [X] +POP_JUMP_IF_NOT_NONE ! [X] +POP_JUMP_FORWARD_IF_NONE ! [X] +POP_JUMP_IF_NONE ! [X] +RAISE_VARARGS [X] [X] +GET_AWAITABLE [X] [X] +MAKE_FUNCTION [X] [X] +BUILD_SLICE [X] [X] +JUMP_BACKWARD_NO_INTERRUPT [X] [X] +MAKE_CELL [X] [X] +LOAD_CLOSURE [X] [X] +LOAD_DEREF [X] [X] +STORE_DEREF [X] [X] +DELETE_DEREF [X] [X] +JUMP_BACKWARD [X] [X] +LOAD_SUPER_ATTR [ ] [X] +CALL_FUNCTION_EX [X] [X] +LOAD_FAST_AND_CLEAR [ ] [X] +EXTENDED_ARG [X] [X] +LIST_APPEND [X] [X] +SET_ADD [X] [X] +MAP_ADD [X] [X] +LOAD_CLASSDEREF [X] [ ] +COPY_FREE_VARS [X] [X] +YIELD_VALUE [ ] [X] +RESUME [X] [X] +MATCH_CLASS [X] [X] +<153> [ ] [ ] +<154> [ ] [ ] +FORMAT_VALUE [X] [X] +BUILD_CONST_KEY_MAP [X] [X] +BUILD_STRING [X] [X] +<158> [ ] [ ] +<159> [ ] [ ] +LOAD_METHOD [X] [ ] +<161> [ ] [ ] +LIST_EXTEND [X] [X] +SET_UPDATE [X] [X] +DICT_MERGE [X] [X] +DICT_UPDATE [X] [X] +PRECALL [X] [ ] +<167> [ ] [ ] +<168> [ ] [ ] +<169> [ ] [ ] +<170> [ ] [ ] +CALL [X] [X] +KW_NAMES [X] [X] +POP_JUMP_BACKWARD_IF_NOT_NONE ! [X] +CALL_INTRINSIC_1 ! [X] +POP_JUMP_BACKWARD_IF_NONE ! [X] +CALL_INTRINSIC_2 ! [X] +POP_JUMP_BACKWARD_IF_FALSE ! [X] +LOAD_FROM_DICT_OR_GLOBALS ! [X] +POP_JUMP_BACKWARD_IF_TRUE ! [X] +LOAD_FROM_DICT_OR_DEREF ! [X] <177> <178> <179> . . . +<234> +<235> +<236> +INSTRUMENTED_LOAD_SUPER_ATTR [ ] [X] +INSTRUMENTED_POP_JUMP_IF_NONE [ ] [X] +INSTRUMENTED_POP_JUMP_IF_NOT_NONE [ ] [X] +INSTRUMENTED_RESUME [ ] [X] +INSTRUMENTED_CALL [ ] [X] +INSTRUMENTED_RETURN_VALUE [ ] [X] +INSTRUMENTED_YIELD_VALUE [ ] [X] +INSTRUMENTED_CALL_FUNCTION_EX [ ] [X] +INSTRUMENTED_JUMP_FORWARD [ ] [X] +INSTRUMENTED_JUMP_BACKWARD [ ] [X] +INSTRUMENTED_RETURN_CONST [ ] [X] +INSTRUMENTED_FOR_ITER [ ] [X] +INSTRUMENTED_POP_JUMP_IF_FALSE [ ] [X] +INSTRUMENTED_POP_JUMP_IF_TRUE [ ] [X] +INSTRUMENTED_END_FOR [ ] [X] +INSTRUMENTED_END_SEND [ ] [X] +INSTRUMENTED_INSTRUCTION [ ] [X] +INSTRUMENTED_LINE [ ] [X] +<255> + + +[Intrinsic 1] 3.12 +INVALID [X] +PRINT [X] +IMPORT_STAR [X] +STOPITERATION_ERROR [X] +ASYNC_GEN_WRAP [X] +UNARY_POSITIVE [X] +LIST_TO_TUPLE [X] +TYPEVAR [X] +PARAMSPEC [X] +TYPEVARTUPLE [X] +SUBSCRIPT_GENERIC [X] +TYPEALIAS [X] + + +[Intrinsic 2] 3.12 +INVALID [X] +PREP_RERAISE_STAR [X] +TYPEVAR_WITH_BOUND [X] +TYPEVAR_WITH_CONSTRAINTS [X] +SET_FUNCTION_TYPE_PARAMS [X] 1.0 1.3 1.4 1.5 1.6 diff --git a/bytecode.cpp b/bytecode.cpp index 6036d0b1f..dd09eb1cf 100644 --- a/bytecode.cpp +++ b/bytecode.cpp @@ -38,6 +38,7 @@ DECLARE_PYTHON(3, 8) DECLARE_PYTHON(3, 9) DECLARE_PYTHON(3, 10) DECLARE_PYTHON(3, 11) +DECLARE_PYTHON(3, 12) const char* Pyc::OpcodeName(int opcode) { @@ -106,6 +107,7 @@ int Pyc::ByteToOpcode(int maj, int min, int opcode) case 9: return python_39_map(opcode); case 10: return python_310_map(opcode); case 11: return python_311_map(opcode); + case 12: return python_312_map(opcode); } break; } @@ -114,7 +116,8 @@ int Pyc::ByteToOpcode(int maj, int min, int opcode) bool Pyc::IsConstArg(int opcode) { - return (opcode == Pyc::LOAD_CONST_A) || (opcode == Pyc::RESERVE_FAST_A); + return (opcode == Pyc::LOAD_CONST_A) || (opcode == Pyc::RESERVE_FAST_A) || + (opcode == Pyc::RETURN_CONST_A); } bool Pyc::IsNameArg(int opcode) @@ -370,6 +373,22 @@ void bc_disasm(std::ostream& pyc_output, PycRef code, PycModule* mod, }; static const size_t binop_strings_len = sizeof(binop_strings) / sizeof(binop_strings[0]); + static const char *intrinsic1_names[] = { + "INTRINSIC_1_INVALID", "INTRINSIC_PRINT", "INTRINSIC_IMPORT_STAR", + "INTRINSIC_STOPITERATION_ERROR", "INTRINSIC_ASYNC_GEN_WRAP", + "INTRINSIC_UNARY_POSITIVE", "INTRINSIC_LIST_TO_TUPLE", "INTRINSIC_TYPEVAR", + "INTRINSIC_PARAMSPEC", "INTRINSIC_TYPEVARTUPLE", + "INTRINSIC_SUBSCRIPT_GENERIC", "INTRINSIC_TYPEALIAS", + }; + static const size_t intrinsic1_names_len = sizeof(intrinsic1_names) / sizeof(intrinsic1_names[0]); + + static const char *intrinsic2_names[] = { + "INTRINSIC_2_INVALID", "INTRINSIC_PREP_RERAISE_STAR", + "INTRINSIC_TYPEVAR_WITH_BOUND", "INTRINSIC_TYPEVAR_WITH_CONSTRAINTS", + "INTRINSIC_SET_FUNCTION_TYPE_PARAMS", + }; + static const size_t intrinsic2_names_len = sizeof(intrinsic2_names) / sizeof(intrinsic2_names[0]); + PycBuffer source(code->code()->value(), code->code()->length()); int opcode, operand; @@ -453,6 +472,16 @@ void bc_disasm(std::ostream& pyc_output, PycRef code, PycModule* mod, formatted_print(pyc_output, "%d (%s)", operand, (operand == 0) ? "in" : (operand == 1) ? "not in" : "UNKNOWN"); + } else if (opcode == Pyc::CALL_INTRINSIC_1_A) { + if (static_cast(operand) < intrinsic1_names_len) + formatted_print(pyc_output, "%d (%s)", operand, intrinsic1_names[operand]); + else + formatted_print(pyc_output, "%d (UNKNOWN)", operand); + } else if (opcode == Pyc::CALL_INTRINSIC_2_A) { + if (static_cast(operand) < intrinsic2_names_len) + formatted_print(pyc_output, "%d (%s)", operand, intrinsic2_names[operand]); + else + formatted_print(pyc_output, "%d (UNKNOWN)", operand); } else { formatted_print(pyc_output, "%d", operand); } diff --git a/bytecode_ops.inl b/bytecode_ops.inl index 7b681fd63..2a4626d5e 100644 --- a/bytecode_ops.inl +++ b/bytecode_ops.inl @@ -111,6 +111,13 @@ OPCODE(BEFORE_WITH) OPCODE(RETURN_GENERATOR) OPCODE(ASYNC_GEN_WRAP) OPCODE(PREP_RERAISE_STAR) +OPCODE(INTERPRETER_EXIT) +OPCODE(END_FOR) +OPCODE(END_SEND) +OPCODE(RESERVED) +OPCODE(BINARY_SLICE) +OPCODE(STORE_SLICE) +OPCODE(CLEANUP_THROW) /* Has parameter word */ OPCODE_A_FIRST(STORE_NAME) @@ -224,3 +231,33 @@ OPCODE_A(POP_JUMP_BACKWARD_IF_NOT_NONE) OPCODE_A(POP_JUMP_BACKWARD_IF_NONE) OPCODE_A(POP_JUMP_BACKWARD_IF_FALSE) OPCODE_A(POP_JUMP_BACKWARD_IF_TRUE) +OPCODE_A(RETURN_CONST) +OPCODE_A(LOAD_FAST_CHECK) +OPCODE_A(POP_JUMP_IF_NOT_NONE) +OPCODE_A(POP_JUMP_IF_NONE) +OPCODE_A(LOAD_SUPER_ATTR) +OPCODE_A(LOAD_FAST_AND_CLEAR) +OPCODE_A(YIELD_VALUE) +OPCODE_A(CALL_INTRINSIC_1) +OPCODE_A(CALL_INTRINSIC_2) +OPCODE_A(LOAD_FROM_DICT_OR_GLOBALS) +OPCODE_A(LOAD_FROM_DICT_OR_DEREF) + +OPCODE_A(INSTRUMENTED_LOAD_SUPER_ATTR) +OPCODE_A(INSTRUMENTED_POP_JUMP_IF_NONE) +OPCODE_A(INSTRUMENTED_POP_JUMP_IF_NOT_NONE) +OPCODE_A(INSTRUMENTED_RESUME) +OPCODE_A(INSTRUMENTED_CALL) +OPCODE_A(INSTRUMENTED_RETURN_VALUE) +OPCODE_A(INSTRUMENTED_YIELD_VALUE) +OPCODE_A(INSTRUMENTED_CALL_FUNCTION_EX) +OPCODE_A(INSTRUMENTED_JUMP_FORWARD) +OPCODE_A(INSTRUMENTED_JUMP_BACKWARD) +OPCODE_A(INSTRUMENTED_RETURN_CONST) +OPCODE_A(INSTRUMENTED_FOR_ITER) +OPCODE_A(INSTRUMENTED_POP_JUMP_IF_FALSE) +OPCODE_A(INSTRUMENTED_POP_JUMP_IF_TRUE) +OPCODE_A(INSTRUMENTED_END_FOR) +OPCODE_A(INSTRUMENTED_END_SEND) +OPCODE_A(INSTRUMENTED_INSTRUCTION) +OPCODE_A(INSTRUMENTED_LINE) diff --git a/bytes/comp_map.py b/bytes/comp_map.py index 6ba295e57..1f4c4891d 100755 --- a/bytes/comp_map.py +++ b/bytes/comp_map.py @@ -27,7 +27,7 @@ maplist = [ 10, 11, 13, 14, 15, 16, 20, 21, 22, 23, 24, 25, 26, 27, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 310, 311 ] + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 310, 311, 312 ] for mapver in maplist: infile = open(os.path.join(sys.argv[1], 'python_%d.map' % mapver), 'rt') diff --git a/bytes/python_312.map b/bytes/python_312.map new file mode 100644 index 000000000..3ffdaabdd --- /dev/null +++ b/bytes/python_312.map @@ -0,0 +1,129 @@ +0 CACHE +1 POP_TOP +2 PUSH_NULL +3 INTERPRETER_EXIT +4 END_FOR +5 END_SEND +9 NOP +11 UNARY_NEGATIVE +12 UNARY_NOT +15 UNARY_INVERT +17 RESERVED +25 BINARY_SUBSCR +26 BINARY_SLICE +27 STORE_SLICE +30 GET_LEN +31 MATCH_MAPPING +32 MATCH_SEQUENCE +33 MATCH_KEYS +35 PUSH_EXC_INFO +36 CHECK_EXC_MATCH +37 CHECK_EG_MATCH +49 WITH_EXCEPT_START +50 GET_AITER +51 GET_ANEXT +52 BEFORE_ASYNC_WITH +53 BEFORE_WITH +54 END_ASYNC_FOR +55 CLEANUP_THROW +60 STORE_SUBSCR +61 DELETE_SUBSCR +68 GET_ITER +69 GET_YIELD_FROM_ITER +71 LOAD_BUILD_CLASS +74 LOAD_ASSERTION_ERROR +75 RETURN_GENERATOR +83 RETURN_VALUE +85 SETUP_ANNOTATIONS +87 LOAD_LOCALS +89 POP_EXCEPT +90 STORE_NAME_A +91 DELETE_NAME_A +92 UNPACK_SEQUENCE_A +93 FOR_ITER_A +94 UNPACK_EX_A +95 STORE_ATTR_A +96 DELETE_ATTR_A +97 STORE_GLOBAL_A +98 DELETE_GLOBAL_A +99 SWAP_A +100 LOAD_CONST_A +101 LOAD_NAME_A +102 BUILD_TUPLE_A +103 BUILD_LIST_A +104 BUILD_SET_A +105 BUILD_MAP_A +106 LOAD_ATTR_A +107 COMPARE_OP_A +108 IMPORT_NAME_A +109 IMPORT_FROM_A +110 JUMP_FORWARD_A +114 POP_JUMP_IF_FALSE_A +115 POP_JUMP_IF_TRUE_A +116 LOAD_GLOBAL_A +117 IS_OP_A +118 CONTAINS_OP_A +119 RERAISE_A +120 COPY_A +121 RETURN_CONST_A +122 BINARY_OP_A +123 SEND_A +124 LOAD_FAST_A +125 STORE_FAST_A +126 DELETE_FAST_A +127 LOAD_FAST_CHECK_A +128 POP_JUMP_IF_NOT_NONE_A +129 POP_JUMP_IF_NONE_A +130 RAISE_VARARGS_A +131 GET_AWAITABLE_A +132 MAKE_FUNCTION_A +133 BUILD_SLICE_A +134 JUMP_BACKWARD_NO_INTERRUPT_A +135 MAKE_CELL_A +136 LOAD_CLOSURE_A +137 LOAD_DEREF_A +138 STORE_DEREF_A +139 DELETE_DEREF_A +140 JUMP_BACKWARD_A +141 LOAD_SUPER_ATTR_A +142 CALL_FUNCTION_EX_A +143 LOAD_FAST_AND_CLEAR_A +144 EXTENDED_ARG_A +145 LIST_APPEND_A +146 SET_ADD_A +147 MAP_ADD_A +149 COPY_FREE_VARS_A +150 YIELD_VALUE_A +151 RESUME_A +152 MATCH_CLASS_A +155 FORMAT_VALUE_A +156 BUILD_CONST_KEY_MAP_A +157 BUILD_STRING_A +162 LIST_EXTEND_A +163 SET_UPDATE_A +164 DICT_MERGE_A +165 DICT_UPDATE_A +171 CALL_A +172 KW_NAMES_A +173 CALL_INTRINSIC_1_A +174 CALL_INTRINSIC_2_A +175 LOAD_FROM_DICT_OR_GLOBALS_A +176 LOAD_FROM_DICT_OR_DEREF_A +237 INSTRUMENTED_LOAD_SUPER_ATTR_A +238 INSTRUMENTED_POP_JUMP_IF_NONE_A +239 INSTRUMENTED_POP_JUMP_IF_NOT_NONE_A +240 INSTRUMENTED_RESUME_A +241 INSTRUMENTED_CALL_A +242 INSTRUMENTED_RETURN_VALUE_A +243 INSTRUMENTED_YIELD_VALUE_A +244 INSTRUMENTED_CALL_FUNCTION_EX_A +245 INSTRUMENTED_JUMP_FORWARD_A +246 INSTRUMENTED_JUMP_BACKWARD_A +247 INSTRUMENTED_RETURN_CONST_A +248 INSTRUMENTED_FOR_ITER_A +249 INSTRUMENTED_POP_JUMP_IF_FALSE_A +250 INSTRUMENTED_POP_JUMP_IF_TRUE_A +251 INSTRUMENTED_END_FOR_A +252 INSTRUMENTED_END_SEND_A +253 INSTRUMENTED_INSTRUCTION_A +254 INSTRUMENTED_LINE_A diff --git a/pyc_module.cpp b/pyc_module.cpp index d2227906c..6f430fab4 100644 --- a/pyc_module.cpp +++ b/pyc_module.cpp @@ -170,6 +170,12 @@ void PycModule::setVersion(unsigned int magic) m_unicode = true; break; + case MAGIC_3_12: + m_maj = 3; + m_min = 12; + m_unicode = true; + break; + /* Bad Magic detected */ default: m_maj = -1; @@ -185,7 +191,7 @@ bool PycModule::isSupportedVersion(int major, int minor) case 2: return (minor >= 0 && minor <= 7); case 3: - return (minor >= 0 && minor <= 11); + return (minor >= 0 && minor <= 12); default: return false; } diff --git a/pyc_module.h b/pyc_module.h index b3e52dbea..4f93abdcf 100644 --- a/pyc_module.h +++ b/pyc_module.h @@ -34,6 +34,7 @@ enum PycMagic { MAGIC_3_9 = 0x0A0D0D61, MAGIC_3_10 = 0x0A0D0D6F, MAGIC_3_11 = 0x0A0D0DA7, + MAGIC_3_12 = 0x0A0D0DCB, INVALID = 0, }; diff --git a/pyc_string.cpp b/pyc_string.cpp index e43e1905c..0a04956f4 100644 --- a/pyc_string.cpp +++ b/pyc_string.cpp @@ -130,7 +130,7 @@ void PycString::print(std::ostream &pyc_output, PycModule* mod, bool triple, // Unicode stored as UTF-8... Let the stream interpret it pyc_output << ch; } else { - formatted_print(pyc_output, "\\x%x", (ch & 0xFF)); + formatted_print(pyc_output, "\\x%02x", (ch & 0xFF)); } } else { if (!useQuotes && ch == '\'') diff --git a/scripts/pymultic b/scripts/pymultic index 47ef24aea..c06cf4d68 100755 --- a/scripts/pymultic +++ b/scripts/pymultic @@ -30,11 +30,12 @@ PYVERS = { '3.4': '3.4.10', '3.5': '3.5.10', '3.6': '3.6.15', - '3.7': '3.7.16', - '3.8': '3.8.16', - '3.9': '3.9.16', - '3.10': '3.10.9', - '3.11': '3.11.1', + '3.7': '3.7.17', + '3.8': '3.8.18', + '3.9': '3.9.18', + '3.10': '3.10.13', + '3.11': '3.11.6', + '3.12': '3.12.0', } OLD_PYTHONS = ('1.0', '1.1', '1.2', '1.3', '1.4', '1.5') @@ -54,6 +55,7 @@ PYVER_CONTAINERS = { '3.9', '3.10', '3.11', + '3.12', } CONTAINER_EXES = ['podman', 'docker'] CONTAINER_EXE_EXTRA_ARGS = { diff --git a/tests/compiled/simple_const.3.12.pyc b/tests/compiled/simple_const.3.12.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4f69d37387dff8701e8b500a1777724ab4c27fda GIT binary patch literal 274 zcmX@j%ge<81kO9=#Qp%%k3k$5V1hC}YXBM38B!Rc7*ZIc7*m*{m{ORdm{VAySW;M1 z*wUGzSX0#h7x7G4&Q>+AYTPl?