Author: Raffael Tfirst <[email protected]>
Branch: py3.5
Changeset: r85401:f2c1dacc1078
Date: 2016-06-27 17:38 +0200
http://bitbucket.org/pypy/pypy/changeset/f2c1dacc1078/

Log:    Implement tuple_ and set_unpack opcodes, create unpack_helper method

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1330,42 +1330,27 @@
             self.space.call_method(w_set, 'add', w_item)
         self.pushvalue(w_set)
 
-    def BUILD_SET_UNPACK(self, itemcount, next_instr):
-        self.BUILD_SET(itemcount, next_instr)
-        #w_sum = self.space.newset()
-        #for i in range(itemcount, 0, -1):
-        #    w_item = self.popvalue()
-        #    #self.space.peek(i)
-        #    self.space.call_method(w_sum, 'update', w_item)
-        ##while itemcount != 0:
-        ##    self.popvalue()
-        ##    itemcount -= 1
-        #self.pushvalue(w_sum)
-
-    def BUILD_TUPLE_UNPACK(self, itemcount, next_instr):
-        self.BUILD_TUPLE(itemcount, next_instr)
-        #w_sum = self.space.newtuple()
-        #for i in range(itemcount, 0, -1):
-        #    w_item = self.popvalue()
-        #    #self.space.peek(i)
-        #    self.space.call_method(w_sum, 'update', w_item)
-        ##while itemcount != 0:
-        ##    self.popvalue()
-        ##    itemcount -= 1
-        #self.pushvalue(w_sum)
-        
-    def BUILD_LIST_UNPACK(self, itemcount, next_instr):
+    def unpack_helper(self, itemcount, next_instr):
         w_sum = []
         for i in range(itemcount, 0, -1):
-        #for i in range(0, itemcount):
-            #w_item = self.popvalue()
             w_item = self.peekvalue(i-1)
             items = self.space.fixedview(w_item)
             w_sum.extend(items)
-            #w_sum.append(w_item)
         while itemcount != 0:
             self.popvalue()
             itemcount -= 1
+        return w_sum
+
+    def BUILD_SET_UNPACK(self, itemcount, next_instr):
+        w_sum = self.unpack_helper(itemcount, next_instr)
+        self.pushvalue(self.space.newset(w_sum))
+
+    def BUILD_TUPLE_UNPACK(self, itemcount, next_instr):
+        w_sum = self.unpack_helper(itemcount, next_instr)
+        self.pushvalue(self.space.newtuple(w_sum))
+        
+    def BUILD_LIST_UNPACK(self, itemcount, next_instr):
+        w_sum = self.unpack_helper(itemcount, next_instr)
         self.pushvalue(self.space.newlist(w_sum))
         
     #TODO
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to