当前位置: 首页>>代码示例>>Python>>正文


Python RPythonTyper.specialize方法代码示例

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


在下文中一共展示了RPythonTyper.specialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_raw_malloc

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:9,代码来源:test_address.py

示例2: test_raw_free

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:9,代码来源:test_address.py

示例3: test_isinstance

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
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,代码行数:35,代码来源:test_nongc.py

示例4: test_ll_calling_ll2

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
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,代码行数:9,代码来源:test_rtyper.py

示例5: test_memcopy

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:10,代码来源:test_address.py

示例6: test_null

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:11,代码来源:test_address.py

示例7: test_address_comparison

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:11,代码来源:test_address.py

示例8: test_memory_access

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:11,代码来源:test_address.py

示例9: test_address_arithmetic

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:12,代码来源:test_address.py

示例10: ll_rtype

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
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,代码行数:12,代码来源:test_rptr.py

示例11: test_addr_as_bool

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:16,代码来源:test_address.py

示例12: test_isinstance

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
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,代码行数:52,代码来源:test_nongc.py

示例13: test_alloc_flavor

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
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,代码行数:16,代码来源:test_nongc.py

示例14: test_c_callback_with_void_arg_3

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
 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,代码行数:18,代码来源:test_ll2ctypes.py

示例15: annotate_rtype_gc

# 需要导入模块: from pypy.rpython.rtyper import RPythonTyper [as 别名]
# 或者: from pypy.rpython.rtyper.RPythonTyper import specialize [as 别名]
    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,代码行数:48,代码来源:gcwrapper.py


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