From 2d1fd84e9c72febfed886b7a28a5bc81f4261875 Mon Sep 17 00:00:00 2001 From: deref3046 Date: Wed, 10 Jun 2026 20:32:07 +0800 Subject: [PATCH] handle py310 unsupported opcodes --- ASTree.cpp | 76 ++++++++++++++++++ tests/compiled/test_assert_310.3.10.pyc | Bin 0 -> 185 bytes .../compiled/test_call_starargs_310.3.10.pyc | Bin 0 -> 306 bytes tests/compiled/test_dict_merge_310.3.10.pyc | Bin 0 -> 208 bytes tests/compiled/test_unpack_ex_310.3.10.pyc | Bin 0 -> 220 bytes tests/input/test_assert_310.py | 2 + tests/input/test_call_starargs_310.py | 3 + tests/input/test_dict_merge_310.py | 2 + tests/input/test_unpack_ex_310.py | 2 + tests/tokenized/test_assert_310.txt | 4 + tests/tokenized/test_call_starargs_310.txt | 5 ++ tests/tokenized/test_dict_merge_310.txt | 2 + tests/tokenized/test_unpack_ex_310.txt | 2 + 13 files changed, 98 insertions(+) create mode 100644 tests/compiled/test_assert_310.3.10.pyc create mode 100644 tests/compiled/test_call_starargs_310.3.10.pyc create mode 100644 tests/compiled/test_dict_merge_310.3.10.pyc create mode 100644 tests/compiled/test_unpack_ex_310.3.10.pyc create mode 100644 tests/input/test_assert_310.py create mode 100644 tests/input/test_call_starargs_310.py create mode 100644 tests/input/test_dict_merge_310.py create mode 100644 tests/input/test_unpack_ex_310.py create mode 100644 tests/tokenized/test_assert_310.txt create mode 100644 tests/tokenized/test_call_starargs_310.txt create mode 100644 tests/tokenized/test_dict_merge_310.txt create mode 100644 tests/tokenized/test_unpack_ex_310.txt diff --git a/ASTree.cpp b/ASTree.cpp index f837152f9..709659b28 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1931,6 +1931,14 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } } break; + case Pyc::JUMP_IF_NOT_EXC_MATCH_A: + { + PycRef right = stack.top(); + stack.pop(); + PycRef left = stack.top(); + stack.pop(); + } + break; case Pyc::RERAISE: case Pyc::RERAISE_A: /* Python 3.11 cleanup opcode. */ @@ -2692,6 +2700,74 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack.push(value); } break; + case Pyc::LOAD_ASSERTION_ERROR: + { + stack.push(PycRef()); + } + break; + case Pyc::LIST_TO_TUPLE: + { + PycRef value = stack.top(); + stack.pop(); + stack.push(value); + } + break; + case Pyc::CALL_FUNCTION_EX_A: + { + bool has_kwargs = (operand & 1); + bool has_args = (operand & 2); + + PycRef kwargs_node; + PycRef args_node; + + if (has_kwargs) { + kwargs_node = stack.top(); + stack.pop(); + } + if (has_args) { + args_node = stack.top(); + stack.pop(); + } + + PycRef func = stack.top(); + stack.pop(); + + ASTCall::pparam_t pparams; + ASTCall::kwparam_t kwparams; + PycRef call = new ASTCall(func, pparams, kwparams); + + if (has_args) { + call.cast()->setVar(args_node); + } + if (has_kwargs) { + call.cast()->setKW(kwargs_node); + } + + stack.push(call); + } + break; + case Pyc::DICT_MERGE_A: + { + stack.pop(); + } + break; + case Pyc::DICT_UPDATE_A: + { + stack.pop(); + } + break; + // MAP_ADD and SET_ADD require comprehension AST reconstruction + case Pyc::UNPACK_EX_A: + { + int before = operand & 0xFF; + int after = (operand >> 8) & 0xFF; + unpack = before + 1 + after; + if (unpack > 0) { + ASTTuple::value_t vals; + stack.push(new ASTTuple(vals)); + } + } + break; default: fprintf(stderr, "Unsupported opcode: %s (%d)\n", Pyc::OpcodeName(opcode), opcode); cleanBuild = false; diff --git a/tests/compiled/test_assert_310.3.10.pyc b/tests/compiled/test_assert_310.3.10.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ddffef2796be4350711356966424b6767988f87d GIT binary patch literal 185 zcmd1j<>g`k0{alnEMXx17{oyaOhAqU5EqL8i4=w?hE#?W#%z{i4ljl##uTPt22JLd zj6kWEK+NE$$#{#gVkJWn3y=dQemUr8r0NH|I=h7W2Iv=5 zCZ{Cpm!uY#6zgZ^6_l2M+3|_R#i>Ol@y3P*dIgoYIBatBQ%ZAE?LgKPgG^>&5MTrV D{(&gO literal 0 HcmV?d00001 diff --git a/tests/compiled/test_call_starargs_310.3.10.pyc b/tests/compiled/test_call_starargs_310.3.10.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0e268569c3139b7a409299b263634d7c3ebaff53 GIT binary patch literal 306 zcmd1j<>g`k0>LoNEDIq07{oyatU!(f5Esh zjEoE^ticSLY{@`1aKHp)F#@qa5Erumi4+E)8b-gB44O>0SQ3lUi*K=ImxJgckTNjw z%UwSsKQ~q1CABEk*ucb0KRG`oRX^C(*(KCBK);|eIVD-YB(=DtSU)qbptJn^4pjS|Ni!lvkXfenUER01UUuZJD1PQ$a3Eg6>c*zW;{WKwR2p2$D ZAm`rVu*uC&Da}c>1DgaA;$RSC0sy-NJIDY4 literal 0 HcmV?d00001 diff --git a/tests/compiled/test_dict_merge_310.3.10.pyc b/tests/compiled/test_dict_merge_310.3.10.pyc new file mode 100644 index 0000000000000000000000000000000000000000..37c3a0bd7f3f568d805472f8b182d3be2e467ad6 GIT binary patch literal 208 zcmd1j<>g`k0*4UIEF~cQ7{oya%s`F<5Esh;i4=wu#!SX2hD?T3hNX-tOexHnj7u4# z7*kk+88lgMF($rb1gg5lnDmkfNc(9rMKPrq0g`k0>LoNEL9-=7{oya%s`F<5En}TiFAe(hDD4~45eD7^9e?m{S;o z88n$RSzj^&6})5u5gZyG_N2rIXgbJ fBHq~0K(C 0 diff --git a/tests/input/test_call_starargs_310.py b/tests/input/test_call_starargs_310.py new file mode 100644 index 000000000..ffc022567 --- /dev/null +++ b/tests/input/test_call_starargs_310.py @@ -0,0 +1,3 @@ +def f(*args, **kwargs): + pass +f(*(1, 2), **{'x': 3}) diff --git a/tests/input/test_dict_merge_310.py b/tests/input/test_dict_merge_310.py new file mode 100644 index 000000000..e3daa993e --- /dev/null +++ b/tests/input/test_dict_merge_310.py @@ -0,0 +1,2 @@ +d1 = {'a': 1} +d2 = {**d1, 'b': 2} diff --git a/tests/input/test_unpack_ex_310.py b/tests/input/test_unpack_ex_310.py new file mode 100644 index 000000000..3ea3558ea --- /dev/null +++ b/tests/input/test_unpack_ex_310.py @@ -0,0 +1,2 @@ +seq = [1, 2, 3, 4, 5] +a, *b, c = seq diff --git a/tests/tokenized/test_assert_310.txt b/tests/tokenized/test_assert_310.txt new file mode 100644 index 000000000..75100eb60 --- /dev/null +++ b/tests/tokenized/test_assert_310.txt @@ -0,0 +1,4 @@ +x = 1 +if not x > 0 : + +raise None diff --git a/tests/tokenized/test_call_starargs_310.txt b/tests/tokenized/test_call_starargs_310.txt new file mode 100644 index 000000000..36b47c444 --- /dev/null +++ b/tests/tokenized/test_call_starargs_310.txt @@ -0,0 +1,5 @@ +def f ( * args , ** kwargs ) : + +pass + +( 1 , 2 ) ( ** { } ) diff --git a/tests/tokenized/test_dict_merge_310.txt b/tests/tokenized/test_dict_merge_310.txt new file mode 100644 index 000000000..344c6d679 --- /dev/null +++ b/tests/tokenized/test_dict_merge_310.txt @@ -0,0 +1,2 @@ +d1 = { 'a' : 1 } +d2 = { } diff --git a/tests/tokenized/test_unpack_ex_310.txt b/tests/tokenized/test_unpack_ex_310.txt new file mode 100644 index 000000000..ce6cb5658 --- /dev/null +++ b/tests/tokenized/test_unpack_ex_310.txt @@ -0,0 +1,2 @@ +seq = [ 1 , 2 , 3 , 4 , 5 ] +( a , b , c ) = seq