diff --git a/ASTree.cpp b/ASTree.cpp index ba31382..c92480e 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1455,6 +1455,33 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } } break; + case Pyc::LIST_EXTEND_A: + { + PycRef rhs = stack.top(); + stack.pop(); + PycRef lhs = stack.top().cast(); + stack.pop(); + + if (rhs.type() != ASTNode::NODE_OBJECT) { + fprintf(stderr, "Unsupported argument found for LIST_EXTEND\n"); + break; + } + + // I've only ever seen this be a SMALL_TUPLE, but let's be careful... + PycRef obj = rhs.cast()->object(); + if (obj->type() != PycObject::TYPE_TUPLE && obj->type() != PycObject::TYPE_SMALL_TUPLE) { + fprintf(stderr, "Unsupported argument type found for LIST_EXTEND\n"); + break; + } + + ASTList::value_t result = lhs->values(); + for (const auto& it : obj.cast()->values()) { + result.push_back(new ASTObject(it)); + } + + stack.push(new ASTList(result)); + } + break; case Pyc::LOAD_ATTR_A: { PycRef name = stack.top(); diff --git a/tests/compiled/list_extend.3.9.pyc b/tests/compiled/list_extend.3.9.pyc new file mode 100644 index 0000000..19fcbe6 Binary files /dev/null and b/tests/compiled/list_extend.3.9.pyc differ diff --git a/tests/input/list_extend.py b/tests/input/list_extend.py new file mode 100644 index 0000000..416a3c7 --- /dev/null +++ b/tests/input/list_extend.py @@ -0,0 +1,8 @@ +a = [1, 2, 3] +b = ['4', 5, 6] +c = [7, (8, 9, 10)] +d = [None] +e = [('a', 'b', 'c')] +f = [a, b] +g = [] +a = [None, None, None] diff --git a/tests/tokenized/list_extend.txt b/tests/tokenized/list_extend.txt new file mode 100644 index 0000000..9bb99d4 --- /dev/null +++ b/tests/tokenized/list_extend.txt @@ -0,0 +1,8 @@ +a = [ 1 , 2 , 3 ] +b = [ '4' , 5 , 6 ] +c = [ 7 , ( 8 , 9 , 10 ) ] +d = [ None ] +e = [ ( 'a' , 'b' , 'c' ) ] +f = [ a , b ] +g = [ ] +a = [ None , None , None ]