[pypy-svn] r12278 - pypy/dist/pypy/objspace/flow

pedronis at codespeak.net pedronis at codespeak.net
Sun May 15 03:38:56 CEST 2005


Author: pedronis
Date: Sun May 15 03:38:56 2005
New Revision: 12278

Modified:
   pypy/dist/pypy/objspace/flow/flowcontext.py
   pypy/dist/pypy/objspace/flow/objspace.py
Log:
attach a constant exception type too as .last_exception to exception links; propagate it

fix some last cases where the graph could contain not normalized exception, StopIteration case and ValueError from unpacking


 


Modified: pypy/dist/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/dist/pypy/objspace/flow/flowcontext.py	Sun May 15 03:38:56 2005
@@ -20,11 +20,13 @@
 
 
 class SpamBlock(Block):
-    dead = False
-      
+    
+    __slots__ = "dead framestate".split()
+
     def __init__(self, framestate):
         Block.__init__(self, framestate.getvariables())
         self.framestate = framestate
+        self.dead = False
 
     def patchframe(self, frame):
         if self.dead:
@@ -35,6 +37,8 @@
 
 class EggBlock(Block):
 
+    __slots__ = "prevblock booloutcome last_exception".split()
+
     def __init__(self, inputargs, prevblock, booloutcome):
         Block.__init__(self, inputargs)
         self.prevblock = prevblock
@@ -55,6 +59,9 @@
             prevblock = block
         return recorder
 
+    def extravars(self, last_exception=None, last_exc_value=None):
+        self.last_exception = last_exception
+
 # ____________________________________________________________
 
 class Recorder:
@@ -117,18 +124,17 @@
             elif replace_last_variable_except_in_first_case is not None:
                 assert block.operations[-1].result is bvars[-1]
                 vars = bvars[:-1]
-                for name in replace_last_variable_except_in_first_case:
-                    newvar = Variable(name)
+                vars2 = bvars[:-1]
+                for name, newvar in replace_last_variable_except_in_first_case(case):
                     attach[name] = newvar
                     vars.append(newvar)
-                vars2 = bvars[:-1]
-                while len(vars2) < len(vars):
                     vars2.append(Variable())
             egg = EggBlock(vars2, block, case)
             ec.pendingblocks.append(egg)
             link = Link(vars, egg, case)
             if attach:
                 link.extravars(**attach)
+                egg.extravars(**attach) # xxx
             links.append(link)
 
         block.exitswitch = w_condition
@@ -218,15 +224,23 @@
         return self.recorder.guessbool(self, w_condition, **kwds)
 
     def guessexception(self, *classes):
+        def replace_exc_values(case):
+            if case is not Exception:
+                yield 'last_exception', Constant(case)
+                yield 'last_exc_value', Variable('last_exc_value')
+            else:
+                yield 'last_exception', Variable('last_exception')
+                yield 'last_exc_value', Variable('last_exc_value')
         outcome = self.guessbool(Constant(last_exception),
                                  cases = [None] + list(classes),
-                                 replace_last_variable_except_in_first_case = [
-                                     'last_exception',   # exc. class
-                                     'last_exc_value'])  # exc. value
+                                 replace_last_variable_except_in_first_case = replace_exc_values)
         if outcome is None:
             w_exc_cls, w_exc_value = None, None
         else:
-            w_exc_cls, w_exc_value = self.recorder.crnt_block.inputargs[-2:]
+            egg = self.recorder.crnt_block
+            w_exc_cls, w_exc_value = egg.inputargs[-2:]
+            if isinstance(egg.last_exception, Constant):
+                w_exc_cls = egg.last_exception
         return outcome, w_exc_cls, w_exc_value
 
     def build_flow(self):
@@ -263,6 +277,7 @@
                 self.recorder.crnt_block.closeblock(link)
 
             except OperationError, e:
+                print "OE", e.w_type, e.w_value
                 link = Link([e.w_type, e.w_value], self.graph.exceptblock)
                 self.recorder.crnt_block.closeblock(link)
 

Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py	(original)
+++ pypy/dist/pypy/objspace/flow/objspace.py	Sun May 15 03:38:56 2005
@@ -284,7 +284,9 @@
             w_len = self.len(w_iterable)
             w_correct = self.eq(w_len, self.wrap(expected_length))
             if not self.is_true(w_correct):
-                raise OperationError(self.w_ValueError, self.w_None)
+                e = OperationError(self.w_ValueError, self.w_None)
+                e.normalize_exception(self)
+                raise e
             return [self.do_operation('getitem', w_iterable, self.wrap(i)) 
                         for i in range(expected_length)]
         return ObjSpace.unpackiterable(self, w_iterable, expected_length)
@@ -313,7 +315,7 @@
         context = self.getexecutioncontext()
         outcome, w_exc_cls, w_exc_value = context.guessexception(StopIteration)
         if outcome is StopIteration:
-            raise OperationError(self.w_StopIteration, self.w_None)
+            raise OperationError(self.w_StopIteration, w_exc_value)
         else:
             return w_item
 
@@ -387,9 +389,10 @@
                 # we assume that the caught exc_cls will be exactly the
                 # one specified by 'outcome', and not a subclass of it,
                 # unless 'outcome' is Exception.
-                if outcome is not Exception:
-                    w_exc_cls = Constant(outcome)
-                raise flowcontext.ImplicitOperationError(w_exc_cls,
+                #if outcome is not Exception:
+                    #w_exc_cls = Constant(outcome) Now done by guessexception itself
+                    #pass
+                 raise flowcontext.ImplicitOperationError(w_exc_cls,
                                                          w_exc_value)
 
 # ______________________________________________________________________



More information about the Pypy-commit mailing list