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

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Feb 4 12:25:33 CET 2008


Author: cfbolz
Date: Mon Feb  4 12:25:32 2008
New Revision: 51244

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 struct and array tests over to test_interpreter.py. skip them all


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	Mon Feb  4 12:25:32 2008
@@ -499,5 +499,417 @@
         assert res == expected
         
 
+    def test_simple_struct(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
+                                          ('world', lltype.Signed),
+                            hints={'immutable': True})
+
+        def ll_function(s):
+            return s.hello * s.world
+
+        def struct_S(string):
+            items = string.split(',')
+            assert len(items) == 2
+            s1 = lltype.malloc(S)
+            s1.hello = int(items[0])
+            s1.world = int(items[1])
+            return s1
+        ll_function.convert_arguments = [struct_S]
+
+        res = self.interpret(ll_function, ["6,7"], [])
+        assert res == 42
+        self.check_insns({'getfield': 2, 'int_mul': 1})
+        res = self.interpret(ll_function, ["8,9"], [0])
+        assert res == 72
+        self.check_insns({})
+
+    def test_simple_array(self):
+        py.test.skip("arrays and structs are not working")
+        A = lltype.GcArray(lltype.Signed, 
+                            hints={'immutable': True})
+        def ll_function(a):
+            return a[0] * a[1]
+
+        def int_array(string):
+            items = [int(x) for x in string.split(',')]
+            n = len(items)
+            a1 = lltype.malloc(A, n)
+            for i in range(n):
+                a1[i] = items[i]
+            return a1
+        ll_function.convert_arguments = [int_array]
+
+        res = self.interpret(ll_function, ["6,7"], [])
+        assert res == 42
+        self.check_insns({'getarrayitem': 2, 'int_mul': 1})
+        res = self.interpret(ll_function, ["8,3"], [0])
+        assert res == 24
+        self.check_insns({})
+
+
+
+    def test_simple_struct_malloc(self):
+        py.test.skip("blue containers: to be reimplemented")
+        S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
+                                          ('world', lltype.Signed))               
+        def ll_function(x):
+            s = lltype.malloc(S)
+            s.hello = x
+            return s.hello + s.world
+
+        res = self.interpret(ll_function, [3], [])
+        assert res == 3
+        self.check_insns({'int_add': 1})
+
+        res = self.interpret(ll_function, [3], [0])
+        assert res == 3
+        self.check_insns({})
+
+    def test_inlined_substructure(self):
+        py.test.skip("blue containers: to be reimplemented")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+        def ll_function(k):
+            t = lltype.malloc(T)
+            t.s.n = k
+            l = t.s.n
+            return l
+        res = self.interpret(ll_function, [7], [])
+        assert res == 7
+        self.check_insns({})
+
+        res = self.interpret(ll_function, [7], [0])
+        assert res == 7
+        self.check_insns({})
+
+    def test_degenerated_before_return(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+
+        def ll_function(flag):
+            t = lltype.malloc(T)
+            t.s.n = 3
+            s = lltype.malloc(S)
+            s.n = 4
+            if flag:
+                s = t.s
+            s.n += 1
+            return s.n * t.s.n
+        res = self.interpret(ll_function, [0], [])
+        assert res == 5 * 3
+        res = self.interpret(ll_function, [1], [])
+        assert res == 4 * 4
+
+    def test_degenerated_before_return_2(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+
+        def ll_function(flag):
+            t = lltype.malloc(T)
+            t.s.n = 3
+            s = lltype.malloc(S)
+            s.n = 4
+            if flag:
+                pass
+            else:
+                s = t.s
+            s.n += 1
+            return s.n * t.s.n
+        res = self.interpret(ll_function, [1], [])
+        assert res == 5 * 3
+        res = self.interpret(ll_function, [0], [])
+        assert res == 4 * 4
+
+    def test_degenerated_at_return(self):
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+        class Result:
+            def convert(self, s):
+                self.s = s
+                return str(s.n)
+        glob_result = Result()
+
+        def ll_function(flag):
+            t = lltype.malloc(T)
+            t.n = 3.25
+            t.s.n = 3
+            s = lltype.malloc(S)
+            s.n = 4
+            if flag:
+                s = t.s
+            return s
+        ll_function.convert_result = glob_result.convert
+
+        res = self.interpret(ll_function, [0], [])
+        assert res == "4"
+        if self.__class__ in (TestLLType, TestOOType):
+            assert lltype.parentlink(glob_result.s._obj) == (None, None)
+        res = self.interpret(ll_function, [1], [])
+        assert res == "3"
+        if self.__class__ in (TestLLType, TestOOType):
+            parent, parentindex = lltype.parentlink(glob_result.s._obj)
+            assert parentindex == 's'
+            assert parent.n == 3.25
+
+    def test_degenerated_via_substructure(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+
+        def ll_function(flag):
+            t = lltype.malloc(T)
+            t.s.n = 3
+            s = lltype.malloc(S)
+            s.n = 7
+            if flag:
+                pass
+            else:
+                s = t.s
+            t.s.n += 1
+            return s.n * t.s.n
+        res = self.interpret(ll_function, [1], [])
+        assert res == 7 * 4
+        res = self.interpret(ll_function, [0], [])
+        assert res == 4 * 4
+
+    def test_degenerate_with_voids(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('y', lltype.Void),
+                                 ('x', lltype.Signed))
+        def ll_function():
+            s = lltype.malloc(S)
+            s.x = 123
+            return s
+        ll_function.convert_result = lambda s: str(s.x)
+        res = self.interpret(ll_function, [], [], policy=P_NOVIRTUAL)
+        assert res == "123"
+
+    def test_plus_minus_all_inlined(self):
+        py.test.skip("arrays and structs are not working")
+        def ll_plus_minus(s, x, y):
+            acc = x
+            n = len(s)
+            pc = 0
+            while pc < n:
+                op = s[pc]
+                op = hint(op, concrete=True)
+                if op == '+':
+                    acc += y
+                elif op == '-':
+                    acc -= y
+                pc += 1
+            return acc
+        ll_plus_minus.convert_arguments = [LLSupport.to_rstr, int, int]
+        res = self.interpret(ll_plus_minus, ["+-+", 0, 2], [0], inline=100000)
+        assert res == ll_plus_minus("+-+", 0, 2)
+        self.check_insns({'int_add': 2, 'int_sub': 1})
+
+    def test_red_virtual_container(self):
+        py.test.skip("arrays and structs are not working")
+        # this checks that red boxes are able to be virtualized dynamically by
+        # the compiler (the P_NOVIRTUAL policy prevents the hint-annotator from
+        # marking variables in blue)
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        def ll_function(n):
+            s = lltype.malloc(S)
+            s.n = n
+            return s.n
+        res = self.interpret(ll_function, [42], [], policy=P_NOVIRTUAL)
+        assert res == 42
+        self.check_insns({})
+
+
+    def test_setarrayitem(self):
+        py.test.skip("arrays and structs are not working")
+        A = lltype.GcArray(lltype.Signed)
+        a = lltype.malloc(A, 2, immortal=True)
+        def ll_function():
+            a[0] = 1
+            a[1] = 2
+            return a[0]+a[1]
+        
+        res = self.interpret(ll_function, [], [], policy=P_NOVIRTUAL)
+        assert res == 3
+
+    def test_red_array(self):
+        py.test.skip("arrays and structs are not working")
+         A = lltype.GcArray(lltype.Signed)
+         def ll_function(x, y, n):
+             a = lltype.malloc(A, 2)
+             a[0] = x
+             a[1] = y
+             return a[n]*len(a)
+
+         res = self.interpret(ll_function, [21, -21, 0], [],
+                              policy=P_NOVIRTUAL)
+         assert res == 42
+         self.check_insns({'malloc_varsize': 1,
+                           'setarrayitem': 2, 'getarrayitem': 1,
+                           'getarraysize': 1, 'int_mul': 1})
+
+         res = self.interpret(ll_function, [21, -21, 1], [],
+                              policy=P_NOVIRTUAL)
+         assert res == -42
+         self.check_insns({'malloc_varsize': 1,
+                           'setarrayitem': 2, 'getarrayitem': 1,
+                           'getarraysize': 1, 'int_mul': 1})
+
+    def test_red_struct_array(self):
+        py.test.skip("arrays and structs are not working")
+         S = lltype.Struct('s', ('x', lltype.Signed))
+         A = lltype.GcArray(S)
+         def ll_function(x, y, n):
+             a = lltype.malloc(A, 2)
+             a[0].x = x
+             a[1].x = y
+             return a[n].x*len(a)
+
+         res = self.interpret(ll_function, [21, -21, 0], [],
+                              policy=P_NOVIRTUAL)
+         assert res == 42
+         self.check_insns({'malloc_varsize': 1,
+                           'setinteriorfield': 2, 'getinteriorfield': 1,
+                           'getarraysize': 1, 'int_mul': 1})
+
+         res = self.interpret(ll_function, [21, -21, 1], [],
+                              policy=P_NOVIRTUAL)
+         assert res == -42
+         self.check_insns({'malloc_varsize': 1,
+                           'setinteriorfield': 2, 'getinteriorfield': 1,
+                           'getarraysize': 1, 'int_mul': 1})
+
+
+    def test_red_varsized_struct(self):
+        py.test.skip("arrays and structs are not working")
+         A = lltype.Array(lltype.Signed)
+         S = lltype.GcStruct('S', ('foo', lltype.Signed), ('a', A))
+         def ll_function(x, y, n):
+             s = lltype.malloc(S, 3)
+             s.foo = len(s.a)-1
+             s.a[0] = x
+             s.a[1] = y
+             return s.a[n]*s.foo
+
+         res = self.interpret(ll_function, [21, -21, 0], [],
+                              policy=P_NOVIRTUAL)
+         assert res == 42
+         self.check_insns(malloc_varsize=1,
+                          getinteriorarraysize=1)
+
+         res = self.interpret(ll_function, [21, -21, 1], [],
+                              policy=P_NOVIRTUAL)
+         assert res == -42
+         self.check_insns(malloc_varsize=1,
+                          getinteriorarraysize=1)
+
+    def test_array_of_voids(self):
+        py.test.skip("arrays and structs are not working")
+        A = lltype.GcArray(lltype.Void)
+        def ll_function(n):
+            a = lltype.malloc(A, 3)
+            a[1] = None
+            b = a[n]
+            res = a, b
+            keepalive_until_here(b)      # to keep getarrayitem around
+            return res
+        ll_function.convert_result = lambda x: str(len(x.item0))
+
+        res = self.interpret(ll_function, [2], [], policy=P_NOVIRTUAL)
+        assert res == "3"
+
+    def test_red_propagate(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        def ll_function(n, k):
+            s = lltype.malloc(S)
+            s.n = n
+            if k < 0:
+                return -123
+            return s.n * k
+        res = self.interpret(ll_function, [3, 8], [], policy=P_NOVIRTUAL)
+        assert res == 24
+        self.check_insns({'int_lt': 1, 'int_mul': 1})
+
+    def test_red_subcontainer(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+        def ll_function(k):
+            t = lltype.malloc(T)
+            s = t.s
+            s.n = k
+            if k < 0:
+                return -123
+            result = s.n * (k-1)
+            keepalive_until_here(t)
+            return result
+        res = self.interpret(ll_function, [7], [], policy=P_NOVIRTUAL)
+        assert res == 42
+        self.check_insns({'int_lt': 1, 'int_mul': 1, 'int_sub': 1})
+
+
+    def test_red_subcontainer_cast(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+        def ll_function(k):
+            t = lltype.malloc(T)
+            s = lltype.cast_pointer(lltype.Ptr(S), t)
+            s.n = k
+            if k < 0:
+                return -123
+            result = s.n * (k-1)
+            keepalive_until_here(t)
+            return result
+        res = self.interpret(ll_function, [7], [], policy=P_NOVIRTUAL)
+        assert res == 42
+        self.check_insns({'int_lt': 1, 'int_mul': 1, 'int_sub': 1})
+
+
+    def test_merge_structures(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        T = lltype.GcStruct('T', ('s', lltype.Ptr(S)), ('n', lltype.Signed))
+
+        def ll_function(flag):
+            if flag:
+                s = lltype.malloc(S)
+                s.n = 1
+                t = lltype.malloc(T)
+                t.s = s
+                t.n = 2
+            else:
+                s = lltype.malloc(S)
+                s.n = 5
+                t = lltype.malloc(T)
+                t.s = s
+                t.n = 6
+            return t.n + t.s.n
+        res = self.interpret(ll_function, [0], [], policy=P_NOVIRTUAL)
+        assert res == 5 + 6
+        self.check_insns({'int_is_true': 1, 'int_add': 1})
+        res = self.interpret(ll_function, [1], [], policy=P_NOVIRTUAL)
+        assert res == 1 + 2
+        self.check_insns({'int_is_true': 1, 'int_add': 1})
+
+
+    def test_green_with_side_effects(self):
+        py.test.skip("arrays and structs are not working")
+        S = lltype.GcStruct('S', ('flag', lltype.Bool))
+        s = lltype.malloc(S)
+        s.flag = False
+        def ll_set_flag(s):
+            s.flag = True
+        def ll_function():
+            s.flag = False
+            ll_set_flag(s)
+            return s.flag
+        res = self.interpret(ll_function, [], [])
+        assert res == True
+        self.check_insns({'setfield': 2, 'getfield': 1})
+
 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	Mon Feb  4 12:25:32 2008
@@ -383,399 +383,6 @@
 class BaseTestTimeshift(TimeshiftingTests):
 
 
-    def test_simple_struct(self):
-        S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
-                                          ('world', lltype.Signed),
-                            hints={'immutable': True})
-
-        def ll_function(s):
-            return s.hello * s.world
-
-        def struct_S(string):
-            items = string.split(',')
-            assert len(items) == 2
-            s1 = lltype.malloc(S)
-            s1.hello = int(items[0])
-            s1.world = int(items[1])
-            return s1
-        ll_function.convert_arguments = [struct_S]
-
-        res = self.timeshift(ll_function, ["6,7"], [])
-        assert res == 42
-        self.check_insns({'getfield': 2, 'int_mul': 1})
-        res = self.timeshift(ll_function, ["8,9"], [0])
-        assert res == 72
-        self.check_insns({})
-
-    def test_simple_array(self):
-        A = lltype.GcArray(lltype.Signed, 
-                            hints={'immutable': True})
-        def ll_function(a):
-            return a[0] * a[1]
-
-        def int_array(string):
-            items = [int(x) for x in string.split(',')]
-            n = len(items)
-            a1 = lltype.malloc(A, n)
-            for i in range(n):
-                a1[i] = items[i]
-            return a1
-        ll_function.convert_arguments = [int_array]
-
-        res = self.timeshift(ll_function, ["6,7"], [])
-        assert res == 42
-        self.check_insns({'getarrayitem': 2, 'int_mul': 1})
-        res = self.timeshift(ll_function, ["8,3"], [0])
-        assert res == 24
-        self.check_insns({})
-
-
-
-    def test_simple_struct_malloc(self):
-        py.test.skip("blue containers: to be reimplemented")
-        S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
-                                          ('world', lltype.Signed))               
-        def ll_function(x):
-            s = lltype.malloc(S)
-            s.hello = x
-            return s.hello + s.world
-
-        res = self.timeshift(ll_function, [3], [])
-        assert res == 3
-        self.check_insns({'int_add': 1})
-
-        res = self.timeshift(ll_function, [3], [0])
-        assert res == 3
-        self.check_insns({})
-
-    def test_inlined_substructure(self):
-        py.test.skip("blue containers: to be reimplemented")
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
-        def ll_function(k):
-            t = lltype.malloc(T)
-            t.s.n = k
-            l = t.s.n
-            return l
-        res = self.timeshift(ll_function, [7], [])
-        assert res == 7
-        self.check_insns({})
-
-        res = self.timeshift(ll_function, [7], [0])
-        assert res == 7
-        self.check_insns({})
-
-    def test_degenerated_before_return(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
-
-        def ll_function(flag):
-            t = lltype.malloc(T)
-            t.s.n = 3
-            s = lltype.malloc(S)
-            s.n = 4
-            if flag:
-                s = t.s
-            s.n += 1
-            return s.n * t.s.n
-        res = self.timeshift(ll_function, [0], [])
-        assert res == 5 * 3
-        res = self.timeshift(ll_function, [1], [])
-        assert res == 4 * 4
-
-    def test_degenerated_before_return_2(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
-
-        def ll_function(flag):
-            t = lltype.malloc(T)
-            t.s.n = 3
-            s = lltype.malloc(S)
-            s.n = 4
-            if flag:
-                pass
-            else:
-                s = t.s
-            s.n += 1
-            return s.n * t.s.n
-        res = self.timeshift(ll_function, [1], [])
-        assert res == 5 * 3
-        res = self.timeshift(ll_function, [0], [])
-        assert res == 4 * 4
-
-    def test_degenerated_at_return(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
-        class Result:
-            def convert(self, s):
-                self.s = s
-                return str(s.n)
-        glob_result = Result()
-
-        def ll_function(flag):
-            t = lltype.malloc(T)
-            t.n = 3.25
-            t.s.n = 3
-            s = lltype.malloc(S)
-            s.n = 4
-            if flag:
-                s = t.s
-            return s
-        ll_function.convert_result = glob_result.convert
-
-        res = self.timeshift(ll_function, [0], [])
-        assert res == "4"
-        if self.__class__ in (TestLLType, TestOOType):
-            assert lltype.parentlink(glob_result.s._obj) == (None, None)
-        res = self.timeshift(ll_function, [1], [])
-        assert res == "3"
-        if self.__class__ in (TestLLType, TestOOType):
-            parent, parentindex = lltype.parentlink(glob_result.s._obj)
-            assert parentindex == 's'
-            assert parent.n == 3.25
-
-    def test_degenerated_via_substructure(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
-
-        def ll_function(flag):
-            t = lltype.malloc(T)
-            t.s.n = 3
-            s = lltype.malloc(S)
-            s.n = 7
-            if flag:
-                pass
-            else:
-                s = t.s
-            t.s.n += 1
-            return s.n * t.s.n
-        res = self.timeshift(ll_function, [1], [])
-        assert res == 7 * 4
-        res = self.timeshift(ll_function, [0], [])
-        assert res == 4 * 4
-
-    def test_degenerate_with_voids(self):
-        S = lltype.GcStruct('S', ('y', lltype.Void),
-                                 ('x', lltype.Signed))
-        def ll_function():
-            s = lltype.malloc(S)
-            s.x = 123
-            return s
-        ll_function.convert_result = lambda s: str(s.x)
-        res = self.timeshift(ll_function, [], [], policy=P_NOVIRTUAL)
-        assert res == "123"
-
-    def test_plus_minus_all_inlined(self):
-        def ll_plus_minus(s, x, y):
-            acc = x
-            n = len(s)
-            pc = 0
-            while pc < n:
-                op = s[pc]
-                op = hint(op, concrete=True)
-                if op == '+':
-                    acc += y
-                elif op == '-':
-                    acc -= y
-                pc += 1
-            return acc
-        ll_plus_minus.convert_arguments = [LLSupport.to_rstr, int, int]
-        res = self.timeshift(ll_plus_minus, ["+-+", 0, 2], [0], inline=100000)
-        assert res == ll_plus_minus("+-+", 0, 2)
-        self.check_insns({'int_add': 2, 'int_sub': 1})
-
-    def test_red_virtual_container(self):
-        # this checks that red boxes are able to be virtualized dynamically by
-        # the compiler (the P_NOVIRTUAL policy prevents the hint-annotator from
-        # marking variables in blue)
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        def ll_function(n):
-            s = lltype.malloc(S)
-            s.n = n
-            return s.n
-        res = self.timeshift(ll_function, [42], [], policy=P_NOVIRTUAL)
-        assert res == 42
-        self.check_insns({})
-
-
-    def test_setarrayitem(self):
-        A = lltype.GcArray(lltype.Signed)
-        a = lltype.malloc(A, 2, immortal=True)
-        def ll_function():
-            a[0] = 1
-            a[1] = 2
-            return a[0]+a[1]
-        
-        res = self.timeshift(ll_function, [], [], policy=P_NOVIRTUAL)
-        assert res == 3
-
-    def test_red_array(self):
-         A = lltype.GcArray(lltype.Signed)
-         def ll_function(x, y, n):
-             a = lltype.malloc(A, 2)
-             a[0] = x
-             a[1] = y
-             return a[n]*len(a)
-
-         res = self.timeshift(ll_function, [21, -21, 0], [],
-                              policy=P_NOVIRTUAL)
-         assert res == 42
-         self.check_insns({'malloc_varsize': 1,
-                           'setarrayitem': 2, 'getarrayitem': 1,
-                           'getarraysize': 1, 'int_mul': 1})
-
-         res = self.timeshift(ll_function, [21, -21, 1], [],
-                              policy=P_NOVIRTUAL)
-         assert res == -42
-         self.check_insns({'malloc_varsize': 1,
-                           'setarrayitem': 2, 'getarrayitem': 1,
-                           'getarraysize': 1, 'int_mul': 1})
-
-    def test_red_struct_array(self):
-         S = lltype.Struct('s', ('x', lltype.Signed))
-         A = lltype.GcArray(S)
-         def ll_function(x, y, n):
-             a = lltype.malloc(A, 2)
-             a[0].x = x
-             a[1].x = y
-             return a[n].x*len(a)
-
-         res = self.timeshift(ll_function, [21, -21, 0], [],
-                              policy=P_NOVIRTUAL)
-         assert res == 42
-         self.check_insns({'malloc_varsize': 1,
-                           'setinteriorfield': 2, 'getinteriorfield': 1,
-                           'getarraysize': 1, 'int_mul': 1})
-
-         res = self.timeshift(ll_function, [21, -21, 1], [],
-                              policy=P_NOVIRTUAL)
-         assert res == -42
-         self.check_insns({'malloc_varsize': 1,
-                           'setinteriorfield': 2, 'getinteriorfield': 1,
-                           'getarraysize': 1, 'int_mul': 1})
-
-
-    def test_red_varsized_struct(self):
-         A = lltype.Array(lltype.Signed)
-         S = lltype.GcStruct('S', ('foo', lltype.Signed), ('a', A))
-         def ll_function(x, y, n):
-             s = lltype.malloc(S, 3)
-             s.foo = len(s.a)-1
-             s.a[0] = x
-             s.a[1] = y
-             return s.a[n]*s.foo
-
-         res = self.timeshift(ll_function, [21, -21, 0], [],
-                              policy=P_NOVIRTUAL)
-         assert res == 42
-         self.check_insns(malloc_varsize=1,
-                          getinteriorarraysize=1)
-
-         res = self.timeshift(ll_function, [21, -21, 1], [],
-                              policy=P_NOVIRTUAL)
-         assert res == -42
-         self.check_insns(malloc_varsize=1,
-                          getinteriorarraysize=1)
-
-    def test_array_of_voids(self):
-        A = lltype.GcArray(lltype.Void)
-        def ll_function(n):
-            a = lltype.malloc(A, 3)
-            a[1] = None
-            b = a[n]
-            res = a, b
-            keepalive_until_here(b)      # to keep getarrayitem around
-            return res
-        ll_function.convert_result = lambda x: str(len(x.item0))
-
-        res = self.timeshift(ll_function, [2], [], policy=P_NOVIRTUAL)
-        assert res == "3"
-
-    def test_red_propagate(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        def ll_function(n, k):
-            s = lltype.malloc(S)
-            s.n = n
-            if k < 0:
-                return -123
-            return s.n * k
-        res = self.timeshift(ll_function, [3, 8], [], policy=P_NOVIRTUAL)
-        assert res == 24
-        self.check_insns({'int_lt': 1, 'int_mul': 1})
-
-    def test_red_subcontainer(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
-        def ll_function(k):
-            t = lltype.malloc(T)
-            s = t.s
-            s.n = k
-            if k < 0:
-                return -123
-            result = s.n * (k-1)
-            keepalive_until_here(t)
-            return result
-        res = self.timeshift(ll_function, [7], [], policy=P_NOVIRTUAL)
-        assert res == 42
-        self.check_insns({'int_lt': 1, 'int_mul': 1, 'int_sub': 1})
-
-
-    def test_red_subcontainer_cast(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
-        def ll_function(k):
-            t = lltype.malloc(T)
-            s = lltype.cast_pointer(lltype.Ptr(S), t)
-            s.n = k
-            if k < 0:
-                return -123
-            result = s.n * (k-1)
-            keepalive_until_here(t)
-            return result
-        res = self.timeshift(ll_function, [7], [], policy=P_NOVIRTUAL)
-        assert res == 42
-        self.check_insns({'int_lt': 1, 'int_mul': 1, 'int_sub': 1})
-
-
-    def test_merge_structures(self):
-        S = lltype.GcStruct('S', ('n', lltype.Signed))
-        T = lltype.GcStruct('T', ('s', lltype.Ptr(S)), ('n', lltype.Signed))
-
-        def ll_function(flag):
-            if flag:
-                s = lltype.malloc(S)
-                s.n = 1
-                t = lltype.malloc(T)
-                t.s = s
-                t.n = 2
-            else:
-                s = lltype.malloc(S)
-                s.n = 5
-                t = lltype.malloc(T)
-                t.s = s
-                t.n = 6
-            return t.n + t.s.n
-        res = self.timeshift(ll_function, [0], [], policy=P_NOVIRTUAL)
-        assert res == 5 + 6
-        self.check_insns({'int_is_true': 1, 'int_add': 1})
-        res = self.timeshift(ll_function, [1], [], policy=P_NOVIRTUAL)
-        assert res == 1 + 2
-        self.check_insns({'int_is_true': 1, 'int_add': 1})
-
-
-    def test_green_with_side_effects(self):
-        S = lltype.GcStruct('S', ('flag', lltype.Bool))
-        s = lltype.malloc(S)
-        s.flag = False
-        def ll_set_flag(s):
-            s.flag = True
-        def ll_function():
-            s.flag = False
-            ll_set_flag(s)
-            return s.flag
-        res = self.timeshift(ll_function, [], [])
-        assert res == True
-        self.check_insns({'setfield': 2, 'getfield': 1})
 
     def test_recursive_with_red_termination_condition(self):
         py.test.skip('Does not terminate')



More information about the Pypy-commit mailing list