[pypy-svn] r51941 - in pypy/branch/jit-refactoring/pypy/jit: rainbow/test timeshifter/test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Feb 29 11:38:54 CET 2008


Author: cfbolz
Date: Fri Feb 29 11:38:53 2008
New Revision: 51941

Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py
Log:
moving over the remaining interpretation test


Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	Fri Feb 29 11:38:53 2008
@@ -1113,7 +1113,6 @@
         self.check_insns({'int_mul': 1, 'int_add': 1, 'int_sub': 1})
 
     def test_green_red_mismatch_in_call(self):
-        #py.test.skip("WIP")
         def add(a,b, u):
             return a+b
 
@@ -1126,5 +1125,605 @@
         res = self.interpret(f, [4, 5, 0], [], policy=P_NOVIRTUAL)
         assert res == 20
 
+
+    def test_recursive_with_red_termination_condition(self):
+        py.test.skip('Does not terminate')
+        def ll_factorial(n):
+            if n <= 0:
+                return 1
+            return n * ll_factorial(n - 1)
+
+        res = self.interpret(ll_factorial, [5], [])
+        assert res == 120
+        
+    def test_simple_indirect_call(self):
+        def g1(v):
+            return v * 2
+
+        def g2(v):
+            return v + 2
+
+        def f(flag, v):
+            if hint(flag, concrete=True):
+                g = g1
+            else:
+                g = g2
+            return g(v)
+
+        res = self.interpret(f, [0, 40], [0])
+        assert res == 42
+        self.check_insns({'int_add': 1})
+
+    def test_normalize_indirect_call(self):
+        def g1(v):
+            return -17
+
+        def g2(v):
+            return v + 2
+
+        def f(flag, v):
+            if hint(flag, concrete=True):
+                g = g1
+            else:
+                g = g2
+            return g(v)
+
+        res = self.interpret(f, [0, 40], [0])
+        assert res == 42
+        self.check_insns({'int_add': 1})
+
+        res = self.interpret(f, [1, 40], [0])
+        assert res == -17
+        self.check_insns({})
+
+    def test_normalize_indirect_call_more(self):
+        py.test.skip("not working yet")
+        def g1(v):
+            if v >= 0:
+                return -17
+            else:
+                return -155
+
+        def g2(v):
+            return v + 2
+
+        def f(flag, v):
+            w = g1(v)
+            if hint(flag, concrete=True):
+                g = g1
+            else:
+                g = g2
+            return g(v) + w
+
+        res = self.interpret(f, [0, 40], [0])
+        assert res == 25
+        self.check_insns({'int_add': 2, 'int_ge': 1})
+
+        res = self.interpret(f, [1, 40], [0])
+        assert res == -34
+        self.check_insns({'int_ge': 2, 'int_add': 1})
+
+        res = self.interpret(f, [0, -1000], [0])
+        assert res == f(False, -1000)
+        self.check_insns({'int_add': 2, 'int_ge': 1})
+
+        res = self.interpret(f, [1, -1000], [0])
+        assert res == f(True, -1000)
+        self.check_insns({'int_ge': 2, 'int_add': 1})
+
+    def test_green_char_at_merge(self):
+        def f(c, x):
+            c = chr(c)
+            c = hint(c, concrete=True)
+            if x:
+                x = 3
+            else:
+                x = 1
+            c = hint(c, variable=True)
+            return len(c*x)
+
+        res = self.interpret(f, [ord('a'), 1], [], policy=P_NOVIRTUAL)
+        assert res == 3
+
+        res = self.interpret(f, [ord('b'), 0], [], policy=P_NOVIRTUAL)
+        assert res == 1
+
+    def test_self_referential_structures(self):
+        py.test.skip("not working yet")
+        S = lltype.GcForwardReference()
+        S.become(lltype.GcStruct('s',
+                                 ('ps', lltype.Ptr(S))))
+
+        def f(x):
+            s = lltype.malloc(S)
+            if x:
+                s.ps = lltype.malloc(S)
+            return s
+        def count_depth(s):
+            x = 0
+            while s:
+                x += 1
+                s = s.ps
+            return str(x)
+        
+        f.convert_result = count_depth
+
+        res = self.interpret(f, [3], [], policy=P_NOVIRTUAL)
+        assert res == '2'
+
+    def test_known_nonzero(self):
+        S = lltype.GcStruct('s', ('x', lltype.Signed))
+        global_s = lltype.malloc(S, immortal=True)
+        global_s.x = 100
+
+        def h():
+            s = lltype.malloc(S)
+            s.x = 50
+            return s
+        def g(s, y):
+            if s:
+                return s.x * 5
+            else:
+                return -12 + y
+        def f(x, y):
+            x = hint(x, concrete=True)
+            if x == 1:
+                return g(lltype.nullptr(S), y)
+            elif x == 2:
+                return g(global_s, y)
+            elif x == 3:
+                s = lltype.malloc(S)
+                s.x = y
+                return g(s, y)
+            elif x == 4:
+                s = h()
+                return g(s, y)
+            else:
+                s = h()
+                if s:
+                    return g(s, y)
+                else:
+                    return 0
+
+        P = StopAtXPolicy(h)
+
+        res = self.interpret(f, [1, 10], [0], policy=P)
+        assert res == -2
+        self.check_insns(int_mul=0, int_add=1)
+
+        res = self.interpret(f, [2, 10], [0], policy=P)
+        assert res == 500
+        self.check_insns(int_mul=1, int_add=0)
+
+        res = self.interpret(f, [3, 10], [0], policy=P)
+        assert res == 50
+        self.check_insns(int_mul=1, int_add=0)
+
+        res = self.interpret(f, [4, 10], [0], policy=P)
+        assert res == 250
+        self.check_insns(int_mul=1, int_add=1)
+
+        res = self.interpret(f, [5, 10], [0], policy=P)
+        assert res == 250
+        self.check_insns(int_mul=1, int_add=0)
+
+    def test_debug_assert_ptr_nonzero(self):
+        py.test.skip("not working yet")
+        S = lltype.GcStruct('s', ('x', lltype.Signed))
+        def h():
+            s = lltype.malloc(S)
+            s.x = 42
+            return s
+        def g(s):
+            # assumes that s is not null here
+            ll_assert(bool(s), "please don't give me a null")
+            return 5
+        def f(m):
+            s = h()
+            n = g(s)
+            if not s:
+                n *= m
+            return n
+
+        P = StopAtXPolicy(h)
+
+        res = self.interpret(f, [17], [], policy=P)
+        assert res == 5
+        self.check_insns(int_mul=0)
+
+    def test_indirect_red_call(self):
+        def h1(n):
+            return n*2
+        def h2(n):
+            return n*4
+        l = [h1, h2]
+        def f(n, x):
+            h = l[n&1]
+            return h(n) + x
+
+        P = StopAtXPolicy()
+        res = self.interpret(f, [7, 3], policy=P)
+        assert res == f(7,3)
+        self.check_insns(indirect_call=1, direct_call=1)
+
+    def test_indirect_red_call_with_exc(self):
+        def h1(n):
+            if n < 0:
+                raise ValueError
+            return n*2
+        def h2(n):
+            if n < 0:
+                raise ValueError
+            return n*4
+        l = [h1, h2]
+        def g(n, x):
+            h = l[n&1]
+            return h(n) + x
+
+        def f(n, x):
+            try:
+                return g(n, x)
+            except ValueError:
+                return -1111
+
+        P = StopAtXPolicy()
+        res = self.interpret(f, [7, 3], policy=P)
+        assert res == f(7,3)
+        self.check_insns(indirect_call=1)
+
+        res = self.interpret(f, [-7, 3], policy=P)
+        assert res == -1111
+        self.check_insns(indirect_call=1)
+
+    def test_indirect_gray_call(self):
+        py.test.skip("not working yet")
+        def h1(w, n):
+            w[0] =  n*2
+        def h2(w, n):
+            w[0] = n*4
+        l = [h1, h2]
+        def f(n, x):
+            w = [0]
+            h = l[n&1]
+            h(w, n)
+            return w[0] + x
+
+        P = StopAtXPolicy()
+        res = self.interpret(f, [7, 3], policy=P)
+        assert res == f(7,3)
+
+    def test_indirect_residual_red_call(self):
+        py.test.skip("not working yet")
+        def h1(n):
+            return n*2
+        def h2(n):
+            return n*4
+        l = [h1, h2]
+        def f(n, x):
+            h = l[n&1]
+            return h(n) + x
+
+        P = StopAtXPolicy(h1, h2)
+        res = self.interpret(f, [7, 3], policy=P)
+        assert res == f(7,3)
+        self.check_insns(indirect_call=1)
+
+    def test_constant_indirect_red_call(self):
+        def h1(x):
+            return x-2
+        def h2(x):
+            return x*4
+        l = [h1, h2]
+        def f(n, x):
+            frozenl = hint(l, deepfreeze=True)
+            h = frozenl[n&1]
+            return h(x)
+
+        P = StopAtXPolicy()
+        res = self.interpret(f, [7, 3], [0], policy=P)
+        assert res == f(7,3)
+        self.check_insns({'int_mul': 1})
+        res = self.interpret(f, [4, 113], [0], policy=P)
+        assert res == f(4,113)
+        self.check_insns({'int_sub': 1})
+
+    def test_indirect_sometimes_residual_pure_red_call(self):
+        def h1(x):
+            return x-2
+        def h2(x):
+            return x*4
+        l = [h1, h2]
+        def f(n, x):
+            hint(None, global_merge_point=True)
+            hint(n, concrete=True)
+            frozenl = hint(l, deepfreeze=True)
+            h = frozenl[n&1]
+            return h(x)
+
+        P = StopAtXPolicy(h1)
+        P.oopspec = True
+        res = self.interpret(f, [7, 3], [], policy=P)
+        assert res == f(7,3)
+        self.check_insns({'int_mul': 1})
+        res = self.interpret(f, [4, 113], [], policy=P)
+        assert res == f(4,113)
+        self.check_insns({'direct_call': 1})
+
+    def test_indirect_sometimes_residual_pure_but_fixed_red_call(self):
+        py.test.skip("not working yet")
+        def h1(x):
+            return x-2
+        def h2(x):
+            return x*4
+        l = [h1, h2]
+        def f(n, x):
+            hint(None, global_merge_point=True)
+            frozenl = hint(l, deepfreeze=True)
+            h = frozenl[n&1]
+            z = h(x)
+            hint(z, concrete=True)
+            return z
+
+        P = StopAtXPolicy(h1)
+        P.oopspec = True
+        res = self.interpret(f, [7, 3], [], policy=P)
+        assert res == f(7,3)
+        self.check_insns({})
+        res = self.interpret(f, [4, 113], [], policy=P)
+        assert res == f(4,113)
+        self.check_insns({})
+
+    def test_manual_marking_of_pure_functions(self):
+        py.test.skip("not working yet")
+        class A(object):
+            pass
+        class B(object):
+            pass
+        a1 = A()
+        a2 = A()
+        d = {}
+        def h1(b, s):
+            try:
+                return d[s]
+            except KeyError:
+                d[s] = r = A()
+                return r
+        h1._pure_function_ = True
+        b = B()
+        def f(n):
+            hint(None, global_merge_point=True)
+            hint(n, concrete=True)
+            if n == 0:
+                s = "abc"
+            else:
+                s = "123"
+            a = h1(b, s)
+            return hint(n, variable=True)
+
+        P = StopAtXPolicy(h1)
+        P.oopspec = True
+        res = self.interpret(f, [0], [], policy=P)
+        assert res == 0
+        self.check_insns({})
+        res = self.interpret(f, [4], [], policy=P)
+        assert res == 4
+        self.check_insns({})
+
+
+    def test_red_int_add_ovf(self):
+        py.test.skip("not working yet")
+        def f(n, m):
+            try:
+                return ovfcheck(n + m)
+            except OverflowError:
+                return -42
+
+        res = self.interpret(f, [100, 20])
+        assert res == 120
+        self.check_insns(int_add_ovf=1)
+        res = self.interpret(f, [sys.maxint, 1])
+        assert res == -42
+        self.check_insns(int_add_ovf=1)
+
+    def test_green_int_add_ovf(self):
+        py.test.skip("not working yet")
+        def f(n, m):
+            try:
+                res = ovfcheck(n + m)
+            except OverflowError:
+                res = -42
+            hint(res, concrete=True)
+            return res
+
+        res = self.interpret(f, [100, 20])
+        assert res == 120
+        self.check_insns({})
+        res = self.interpret(f, [sys.maxint, 1])
+        assert res == -42
+        self.check_insns({})
+
+    def test_nonzeroness_assert_while_compiling(self):
+        class X:
+            pass
+        class Y:
+            pass
+
+        def g(x, y):
+            if y.flag:
+                return x.value
+            else:
+                return -7
+
+        def h(n):
+            if n:
+                x = X()
+                x.value = n
+                return x
+            else:
+                return None
+
+        y = Y()
+
+        def f(n):
+            y.flag = True
+            g(h(n), y)
+            y.flag = False
+            return g(h(0), y)
+
+        res = self.interpret(f, [42], policy=P_NOVIRTUAL)
+        assert res == -7
+
+    def test_segfault_while_compiling(self):
+        class X:
+            pass
+        class Y:
+            pass
+
+        def g(x, y):
+            x = hint(x, deepfreeze=True)
+            if y.flag:
+                return x.value
+            else:
+                return -7
+
+        def h(n):
+            if n:
+                x = X()
+                x.value = n
+                return x
+            else:
+                return None
+
+        y = Y()
+
+        def f(n):
+            y.flag = True
+            g(h(n), y)
+            y.flag = False
+            return g(h(0), y)
+
+        res = self.interpret(f, [42], policy=P_NOVIRTUAL)
+        assert res == -7
+
+    def test_switch(self):
+        py.test.skip("not working yet")
+        def g(n):
+            if n == 0:
+                return 12
+            elif n == 1:
+                return 34
+            elif n == 3:
+                return 56
+            elif n == 7:
+                return 78
+            else:
+                return 90
+        def f(n, m):
+            x = g(n)   # gives a red switch
+            y = g(hint(m, concrete=True))   # gives a green switch
+            return x - y
+
+        res = self.interpret(f, [7, 2], backendoptimize=True)
+        assert res == 78 - 90
+        res = self.interpret(f, [8, 1], backendoptimize=True)
+        assert res == 90 - 34
+
+    def test_switch_char(self):
+        py.test.skip("not working yet")
+        def g(n):
+            n = chr(n)
+            if n == '\x00':
+                return 12
+            elif n == '\x01':
+                return 34
+            elif n == '\x02':
+                return 56
+            elif n == '\x03':
+                return 78
+            else:
+                return 90
+        def f(n, m):
+            x = g(n)   # gives a red switch
+            y = g(hint(m, concrete=True))   # gives a green switch
+            return x - y
+
+        res = self.interpret(f, [3, 0], backendoptimize=True)
+        assert res == 78 - 12
+        res = self.interpret(f, [2, 4], backendoptimize=True)
+        assert res == 56 - 90
+
+    def test_substitute_graph(self):
+        py.test.skip("not working yet")
+
+        class MetaG:
+            __metaclass__ = cachedtype
+
+            def __init__(self, hrtyper):
+                pass
+
+            def _freeze_(self):
+                return True
+
+            def metafunc(self, jitstate, space, mbox):
+                from pypy.jit.timeshifter.rvalue import IntRedBox
+                builder = jitstate.curbuilder
+                gv_result = builder.genop1("int_neg", mbox.getgenvar(jitstate))
+                return IntRedBox(mbox.kind, gv_result)
+
+        class Fz(object):
+            x = 10
+            
+            def _freeze_(self):
+                return True
+
+        def g(fz, m):
+            return m * fz.x
+
+        fz = Fz()
+
+        def f(n, m):
+            x = g(fz, n)
+            y = g(fz, m)
+            hint(y, concrete=True)
+            return x + g(fz, y)
+
+        class MyPolicy(HintAnnotatorPolicy):
+            novirtualcontainer = True
+            
+            def look_inside_graph(self, graph):
+                if graph.func is g:
+                    return MetaG   # replaces g with a meta-call to metafunc()
+                else:
+                    return True
+
+        res = self.interpret(f, [3, 6], policy=MyPolicy())
+        assert res == -3 + 600
+        self.check_insns({'int_neg': 1, 'int_add': 1})
+
+    def test_hash_of_green_string_is_green(self):
+        py.test.skip("unfortunately doesn't work")
+        def f(n):
+            if n == 0:
+                s = "abc"
+            elif n == 1:
+                s = "cde"
+            else:
+                s = "fgh"
+            return hash(s)
+
+        res = self.interpret(f, [0])
+        self.check_insns({'int_eq': 2})
+        assert res == f(0)
+
+    def test_misplaced_global_merge_point(self):
+        py.test.skip("not working yet")
+        def g(n):
+            hint(None, global_merge_point=True)
+            return n+1
+        def f(n):
+            hint(None, global_merge_point=True)
+            return g(n)
+        py.test.raises(AssertionError, self.interpret, f, [7], [])
+
 class TestLLType(SimpleTests):
     type_system = "lltype"

Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/test/test_timeshift.py	Fri Feb 29 11:38:53 2008
@@ -381,594 +381,7 @@
 
 
 class BaseTestTimeshift(TimeshiftingTests):
-
-
-
-    def test_recursive_with_red_termination_condition(self):
-        py.test.skip('Does not terminate')
-        def ll_factorial(n):
-            if n <= 0:
-                return 1
-            return n * ll_factorial(n - 1)
-
-        res = self.timeshift(ll_factorial, [5], [])
-        assert res == 120
-        
-    def test_simple_indirect_call(self):
-        def g1(v):
-            return v * 2
-
-        def g2(v):
-            return v + 2
-
-        def f(flag, v):
-            if hint(flag, concrete=True):
-                g = g1
-            else:
-                g = g2
-            return g(v)
-
-        res = self.timeshift(f, [0, 40], [0])
-        assert res == 42
-        self.check_insns({'int_add': 1})
-
-    def test_normalize_indirect_call(self):
-        def g1(v):
-            return -17
-
-        def g2(v):
-            return v + 2
-
-        def f(flag, v):
-            if hint(flag, concrete=True):
-                g = g1
-            else:
-                g = g2
-            return g(v)
-
-        res = self.timeshift(f, [0, 40], [0])
-        assert res == 42
-        self.check_insns({'int_add': 1})
-
-        res = self.timeshift(f, [1, 40], [0])
-        assert res == -17
-        self.check_insns({})
-
-    def test_normalize_indirect_call_more(self):
-        def g1(v):
-            if v >= 0:
-                return -17
-            else:
-                return -155
-
-        def g2(v):
-            return v + 2
-
-        def f(flag, v):
-            w = g1(v)
-            if hint(flag, concrete=True):
-                g = g1
-            else:
-                g = g2
-            return g(v) + w
-
-        res = self.timeshift(f, [0, 40], [0])
-        assert res == 25
-        self.check_insns({'int_add': 2, 'int_ge': 1})
-
-        res = self.timeshift(f, [1, 40], [0])
-        assert res == -34
-        self.check_insns({'int_ge': 2, 'int_add': 1})
-
-        res = self.timeshift(f, [0, -1000], [0])
-        assert res == f(False, -1000)
-        self.check_insns({'int_add': 2, 'int_ge': 1})
-
-        res = self.timeshift(f, [1, -1000], [0])
-        assert res == f(True, -1000)
-        self.check_insns({'int_ge': 2, 'int_add': 1})
-
-    def test_green_char_at_merge(self):
-        def f(c, x):
-            c = chr(c)
-            c = hint(c, concrete=True)
-            if x:
-                x = 3
-            else:
-                x = 1
-            c = hint(c, variable=True)
-            return len(c*x)
-
-        res = self.timeshift(f, [ord('a'), 1], [], policy=P_NOVIRTUAL)
-        assert res == 3
-
-        res = self.timeshift(f, [ord('b'), 0], [], policy=P_NOVIRTUAL)
-        assert res == 1
-
-    def test_self_referential_structures(self):
-        S = lltype.GcForwardReference()
-        S.become(lltype.GcStruct('s',
-                                 ('ps', lltype.Ptr(S))))
-
-        def f(x):
-            s = lltype.malloc(S)
-            if x:
-                s.ps = lltype.malloc(S)
-            return s
-        def count_depth(s):
-            x = 0
-            while s:
-                x += 1
-                s = s.ps
-            return str(x)
-        
-        f.convert_result = count_depth
-
-        res = self.timeshift(f, [3], [], policy=P_NOVIRTUAL)
-        assert res == '2'
-
-    def test_known_nonzero(self):
-        S = lltype.GcStruct('s', ('x', lltype.Signed))
-        global_s = lltype.malloc(S, immortal=True)
-        global_s.x = 100
-
-        def h():
-            s = lltype.malloc(S)
-            s.x = 50
-            return s
-        def g(s, y):
-            if s:
-                return s.x * 5
-            else:
-                return -12 + y
-        def f(x, y):
-            x = hint(x, concrete=True)
-            if x == 1:
-                return g(lltype.nullptr(S), y)
-            elif x == 2:
-                return g(global_s, y)
-            elif x == 3:
-                s = lltype.malloc(S)
-                s.x = y
-                return g(s, y)
-            elif x == 4:
-                s = h()
-                return g(s, y)
-            else:
-                s = h()
-                if s:
-                    return g(s, y)
-                else:
-                    return 0
-
-        P = StopAtXPolicy(h)
-
-        res = self.timeshift(f, [1, 10], [0], policy=P)
-        assert res == -2
-        self.check_insns(int_mul=0, int_add=1)
-
-        res = self.timeshift(f, [2, 10], [0], policy=P)
-        assert res == 500
-        self.check_insns(int_mul=1, int_add=0)
-
-        res = self.timeshift(f, [3, 10], [0], policy=P)
-        assert res == 50
-        self.check_insns(int_mul=1, int_add=0)
-
-        res = self.timeshift(f, [4, 10], [0], policy=P)
-        assert res == 250
-        self.check_insns(int_mul=1, int_add=1)
-
-        res = self.timeshift(f, [5, 10], [0], policy=P)
-        assert res == 250
-        self.check_insns(int_mul=1, int_add=0)
-
-    def test_debug_assert_ptr_nonzero(self):
-        S = lltype.GcStruct('s', ('x', lltype.Signed))
-        def h():
-            s = lltype.malloc(S)
-            s.x = 42
-            return s
-        def g(s):
-            # assumes that s is not null here
-            ll_assert(bool(s), "please don't give me a null")
-            return 5
-        def f(m):
-            s = h()
-            n = g(s)
-            if not s:
-                n *= m
-            return n
-
-        P = StopAtXPolicy(h)
-
-        res = self.timeshift(f, [17], [], policy=P)
-        assert res == 5
-        self.check_insns(int_mul=0)
-
-    def test_indirect_red_call(self):
-        def h1(n):
-            return n*2
-        def h2(n):
-            return n*4
-        l = [h1, h2]
-        def f(n, x):
-            h = l[n&1]
-            return h(n) + x
-
-        P = StopAtXPolicy()
-        res = self.timeshift(f, [7, 3], policy=P)
-        assert res == f(7,3)
-        self.check_insns(indirect_call=1, direct_call=1)
-
-    def test_indirect_red_call_with_exc(self):
-        def h1(n):
-            if n < 0:
-                raise ValueError
-            return n*2
-        def h2(n):
-            if n < 0:
-                raise ValueError
-            return n*4
-        l = [h1, h2]
-        def g(n, x):
-            h = l[n&1]
-            return h(n) + x
-
-        def f(n, x):
-            try:
-                return g(n, x)
-            except ValueError:
-                return -1111
-
-        P = StopAtXPolicy()
-        res = self.timeshift(f, [7, 3], policy=P)
-        assert res == f(7,3)
-        self.check_insns(indirect_call=1)
-
-        res = self.timeshift(f, [-7, 3], policy=P)
-        assert res == -1111
-        self.check_insns(indirect_call=1)
-
-    def test_indirect_gray_call(self):
-        def h1(w, n):
-            w[0] =  n*2
-        def h2(w, n):
-            w[0] = n*4
-        l = [h1, h2]
-        def f(n, x):
-            w = [0]
-            h = l[n&1]
-            h(w, n)
-            return w[0] + x
-
-        P = StopAtXPolicy()
-        res = self.timeshift(f, [7, 3], policy=P)
-        assert res == f(7,3)
-
-    def test_indirect_residual_red_call(self):
-        def h1(n):
-            return n*2
-        def h2(n):
-            return n*4
-        l = [h1, h2]
-        def f(n, x):
-            h = l[n&1]
-            return h(n) + x
-
-        P = StopAtXPolicy(h1, h2)
-        res = self.timeshift(f, [7, 3], policy=P)
-        assert res == f(7,3)
-        self.check_insns(indirect_call=1)
-
-    def test_constant_indirect_red_call(self):
-        def h1(x):
-            return x-2
-        def h2(x):
-            return x*4
-        l = [h1, h2]
-        def f(n, x):
-            frozenl = hint(l, deepfreeze=True)
-            h = frozenl[n&1]
-            return h(x)
-
-        P = StopAtXPolicy()
-        res = self.timeshift(f, [7, 3], [0], policy=P)
-        assert res == f(7,3)
-        self.check_insns({'int_mul': 1})
-        res = self.timeshift(f, [4, 113], [0], policy=P)
-        assert res == f(4,113)
-        self.check_insns({'int_sub': 1})
-
-    def test_indirect_sometimes_residual_pure_red_call(self):
-        def h1(x):
-            return x-2
-        def h2(x):
-            return x*4
-        l = [h1, h2]
-        def f(n, x):
-            hint(None, global_merge_point=True)
-            hint(n, concrete=True)
-            frozenl = hint(l, deepfreeze=True)
-            h = frozenl[n&1]
-            return h(x)
-
-        P = StopAtXPolicy(h1)
-        P.oopspec = True
-        res = self.timeshift(f, [7, 3], [], policy=P)
-        assert res == f(7,3)
-        self.check_insns({'int_mul': 1})
-        res = self.timeshift(f, [4, 113], [], policy=P)
-        assert res == f(4,113)
-        self.check_insns({'direct_call': 1})
-
-    def test_indirect_sometimes_residual_pure_but_fixed_red_call(self):
-        def h1(x):
-            return x-2
-        def h2(x):
-            return x*4
-        l = [h1, h2]
-        def f(n, x):
-            hint(None, global_merge_point=True)
-            frozenl = hint(l, deepfreeze=True)
-            h = frozenl[n&1]
-            z = h(x)
-            hint(z, concrete=True)
-            return z
-
-        P = StopAtXPolicy(h1)
-        P.oopspec = True
-        res = self.timeshift(f, [7, 3], [], policy=P)
-        assert res == f(7,3)
-        self.check_insns({})
-        res = self.timeshift(f, [4, 113], [], policy=P)
-        assert res == f(4,113)
-        self.check_insns({})
-
-    def test_manual_marking_of_pure_functions(self):
-        class A(object):
-            pass
-        class B(object):
-            pass
-        a1 = A()
-        a2 = A()
-        d = {}
-        def h1(b, s):
-            try:
-                return d[s]
-            except KeyError:
-                d[s] = r = A()
-                return r
-        h1._pure_function_ = True
-        b = B()
-        def f(n):
-            hint(None, global_merge_point=True)
-            hint(n, concrete=True)
-            if n == 0:
-                s = "abc"
-            else:
-                s = "123"
-            a = h1(b, s)
-            return hint(n, variable=True)
-
-        P = StopAtXPolicy(h1)
-        P.oopspec = True
-        res = self.timeshift(f, [0], [], policy=P)
-        assert res == 0
-        self.check_insns({})
-        res = self.timeshift(f, [4], [], policy=P)
-        assert res == 4
-        self.check_insns({})
-
-
-    def test_red_int_add_ovf(self):
-        def f(n, m):
-            try:
-                return ovfcheck(n + m)
-            except OverflowError:
-                return -42
-
-        res = self.timeshift(f, [100, 20])
-        assert res == 120
-        self.check_insns(int_add_ovf=1)
-        res = self.timeshift(f, [sys.maxint, 1])
-        assert res == -42
-        self.check_insns(int_add_ovf=1)
-
-    def test_green_int_add_ovf(self):
-        def f(n, m):
-            try:
-                res = ovfcheck(n + m)
-            except OverflowError:
-                res = -42
-            hint(res, concrete=True)
-            return res
-
-        res = self.timeshift(f, [100, 20])
-        assert res == 120
-        self.check_insns({})
-        res = self.timeshift(f, [sys.maxint, 1])
-        assert res == -42
-        self.check_insns({})
-
-    def test_nonzeroness_assert_while_compiling(self):
-        class X:
-            pass
-        class Y:
-            pass
-
-        def g(x, y):
-            if y.flag:
-                return x.value
-            else:
-                return -7
-
-        def h(n):
-            if n:
-                x = X()
-                x.value = n
-                return x
-            else:
-                return None
-
-        y = Y()
-
-        def f(n):
-            y.flag = True
-            g(h(n), y)
-            y.flag = False
-            return g(h(0), y)
-
-        res = self.timeshift(f, [42], policy=P_NOVIRTUAL)
-        assert res == -7
-
-    def test_segfault_while_compiling(self):
-        class X:
-            pass
-        class Y:
-            pass
-
-        def g(x, y):
-            x = hint(x, deepfreeze=True)
-            if y.flag:
-                return x.value
-            else:
-                return -7
-
-        def h(n):
-            if n:
-                x = X()
-                x.value = n
-                return x
-            else:
-                return None
-
-        y = Y()
-
-        def f(n):
-            y.flag = True
-            g(h(n), y)
-            y.flag = False
-            return g(h(0), y)
-
-        res = self.timeshift(f, [42], policy=P_NOVIRTUAL)
-        assert res == -7
-
-    def test_switch(self):
-        def g(n):
-            if n == 0:
-                return 12
-            elif n == 1:
-                return 34
-            elif n == 3:
-                return 56
-            elif n == 7:
-                return 78
-            else:
-                return 90
-        def f(n, m):
-            x = g(n)   # gives a red switch
-            y = g(hint(m, concrete=True))   # gives a green switch
-            return x - y
-
-        res = self.timeshift(f, [7, 2], backendoptimize=True)
-        assert res == 78 - 90
-        res = self.timeshift(f, [8, 1], backendoptimize=True)
-        assert res == 90 - 34
-
-    def test_switch_char(self):
-        def g(n):
-            n = chr(n)
-            if n == '\x00':
-                return 12
-            elif n == '\x01':
-                return 34
-            elif n == '\x02':
-                return 56
-            elif n == '\x03':
-                return 78
-            else:
-                return 90
-        def f(n, m):
-            x = g(n)   # gives a red switch
-            y = g(hint(m, concrete=True))   # gives a green switch
-            return x - y
-
-        res = self.timeshift(f, [3, 0], backendoptimize=True)
-        assert res == 78 - 12
-        res = self.timeshift(f, [2, 4], backendoptimize=True)
-        assert res == 56 - 90
-
-    def test_substitute_graph(self):
-
-        class MetaG:
-            __metaclass__ = cachedtype
-
-            def __init__(self, hrtyper):
-                pass
-
-            def _freeze_(self):
-                return True
-
-            def metafunc(self, jitstate, space, mbox):
-                from pypy.jit.timeshifter.rvalue import IntRedBox
-                builder = jitstate.curbuilder
-                gv_result = builder.genop1("int_neg", mbox.getgenvar(jitstate))
-                return IntRedBox(mbox.kind, gv_result)
-
-        class Fz(object):
-            x = 10
-            
-            def _freeze_(self):
-                return True
-
-        def g(fz, m):
-            return m * fz.x
-
-        fz = Fz()
-
-        def f(n, m):
-            x = g(fz, n)
-            y = g(fz, m)
-            hint(y, concrete=True)
-            return x + g(fz, y)
-
-        class MyPolicy(HintAnnotatorPolicy):
-            novirtualcontainer = True
-            
-            def look_inside_graph(self, graph):
-                if graph.func is g:
-                    return MetaG   # replaces g with a meta-call to metafunc()
-                else:
-                    return True
-
-        res = self.timeshift(f, [3, 6], policy=MyPolicy())
-        assert res == -3 + 600
-        self.check_insns({'int_neg': 1, 'int_add': 1})
-
-    def test_hash_of_green_string_is_green(self):
-        py.test.skip("unfortunately doesn't work")
-        def f(n):
-            if n == 0:
-                s = "abc"
-            elif n == 1:
-                s = "cde"
-            else:
-                s = "fgh"
-            return hash(s)
-
-        res = self.timeshift(f, [0])
-        self.check_insns({'int_eq': 2})
-        assert res == f(0)
-
-    def test_misplaced_global_merge_point(self):
-        def g(n):
-            hint(None, global_merge_point=True)
-            return n+1
-        def f(n):
-            hint(None, global_merge_point=True)
-            return g(n)
-        py.test.raises(AssertionError, self.timeshift, f, [7], [])
+    pass
 
 class TestLLType(BaseTestTimeshift):
     type_system = 'lltype'



More information about the Pypy-commit mailing list