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


Python gateway.interp2app函数代码示例

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


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

示例1: setup_class

    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Can't run this test with -A")
        space = gettestobjspace(usemodules=('pypyjit',))
        cls.space = space
        w_f = space.appexec([], """():
        def f():
            pass
        return f
        """)
        ll_code = cast_instance_to_base_ptr(w_f.code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2]
        i3 = int_add(i1, i2)
        guard_true(i3) []
        """, namespace={'ptr0': 3}).operations

        def interp_on_compile():
            pypyjitdriver.on_compile(logger, LoopToken(), oplist, 'loop',
                                     0, False, ll_code)

        def interp_on_compile_bridge():
            pypyjitdriver.on_compile_bridge(logger, LoopToken(), oplist, 0)
        
        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
开发者ID:pombredanne,项目名称:pypy,代码行数:28,代码来源:test_jit_hook.py

示例2: setup_class

 def setup_class(cls):
     cls.space = gettestobjspace(**{"objspace.std.withcelldict": True})
     cls.w_impl_used = cls.space.appexec([], """():
         import __pypy__
         def impl_used(obj):
             assert "ModuleDictImplementation" in __pypy__.internal_repr(obj)
         return impl_used
     """)
     def is_in_cache(space, w_code, w_globals, w_name):
         name = space.str_w(w_name)
         cache = get_global_cache(space, w_code, w_globals)
         index = [space.str_w(w_n) for w_n in w_code.co_names_w].index(name)
         return space.wrap(cache[index].w_value is not None)
     is_in_cache = gateway.interp2app(is_in_cache)
     cls.w_is_in_cache = cls.space.wrap(is_in_cache) 
     stored_builtins = []
     def rescue_builtins(space):
         w_dict = space.builtin.getdict()
         content = {}
         for key, cell in w_dict.implementation.content.iteritems():
             newcell = ModuleCell()
             newcell.w_value = cell.w_value
             content[key] = newcell
         stored_builtins.append(content)
     rescue_builtins = gateway.interp2app(rescue_builtins)
     cls.w_rescue_builtins = cls.space.wrap(rescue_builtins) 
     def restore_builtins(space):
         w_dict = space.builtin.getdict()
         if not isinstance(w_dict.implementation, ModuleDictImplementation):
             w_dict.implementation = ModuleDictImplementation(space)
         w_dict.implementation.content = stored_builtins.pop()
     restore_builtins = gateway.interp2app(restore_builtins)
     cls.w_restore_builtins = cls.space.wrap(restore_builtins) 
开发者ID:enyst,项目名称:plexnet,代码行数:33,代码来源:test_celldict.py

示例3: test_interp2app_unwrap_spec_c_int

    def test_interp2app_unwrap_spec_c_int(self):
        from rpython.rlib.rarithmetic import r_longlong

        space = self.space
        w = space.wrap

        def g(space, x):
            return space.wrap(x + 6)

        app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "c_int"])
        app_ug = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "c_uint"])
        app_ng = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "c_nonnegint"])
        assert app_ug is not app_g
        w_app_g = space.wrap(app_g)
        w_app_ug = space.wrap(app_ug)
        w_app_ng = space.wrap(app_ng)
        #
        assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)), space.wrap(13))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_g, space.wrap(r_longlong(0x80000000)))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_g, space.wrap(r_longlong(-0x80000001)))
        #
        assert self.space.eq_w(space.call_function(w_app_ug, space.wrap(7)), space.wrap(13))
        assert self.space.eq_w(
            space.call_function(w_app_ug, space.wrap(0x7FFFFFFF)), space.wrap(r_longlong(0x7FFFFFFF + 6))
        )
        space.raises_w(space.w_ValueError, space.call_function, w_app_ug, space.wrap(-1))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_ug, space.wrap(r_longlong(0x100000000)))
        #
        assert self.space.eq_w(space.call_function(w_app_ng, space.wrap(7)), space.wrap(13))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_ng, space.wrap(r_longlong(0x80000000)))
        space.raises_w(space.w_ValueError, space.call_function, w_app_ng, space.wrap(-1))
开发者ID:Qointum,项目名称:pypy,代码行数:31,代码来源:test_gateway.py

示例4: _attach_helpers

def _attach_helpers(space):
    from pypy.interpreter import pytraceback

    def hide_top_frame(space, w_frame):
        w_last = None
        while w_frame.f_backref():
            w_last = w_frame
            w_frame = w_frame.f_backref()
        assert w_last
        w_saved = w_last.f_backref()
        w_last.f_backref = vref_None
        return w_saved

    def restore_top_frame(space, w_frame, w_saved):
        while w_frame.f_backref():
            w_frame = w_frame.f_backref()
        w_frame.f_backref = non_virtual_ref(w_saved)

    def read_exc_type(space, w_frame):
        if w_frame.last_exception is None:
            return space.w_None
        else:
            return w_frame.last_exception.w_type

    from pypy.interpreter import gateway

    hide_gw = gateway.interp2app(hide_top_frame)
    space.setitem(space.builtin.w_dict, space.wrap("hide_top_frame"), space.wrap(hide_gw))
    restore_gw = gateway.interp2app(restore_top_frame)
    space.setitem(space.builtin.w_dict, space.wrap("restore_top_frame"), space.wrap(restore_gw))

    read_exc_type_gw = gateway.interp2app(read_exc_type)
    space.setitem(space.builtin.w_dict, space.wrap("read_exc_type"), space.wrap(read_exc_type_gw))
开发者ID:GaussDing,项目名称:pypy,代码行数:33,代码来源:test_zzpickle_and_slow.py

示例5: setup_class

    def setup_class(cls):
        cls.w_TEXT = cls.space.wrapbytes(TEXT)
        cls.DATA = DATA
        cls.w_DATA = cls.space.wrapbytes(DATA)
        cls.DATA_CRLF = DATA_CRLF
        cls.w_DATA_CRLF = cls.space.wrapbytes(DATA_CRLF)
        cls.temppath = str(py.test.ensuretemp("bz2").join("foo"))
        cls.w_temppath = cls.space.wrap(cls.temppath)
        if cls.runappdirect:
            cls.w_create_temp_file = create_temp_file
            cls.w_create_broken_temp_file = create_broken_temp_file
            cls.w_decompress = decompress
        else:
            @gateway.unwrap_spec(crlf=bool)
            def create_temp_file_w(crlf=False):
                create_temp_file(cls, crlf)
            cls.w_create_temp_file = cls.space.wrap(
                gateway.interp2app(create_temp_file_w))

            @gateway.unwrap_spec(data=bytes)
            def decompress_w(space, data):
                return space.wrapbytes(decompress(cls, data))
            cls.w_decompress = cls.space.wrap(gateway.interp2app(decompress_w))

            def create_broken_temp_file_w():
                create_broken_temp_file(cls)
            cls.w_create_broken_temp_file = cls.space.wrap(
                gateway.interp2app(create_broken_temp_file_w))
        cls.w_random_data = cls.space.wrapbytes(RANDOM_DATA)
开发者ID:Qointum,项目名称:pypy,代码行数:29,代码来源:test_bz2_file.py

示例6: setup_class

    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Can't run this test with -A")
        space = gettestobjspace(usemodules=('pypyjit',))
        cls.space = space
        w_f = space.appexec([], """():
        def function():
            pass
        return function
        """)
        cls.w_f = w_f
        ll_code = cast_instance_to_base_ptr(w_f.code)
        code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2, p2]
        i3 = int_add(i1, i2)
        debug_merge_point(0, 0, 0, 0, 0, ConstPtr(ptr0))
        guard_nonnull(p2) []
        guard_true(i3) []
        """, namespace={'ptr0': code_gcref}).operations
        greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)]
        offset = {}
        for i, op in enumerate(oplist):
            if i != 1:
               offset[op] = i

        di_loop = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                               oplist, 'loop', greenkey)
        di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                        oplist, 'loop', greenkey)
        di_loop.asminfo = AsmInfo(offset, 0, 0)
        di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                 oplist, 'bridge', fail_descr_no=0)
        di_bridge.asminfo = AsmInfo(offset, 0, 0)

        def interp_on_compile():
            di_loop.oplist = cls.oplist
            pypy_hooks.after_compile(di_loop)

        def interp_on_compile_bridge():
            pypy_hooks.after_compile_bridge(di_bridge)

        def interp_on_optimize():
            di_loop_optimize.oplist = cls.oplist
            pypy_hooks.before_compile(di_loop_optimize)

        def interp_on_abort():
            pypy_hooks.on_abort(ABORT_TOO_LONG, pypyjitdriver, greenkey,
                                'blah')

        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
        cls.w_on_abort = space.wrap(interp2app(interp_on_abort))
        cls.w_int_add_num = space.wrap(rop.INT_ADD)
        cls.w_dmp_num = space.wrap(rop.DEBUG_MERGE_POINT)
        cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize))
        cls.orig_oplist = oplist
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:test_jit_hook.py

示例7: create_builder

def create_builder(name, strtype, builder_cls):
    class W_Builder(W_Root):
        def __init__(self, space, size):
            if size < 0:
                self.builder = builder_cls()
            else:
                self.builder = builder_cls(size)

        def _check_done(self, space):
            if self.builder is None:
                raise OperationError(space.w_ValueError, space.wrap(
                        "Can't operate on a built builder"))

        @unwrap_spec(size=int)
        def descr__new__(space, w_subtype, size=-1):
            return W_Builder(space, size)

        @unwrap_spec(s=strtype)
        def descr_append(self, space, s):
            self._check_done(space)
            self.builder.append(s)

        @unwrap_spec(s=strtype, start=int, end=int)
        def descr_append_slice(self, space, s, start, end):
            self._check_done(space)
            if not 0 <= start <= end <= len(s):
                raise OperationError(space.w_ValueError, space.wrap(
                        "bad start/stop"))
            self.builder.append_slice(s, start, end)

        def descr_build(self, space):
            self._check_done(space)
            s = self.builder.build()
            self.builder = None
            if strtype is str:
                return space.wrapbytes(s)
            else:
                return space.wrap(s)

        def descr_len(self, space):
            if self.builder is None:
                raise OperationError(space.w_ValueError, space.wrap(
                        "no length of built builder"))
            return space.wrap(self.builder.getlength())

    W_Builder.__name__ = "W_%s" % name
    W_Builder.typedef = TypeDef(name,
        __new__ = interp2app(func_with_new_name(
                                    W_Builder.descr__new__.im_func,
                                    '%s_new' % (name,))),
        append = interp2app(W_Builder.descr_append),
        append_slice = interp2app(W_Builder.descr_append_slice),
        build = interp2app(W_Builder.descr_build),
        __len__ = interp2app(W_Builder.descr_len),
    )
    W_Builder.typedef.acceptable_as_base_class = False
    return W_Builder
开发者ID:Qointum,项目名称:pypy,代码行数:57,代码来源:interp_builders.py

示例8: test_interp2app_unwrap_spec_bool

 def test_interp2app_unwrap_spec_bool(self):
     space = self.space
     w = space.wrap
     def g(space, b):
         return space.wrap(b)
     app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, bool])
     app_g2 = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, bool])
     assert app_g is app_g2
     w_app_g = space.wrap(app_g)
     assert self.space.eq_w(space.call_function(w_app_g, space.wrap(True)),
                            space.wrap(True))
开发者ID:enyst,项目名称:plexnet,代码行数:11,代码来源:test_gateway.py

示例9: test_caching_methods

    def test_caching_methods(self):
        class Base(gateway.Wrappable):
            def f(self):
                return 1

        class A(Base):
            pass
        class B(Base):
            pass
        app_A = gateway.interp2app(A.f)
        app_B = gateway.interp2app(B.f)
        assert app_A is not app_B
开发者ID:enyst,项目名称:plexnet,代码行数:12,代码来源:test_gateway.py

示例10: test_interp2app_unwrap_spec_nonnegint

    def test_interp2app_unwrap_spec_nonnegint(self):
        space = self.space
        w = space.wrap

        def g(space, x):
            return space.wrap(x * 6)

        app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "nonnegint"])
        app_g2 = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "nonnegint"])
        assert app_g is app_g2
        w_app_g = space.wrap(app_g)
        assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)), space.wrap(42))
        assert self.space.eq_w(space.call_function(w_app_g, space.wrap(0)), space.wrap(0))
        space.raises_w(space.w_ValueError, space.call_function, w_app_g, space.wrap(-1))
开发者ID:Qointum,项目名称:pypy,代码行数:14,代码来源:test_gateway.py

示例11: setup_class

 def setup_class(cls):
     cls.w_TEXT = cls.space.wrap(TEXT)
     cls.w_DATA = cls.space.wrap(DATA)
     cls.w_DATA_CRLF = cls.space.wrap(DATA_CRLF)
     cls.w_temppath = cls.space.wrap(
         str(py.test.ensuretemp("bz2").join("foo")))
     if cls.runappdirect:
         cls.w_create_temp_file = create_temp_file
         cls.w_create_broken_temp_file = lambda self: create_broken_temp_file()
         cls.w_decompress = lambda self, *args: decompress(cls.space, *args)
     else:
         cls.w_create_temp_file = cls.space.wrap(interp2app(create_temp_file))
         cls.w_create_broken_temp_file = cls.space.wrap(interp2app(create_broken_temp_file))
         cls.w_decompress = cls.space.wrap(interp2app(decompress))
     cls.w_random_data = cls.space.wrap(RANDOM_DATA)
开发者ID:charred,项目名称:pypy,代码行数:15,代码来源:test_bz2_file.py

示例12: register_builtin_error_handlers

def register_builtin_error_handlers(space):
    "NOT_RPYTHON"
    state = space.fromcache(CodecState)
    for error in ("strict", "ignore", "replace", "xmlcharrefreplace",
                  "backslashreplace"):
        name = error + "_errors"
        state.codec_error_registry[error] = space.wrap(interp2app(globals()[name]))
开发者ID:Darriall,项目名称:pypy,代码行数:7,代码来源:interp_codecs.py

示例13: setup_method

    def setup_method(self, func):
        @unwrap_spec(name=str, init=str, body=str)
        def create_cdll(space, name, init, body):
            # the following is loosely from test_cpyext.py import_module; it
            # is copied here to be able to tweak the call to
            # compile_extension_module and to get a different return result
            # than in that function
            code = """
            #include <Python.h>
            /* fix for cpython 2.7 Python.h if running tests with -A
               since pypy compiles with -fvisibility-hidden */
            #undef PyMODINIT_FUNC
            #define PyMODINIT_FUNC RPY_EXPORTED void

            %(body)s

            PyMODINIT_FUNC
            init%(name)s(void) {
            %(init)s
            }
            """ % dict(
                name=name, init=init, body=body
            )
            kwds = dict(separate_module_sources=[code])
            mod = compile_extension_module(space, name, **kwds)

            # explicitly load the module as a CDLL rather than as a module
            from pypy.module.imp.importing import get_so_extension

            fullmodname = os.path.join(os.path.dirname(mod), name + get_so_extension(space))
            return space.wrap(fullmodname)

        self.w_create_cdll = self.space.wrap(interp2app(create_cdll))
开发者ID:mozillazg,项目名称:pypy,代码行数:33,代码来源:test_crossing.py

示例14: patch_unicodedb

def patch_unicodedb():
    from pypy.module.unicodedata import unicodedb_4_1_0
    from pypy.module.unicodedata.interp_ucd import UCD, methods, \
         unichr_to_code_w
    from pypy.interpreter.gateway import W_Root, ObjSpace, NoneNotWrapped
    from unicodedb import _casefold
    from pypy.interpreter.typedef import TypeDef, interp_attrproperty
    from pypy.interpreter.gateway import  interp2app

    def casefold(code):
        try:
            return _casefold[code]
        except KeyError:
            return [code]

    unicodedb_4_1_0.casefold = casefold

    # patch the app-level, so it's exposed
    def interp_casefold(self, space, w_unichr):
        code = unichr_to_code_w(space, w_unichr)
        return space.newlist([space.wrap(c) for c in casefold(code)])
    unwrap_spec = ['self', ObjSpace, W_Root]
    
    UCD.casefold = interp_casefold
    methods['casefold'] = interp2app(UCD.casefold, unwrap_spec=unwrap_spec)
    UCD.typedef = TypeDef("unicodedata.UCD",
                          __doc__ = "",
                          unidata_version = interp_attrproperty('version', UCD),
                          **methods)
开发者ID:enyst,项目名称:plexnet,代码行数:29,代码来源:pypy_startup.py

示例15: setup_class

    def setup_class(cls):
        from pypy.interpreter import gateway
        import sys

        space = cls.space
        cls.w_cpython_behavior = space.wrap(not option.runappdirect)
        cls.w_cpython_version = space.wrap(tuple(sys.version_info))
        cls.w_appdirect = space.wrap(option.runappdirect)
        cls.w_cpython_apptest = space.wrap(option.runappdirect and not hasattr(sys, 'pypy_translation_info'))

        def w_unwrap_wrap_unicode(space, w_obj):
            return space.wrap(space.unicode_w(w_obj))
        cls.w_unwrap_wrap_unicode = space.wrap(gateway.interp2app(w_unwrap_wrap_unicode))
        def w_unwrap_wrap_bytes(space, w_obj):
            return space.wrapbytes(space.bytes_w(w_obj))
        cls.w_unwrap_wrap_bytes = space.wrap(gateway.interp2app(w_unwrap_wrap_bytes))
开发者ID:Qointum,项目名称:pypy,代码行数:16,代码来源:test_obj.py


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