• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rtyper.RPythonTyper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.rpython.rtyper.RPythonTyper的典型用法代码示例。如果您正苦于以下问题:Python RPythonTyper类的具体用法?Python RPythonTyper怎么用?Python RPythonTyper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了RPythonTyper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_address.py


示例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
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_rtyper.py


示例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
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:test_nongc.py


示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_address.py


示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:test_address.py


示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:test_address.py


示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:test_address.py


示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:test_address.py


示例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
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_rtyper.py


示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:test_address.py


示例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
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_rptr.py


示例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    
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:test_nongc.py


示例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
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:50,代码来源:test_nongc.py


示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:14,代码来源:test_address.py


示例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
开发者ID:alkorzt,项目名称:pypy,代码行数:16,代码来源:test_ll2ctypes.py


示例16: annotate_rtype_gc

    def annotate_rtype_gc(self):
        # annotate and specialize functions
        gc_class = self.gc.__class__
        AddressLinkedList = self.AddressLinkedList
        def instantiate_linked_list():
            return AddressLinkedList()
        f1, f2, f3, f4, f5, f6, f7, f8 = self.query_types.create_query_functions()
        the_gc = gc_class(AddressLinkedList)
        def instantiate_gc():
            the_gc.set_query_functions(f1, f2, f3, f4, f5, f6, f7, f8)
            the_gc.setup()
            return the_gc
        func, dummy_get_roots1, dummy_get_roots2 = gc.get_dummy_annotate(
            the_gc, self.AddressLinkedList)
        self.gc.get_roots = dummy_get_roots1
        a = RPythonAnnotator()
        a.build_types(instantiate_gc, [])
        a.build_types(func, [])
        a.build_types(instantiate_linked_list, [])
        typer = RPythonTyper(a)
        typer.specialize()
        self.annotator = a
        
        # convert constants
        fgcc = FlowGraphConstantConverter(a.translator.graphs)
        fgcc.convert()
        self.malloc_graph = a.bookkeeper.getdesc(self.gc.malloc.im_func).getuniquegraph()
        self.write_barrier_graph = a.bookkeeper.getdesc(self.gc.write_barrier.im_func).getuniquegraph()

        # create a gc via invoking instantiate_gc
        self.gcptr = self.llinterp.eval_graph(
            a.bookkeeper.getdesc(instantiate_gc).getuniquegraph())
        GETROOTS_FUNCTYPE = lltype.typeOf(
            getfunctionptr(a, dummy_get_roots1)).TO
        setattr(self.gcptr, "inst_get_roots",
                lltypesimulation.functionptr(GETROOTS_FUNCTYPE, "get_roots",
                                             _callable=self.get_roots))
        #get funcptrs neccessary to build the result of get_roots
        self.instantiate_linked_list = getfunctionptr(
            a, instantiate_linked_list)
        self.append_linked_list = getfunctionptr(
            a, AddressLinkedList.append.im_func)
        self.pop_linked_list = getfunctionptr(
            a, AddressLinkedList.pop.im_func)
        self.gc.get_roots = None
        self.translator = a.translator
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:46,代码来源:gcwrapper.py


示例17: test_rtype_nongc_object

def test_rtype_nongc_object():
    class TestClass(object):
        _alloc_flavor_ = "raw"
        def __init__(self, a):
            self.a = a
        def method1(self):
            return self.a
    def malloc_and_free(a):
        ci = TestClass(a)
        b = ci.method1()
        free_non_gc_object(ci)
        return b
    a = RPythonAnnotator()
    #does not raise:
    s = a.build_types(malloc_and_free, [annmodel.SomeAddress()])
    assert isinstance(s, annmodel.SomeAddress)
    rtyper = RPythonTyper(a)
    rtyper.specialize()
开发者ID:alkorzt,项目名称:pypy,代码行数:18,代码来源:test_nongc.py


示例18: test_alloc_flavor_subclassing

def test_alloc_flavor_subclassing():
    class A:
        _alloc_flavor_ = "raw"
    class B(A):
        def __init__(self, a):
            self.a = a
    def f():
        return B(0)
    a = RPythonAnnotator()
    #does not raise:
    s = a.build_types(f, [])
    Adef = a.bookkeeper.getuniqueclassdef(A)
    Bdef = a.bookkeeper.getuniqueclassdef(B)
    assert s.knowntype == Bdef
    rtyper = RPythonTyper(a)
    rtyper.specialize()
    assert (Adef, 'raw') in rtyper.instance_reprs
    assert (Adef, 'gc') not in rtyper.instance_reprs
    assert (Bdef, 'raw') in rtyper.instance_reprs
    assert (Bdef, 'gc') not in rtyper.instance_reprs        
开发者ID:alkorzt,项目名称:pypy,代码行数:20,代码来源:test_nongc.py


示例19: test_is

def test_is():
    class A:
        _alloc_flavor_ = "raw"
        pass
    class B(A): pass
    class C:
        _alloc_flavor_ = "raw"
    def f(i):
        a = A()
        b = B()
        c = C()
        d = None
        e = None
        if i == 0:
            d = a
        elif i == 1:
            d = b
        elif i == 2:
            e = c
        res =  (0x0001*(a is b) | 0x0002*(a is c) | 0x0004*(a is d) |
                0x0008*(a is e) | 0x0010*(b is c) | 0x0020*(b is d) |
                0x0040*(b is e) | 0x0080*(c is d) | 0x0100*(c is e) |
                0x0200*(d is e))
        free_non_gc_object(a)
        free_non_gc_object(b)
        free_non_gc_object(c)
        return res
    a = RPythonAnnotator()
    #does not raise:
    s = a.build_types(f, [int])
    assert s.knowntype == int
    rtyper = RPythonTyper(a)
    rtyper.specialize()
    res = interpret(f, [0])
    assert res == 0x0004
    res = interpret(f, [1])
    assert res == 0x0020
    res = interpret(f, [2])
    assert res == 0x0100
    res = interpret(f, [3])
    assert res == 0x0200
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:41,代码来源:test_nongc.py


示例20: test_implicit_cast

 def test_implicit_cast(self):
     z = llexternal('z', [USHORT, ULONG, USHORT, DOUBLE], USHORT,
                    sandboxsafe=True)   # to allow the wrapper to be inlined
 
     def f(x, y, xx, yy):
         return z(x, y, xx, yy)
 
     a = RPythonAnnotator()
     r = a.build_types(f, [int, int, int, int])
     rtyper = RPythonTyper(a)
     rtyper.specialize()
     a.translator.rtyper = rtyper
     backend_optimizations(a.translator)
     if option.view:
         a.translator.view()
     graph = graphof(a.translator, f)
     s = summary(graph)
     # there should be not too many operations here by now
     expected = {'force_cast': 3, 'cast_int_to_float': 1, 'direct_call': 1}
     for k, v in expected.items():
         assert s[k] == v
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:21,代码来源:test_rffi.py



注:本文中的pypy.rpython.rtyper.RPythonTyper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_llinterp.interpret函数代码示例发布时间:2022-05-27
下一篇:
Python rmodel.inputconst函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap