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

Python sourcetools.func_with_new_name函数代码示例

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

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



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

示例1: register_stat_variant

def register_stat_variant(name):
    if sys.platform.startswith('win'):
        _functions = {'stat':  '_stati64',
                      'fstat': '_fstati64',
                      'lstat': '_stati64'}    # no lstat on Windows
        c_func_name = _functions[name]
    elif sys.platform.startswith('linux'):
        # because we always use _FILE_OFFSET_BITS 64 - this helps things work that are not a c compiler 
        _functions = {'stat':  'stat64',
                      'fstat': 'fstat64',
                      'lstat': 'lstat64'}
        c_func_name = _functions[name]
    else:
        c_func_name = name

    arg_is_path = (name != 'fstat')
    if arg_is_path:
        ARG1 = rffi.CCHARP
    else:
        ARG1 = rffi.INT
    os_mystat = rffi.llexternal(c_func_name, [ARG1, STAT_STRUCT], rffi.INT,
                                compilation_info=compilation_info)

    def os_mystat_llimpl(arg):
        stresult = lltype.malloc(STAT_STRUCT.TO, flavor='raw')
        try:
            if arg_is_path:
                arg = rffi.str2charp(arg)
            error = rffi.cast(rffi.LONG, os_mystat(arg, stresult))
            if arg_is_path:
                rffi.free_charp(arg)
            if error != 0:
                raise OSError(rposix.get_errno(), "os_?stat failed")
            return build_stat_result(stresult)
        finally:
            lltype.free(stresult, flavor='raw')

    def fakeimpl(arg):
        st = getattr(os, name)(arg)
        fields = [TYPE for fieldname, TYPE in LL_STAT_FIELDS]
        TP = TUPLE_TYPE(fields)
        ll_tup = lltype.malloc(TP.TO)
        for i, (fieldname, TYPE) in enumerate(LL_STAT_FIELDS):
            val = getattr(st, fieldname)
            rffi.setintfield(ll_tup, 'item%d' % i, int(val))
        return ll_tup

    if arg_is_path:
        s_arg = str
    else:
        s_arg = int
    register_external(getattr(os, name), [s_arg], s_StatResult,
                      "ll_os.ll_os_%s" % (name,),
                      llimpl=func_with_new_name(os_mystat_llimpl,
                                                'os_%s_llimpl' % (name,)),
                      llfakeimpl=func_with_new_name(fakeimpl,
                                                    'os_%s_fake' % (name,)))
开发者ID:antoine1fr,项目名称:pygirl,代码行数:57,代码来源:ll_os_stat.py


示例2: _reduce_argmax_argmin_impl

 def _reduce_argmax_argmin_impl(op_name):
     reduce_driver = jit.JitDriver(
         greens=['shapelen', 'signature'],
         reds=['result', 'idx', 'i', 'self', 'cur_best', 'dtype']
     )
     def loop(self):
         i = self.start_iter()
         cur_best = self.eval(i)
         shapelen = len(self.shape)
         i = i.next(shapelen)
         dtype = self.find_dtype()
         result = 0
         idx = 1
         while not i.done():
             reduce_driver.jit_merge_point(signature=self.signature,
                                           shapelen=shapelen,
                                           self=self, dtype=dtype,
                                           i=i, result=result, idx=idx,
                                           cur_best=cur_best)
             new_best = getattr(dtype, op_name)(cur_best, self.eval(i))
             if dtype.ne(new_best, cur_best):
                 result = idx
                 cur_best = new_best
             i = i.next(shapelen)
             idx += 1
         return result
     def impl(self, space):
         size = self.find_size()
         if size == 0:
             raise OperationError(space.w_ValueError,
                 space.wrap("Can't call %s on zero-size arrays" \
                         % op_name))
         return space.wrap(loop(self))
     return func_with_new_name(impl, "reduce_arg%s_impl" % op_name)
开发者ID:craigkerstiens,项目名称:pypy,代码行数:34,代码来源:interp_numarray.py


示例3: _unaryop_impl

    def _unaryop_impl(ufunc_name):
        def impl(self, space, w_out=None):
            from pypy.module.micronumpy import interp_ufuncs

            return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [self, w_out])

        return func_with_new_name(impl, "unaryop_%s_impl" % ufunc_name)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:7,代码来源:interp_boxes.py


示例4: _binop_right_impl

    def _binop_right_impl(ufunc_name):
        def impl(self, space, w_other, w_out=None):
            from pypy.module.micronumpy import interp_ufuncs

            return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [w_other, self, w_out])

        return func_with_new_name(impl, "binop_right_%s_impl" % ufunc_name)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:7,代码来源:interp_boxes.py


示例5: generic_new_descr

def generic_new_descr(W_Type):
    def descr_new(space, w_subtype, __args__):
        self = space.allocate_instance(W_Type, w_subtype)
        W_Type.__init__(self, space)
        return space.wrap(self)
    descr_new = func_with_new_name(descr_new, 'descr_new_%s' % W_Type.__name__)
    return interp2app(descr_new)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:typedef.py


示例6: _make_binop_impl

def _make_binop_impl(symbol, specialnames):
    left, right = specialnames
    def binop_impl(space, w_obj1, w_obj2):
        w_typ1 = space.type(w_obj1)
        w_typ2 = space.type(w_obj2)
        w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
        if space.is_w(w_typ1, w_typ2):
            w_right_impl = None
        else:
            w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, right)
            # the logic to decide if the reverse operation should be tried
            # before the direct one is very obscure.  For now, and for
            # sanity reasons, we just compare the two places where the
            # __xxx__ and __rxxx__ methods where found by identity.
            # Note that space.is_w() is potentially not happy if one of them
            # is None (e.g. with the thunk space)...
            if (w_left_src is not w_right_src    # XXX
                and space.is_true(space.issubtype(w_typ2, w_typ1))):
                w_obj1, w_obj2 = w_obj2, w_obj1
                w_left_impl, w_right_impl = w_right_impl, w_left_impl

        w_res = _invoke_binop(space, w_left_impl, w_obj1, w_obj2)
        if w_res is not None:
            return w_res
        w_res = _invoke_binop(space, w_right_impl, w_obj2, w_obj1)
        if w_res is not None:
            return w_res
        raise OperationError(space.w_TypeError,
                space.wrap("unsupported operand type(s) for %s" % symbol))
    return func_with_new_name(binop_impl, "binop_%s_impl"%left.strip('_'))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:30,代码来源:descroperation.py


示例7: install_w_args_trampoline

def install_w_args_trampoline(type_, mm, is_local, op_name):
    def function(space, w_transparent_list, *args_w):
        args = Arguments(space, [space.wrap(op_name)] + list(args_w[:-1]), w_stararg=args_w[-1])
        return space.call_args(w_transparent_list.w_controller, args)
    
    function = func_with_new_name(function, mm.name)
    mm.register(function, type_, *([W_ANY] * (mm.arity - 1)))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:proxy_helpers.py


示例8: install_general_args_trampoline

def install_general_args_trampoline(type_, mm, is_local, op_name):
    def function(space, w_transparent_list, __args__):
        args = __args__.prepend(space.wrap(op_name))
        return space.call_args(w_transparent_list.w_controller, args)
    
    function = func_with_new_name(function, mm.name)
    mm.register(function, type_)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:proxy_helpers.py


示例9: add

 def add(Proto):
     for key, value in Proto.__dict__.items():
         if (not key.startswith('__') and not key.startswith('_mixin_') 
                 or key == '__del__'):
             if hasattr(value, "func_name"):
                 value = func_with_new_name(value, value.func_name)
             body[key] = value
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:typedef.py


示例10: _make_comparison_impl

def _make_comparison_impl(symbol, specialnames):
    left, right = specialnames
    op = getattr(operator, left)
    def comparison_impl(space, w_obj1, w_obj2):
        #from pypy.objspace.std.tlistobject import W_TransparentList
        #if isinstance(w_obj1, W_TransparentList):
        #    import pdb;pdb.set_trace()
        w_typ1 = space.type(w_obj1)
        w_typ2 = space.type(w_obj2)
        w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
        w_first = w_obj1
        w_second = w_obj2
        
        if space.is_w(w_typ1, w_typ2):
            w_right_impl = None
        else:
            w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, right)
            if (w_left_src is not w_right_src    # XXX see binop_impl
                and space.is_true(space.issubtype(w_typ2, w_typ1))):
                w_obj1, w_obj2 = w_obj2, w_obj1
                w_left_impl, w_right_impl = w_right_impl, w_left_impl

        w_res = _invoke_binop(space, w_left_impl, w_obj1, w_obj2)
        if w_res is not None:
            return w_res
        w_res = _invoke_binop(space, w_right_impl, w_obj2, w_obj1)
        if w_res is not None:
            return w_res
        # fallback: lt(a, b) <= lt(cmp(a, b), 0) ...
        w_res = _cmp(space, w_first, w_second)
        res = space.int_w(w_res)
        return space.wrap(op(res, 0))

    return func_with_new_name(comparison_impl, 'comparison_%s_impl'%left.strip('_'))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:34,代码来源:descroperation.py


示例11: make_helper

 def make_helper(firstarg, stmt, miniglobals):
     header = "def f(%s):" % (', '.join(argnames[firstarg:],))
     source = py.code.Source(stmt)
     source = source.putaround(header)
     exec source.compile() in miniglobals
     f = miniglobals['f']
     return func_with_new_name(f, 'memo_%s_%d' % (name, firstarg))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:specialize.py


示例12: specialize_call

 def specialize_call(self, hop):
     rtyper = hop.rtyper
     signature_args = self.normalize_args(*hop.args_s)
     args_r = [rtyper.getrepr(s_arg) for s_arg in signature_args]
     args_ll = [r_arg.lowleveltype for r_arg in args_r]
     s_result = hop.s_result
     r_result = rtyper.getrepr(s_result)
     ll_result = r_result.lowleveltype
     name = getattr(self, 'name', None) or self.instance.__name__
     method_name = rtyper.type_system.name[:2] + 'typeimpl'
     fake_method_name = rtyper.type_system.name[:2] + 'typefakeimpl'
     impl = getattr(self, method_name, None)
     fakeimpl = getattr(self, fake_method_name, self.instance)
     if impl:
         if hasattr(self, fake_method_name):
             # If we have both an {ll,oo}impl and a {ll,oo}fakeimpl,
             # we need a wrapper that selects the proper one and calls it
             from pypy.tool.sourcetools import func_with_new_name
             # Using '*args' is delicate because this wrapper is also
             # created for init-time functions like llarena.arena_malloc
             # which are called before the GC is fully initialized
             args = ', '.join(['arg%d' % i for i in range(len(args_ll))])
             d = {'original_impl': impl,
                  's_result': s_result,
                  'fakeimpl': fakeimpl,
                  '__name__': __name__,
                  }
             exec py.code.compile("""
                 from pypy.rlib.objectmodel import running_on_llinterp
                 from pypy.rlib.debug import llinterpcall
                 def ll_wrapper(%s):
                     if running_on_llinterp:
                         return llinterpcall(s_result, fakeimpl, %s)
                     else:
                         return original_impl(%s)
             """ % (args, args, args)) in d
             impl = func_with_new_name(d['ll_wrapper'], name + '_wrapper')
         if rtyper.annotator.translator.config.translation.sandbox:
             impl._dont_inline_ = True
         # store some attributes to the 'impl' function, where
         # the eventual call to rtyper.getcallable() will find them
         # and transfer them to the final lltype.functionptr().
         impl._llfnobjattrs_ = {
             '_name': self.name,
             '_safe_not_sandboxed': self.safe_not_sandboxed,
             }
         obj = rtyper.getannmixlevel().delayedfunction(
             impl, signature_args, hop.s_result)
     else:
         #if not self.safe_not_sandboxed:
         #    print '>>>>>>>>>>>>>-----------------------------------'
         #    print name, self.name
         #    print '<<<<<<<<<<<<<-----------------------------------'
         obj = rtyper.type_system.getexternalcallable(args_ll, ll_result,
                              name, _external_name=self.name, _callable=fakeimpl,
                              _safe_not_sandboxed=self.safe_not_sandboxed)
     vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r)
     hop.exception_is_here()
     return hop.genop('direct_call', vlist, r_result)
开发者ID:alkorzt,项目名称:pypy,代码行数:59,代码来源:extfunc.py


示例13: _make_unaryop_impl

def _make_unaryop_impl(symbol, specialnames):
    specialname, = specialnames
    def unaryop_impl(space, w_obj):
        w_impl = space.lookup(w_obj, specialname)
        if w_impl is None:
            raise OperationError(space.w_TypeError,
                   space.wrap("operand does not support unary %s" % symbol))
        return space.get_and_call_function(w_impl, w_obj)
    return func_with_new_name(unaryop_impl, 'unaryop_%s_impl'%specialname.strip('_'))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:descroperation.py


示例14: new_malloc

def new_malloc(TP, name):
    def mallocstr(length):
        ll_assert(length >= 0, "negative string length")
        r = malloc(TP, length)
        if not we_are_translated() or not malloc_zero_filled:
            r.hash = 0
        return r
    mallocstr._annspecialcase_ = 'specialize:semierased'
    return func_with_new_name(mallocstr, name)
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:rstr.py


示例15: ufunc

def ufunc(func):
    signature = Signature()
    def impl(space, w_obj):
        if isinstance(w_obj, BaseArray):
            w_res = Call1(func, w_obj, w_obj.signature.transition(signature))
            w_obj.invalidates.append(w_res)
            return w_res
        return space.wrap(func(space.float_w(w_obj)))
    return func_with_new_name(impl, "%s_dispatcher" % func.__name__)
开发者ID:ieure,项目名称:pypy,代码行数:9,代码来源:interp_ufuncs.py


示例16: build

    def build(cache, func):
        space = cache.space
        # make a built-in function
        assert isinstance(func.code, BuiltinCode)   # XXX
        bltin = func.code._bltin
        unwrap_spec = func.code._unwrap_spec
        from pypy.interpreter import pycode
        argnames, varargname, kwargname = pycode.cpython_code_signature(
            bltin.func_code)
        orig_sig = Signature(bltin, argnames, varargname, kwargname)

        tramp = UnwrapSpec_Trampoline(orig_sig)
        tramp.miniglobals = {
            '___space':           space,
            '___W_Object':        CPyObjSpace.W_Object,
            '___bltin':           bltin,
            '___OperationError':  OperationError,
            '___reraise':         reraise,
            }
        tramp.apply_over(unwrap_spec)

        sourcelines = ['def trampoline(%s):' % (', '.join(tramp.inputargs),)]
        # this description is to aid viewing in graphviewer
        sourcelines.append('    "wrapper for fn: %s"' % func.name)
        for line in tramp.wrappings:
            sourcelines.append('    ' + line)
        sourcelines.append('    try:')
        sourcelines.append('        w_result = ___bltin(%s)' % (
            ', '.join(tramp.passedargs),))
        sourcelines.append('    except ___OperationError, e:')
        sourcelines.append('        ___reraise(e)')
        # the following line is not reached, unless we are translated
        # in which case it makes the function return (PyObject*)NULL.
        sourcelines.append('        w_result = ___W_Object()')
        sourcelines.append('    else:')
        #                           # convert None to Py_None
        sourcelines.append('        if w_result is None:')
        sourcelines.append('            return None')
        sourcelines.append('    return w_result.value')
        sourcelines.append('')

        miniglobals = tramp.miniglobals
        exec py.code.Source('\n'.join(sourcelines)).compile() in miniglobals

        trampoline = miniglobals['trampoline']
        trampoline = func_with_new_name(trampoline, func.name)
        trampoline.nb_args = len(tramp.inputargs)
        trampoline.star_arg = tramp.star_arg
        trampoline.allow_someobjects = True    # annotator hint
        trampoline._annspecialcase_ = "specialize:all_someobjects"
        if func.defs_w:
            trampoline.func_defaults = tuple([space.unwrap(w_x)
                                              for w_x in func.defs_w])
        w_result = W_Object(trampoline)
        space.wrap_cache[id(w_result)] = w_result, func, follow_annotations
        return w_result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:56,代码来源:function.py


示例17: unaryoperation

def unaryoperation(operationname):
    """NOT_RPYTHON"""
    def opimpl(f, *ignored):
        operation = getattr(f.space, operationname)
        w_1 = f.popvalue()
        w_result = operation(w_1)
        f.pushvalue(w_result)
    opimpl.unaryop = operationname

    return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:10,代码来源:pyopcode.py


示例18: make_generic

def make_generic(funcname):
    def func(space, w_self): 
        v = w_self._value
        if len(v) == 0:
            return space.w_False
        for idx in range(len(v)):
            if not getattr(unicodedb, funcname)(ord(v[idx])):
                return space.w_False
        return space.w_True
    return func_with_new_name(func, "unicode_%s__Unicode" % (funcname, ))
开发者ID:antoine1fr,项目名称:pygirl,代码行数:10,代码来源:unicodeobject.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python udir.ensure函数代码示例发布时间:2022-05-27
下一篇:
Python sourcetools.compile2函数代码示例发布时间: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