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

Python test_llinterp.interpret函数代码示例

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

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



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

示例1: test_callback_field_bound_method

def test_callback_field_bound_method():
    py.test.skip("needs an rtyping hack to help the js backend "
                 "or generalized bound methods support in many places")
    class A:
        def x(self, i):
            return float(i)

    aa = A()

    def callback(x):
        return 8.3 + x

    def callback_field(i):
        a = CD()
        if i:
            a.callback_field = aa.x
        else:
            a.callback_field = callback
        return a.callback_field(i+1)
    
    res = interpret(callback_field, [1], type_system="ootype")
    assert res == 2.0
    assert isinstance(res, float)
    res = interpret(callback_field, [0], type_system="ootype")
    assert res == 8.3
开发者ID:antoine1fr,项目名称:pygirl,代码行数:25,代码来源:test_bltann.py


示例2: test_overflow_bug

def test_overflow_bug():
    CASE = [
        (-144, -248),  # \ cycle
        (-248, -144),  # /
        (-488, -416),  # \ two usages of -488
        (-488, -480),  # /
        (-488, -488),  # - one self-application of -488
    ]

    class FakeAssembler:
        def regalloc_mov(self, src, dst):
            print "mov", src, dst

        def regalloc_push(self, x):
            print "push", x

        def regalloc_pop(self, x):
            print "pop", x

        def regalloc_immedmem2mem(self, x, y):
            print "?????????????????????????"

    def main():
        srclocs = [StackLoc(9999, x, "i") for x, y in CASE]
        dstlocs = [StackLoc(9999, y, "i") for x, y in CASE]
        remap_frame_layout(FakeAssembler(), srclocs, dstlocs, eax)

    # it works when run directly
    main()
    # but it used to crash when translated,
    # because of a -sys.maxint-2 overflowing to sys.maxint
    from pypy.rpython.test.test_llinterp import interpret

    interpret(main, [])
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:34,代码来源:test_jump.py


示例3: test_convert_pointers

    def test_convert_pointers(self):
        py.test.skip("in-progress")
        from pypy.rpython.rctypes.rchar_p import ll_strlen
        strlen = CFUNCTYPE(c_int, c_char_p)()   # not directly executable!
        strlen.__name__ = 'strlen'
        strlen.llinterp_friendly_version = ll_strlen
        PTR = c_char_p("hello")
        BUF = create_string_buffer(10)
        BUF.value = "hello"

        def func(n):
            # constant arguments
            assert strlen("hello") == 5
            assert strlen(PTR) == 5
            assert strlen(BUF) == 5
            # variable arguments
            s = chr(n) + 'bc'
            assert strlen(s) == 3
            assert strlen(c_char_p(s)) == 3
            assert strlen((c_char * 6)('a', 'b')) == 2
            buf = create_string_buffer(10)
            buf.value = "hello"
            assert strlen(buf) == 5

        interpret(func, [65])
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:25,代码来源:test_rchar_p.py


示例4: test_some_generic_function_call

    def test_some_generic_function_call(self):
        def h(x):
            return int(x)

        def c(x):
            return int(x) + 1

        def default(x):
            return int(x) + 3
        
        def g(a, x):
            if x == -1:
                a = None
            if x > 0:
                if x == 1:
                    a = h
                else:
                    a = c
                x = x + 0.01
            return a(x)

        def f(x):
            return g(default, x)

        g._annenforceargs_ = policy.Sig(annmodel.SomeGenericCallable(
            args=[annmodel.SomeFloat()], result=annmodel.SomeInteger()),
                                        float)

        assert interpret(f, [1.]) == 1
        assert interpret(f, [10.]) == 11
        assert interpret(f, [-3.]) == 0
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:test_rgeneric.py


示例5: test_rpython_merge_RWeakValueDictionary2

def test_rpython_merge_RWeakValueDictionary2():
    class A(object):
        def __init__(self):
            self.d = RWeakValueDictionary(A)
        def f(self, key):
            a = A()
            self.d.set(key, a)
            return a
    empty = A()
    def f(x):
        a = A()
        if x:
            a = empty
        a2 = a.f("a")
        assert a.d.get("a") is a2
    f(0)
    interpret(f, [0])
    f(1)
    interpret(f, [1])

    def g(x):
        if x:
            d = RWeakValueDictionary(X)
        else:
            d = RWeakValueDictionary(Y)
        d.set("x", X())
        return 41
    py.test.raises(Exception, interpret, g, [1])
开发者ID:alkorzt,项目名称:pypy,代码行数:28,代码来源:test_rweakref.py


示例6: test_convert_from_llvalue

 def test_convert_from_llvalue(self):
     def func():
         x = c_ushort(5)
         pointer(x)[0] += 1
         assert x.value == 6
         x = c_char('A')
         pointer(x)[0] = chr(ord(pointer(x)[0]) + 1)
         assert x.value == 'B'
         x = c_longlong(5)
         pointer(x)[0] += 1
         assert x.value == r_longlong(6)
         x = c_ulonglong(5)
         pointer(x)[0] += 1
         assert x.value == r_ulonglong(6)
         # x = c_float(2.5)
         # pointer(x)[0] += 0.25
         # assert x.value == 2.75
         # pointer(x)[0] -= 1
         # assert x.value == 1.75
         x = c_double(2.5)
         pointer(x)[0] += 0.25
         assert x.value == 2.75
         pointer(x)[0] -= 1
         assert x.value == 1.75
         # x = c_wchar(u'A')
         # pointer(x)[0] = unichr(ord(pointer(x)[0]) + 1)
         # assert x.value == u'B'
     interpret(func, [])
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:28,代码来源:test_rprimitive.py


示例7: test_mix_class_record_instance

def test_mix_class_record_instance():
    I = Instance("test", ROOT, {"a": Signed})
    R = Record({"x": Signed})
    L = List(Signed)

    c1 = runtimeClass(I)
    c2 = runtimeClass(R)
    c3 = runtimeClass(L)
    c4 = runtimeClass(Class)
    def fn(flag):
        if flag == 0:
            return c1
        elif flag == 1:
            return c2
        elif flag == 2:
            return c3
        else:
            return c4

    res = interpret(fn, [0], type_system='ootype')
    assert res is c1
    res = interpret(fn, [1], type_system='ootype')
    assert res is c2
    res = interpret(fn, [2], type_system='ootype')
    assert res is c3
    res = interpret(fn, [3], type_system='ootype')
    assert res is c4
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:test_oortype.py


示例8: test_ntpath

def test_ntpath():
    import ntpath
    def f():
        assert ntpath.join("\\foo", "bar") == "\\foo\\bar"
        assert ntpath.join("c:\\foo", "spam\\egg") == "c:\\foo\\spam\\egg"
        assert ntpath.join("c:\\foo", "d:\\bar") == "d:\\bar"
    interpret(f, [])
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_ll_os_path.py


示例9: test_specialize_null_pointer

 def test_specialize_null_pointer(self):
     def fn():
         p = POINTER(c_int)()
         assert not p
         p.contents = c_int(12)
         assert p
     interpret(fn, [])
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_rpointer.py


示例10: test_prebuilt

def test_prebuilt():
    c = C(111)
    b = B(939393)

    def makeint(n):
        if n < 0:
            x = c
        elif n > 0:
            x = C(n)
        else:
            x = b
        return x

    def fn(n):
        x = makeint(n)
        if isinstance(x, B):
            return 'B', x.normalint
        elif isinstance(x, C):
            return 'C', x.smallint
        else:
            return 'A', 0

    res = interpret(fn, [12], taggedpointers=True)
    assert res.item0 == 'C'
    assert res.item1 == 12
    res = interpret(fn, [-1], taggedpointers=True)
    assert res.item0 == 'C'
    assert res.item1 == 111
    res = interpret(fn, [0], taggedpointers=True)
    assert res.item0 == 'B'
    assert res.item1 == 939393
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:test_rtagged.py


示例11: test_specialize_array_add_1_0

    def test_specialize_array_add_1_0(self):
        def f():
            a1 = numpy.array(range(4, 10))
            a2 = numpy.array([3])
            return a1 + a2

        data = [i + 3 for i in range(4, 10)]
        res = interpret(f, [])
        for i in range(len(data)):
            assert res.dataptr[i] == data[i]

        def f():
            a = numpy.array(range(4, 10))
            return a + 3

        res = interpret(f, [])
        for i in range(len(data)):
            assert res.dataptr[i] == data[i]

        def f():
            a = numpy.array(range(4, 10))
            return 3 + a

        res = interpret(f, [])
        for i in range(len(data)):
            assert res.dataptr[i] == data[i]
开发者ID:alkorzt,项目名称:pypy,代码行数:26,代码来源:test_array.py


示例12: test_around_extcall

 def test_around_extcall(self):
     if sys.platform == "win32":
         py.test.skip('No pipes on windows')
     import os
     from pypy.annotation import model as annmodel
     from pypy.rlib.objectmodel import invoke_around_extcall
     from pypy.rpython.extfuncregistry import register_external
     read_fd, write_fd = os.pipe()
     try:
         # we need an external function that is not going to get wrapped around
         # before()/after() calls, in order to call it from before()/after()...
         def mywrite(s):
             os.write(write_fd, s)
         def llimpl(s):
             s = ''.join(s.chars)
             os.write(write_fd, s)
         register_external(mywrite, [str], annmodel.s_None, 'll_mywrite',
                           llfakeimpl=llimpl, sandboxsafe=True)
 
         def before():
             mywrite("B")
         def after():
             mywrite("A")
         def f():
             os.write(write_fd, "-")
             invoke_around_extcall(before, after)
             os.write(write_fd, "E")
 
         interpret(f, [])
         data = os.read(read_fd, 99)
         assert data == "-BEA"
 
     finally:
         os.close(write_fd)
         os.close(read_fd)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:35,代码来源:test_rffi.py


示例13: test_specialize_array_sub_1_0

    def test_specialize_array_sub_1_0(self):
        def f():
            a1 = numpy.array(range(4, 10))
            a2 = numpy.array([3])
            return a1 - a2

        data = [i - 3 for i in range(4, 10)]
        res = interpret(f, [])
        for i in range(len(data)):
            assert res.dataptr[i] == data[i]

        def f():
            a = numpy.array(range(4, 10))
            return a - 3

        res = interpret(f, [])
        for i in range(len(data)):
            assert res.dataptr[i] == data[i]

        def f():
            a = numpy.array(range(4, 10))
            return 3 - a

        data = [3 - i for i in range(4, 10)]
        res = interpret(f, [])
        for i in range(len(data)):
            assert res.dataptr[i] == data[i]
开发者ID:alkorzt,项目名称:pypy,代码行数:27,代码来源:test_array.py


示例14: test_convert_pointers

    def test_convert_pointers(self):
        strlen = CFUNCTYPE(c_int, c_void_p)()
        strlen.__name__ = 'strlen'
        def ll_strlen_from_void_p(adr):
            i = 0
            while adr.char[i] != '\x00':
                i += 1
            return i
        strlen.llinterp_friendly_version = ll_strlen_from_void_p
        PTR = c_char_p("hello")
        BUF = create_string_buffer(10)
        BUF.value = "hello"
        ARR = (c_byte * 10)(65, 66, 67)

        def func(n):
            # constant arguments XXX in-progress
            ##   assert strlen("hello") == 5
            ##   assert strlen(PTR) == 5
            ##   assert strlen(BUF) == 5
            ##   assert strlen(ARR) == 3
            # variable arguments
            s = chr(n) + 'bc'
            assert strlen(s) == 3
            assert strlen(c_char_p(s)) == 3
            assert strlen((c_char * 6)('a', 'b')) == 2
            # XXX Bytes are not chars in llinterp.
            # assert strlen((c_byte * 6)(104,101,108,108,111)) == 5
            buf = create_string_buffer(10)
            buf.value = "hello"
            assert strlen(buf) == 5

        interpret(func, [65])
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:32,代码来源:test_rvoid_p.py


示例15: test_specialize_broadcast

    def test_specialize_broadcast(self):
        def f():
            a = numpy.empty((4, 3), dtype="i")
            b = numpy.array([33])
            a[:, :] = b
            return a

        res = interpret(f, [])
        for i in range(4 * 3):
            assert res.dataptr[i] == 33

        def f():
            a = numpy.empty((4, 3), dtype="i")
            b = numpy.array([33])
            a[:,] = b
            return a

        res = interpret(f, [])
        for i in range(4 * 3):
            assert res.dataptr[i] == 33

        def f():
            a = numpy.empty((4, 3, 2), dtype="i")
            a[:] = numpy.array([33])
            a[0, :] = numpy.array([22])
            return a

        res = interpret(f, [])
        data = [22] * 6 + [33] * 18
        for i in range(3 * 4 * 2):
            assert res.dataptr[i] == data[i]
开发者ID:alkorzt,项目名称:pypy,代码行数:31,代码来源:test_array.py


示例16: test_find

    def test_find(self):
        f = open(self.tmpname + "g", "w+")
        f.write("foobarfoobar\0")
        f.flush()

        def func(no):
            m = mmap.mmap(no, 12)
            assert m.find("\0", 0, 13) == -1    # no searching past the stop
            assert m.find("\0", 0, 13, True) == -1
            m.close()
            #
            m = mmap.mmap(no, 13)
            assert m.find("b", 0, 7) == 3
            assert m.find("z", 0, 7) == -1
            assert m.find("o", 11, 13) == -1
            assert m.find("ob", 0, 7) == 2
            assert m.find("\0", 0, 13) == 12
            assert m.find("o", 1, 4) == 1
            assert m.find("o", 2, 4) == 2
            assert m.find("o", 2, -4) == 2
            assert m.find("o", 8, -5) == -1
            m.close()

        func(f.fileno())
        interpret(func, [f.fileno()])
        f.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:26,代码来源:test_rmmap.py


示例17: test_set_item

    def test_set_item(self):
        f = open(self.tmpname + "s", "w+")
        f.write("foobar")
        f.flush()

        def func(no):
            m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)

            # def f(m): m[1:3] = u'xx'
            # py.test.raises(IndexError, f, m)
            # def f(m): m[1:4] = "zz"
            # py.test.raises(IndexError, f, m)
            # def f(m): m[1:6] = "z" * 6
            # py.test.raises(IndexError, f, m)
            # def f(m): m[:2] = "z" * 5
            # m[1:3] = 'xx'
            # assert m.read(6) == "fxxbar"
            # m.seek(0)
            m.setitem(0, 'x')
            assert m.getitem(0) == 'x'
            m.setitem(-6, 'y')
            data = m.read(6)
            assert data == "yoobar" # yxxbar with slice's stuff
            m.close()

        interpret(func, [f.fileno()])
        f.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:27,代码来源:test_rmmap.py


示例18: test_rename

    def test_rename(self):
        def f():
            return rposix.rename(self.path, self.path2)

        interpret(f, [])
        assert not os.path.exists(self.ufilename)
        assert os.path.exists(self.ufilename + '.new')
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_rposix.py


示例19: test_value_for_various_types

 def test_value_for_various_types(self):
     def func():
         x = c_ushort(5)
         x.value += 1
         assert x.value == 6
         x = c_char('A')
         x.value = chr(ord(x.value) + 1)
         assert x.value == 'B'
         x = c_longlong(5)
         x.value += 1
         assert x.value == r_longlong(6)
         x = c_ulonglong(5)
         x.value += 1
         assert x.value == r_ulonglong(6)
         # x = c_float(2.5)
         # x.value += 0.25
         # assert x.value == 2.75
         # x.value -= 1
         # assert x.value == 1.75
         x = c_double(2.5)
         x.value += 0.25
         assert x.value == 2.75
         x.value -= 1
         assert x.value == 1.75
         # x = c_wchar(u'A')
         # x.value = unichr(ord(x.value) + 1)
         # assert x.value == u'B'
     interpret(func, [])
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:28,代码来源:test_rprimitive.py


示例20: test_posixpath

def test_posixpath():
    import posixpath
    def f():
        assert posixpath.join("/foo", "bar") == "/foo/bar"
        assert posixpath.join("/foo", "spam/egg") == "/foo/spam/egg"
        assert posixpath.join("/foo", "/bar") == "/bar"
    interpret(f, [])
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_ll_os_path.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python rffi_platform.configure函数代码示例发布时间:2022-05-27
下一篇:
Python rtyper.RPythonTyper类代码示例发布时间: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