Author: Antonio Cuni <anto.c...@gmail.com> Branch: faster-rstruct-2 Changeset: r91248:22c587e1da2b Date: 2017-05-11 16:09 +0200 http://bitbucket.org/pypy/pypy/changeset/22c587e1da2b/
Log: deleting strstorage tests was a mistake, because they were the only ones to test llop.gc_load_indexed. Rewrite them in a more direct way diff --git a/rpython/rtyper/test/test_llop.py b/rpython/rtyper/test/test_llop.py new file mode 100644 --- /dev/null +++ b/rpython/rtyper/test/test_llop.py @@ -0,0 +1,46 @@ +import struct +from rpython.rtyper.test.tool import BaseRtypingTest +from rpython.rtyper.lltypesystem import lltype, llmemory, rffi +from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rtyper.lltypesystem.rstr import STR +from rpython.rtyper.annlowlevel import llstr +from rpython.rlib.rarithmetic import r_singlefloat + +def str_offset(): + base_ofs = (llmemory.offsetof(STR, 'chars') + + llmemory.itemoffsetof(STR.chars, 0)) + scale_factor = llmemory.sizeof(lltype.Char) + return base_ofs, scale_factor + +class BaseLLOpTest(object): + + def test_gc_load_indexed(self): + buf = struct.pack('dfi', 123.456, 123.456, 0x12345678) + val = self.gc_load_from_string(rffi.DOUBLE, buf, 0) + assert val == 123.456 + # + val = self.gc_load_from_string(rffi.FLOAT, buf, 8) + assert val == r_singlefloat(123.456) + # + val = self.gc_load_from_string(rffi.INT, buf, 12) + assert val == 0x12345678 + + +class TestDirect(BaseLLOpTest): + + def gc_load_from_string(self, TYPE, buf, offset): + base_ofs, scale_factor = str_offset() + lls = llstr(buf) + return llop.gc_load_indexed(TYPE, lls, offset, + scale_factor, base_ofs) + + +class TestRTyping(BaseLLOpTest, BaseRtypingTest): + + def gc_load_from_string(self, TYPE, buf, offset): + def fn(offset): + lls = llstr(buf) + base_ofs, scale_factor = str_offset() + return llop.gc_load_indexed(TYPE, lls, offset, + scale_factor, base_ofs) + return self.interpret(fn, [offset]) diff --git a/rpython/translator/c/test/test_llop.py b/rpython/translator/c/test/test_llop.py new file mode 100644 --- /dev/null +++ b/rpython/translator/c/test/test_llop.py @@ -0,0 +1,31 @@ +from rpython.rtyper.lltypesystem import lltype, llmemory, rffi +from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rtyper.annlowlevel import llstr +from rpython.rtyper.test.test_llop import BaseLLOpTest, str_offset +from rpython.translator.c.test.test_genc import compile + + +class TestLLOp(BaseLLOpTest): + cache = {} + + def gc_load_from_string(self, TYPE, buf, offset): + if TYPE not in self.cache: + 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): + base_ofs, scale_factor = str_offset() + lls = llstr(buf) + x = llop.gc_load_indexed(TYPE, lls, offset, + scale_factor, base_ofs) + return lltype.cast_primitive(TARGET_TYPE, x) + + fn = compile(llf, [str, int]) + self.cache[TYPE] = fn + # + fn = self.cache[TYPE] + x = fn(buf, offset) + return lltype.cast_primitive(TYPE, x) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit