diff --git a/ASTree.cpp b/ASTree.cpp index c58b7be..f85f7f7 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1884,6 +1884,7 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) // Ignore break; case Pyc::SETUP_WITH_A: + case Pyc::WITH_EXCEPT_START: { PycRef withblock = new ASTWithBlock(pos+operand); blocks.push(withblock); @@ -2463,6 +2464,24 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) case Pyc::GEN_START_A: stack.pop(); break; + case Pyc::SWAP_A: + { + unpack = operand; + ASTTuple::value_t values; + ASTTuple::value_t next_tuple; + values.resize(operand); + for (int i = 0; i < operand; i++) { + values[operand - i - 1] = stack.top(); + stack.pop(); + } + auto tup = new ASTTuple(values); + tup->setRequireParens(false); + auto next_tup = new ASTTuple(next_tuple); + next_tup->setRequireParens(false); + stack.push(tup); + stack.push(next_tup); + } + break; default: fprintf(stderr, "Unsupported opcode: %s\n", Pyc::OpcodeName(opcode & 0xFF)); cleanBuild = false; diff --git a/tests/compiled/swap.3.11.pyc b/tests/compiled/swap.3.11.pyc new file mode 100644 index 0000000..f1e631b Binary files /dev/null and b/tests/compiled/swap.3.11.pyc differ diff --git a/tests/input/swap.py b/tests/input/swap.py new file mode 100644 index 0000000..cc0bbe4 --- /dev/null +++ b/tests/input/swap.py @@ -0,0 +1,12 @@ +def SWAP(): + my_array = [ + 1, + 2, + 3, + 4, + 5, + 6, + 8] + i = 1 + j = 3 + my_array[i], my_array[j], my_array[2] = my_array[j], my_array[i], my_array[4] diff --git a/tests/tokenized/swap.txt b/tests/tokenized/swap.txt new file mode 100644 index 0000000..5070b40 --- /dev/null +++ b/tests/tokenized/swap.txt @@ -0,0 +1,6 @@ +def SWAP ( ) : + +my_array = [ 1 , 2 , 3 , 4 , 5 , 6 , 8 ] +i = 1 +j = 3 +my_array [ i ] , my_array [ j ] , my_array [ 2 ] = my_array [ j ] , my_array [ i ] , my_array [ 4 ]