changeset 236:e1442a016352

range_analysis: finally got rid of that prime
author Sigurd Meldgaard <stm@daimi.au.dk>
date Tue, 05 Jan 2010 11:13:34 +0100
parents b84406fbb267
children 95721959e087
files pysmcl/range_analysis.py
diffstat 1 files changed, 14 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/range_analysis.py	Mon Jan 04 14:08:57 2010 +0100
+++ b/pysmcl/range_analysis.py	Tue Jan 05 11:13:34 2010 +0100
@@ -144,9 +144,8 @@
     # The key used in the flow framework for our analysis
     key = "range"
 
-    def __init__(self, prime):
-        """prime (integer) defines the field of computation, Zp."""
-        self.prime = prime
+    def __init__(self):
+        pass
 
     def apply(self, function, initial_env = {}):
         """Perform the analysis
@@ -184,7 +183,7 @@
             if self.is_comparison(x.test):
                 a = dict(x.out_values[self.key])
                 old = a[x.test.left.id]
-                compared_value = RangeVisitor(self.prime,
+                compared_value = RangeVisitor(
                     x.out_values[self.key]).visit(x.test.comparators[0])
                 a[x.test.left.id] = (min(old[0], compared_value[1]),
                                          min(old[1], compared_value[1]))
@@ -204,8 +203,6 @@
           May be None if the env is uninitialized.
         """
 
-        prime = self.prime
-
         if debug:
             print "========= Combining ==========="
             print "Node, env", node, env
@@ -218,7 +215,7 @@
 
             def visit_Assign(self, node):
                 target = node.targets[0]
-                r = find_range(prime, node.value, env)
+                r = find_range(node.value, env)
                 if(isinstance(target, ast.Name)):
                     env[target.id] = r
                 elif(isinstance(target, ast.Subscript)):
@@ -229,7 +226,7 @@
 
             def visit_For(self, node):
                 target = node.target
-                r = find_range(prime, node.iter, env)
+                r = find_range(node.iter, env)
                 if(isinstance(target, ast.Name)):
                     env[target.id] = r
                 else:
@@ -255,7 +252,7 @@
                             break
                 for arg in node.args.args:
                     if not arg.id in param_range:
-                        env[arg.id] = full_range(prime)
+                        env[arg.id] = Bottom()
                     else:
                         env[arg.id] = param_range[arg.id]
                 return env
@@ -288,11 +285,11 @@
         return r
 
 
-def find_range(prime, node, env):
+def find_range(node, env):
     """range performs the computation of range of the given expression
     in node. Assuming that variables have values as in the env dict.
     """
-    rangeVisitor = RangeVisitor(prime, env)
+    rangeVisitor = RangeVisitor(env)
     return rangeVisitor.visit(node)
 
 
@@ -300,12 +297,10 @@
     """RangeVisitor is the visitor which actually implements the range
     computation."""
 
-    def __init__(self, prime, env):
+    def __init__(self, env):
         """
-        prime (integer) defines the field of computation, Zp.
         env (dict) An environment of variables and their range.
         """
-        self.prime = prime
         self.env = env
 
     def visit_Num(self, node):
@@ -314,16 +309,16 @@
     def visit_Name(self, node):
         if node.id in self.env.keys():
             return self.env[node.id]
-        return full_range(self.prime)
+        return Bottom()
 
     def visit_Subscript(self, node):
         if node.value.id in self.env.keys():
             return self.env[node.value.id]
-        return full_range(self.prime)
+        return Bottom()
 
     def visit_List(self, node):
         if node.elts == []:
-            return full_range(self.prime)
+            return Bottom()
         else:
             r = self.visit(node.elts[0])
             for i in node.elts[1:]:
@@ -369,7 +364,7 @@
         if node.func.id == "id":
             return Range(1, setup.nr_of_players)
         if node.func.id == "random":
-            return full_range(self.prime)
+            return Bottom()
         if node.func.id == "output":
             return self.visit(node.args[0])
         if node.func.id == "get":
@@ -383,7 +378,7 @@
                 return lower.combine(self.visit(node.args[0]) - 1)
         if node.func.id == "random_bit":
             return Range(0, 1)
-        return full_range(self.prime)
+        return Bottom()
 
 
 def combine_env(env1, env2):