changeset 41:74ee6ce00b8b

Added implementation of mult.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 26 May 2009 14:36:45 +0200
parents 95c5e9e0c5f8
children 43a8f007edcb
files pysmcl/range_analysis.py pysmcl/test/unit/test_rangeanalysis.py
diffstat 2 files changed, 27 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/range_analysis.py	Tue May 26 11:38:06 2009 +0200
+++ b/pysmcl/range_analysis.py	Tue May 26 14:36:45 2009 +0200
@@ -91,6 +91,7 @@
 #                  | RShift | BitOr | BitXor | BitAnd | FloorDiv
         left = self.visit(node.left)
         right = self.visit(node.right)
+
         if isinstance(node.op, ast.Add):
             r0 = left[0] + right[0]
             r1 = left[1] + right[1]
@@ -99,6 +100,15 @@
             if r1 >= self.prime:
                 r1 = Bottom()
             return (r0, r1)
+
+        if isinstance(node.op, ast.Mult):
+            r0 = left[0] * right[0]
+            r1 = left[1] * right[1]
+            if r0 >= self.prime:
+                r0 = Bottom()
+            if r1 >= self.prime:
+                r1 = Bottom()
+            return (r0, r1)
         raise Exception("Operator not implemented.") 
 
 class TargetVisitor(ast.NodeVisitor):
--- a/pysmcl/test/unit/test_rangeanalysis.py	Tue May 26 11:38:06 2009 +0200
+++ b/pysmcl/test/unit/test_rangeanalysis.py	Tue May 26 14:36:45 2009 +0200
@@ -47,23 +47,24 @@
         r = prog.body[0].body[2].out_values["range"]
         self.assertEquals(r, {'y': (2, 2), 'x': (6, 6), 'z': (Bottom(), Bottom())})
 
-#     def test_range_mul(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': (6, 6)})
+    def test_range_mul(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 = prog.body[0].body[2].out_values["range"]
+        self.assertEquals(r, {'y': (2, 2), 'x': (3, 3), 'z': (6, 6)})
 
-#     def test_range_mul_wrap(self):
-#         p = 7
-#         prog = parse("def f(x):\n\tx=3\n\ty=3\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_mul_wrap(self):
+        p = 7
+        prog = parse("def f(x):\n\tx=3\n\ty=3\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': (3, 3), 'x': (3, 3), 'z': (Bottom(), Bottom())})
+
 
 #     def test_range_minus(self):
 #         p = 7