Debian Codegraph @

rpython/translator/test/test_interactive.py

raw symbols SCIP
1 from rpython.translator.interactive import Translation
2 import py
3
4 def test_simple_annotate():
5
6 def f(x,y):
7 return x+y
8
9 t = Translation(f, [int, int])
10 assert t.context is t.driver.translator
11 assert t.config is t.driver.config is t.context.config
12
13 s = t.annotate()
14 assert s.knowntype == int
15
16 t = Translation(f, [int, int])
17 s = t.annotate()
18 assert s.knowntype == int
19
20
21 def test_simple_rtype():
22
23 def f(x,y):
24 return x+y
25
26 t = Translation(f, [int, int])
27 t.annotate()
28 t.rtype()
29
30 assert 'rtype_lltype' in t.driver.done
31
32 def test_simple_backendopt():
33 def f(x, y):
34 return x,y
35
36 t = Translation(f, [int, int], backend='c')
37 t.backendopt()
38
39 assert 'backendopt_lltype' in t.driver.done
40
41 def test_simple_source():
42 def f(x, y):
43 return x,y
44
45 t = Translation(f, [int, int], backend='c')
46 t.annotate()
47 t.source()
48 assert 'source_c' in t.driver.done
49
50 t = Translation(f, [int, int])
51 t.source_c()
52 assert 'source_c' in t.driver.done
53
54 t = Translation(f, [int, int])
55 py.test.raises(Exception, "t.source()")
56
57 def test_disable_logic():
58
59 def f(x,y):
60 return x+y
61
62 t = Translation(f, [int, int])
63 t.disable(['backendopt'])
64 t.source_c()
65
66 assert 'backendopt' not in t.driver.done
67
68 def test_simple_compile_c():
69 import ctypes
70
71 def f(x,y):
72 return x+y
73
74 t = Translation(f, [int, int])
75 t.source(backend='c')
76 t.compile()
77
78 dll = ctypes.CDLL(str(t.driver.c_entryp))
79 f = dll.pypy_g_f
80 assert f(2, 3) == 5
81
82 def test_check_that_driver_uses_replace_we_are_jitted():
83 from rpython.rlib import jit
84 def f():
85 if jit.we_are_jitted():
86 return 1
87 return 2 + jit.we_are_jitted()
88
89 t = Translation(f, [])
90 t.backendopt()
91 graph = t.driver.translator.graphs[0]
92 assert graph.startblock.exits[0].args[0].value == 2