[pypy-svn] r66212 - in pypy/branch/parser-compiler/pypy/interpreter/astcompiler: . test
benjamin at codespeak.net
benjamin at codespeak.net
Tue Jul 14 18:39:56 CEST 2009
Author: benjamin
Date: Tue Jul 14 18:39:55 2009
New Revision: 66212
Modified:
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py
Log:
add a temporary variable for list comps
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py Tue Jul 14 18:39:55 2009
@@ -259,6 +259,7 @@
self.scopes = {}
self.scope = None
self.stack = []
+ self.tmp_name_counter = 0
top = ModuleScope(module)
self.globs = top.roles
self.push_scope(top)
@@ -289,6 +290,10 @@
name = ".%i" % (pos,)
self.note_symbol(name, SYM_PARAM)
+ def new_temporary_name(self):
+ self.note_symbol("_[%i]" % (self.tmp_name_counter,), SYM_ASSIGNED)
+ self.tmp_name_counter += 1
+
def note_symbol(self, identifier, role):
mangled = self.scope.note_symbol(identifier, role)
if role & SYM_GLOBAL:
@@ -369,6 +374,10 @@
genexp.elt.walkabout(self)
self.pop_scope()
+ def visit_ListComp(self, lc):
+ self.new_temporary_name()
+ ast.GenericASTVisitor.visit_ListComp(self, lc)
+
def visit_arguments(self, arguments):
assert isinstance(self.scope, FunctionScope) # Annotator hint.
if arguments.args:
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py Tue Jul 14 18:39:55 2009
@@ -288,3 +288,7 @@
for input in ("class x: return", "return"):
exc = py.test.raises(SyntaxError, self.func_scope, input).value
assert exc.msg == "return outside function"
+
+ def test_listcomp_tmpname(self):
+ scp = self.mod_scope("[x for x in y]")
+ assert scp.lookup("_[0]") == symtable.SCOPE_LOCAL
More information about the Pypy-commit
mailing list