def test_basic(): @signature(types.int(), types.str(), returns=types.char()) def f(a, b): return b[a] assert getsig(f) == [ model.SomeInteger(), model.SomeString(), model.SomeChar() ]
def test_unmarshaller(): buf = 'i\x05\x00\x00\x00' assert get_unmarshaller(int)(buf) == 5 buf = 'i\x00\xf0\xff\xff' assert get_unmarshaller(int)(buf) == -4096 buf = 'f\x043.25' assert get_unmarshaller(float)(buf) == 3.25 buf = 's\x0c\x00\x00\x00hello, world' assert get_unmarshaller(str)(buf) == "hello, world" buf = 's\x01\x00\x00\x00X' assert get_unmarshaller(annmodel.SomeChar())(buf) == "X" buf = 'i\x05\x00\x00\x00' py.test.raises(ValueError, get_unmarshaller(str), buf) buf = 'F' assert get_unmarshaller(bool)(buf) is False buf = 'T' assert get_unmarshaller(bool)(buf) is True buf = 'I\x07\x00\x00\x80\x23\x01\x00\x00' assert get_unmarshaller(r_longlong)(buf) == 0x12380000007 buf = 'I\x00\x00\x01\x83\x80\x00\x00\x97' assert get_unmarshaller(r_longlong)(buf) == -7566046822028738560L if LONG_BIT > 32: buf = 'I\x07\x00\x00\x80\x23\x01\x00\x00' assert get_unmarshaller(int)(buf) == 0x12380000007 buf = 'I\x00\x00\x01\x83\x80\x00\x00\x97' assert get_unmarshaller(int)(buf) == -7566046822028738560 buf = ('[\x03\x00\x00\x00i\x02\x00\x00\x00i\x05\x00\x00\x00' 'i\xf9\xff\xff\xff') assert get_unmarshaller([int])(buf) == [2, 5, -7] buf = ('(\x02\x00\x00\x00i\x07\x00\x00\x00(\x02\x00\x00\x00' 's\x03\x00\x00\x00foo(\x00\x00\x00\x00') res = get_unmarshaller((int, (str, ())))(buf) assert res == (7, ("foo", ())) buf = ('{i\xfb\xff\xff\xffs\x03\x00\x00\x00bar' 'i\x06\x00\x00\x00s\x00\x00\x00\x000') res = get_unmarshaller({int: str})(buf) assert res == {-5: "bar", 6: ""} for typ in types_that_can_be_none: buf = 'N' assert get_unmarshaller(typ)(buf) is None
def char(): return model.SomeChar()
TYPE_NONE = 'N' TYPE_FALSE = 'F' TYPE_TRUE = 'T' TYPE_INT = 'i' TYPE_INT64 = 'I' TYPE_FLOAT = 'f' TYPE_STRING = 's' TYPE_TUPLE = '(' TYPE_LIST = '[' TYPE_DICT = '{' dumpers = [] loaders = [] s_list_of_chars = annmodel.SomeList( ListDef(None, annmodel.SomeChar(), mutated=True, resized=True)) def add_dumper(s_obj, dumper): dumpers.append((s_obj, dumper)) dumper.s_obj = s_obj dumper._annenforceargs_ = [s_list_of_chars, s_obj] def add_loader(s_obj, loader): # 's_obj' should be the **least general annotation** that we're # interested in, somehow loaders.append((s_obj, loader)) def get_dumper_annotation(dumper):
# Dumpers and loaders TYPE_NONE = 'N' TYPE_FALSE = 'F' TYPE_TRUE = 'T' TYPE_INT = 'i' TYPE_INT64 = 'I' TYPE_FLOAT = 'f' TYPE_STRING = 's' TYPE_TUPLE = '(' TYPE_LIST = '[' TYPE_DICT = '{' dumpers = [] loaders = [] s_list_of_chars = annmodel.SomeList(ListDef(None, annmodel.SomeChar(), mutated=True, resized=True)) def add_dumper(s_obj, dumper): dumpers.append((s_obj, dumper)) dumper.s_obj = s_obj dumper._annenforceargs_ = [s_list_of_chars, s_obj] def add_loader(s_obj, loader): loaders.append((s_obj, loader)) def get_dumper_annotation(dumper): return dumper.s_obj def find_dumper(s_obj): # select a suitable dumper - the condition is that the dumper must
from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.ootypesystem import ootype from rpython.rlib.rarithmetic import r_uint, r_ulonglong, r_longlong, ovfcheck from rpython.rlib import rstack from rpython.annotator import model as annmodel import sys char = annmodel.SomeChar() def fn_eq(x, y): return x == y def fn_ne(x, y): return x != y def fn_ge(x, y): return x >= y def fn_le(x, y): return x <= y class BaseTestOperations(object): FLOAT_PRECISION = 8 def _check(self, fn, annotation, args):