changeset 53:52e6dad22cf5

Corrected subtraction range analysis
author Sigurd Meldgaard <stm@daimi.au.dk>
date Tue, 26 May 2009 17:01:07 +0200
parents add1aa244d26
children 996d9e5da978
files pysmcl/range_analysis.py
diffstat 1 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/range_analysis.py	Tue May 26 16:53:55 2009 +0200
+++ b/pysmcl/range_analysis.py	Tue May 26 17:01:07 2009 +0200
@@ -6,7 +6,7 @@
 debug = False
 
 class Bottom(object):
-    
+
     def __eq__(self, other):
         if other is not None:
             return isinstance(other, Bottom)
@@ -49,7 +49,7 @@
                 for target in node.targets:
                     targetVisitor.visit(target)
                 return env
-           
+
             def visit_FunctionDef(self, node):
                 for arg in node.args.args:
                     env[arg.id] = (0, self.prime)
@@ -68,7 +68,7 @@
 
 def range(prime, node, env):
     rangeVisitor = RangeVisitor(prime, env)
-    return rangeVisitor.visit(node)        
+    return rangeVisitor.visit(node)
 
 class RangeVisitor(ast.NodeVisitor):
 
@@ -85,7 +85,7 @@
         return (0, self.prime)
 
     def visit_BinOp(self, node):
-        # operator = Add | Sub | Mult | Div | Mod | Pow | LShift 
+        # operator = Add | Sub | Mult | Div | Mod | Pow | LShift
         #          | RShift | BitOr | BitXor | BitAnd | FloorDiv
         left = self.visit(node.left)
         right = self.visit(node.right)
@@ -100,8 +100,8 @@
             return (r0, r1)
 
         if isinstance(node.op, ast.Sub):
-            r0 = left[0] - right[0]
-            r1 = left[1] - right[1]
+            r0 = left[0] - right[1]
+            r1 = left[1] - right[0]
             if r0 < 0:
                 r0 = Bottom()
             if r1 < 0:
@@ -116,7 +116,7 @@
             if r1 >= self.prime:
                 r1 = Bottom()
             return (r0, r1)
-        raise Exception("Operator not implemented: ", node.op) 
+        raise Exception("Operator not implemented: ", node.op)
 
     def visit_Compare(self, node):
         # cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
@@ -131,7 +131,7 @@
         return (0, self.prime)
 
 class TargetVisitor(ast.NodeVisitor):
-    """The following expression can appear in assignment context """                         
+    """The following expression can appear in assignment context """
 
     def __init__(self, env, range):
         self.env = env
@@ -178,5 +178,5 @@
     if h1 > h2:
         r[1] = h1
     else:
-        r[1] = h2    
+        r[1] = h2
     return r