本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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,)))
示例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)
示例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)
示例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)
示例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)
示例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('_'))
示例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)))
示例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_)
示例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
示例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('_'))
示例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))
示例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)
示例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('_'))
示例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)
示例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__)