[pypy-svn] r18160 - pypy/dist/pypy/interpreter/astcompiler
ac at codespeak.net
ac at codespeak.net
Tue Oct 4 19:32:26 CEST 2005
Author: ac
Date: Tue Oct 4 19:32:25 2005
New Revision: 18160
Modified:
pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
pypy/dist/pypy/interpreter/astcompiler/symbols.py
Log:
Refactor finding incorrect returns
Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py Tue Oct 4 19:32:25 2005
@@ -1006,8 +1006,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.lineno)
node.value.accept( self )
self.emit('RETURN_VALUE')
Modified: pypy/dist/pypy/interpreter/astcompiler/symbols.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/symbols.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/symbols.py Tue Oct 4 19:32:25 2005
@@ -31,6 +31,7 @@
# i.e. if it is nested within another function.
self.nested = 0
self.generator = False
+ self.firstReturnWithArgument = None
self.klass = None
if klass is not None:
for i in range(len(klass)):
@@ -232,7 +233,7 @@
self.klass = None
self.scope_stack = []
self.assign_stack = [ False ]
-
+
def cur_assignment(self):
return self.assign_stack[-1]
@@ -303,7 +304,6 @@
self.handle_free_vars(scope, parent)
def visitGenExprInner(self, node ):
- #scope = self.cur_scope()
for genfor in node.quals:
genfor.accept( self )
@@ -483,23 +483,27 @@
# prune if statements if tests are false
- def visitIf(self, node ):
- for test, body in node.tests:
- if isinstance(test, ast.Const):
- if not self.space.is_true(test.value):
- continue
- test.accept( self )
- body.accept( self )
- if node.else_:
- node.else_.accept( self )
-
# a yield statement signals a generator
def visitYield(self, node ):
scope = self.cur_scope()
scope.generator = True
+ if scope.firstReturnWithArgument is not None:
+ raise SyntaxError("'return' with argument inside generator",
+ scope.firstReturnWithArgument.lineno)
+
node.value.accept( self )
-
+
+ def visitReturn(self, node):
+ scope = self.cur_scope()
+ if node.value is not None:
+ if scope.generator:
+ raise SyntaxError("'return' with argument inside generator",
+ node.lineno)
+ if scope.firstReturnWithArgument is None:
+ scope.firstReturnWithArgument = node
+ node.value.accept(self)
+
def sort(l):
l = l[:]
l.sort()
More information about the Pypy-commit
mailing list