Debian Codegraph @

rpython/jit/backend/llsupport/test/zrpy_gc_boehm_test.py

raw symbols SCIP
1
2 import weakref
3 from rpython.rlib.jit import JitDriver, dont_look_inside
4 from rpython.jit.backend.llsupport.test.zrpy_gc_test import run, get_entry, compile
5
6 class X(object):
7 def __init__(self, x=0):
8 self.x = x
9
10 next = None
11
12 class CheckError(Exception):
13 pass
14
15 def check(flag):
16 if not flag:
17 raise CheckError
18
19 def compile_and_run(f, gc, **kwds):
20 cbuilder = compile(f, gc, **kwds)
21 return run(cbuilder)
22
23 def get_g(main):
24 main._dont_inline_ = True
25 def g(name, n):
26 x = X()
27 x.foo = 2
28 main(n, x)
29 x.foo = 5
30 return weakref.ref(x)
31 g._dont_inline_ = True
32 return g
33
34 def compile_boehm_test():
35 myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
36 @dont_look_inside
37 def see(lst, n):
38 assert len(lst) == 3
39 assert lst[0] == n+10
40 assert lst[1] == n+20
41 assert lst[2] == n+30
42 def main(n, x):
43 while n > 0:
44 myjitdriver.can_enter_jit(n=n, x=x)
45 myjitdriver.jit_merge_point(n=n, x=x)
46 y = X()
47 y.foo = x.foo
48 n -= y.foo
49 see([n+10, n+20, n+30], n)
50 res = compile_and_run(get_entry(get_g(main)), "boehm", jit=True)
51 assert int(res) >= 16