File: test_llop.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (48 lines) | stat: -rw-r--r-- 1,645 bytes parent folder | download | duplicates (7)
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
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.rtyper.test.test_llop import (BaseLLOpTest, str_gc_load,
                                           newlist_and_gc_store)
from rpython.translator.c.test.test_genc import compile


class TestLLOp(BaseLLOpTest):
    cache_load = {}
    cache_store = {}

    def gc_load_from_string(self, TYPE, buf, offset):
        if TYPE not in self.cache_load:
            assert isinstance(TYPE, lltype.Primitive)
            if TYPE in (lltype.Float, lltype.SingleFloat):
                TARGET_TYPE = lltype.Float
            else:
                TARGET_TYPE = lltype.Signed

            def llf(buf, offset):
                x = str_gc_load(TYPE, buf, offset)
                return lltype.cast_primitive(TARGET_TYPE, x)

            fn = compile(llf, [str, int])
            self.cache_load[TYPE] = fn
        #
        fn = self.cache_load[TYPE]
        x = fn(buf, offset)
        return lltype.cast_primitive(TYPE, x)

    def newlist_and_gc_store(self, TYPE, value, expected):
        if TYPE not in self.cache_store:
            assert isinstance(TYPE, lltype.Primitive)
            if TYPE in (lltype.Float, lltype.SingleFloat):
                argtype = float
            else:
                argtype = int

            def llf(value):
                value = lltype.cast_primitive(TYPE, value)
                lst = newlist_and_gc_store(TYPE, value)
                return ''.join(lst)

            fn = compile(llf, [argtype])
            self.cache_store[TYPE] = fn
        #
        fn = self.cache_store[TYPE]
        got = fn(value)
        assert got == expected