本文整理汇总了Python中pypy.rpython.rtyper.RPythonTyper类的典型用法代码示例。如果您正苦于以下问题:Python RPythonTyper类的具体用法?Python RPythonTyper怎么用?Python RPythonTyper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RPythonTyper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_raw_malloc
def test_raw_malloc(self):
def f():
return raw_malloc(100)
a = RPythonAnnotator()
s = a.build_types(f, [])
rtyper = RPythonTyper(a)
rtyper.specialize() #does not raise
示例2: test_ll_calling_ll2
def test_ll_calling_ll2():
import test_llann
tst = test_llann.TestLowLevelAnnotateTestCase()
a, vTs = tst.test_ll_calling_ll2()
rt = RPythonTyper(a)
rt.specialize()
assert [vT.concretetype for vT in vTs] == [Void] * 3
示例3: test_isinstance
def test_isinstance():
class A:
_alloc_flavor_ = "raw"
class B(A):
pass
class C(B):
pass
def f(i):
if i == 0:
o = None
elif i == 1:
o = A()
elif i == 2:
o = B()
else:
o = C()
return 100*isinstance(o, A)+10*isinstance(o, B)+1*isinstance(o ,C)
a = RPythonAnnotator()
#does not raise:
s = a.build_types(f, [int])
assert s.knowntype == int
rtyper = RPythonTyper(a)
rtyper.specialize()
res = interpret(f, [1])
assert res == 100
res = interpret(f, [2])
assert res == 110
res = interpret(f, [3])
assert res == 111
res = interpret(f, [0])
assert res == 0
示例4: test_raw_free
def test_raw_free(self):
def f(addr):
raw_free(addr)
a = RPythonAnnotator()
s = a.build_types(f, [annmodel.SomeAddress()])
rtyper = RPythonTyper(a)
rtyper.specialize() #does not raise
示例5: test_memcopy
def test_memcopy(self):
def f(addr1, addr2):
raw_memcopy(addr1, addr2, 100)
a = RPythonAnnotator()
#does not raise:
s = a.build_types(f, [annmodel.SomeAddress(), annmodel.SomeAddress()])
rtyper = RPythonTyper(a)
rtyper.specialize() #does not raise
示例6: test_memory_access
def test_memory_access(self):
def f(offset, value):
addr = raw_malloc(offset * 2 + 1)
addr.signed[offset] = value
return addr.signed[offset]
a = RPythonAnnotator()
s = a.build_types(f, [annmodel.SomeInteger(), annmodel.SomeInteger()])
rtyper = RPythonTyper(a)
rtyper.specialize() #does not raise
示例7: test_null
def test_null(self):
def f():
return NULL
a = RPythonAnnotator()
s = a.build_types(f, [])
rtyper = RPythonTyper(a)
rtyper.specialize()
rtyp = graphof(a.translator, f).returnblock.inputargs[0].concretetype
assert rtyp == Address
示例8: test_address_comparison
def test_address_comparison(self):
def f(offset):
return NULL < NULL + offset
a = RPythonAnnotator()
s = a.build_types(f, [annmodel.SomeInteger()])
rtyper = RPythonTyper(a)
rtyper.specialize() #does not raise
graph = graphof(a.translator, f)
assert graph.startblock.operations[0].result.concretetype == Address
示例9: test_reprkeys_dont_clash
def test_reprkeys_dont_clash():
stup1 = annmodel.SomeTuple((annmodel.SomeFloat(),
annmodel.SomeInteger()))
stup2 = annmodel.SomeTuple((annmodel.SomeString(),
annmodel.SomeInteger()))
rtyper = RPythonTyper(annrpython.RPythonAnnotator(None))
key1 = rtyper.makekey(stup1)
key2 = rtyper.makekey(stup2)
assert key1 != key2
示例10: test_address_arithmetic
def test_address_arithmetic(self):
def f(offset, char):
addr = raw_malloc(10000)
same_offset = (addr + offset) - addr
addr.char[offset] = char
return (addr + same_offset).char[0]
a = RPythonAnnotator()
s = a.build_types(f, [annmodel.SomeInteger(), annmodel.SomeChar()])
rtyper = RPythonTyper(a)
rtyper.specialize() #does not raise
示例11: ll_rtype
def ll_rtype(llfn, argtypes=[]):
a = RPythonAnnotator()
graph = annotate_lowlevel_helper(a, llfn, argtypes)
s = a.binding(graph.getreturnvar())
t = a.translator
typer = RPythonTyper(a)
typer.specialize()
#t.view()
t.checkgraphs()
return s, t
示例12: test_alloc_flavor
def test_alloc_flavor():
class A:
_alloc_flavor_ = "raw"
def f():
return A()
a = RPythonAnnotator()
#does not raise:
s = a.build_types(f, [])
Adef = a.bookkeeper.getuniqueclassdef(A)
assert s.knowntype == Adef
rtyper = RPythonTyper(a)
rtyper.specialize()
assert (Adef, 'raw') in rtyper.instance_reprs
assert (Adef, 'gc') not in rtyper.instance_reprs
示例13: test_isinstance
def test_isinstance():
class A(object):
_alloc_flavor_ = "raw"
class B(A):
pass
class C(B):
pass
def f(i):
if i == 0:
o = None
elif i == 1:
o = A()
elif i == 2:
o = B()
else:
o = C()
res = 100*isinstance(o, A) + 10*isinstance(o, B) + 1*isinstance(o, C)
if i == 0:
pass
elif i == 1:
assert isinstance(o, A)
free_non_gc_object(o)
elif i == 2:
assert isinstance(o, B)
free_non_gc_object(o)
else:
assert isinstance(o, C)
free_non_gc_object(o)
return res
assert f(1) == 100
assert f(2) == 110
assert f(3) == 111
assert f(0) == 0
a = RPythonAnnotator()
#does not raise:
s = a.build_types(f, [int])
assert s.knowntype == int
rtyper = RPythonTyper(a)
rtyper.specialize()
res = interpret(f, [1])
assert res == 100
res = interpret(f, [2])
assert res == 110
res = interpret(f, [3])
assert res == 111
res = interpret(f, [0])
assert res == 0
示例14: test_addr_as_bool
def test_addr_as_bool(self):
def f(addr1, addr2):
if addr1:
return 1
else:
if not addr2:
return 0
else:
return -1
a = RPythonAnnotator()
#does not raise:
s = a.build_types(f, [annmodel.SomeAddress(), annmodel.SomeAddress()])
rtyper = RPythonTyper(a)
rtyper.specialize() #does not raise
示例15: test_c_callback_with_void_arg_3
def test_c_callback_with_void_arg_3(self):
import pypy
def f(i):
x = 'X' * i
return x[-2]
a = RPythonAnnotator()
r = a.build_types(f, [int])
rtyper = RPythonTyper(a)
rtyper.specialize()
a.translator.rtyper = rtyper
graph = a.translator.graphs[0]
op = graph.startblock.operations[-1]
assert op.opname == 'direct_call'
assert op.args[0].value._obj._callable == pypy.rpython.lltypesystem.rstr.LLHelpers.ll_stritem.im_func
assert op.args[1].value == pypy.rpython.lltypesystem.rstr.LLHelpers
assert op.args[3].value == -2