Commits

Hakan Ardo  committed e69dd4c

allow more compilcated datastructures to be formed

  • Participants
  • Parent commits 8e58b84
  • Branches jit-usable_retrace_3

Comments (0)

Files changed (1)

File pypy/jit/metainterp/test/test_random_loops.py

 from pypy.jit.metainterp.test.support import LLJitMixin
-from pypy.rlib.jit import JitDriver
+from pypy.rlib.jit import JitDriver, unroll_safe
 from random import choice, randrange
 from pypy.rlib.rarithmetic import ovfcheck
 import re
 
     def value(self):
         return self.val
+    
+    final_value = value
 
     def add(self, other):
         try:
     def eq(self, other):
         return IntBox(self.value() == other.value())
 
+    def set_left(self, val):
+        self.val = val.value()
+        
+    def set_right(self, val):
+        self.val = val.value()
+        
+    def get_right(self):
+        return self
+    
+    def get_left(self):
+        return self
+                    
+class PairBox(IntBox):
+    def __init__(self, left, right):
+        self.left = left
+        self.right = right
+        self._inlist = False
+        
+    def final_value(self):
+        sa = i = 0
+        all_nodes = [self]
+        while i < len(all_nodes):
+            node = all_nodes[i]
+            i += 1            
+            if isinstance(node, PairBox):
+                if node._inlist:
+                    continue
+                node._inlist = True
+                all_nodes.append(node.left)
+                all_nodes.append(node.right)
+            else:
+                sa ^= node.value()
+        for node in all_nodes:
+            if isinstance(node, PairBox):
+                node._inlist = False
+        return sa
+            
+    @unroll_safe
+    def value(self):
+        node = self
+        for i in xrange(5):
+            if isinstance(node, PairBox):
+                node = node.left
+            else:
+                return node.value()
+        return 0
+            
+    def set_left(self, val):
+        self.left = val
+        
+    def set_right(self, val):
+        self.right = val
+    
+    def get_right(self):
+        return self.right
+    
+    def get_left(self):
+        return self.left
+
 
 class UnknonwOpCode(Exception):
     pass
                         pc += offsets[pc]
                 elif op == ')':
                     value = IntBox(0)
+                elif op == 'P':
+                    value = PairBox(prev, value)
+                elif op == 'l':
+                    value = value.get_left()
+                elif op == 'r':
+                    value = value.get_right()
+                elif op == 'L':
+                    prev.set_left(value)
+                elif op == 'R':
+                    prev.set_right(value)
                 else:
                     raise UnknonwOpCode
 
                 prev = current
                 pc += 1
-            return a.value(), b.value(), c.value(), d.value(), e.value()
+            return a.final_value(), b.final_value(), c.final_value(), d.final_value(), e.final_value()
         
         obj = interpreter(*args)
         expected = {'a': obj[0], 'b': obj[1], 'c': obj[2], 'd': obj[3], 'e': obj[4]}
         return choice([self.variable, self.constant])()
 
     def binop(self):
-        return self.value() + self.value() + choice('+-') + self.variable().upper()
+        return self.value() + self.value() + choice('+-P') + self.variable().upper()
 
     def break_loop(self):
         return 'x'
 
     def compare(self):
         return self.value() + self.value() + choice('<>=')
+    
+    def setitem(self):
+        return self.value() + self.variable() + choice('LR')
+    
+    def getitem(self):
+        return self.variable() + choice('lr') + self.variable().uppder()
 
     def while_loop(self):
         self.levels -= 1
     def test_overflow(self):
         self.check('9A{aa+A}', max_back_jumps=100)
         self.check('09-A{aa+A}', max_back_jumps=100)
+        
+    def test_pair(self):
+        self.check('12PA', a=3)
+        self.check('12PAa1R', a=0)
+        self.check('12PAa2L', a=0)
+        self.check('12PAalBarC', a=3, b=1, c=2)
+        self.check('12PA3Bab+EelCerD', a=3, b=3, c=4, d=4)
+        self.check('12PA3Bab-EelCerD', a=3, b=3, c=-2, d=-2)
+
+    def test_recursive_pair(self):
+        self.check('12PAaaR3Bab+Caa+DaE', a=1, b=3, c=4, d=2, e=1)
+        
+    def test_huge_pair(self):
+        self.check('1A{1BabPAa()}', max_back_jumps=1000, a=1)
 
     def test_failure1(self):
         self.check('{{7d<(37>(c6-A{a6>n(x)5b<()(bb+Bea-A){7d>n(x)1e+A7d-B3d+E35+Eac-B2b<(04+Cxe8+D9d+C)(){c6<n(x)ad+B6a+Cx20-Cce+Ac8-D}}{b9>n(x)a5=(2c+E)(xxe9-A)ec>(b7-A40+Ce0-Cx06-A)(xc0-Ad2-A1e+B0d+Bx09+B0b-D)}be-Ab7=(3a+Ab7-Dde<(x))(ec+Cd4+D5d<(x10+A)(cb-Cb9-C))59<(2b-C00-Ab0<(bc-Bde+Bxa2-E4d+A))(e7+Eb3<(c4-Bxx)59-C7c+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