[pypy-commit] pypy py3k: Implement py3k's tuple unpacking in the code generator
rguillebert
noreply at buildbot.pypy.org
Wed Jan 18 17:09:18 CET 2012
Author: Romain Guillebert <romain.py at gmail.com>
Branch: py3k
Changeset: r51446:f4cb22c63136
Date: 2012-01-18 13:55 +0100
http://bitbucket.org/pypy/pypy/changeset/f4cb22c63136/
Log: Implement py3k's tuple unpacking in the code generator
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -833,11 +833,22 @@
self.update_position(tup.lineno)
elt_count = len(tup.elts) if tup.elts is not None else 0
if tup.ctx == ast.Store:
- self.emit_op_arg(ops.UNPACK_SEQUENCE, elt_count)
+ star_pos = -1
+ if elt_count > 0:
+ for i, elt in enumerate(tup.elts):
+ if isinstance(elt, ast.Starred):
+ star_pos = i
+ if star_pos > -1:
+ self.emit_op_arg(ops.UNPACK_EX, star_pos | (elt_count-star_pos-1)<<8)
+ else:
+ self.emit_op_arg(ops.UNPACK_SEQUENCE, elt_count)
self.visit_sequence(tup.elts)
if tup.ctx == ast.Load:
self.emit_op_arg(ops.BUILD_TUPLE, elt_count)
+ def visit_Starred(self, star):
+ star.value.walkabout(self)
+
def visit_List(self, l):
self.update_position(l.lineno)
elt_count = len(l.elts) if l.elts is not None else 0
More information about the pypy-commit
mailing list