Debian Codegraph @

rpython/jit/metainterp/test/test_tlc.py

raw symbols SCIP
1 import py
2
3 from rpython.jit.tl import tlc
4
5 from rpython.jit.metainterp.test.support import LLJitMixin
6
7
8 class TLCTests:
9
10 def _get_interp(self, bytecode, pool):
11 codes = [bytecode, '']
12 pools = [pool, None]
13 def interp(i, inputarg):
14 args = [tlc.IntObj(inputarg)]
15 obj = tlc.interp_eval(codes[i], 0, args, pools[i])
16 return obj.int_o()
17 return interp
18
19 def exec_code(self, src, inputarg):
20 pool = tlc.ConstantPool()
21 bytecode = tlc.compile(src, pool)
22 interp = self._get_interp(bytecode, pool)
23 return self.meta_interp(interp, [0, inputarg])
24
25 def test_method(self):
26 code = """
27 NEW foo,meth=meth
28 PICK 0
29 PUSHARG
30 SETATTR foo
31 PUSH 2
32 SEND meth/1
33 RETURN
34 meth:
35 PUSHARG
36 GETATTR foo
37 PUSHARGN 1
38 ADD
39 RETURN
40 """
41 res = self.exec_code(code, 40)
42 assert res == 42
43
44 def test_accumulator(self):
45 py.test.skip("buggy interpreter")
46 path = py.path.local(tlc.__file__).dirpath('accumulator.tlc.src')
47 code = path.read()
48 res = self.exec_code(code, 20)
49 assert res == sum(range(20))
50 res = self.exec_code(code, -10)
51 assert res == 10
52
53
54 class TestLLtype(TLCTests, LLJitMixin):
55 pass