File: test_short.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (55 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download | duplicates (8)
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

""" Short preamble tests
"""

import py
from rpython.jit.metainterp.resoperation import InputArgInt, ResOperation, rop
from rpython.jit.metainterp.optimizeopt.shortpreamble import ShortBoxes
from rpython.jit.metainterp.history import AbstractDescr

class Descr(AbstractDescr):
    pass

class Opt(object):
    def __init__(self, oplist):
        self.oplist = oplist
    
    def produce_potential_short_preamble_ops(self, sb):
        for op in self.oplist:
            if isinstance(op, tuple):
                sb.add_heap_op(*op)
            else:
                sb.add_pure_op(op)

class TestShortBoxes(object):
    def test_pure_ops(self):
        i0 = InputArgInt()
        i1 = InputArgInt()
        op = ResOperation(rop.INT_ADD, [i0, i1])
        sb = ShortBoxes()
        short_boxes = sb.create_short_boxes(Opt([op]), [i0, i1], [i0, i1])
        assert len(short_boxes) == 3
        short_boxes.sort(key=str)
        # inputarg
        for i in range(3):
            if short_boxes[i].short_op.res is i0:
                assert short_boxes[i].preamble_op is sb.short_inputargs[0]
                break
        else:
            raise Exception("did not find!")
        # pure op
        for i in range(3):
            if short_boxes[2].preamble_op.getarg(0) is sb.short_inputargs[0]:
                assert short_boxes[2].short_op.res is op
                break
        else:
            raise Exception("did not find!")

    def test_pure_ops_does_not_work(self):
        i0 = InputArgInt()
        i1 = InputArgInt()
        op = ResOperation(rop.INT_ADD, [i0, i1])
        sb = ShortBoxes()
        short_boxes = sb.create_short_boxes(Opt([op]), [i0], [i0])
        assert len(short_boxes) == 1 # just inparg