[pypy-svn] rev 2227 - in pypy/trunk/src/pypy: objspace/flow translator

arigo at codespeak.net arigo at codespeak.net
Wed Nov 19 18:38:23 CET 2003


Author: arigo
Date: Wed Nov 19 18:38:23 2003
New Revision: 2227

Modified:
   pypy/trunk/src/pypy/objspace/flow/objspace.py
   pypy/trunk/src/pypy/translator/genpyrex.py
Log:
Yup! Finally got rid of the awful 'next_and_flag' operation.  Now it is,
expectedly, just a 'next' that can raise a StopIteration.


Modified: pypy/trunk/src/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/objspace.py	Wed Nov 19 18:38:23 2003
@@ -96,13 +96,14 @@
         return context.guessbool(w_truthvalue)
 
     def next(self, w_iter):
-        w_tuple = self.do_operation("next_and_flag", w_iter)
-        w_flag = self.do_operation("getitem", w_tuple, Constant(1))
+        w_item = self.do_operation("next", w_iter)
+        w_curexc = self.do_operation('exception', w_item)
         context = self.getexecutioncontext()
-        if context.guessbool(w_flag):
-            return self.do_operation("getitem", w_tuple, Constant(0))
-        else:
+        outcome = context.guessbool(w_curexc, [None, StopIteration])
+        if outcome is StopIteration:
             raise NoValue
+        else:
+            return w_item
 
 # ______________________________________________________________________
 

Modified: pypy/trunk/src/pypy/translator/genpyrex.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genpyrex.py	(original)
+++ pypy/trunk/src/pypy/translator/genpyrex.py	Wed Nov 19 18:38:23 2003
@@ -50,15 +50,15 @@
 
         return "%s = %s(%s)" % (self.resultname, self.op.opname, ", ".join(self.argnames)) 
     
-    def op_next_and_flag(self):
+    def op_next(self):
         lines = []
         args = self.argnames
         lines.append("try:")
-        lines.append("  _nextval = %s.next()" % args[0])
+        lines.append("  %s = %s.next()" % (self.resultname, args[0]))
         lines.append("except StopIteration:")
-        lines.append("  %s = None, 0" % self.resultname)
+        lines.append("  last_exc = StopIteration")
         lines.append("else:")
-        lines.append("  %s = _nextval, 1" % self.resultname)
+        lines.append("  last_exc = None")
         return "\n".join(lines)
 
     def op_getitem(self):
@@ -134,10 +134,7 @@
         return "%s = not not %s" % (self.resultname, self.argnames[0])
 
     def op_exception(self):
-        # Cheat!  This cannot really detect an exception because any
-        # exception would already have been raised by Pyrex in the previous
-        # instructions.
-        return "%s = None #exception(%s)" % (self.resultname, self.argnames[0])
+        return "%s, last_exc = last_exc, None" % (self.resultname,)
 
 class GenPyrex:
     def __init__(self, functiongraph):
@@ -178,6 +175,7 @@
         currentlines = self.lines
         self.lines = []
         self.indent += 1 
+        self.putline("last_exc = None")
         self.gen_block(fun.startblock)
         self.indent -= 1
         # emit the header after the body


More information about the Pypy-commit mailing list