changeset 46:53d7060adc77

Implemented subtraction.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 26 May 2009 16:13:42 +0200
parents d16b44bf5ca2
children 961d8bf9b00c
files pysmcl/range_analysis.py pysmcl/test/unit/test_rangeanalysis.py
diffstat 2 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/range_analysis.py	Tue May 26 16:10:07 2009 +0200
+++ b/pysmcl/range_analysis.py	Tue May 26 16:13:42 2009 +0200
@@ -93,6 +93,15 @@
                 r1 = Bottom()
             return (r0, r1)
 
+        if isinstance(node.op, ast.Sub):
+            r0 = left[0] - right[0]
+            r1 = left[1] - right[1]
+            if r0 < 0:
+                r0 = Bottom()
+            if r1 < 0:
+                r1 = Bottom()
+            return (r0, r1)
+
         if isinstance(node.op, ast.Mult):
             r0 = left[0] * right[0]
             r1 = left[1] * right[1]
--- a/pysmcl/test/unit/test_rangeanalysis.py	Tue May 26 16:10:07 2009 +0200
+++ b/pysmcl/test/unit/test_rangeanalysis.py	Tue May 26 16:13:42 2009 +0200
@@ -65,23 +65,24 @@
         r = prog.body[0].body[2].out_values["range"]
         self.assertEquals(r, {'y': (3, 3), 'x': (3, 3), 'z': (Bottom(), Bottom())})
 
-#     def test_range_minus(self):
-#         p = 7
-#         prog = parse("def f(x):\n\tx=3\n\ty=2\n\tz=x-y\n")
-#         init_statements(prog)
-#         range_analysis = RangeAnalysis(p)
-#         range_analysis.visit(prog.body[0])
-#         r = range_analysis.result
-#         self.assertEquals(r, {'z': (1, 1)})
+    def test_range_minus(self):
+        p = 7
+        prog = parse("def f(x):\n\tx=3\n\ty=2\n\tz=x-y\n")
+        init_statements(prog)
+        range_analysis = RangeAnalysis(p)
+        range_analysis.apply(prog.body[0])
+        r = range_analysis.result
+        r = prog.body[0].body[2].out_values["range"]
+        self.assertEquals(r, {'y': (2, 2), 'x': (3, 3), 'z': (1, 1)})
 
-#     def test_range_minus_wrap(self):
-#         p = 7
-#         prog = parse("def f(x):\n\tx=3\n\ty=4\n\tz=x-y\n")
-#         init_statements(prog)
-#         range_analysis = RangeAnalysis(p)
-#         range_analysis.visit(prog.body[0])
-#         r = range_analysis.result
-#         self.assertEquals(r, {'z': (Bottom(), Bottom())})
+    def test_range_minus_wrap(self):
+        p = 7
+        prog = parse("def f(x):\n\tx=3\n\ty=4\n\tz=x-y\n")
+        init_statements(prog)
+        range_analysis = RangeAnalysis(p)
+        range_analysis.apply(prog.body[0])
+        r = prog.body[0].body[2].out_values["range"]
+        self.assertEquals(r, {'y': (4, 4), 'x': (3, 3), 'z': (Bottom(), Bottom())})
 
 #     def test_range_equals(self):
 #         p = 7