[pypy-svn] r38523 - pypy/dist/pypy/interpreter/astcompiler
arigo at codespeak.net
arigo at codespeak.net
Sun Feb 11 22:05:42 CET 2007
Author: arigo
Date: Sun Feb 11 22:05:41 2007
New Revision: 38523
Modified:
pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
pypy/dist/pypy/interpreter/astcompiler/symbols.py
Log:
Try harder to generate the correct SyntaxError in case of 'return arg'
and 'yield arg' in the same function.
Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py Sun Feb 11 22:05:41 2007
@@ -1096,8 +1096,6 @@
if node.value is None:
self.emitop_obj('LOAD_CONST', self.space.w_None)
else:
- if self.scope.generator:
- raise SyntaxError("'return' with argument inside generator")
node.value.accept( self )
self.emit('RETURN_VALUE')
@@ -1407,6 +1405,10 @@
self.graph.setCellVars(self.scope.get_cell_vars())
if self.scope.generator:
self.graph.setFlag(CO_GENERATOR)
+ if self.scope.return_with_arg is not None:
+ node = self.scope.return_with_arg
+ raise SyntaxError("'return' with argument inside generator",
+ node.lineno)
class GenExprCodeGenerator(AbstractFunctionCode):
Modified: pypy/dist/pypy/interpreter/astcompiler/symbols.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/symbols.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/symbols.py Sun Feb 11 22:05:41 2007
@@ -64,7 +64,7 @@
self.varroles[name] = ROLE_GLOBAL
return prevrole
- def add_return(self):
+ def add_return(self, node):
raise SyntaxError("'return' outside function")
def add_yield(self):
@@ -217,6 +217,7 @@
class FunctionScope(Scope):
generator = False
+ return_with_arg = None # or the node
def add_param(self, name):
name = self.mangle(name)
@@ -225,8 +226,11 @@
raise SyntaxError(msg)
self.varroles[name] = ROLE_PARAM
- def add_return(self):
- pass
+ def add_return(self, node):
+ if node.value is not None:
+ # record the first 'return expr' that we see, for error checking
+ if self.return_with_arg is None:
+ self.return_with_arg = node
def add_yield(self):
self.generator = True
@@ -563,7 +567,7 @@
def visitReturn(self, node):
scope = self.cur_scope()
- scope.add_return()
+ scope.add_return(node)
if node.value is not None:
node.value.accept(self)
More information about the Pypy-commit
mailing list