File: test_greenfield.py

package info (click to toggle)
pypy 2.4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 86,992 kB
  • ctags: 170,715
  • sloc: python: 1,030,417; ansic: 43,437; cpp: 5,241; asm: 5,169; sh: 458; makefile: 408; xml: 231; lisp: 45
file content (57 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from rpython.jit.metainterp.test.support import LLJitMixin
from rpython.rlib.jit import JitDriver


class GreenFieldsTests:

    def test_green_field_1(self):
        myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx'])
        class Ctx(object):
            _immutable_fields_ = ['x']
            def __init__(self, x, y):
                self.x = x
                self.y = y
        def f(x, y):
            ctx = Ctx(x, y)
            while 1:
                myjitdriver.can_enter_jit(ctx=ctx)
                myjitdriver.jit_merge_point(ctx=ctx)
                ctx.y -= 1
                if ctx.y < 0:
                    return ctx.y
        def g(y):
            return f(5, y) + f(6, y)
        #
        res = self.meta_interp(g, [7])
        assert res == -2
        self.check_trace_count(2)
        self.check_resops(guard_value=0)

    def test_green_field_2(self):
        myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx'])
        class Ctx(object):
            _immutable_fields_ = ['x']
            def __init__(self, x, y):
                self.x = x
                self.y = y
        def f(x, y):
            ctx = Ctx(x, y)
            while 1:
                myjitdriver.can_enter_jit(ctx=ctx)
                myjitdriver.jit_merge_point(ctx=ctx)
                ctx.y -= 1
                if ctx.y < 0:
                    pass     # to just make two paths
                if ctx.y < -10:
                    return ctx.y
        def g(y):
            return f(5, y) + f(6, y)
        #
        res = self.meta_interp(g, [7])
        assert res == -22
        self.check_trace_count(6)
        self.check_resops(guard_value=0)


class TestLLtypeGreenFieldsTests(GreenFieldsTests, LLJitMixin):
    pass