[pypy-svn] r75596 - in pypy/branch/fast-forward/pypy/interpreter: . astcompiler test
benjamin at codespeak.net
benjamin at codespeak.net
Fri Jun 25 16:44:29 CEST 2010
Author: benjamin
Date: Fri Jun 25 16:44:27 2010
New Revision: 75596
Modified:
pypy/branch/fast-forward/pypy/interpreter/astcompiler/codegen.py
pypy/branch/fast-forward/pypy/interpreter/pyopcode.py
pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py
Log:
implicit set literal opcodes
Modified: pypy/branch/fast-forward/pypy/interpreter/astcompiler/codegen.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/astcompiler/codegen.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/astcompiler/codegen.py Fri Jun 25 16:44:27 2010
@@ -939,6 +939,11 @@
d.keys[i].walkabout(self)
self.emit_op(ops.STORE_SUBSCR)
+ def visit_Set(self, s):
+ self.update_position(s.lineno)
+ self.visit_sequence(s.elts)
+ self.emit_op_arg(ops.BUILD_SET, len(s.elts))
+
def visit_Name(self, name):
self.update_position(name.lineno)
self.name_op(name.id, name.ctx)
Modified: pypy/branch/fast-forward/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyopcode.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyopcode.py Fri Jun 25 16:44:27 2010
@@ -1062,6 +1062,11 @@
def BUILD_SET(self, itemcount, next_instr):
w_set = self.space.call_function(self.space.w_set)
+ if itemcount:
+ w_add = self.space.getattr(w_set, self.space.wrap("add"))
+ for i in range(itemcount):
+ w_item = self.popvalue()
+ self.space.call_function(w_add, w_item)
self.pushvalue(w_set)
def STORE_MAP(self, zero, next_instr):
Modified: pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/test/test_syntax.py Fri Jun 25 16:44:27 2010
@@ -384,6 +384,14 @@
s = eval("{x for x in range(10) if x % 2}")
assert s == set(x for x in range(10) if x % 2)
+ def test_set_literal(self):
+ s = eval("{1}")
+ assert isinstance(s, set)
+ assert s == set((1,))
+ s = eval("{0, 1, 2, 3}")
+ assert isinstance(s, set)
+ assert s == set(range(4))
+
class AppTestWith:
def test_with_simple(self):
More information about the Pypy-commit
mailing list