Author: Romain Guillebert <romain...@gmail.com>
Branch: py3k
Changeset: r51447:6face22d8492
Date: 2012-01-18 14:11 +0100
http://bitbucket.org/pypy/pypy/changeset/6face22d8492/

Log:    Implement the UNPACK_EX bytecode which is used by py3k's new tuple
        unpacking

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -582,7 +582,25 @@
         self.pushrevvalues(itemcount, items)
 
     def UNPACK_EX(self, oparg, next_instr):
-        raise NotImplementedError
+        left = oparg & 0xFF
+        right = (oparg & 0xFF00) >> 8
+        w_iterable = self.popvalue()
+
+        items = self.space.fixedview(w_iterable)
+        itemcount = len(items)
+
+        i = itemcount - 1
+        while i >= itemcount-right:
+            self.pushvalue(items[i])
+            i -= 1
+
+        self.pushvalue(self.space.newlist(items[left:itemcount-right]))
+
+        i = left - 1
+        while i >= 0:
+            self.pushvalue(items[i])
+            i -= 1
+
 
     def STORE_ATTR(self, nameindex, next_instr):
         "obj.attributename = newvalue"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to