Debian Codegraph @

rpython/translator/c/test/test_llop.py

raw symbols SCIP
1 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
2 from rpython.rtyper.test.test_llop import (BaseLLOpTest, str_gc_load,
3 newlist_and_gc_store)
4 from rpython.translator.c.test.test_genc import compile
5
6
7 class TestLLOp(BaseLLOpTest):
8 cache_load = {}
9 cache_store = {}
10
11 def gc_load_from_string(self, TYPE, buf, offset):
12 if TYPE not in self.cache_load:
13 assert isinstance(TYPE, lltype.Primitive)
14 if TYPE in (lltype.Float, lltype.SingleFloat):
15 TARGET_TYPE = lltype.Float
16 else:
17 TARGET_TYPE = lltype.Signed
18
19 def llf(buf, offset):
20 x = str_gc_load(TYPE, buf, offset)
21 return lltype.cast_primitive(TARGET_TYPE, x)
22
23 fn = compile(llf, [str, int])
24 self.cache_load[TYPE] = fn
25 #
26 fn = self.cache_load[TYPE]
27 x = fn(buf, offset)
28 return lltype.cast_primitive(TYPE, x)
29
30 def newlist_and_gc_store(self, TYPE, value, expected):
31 if TYPE not in self.cache_store:
32 assert isinstance(TYPE, lltype.Primitive)
33 if TYPE in (lltype.Float, lltype.SingleFloat):
34 argtype = float
35 else:
36 argtype = int
37
38 def llf(value):
39 value = lltype.cast_primitive(TYPE, value)
40 lst = newlist_and_gc_store(TYPE, value)
41 return ''.join(lst)
42
43 fn = compile(llf, [argtype])
44 self.cache_store[TYPE] = fn
45 #
46 fn = self.cache_store[TYPE]
47 got = fn(value)
48 assert got == expected