changeset 231:a096603611ba

range_analysis: range is now not including the upper bound
author Sigurd Meldgaard Mon, 04 Jan 2010 12:54:47 +0100 0d4a1589f475 3a5b4f442381 pysmcl/range_analysis.py 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
```--- a/pysmcl/range_analysis.py	Mon Jan 04 12:34:09 2010 +0100
+++ b/pysmcl/range_analysis.py	Mon Jan 04 12:54:47 2010 +0100
@@ -5,6 +5,7 @@
range in a given function. A range is represented as a tuple of two
numbers or the bottom element.
"""
+import numbers
import pysmcl.ast_wrapper as ast
from pysmcl import flow
import pysmcl.setup as setup
@@ -60,6 +61,12 @@
covered by that of other. """
return self.a >= other.a and self.b <= other.b

+    def __sub__(self, other):
+        if(isinstance(other, numbers.Number)):
+            return Range(self[0] - other, self[1] - other)
+        else:
+            raise NotImplemented
+
def __eq__(self, other):
if isinstance(other, Bottom):
return False
@@ -112,6 +119,12 @@
"""Combining with bottom yields bottom"""
return self

+    def __sub__(self, other):
+        if(isinstance(other, numbers.Number)):
+            return self
+        else:
+            raise NotImplemented
+
def __repr__(self):
return "_|_"

@@ -357,10 +370,10 @@
if node.func.id == "range":
if(len(node.args) > 1):
lower = self.visit(node.args[0])
-                return lower.combine(self.visit(node.args[1]))
+                return lower.combine(self.visit(node.args[1]) - 1)
else:
lower = Range(0, 0)
-                return lower.combine(self.visit(node.args[0]))
+                return lower.combine(self.visit(node.args[0]) - 1)
if node.func.id == "random_bit":
return Range(0, 1)
return full_range(self.prime)```