本文整理汇总了Python中pypy.rlib.unroll.unrolling_iterable函数的典型用法代码示例。如果您正苦于以下问题:Python unrolling_iterable函数的具体用法?Python unrolling_iterable怎么用?Python unrolling_iterable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unrolling_iterable函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _rebuild_action_dispatcher
def _rebuild_action_dispatcher(self):
periodic_actions = unrolling_iterable(self._periodic_actions)
nonperiodic_actions = unrolling_iterable(self._nonperiodic_actions)
has_bytecode_counter = self.has_bytecode_counter
def action_dispatcher(ec, frame):
# periodic actions
if has_bytecode_counter:
ticker = self.get()
if ticker & self.BYTECODE_COUNTER_OVERFLOW_BIT:
# We must run the periodic actions now, but first
# reset the bytecode counter (the following line
# works by assuming that we just overflowed the
# counter, i.e. BYTECODE_COUNTER_OVERFLOW_BIT is
# set but none of the BYTECODE_COUNTER_MASK bits
# are).
ticker -= ec.space.sys.checkinterval
self.set(ticker)
for action in periodic_actions:
action.perform(ec, frame)
# nonperiodic actions
for action, bitmask in nonperiodic_actions:
ticker = self.get()
if ticker & bitmask:
self.set(ticker & ~ bitmask)
action.perform(ec, frame)
action_dispatcher._dont_inline_ = True
self.action_dispatcher = action_dispatcher
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:30,代码来源:executioncontext.py
示例2: make_set_future_values
def make_set_future_values(self):
"NOT_RPYTHON"
if hasattr(self, 'set_future_values'):
return self.set_future_values
warmrunnerdesc = self.warmrunnerdesc
jitdriver_sd = self.jitdriver_sd
cpu = self.cpu
vinfo = jitdriver_sd.virtualizable_info
red_args_types = unrolling_iterable(jitdriver_sd._red_args_types)
#
def set_future_values(*redargs):
i = 0
for typecode in red_args_types:
set_future_value(cpu, i, redargs[i], typecode)
i = i + 1
if vinfo is not None:
set_future_values_from_vinfo(*redargs)
#
if vinfo is not None:
i0 = len(jitdriver_sd._red_args_types)
num_green_args = jitdriver_sd.num_green_args
index_of_virtualizable = jitdriver_sd.index_of_virtualizable
vable_static_fields = unrolling_iterable(
zip(vinfo.static_extra_types, vinfo.static_fields))
vable_array_fields = unrolling_iterable(
zip(vinfo.arrayitem_extra_types, vinfo.array_fields))
getlength = cpu.ts.getlength
getarrayitem = cpu.ts.getarrayitem
#
def set_future_values_from_vinfo(*redargs):
i = i0
virtualizable = redargs[index_of_virtualizable]
virtualizable = vinfo.cast_to_vtype(virtualizable)
for typecode, fieldname in vable_static_fields:
x = getattr(virtualizable, fieldname)
set_future_value(cpu, i, x, typecode)
i = i + 1
for typecode, fieldname in vable_array_fields:
lst = getattr(virtualizable, fieldname)
for j in range(getlength(lst)):
x = getarrayitem(lst, j)
set_future_value(cpu, i, x, typecode)
i = i + 1
else:
set_future_values_from_vinfo = None
#
self.set_future_values = set_future_values
return set_future_values
开发者ID:ieure,项目名称:pypy,代码行数:49,代码来源:warmstate.py
示例3: ARRAY_ITER
def ARRAY_ITER(ARRAY, INDEXARRAY, ITEM):
ndim = dim_of_ARRAY(ARRAY)
unroll_ndim = unrolling_iterable(range(ndim))
def ll_iter_reset(it, dataptr):
it.index = 0
it.dataptr = dataptr
for i in unroll_ndim:
it.coordinates[i] = 0
ll_iter_reset._always_inline_ = True
unroll_ndim_rev = unrolling_iterable(reversed(range(ndim)))
def ll_iter_next(it):
it.index += 1
for i in unroll_ndim_rev:
if it.coordinates[i] < it.dims_m1[i]:
it.coordinates[i] += 1
it.dataptr = direct_ptradd(it.dataptr, it.strides[i])
break
it.coordinates[i] = 0
it.dataptr = direct_ptradd(it.dataptr, -it.backstrides[i])
ll_iter_next._always_inline_ = True
DATA_PTR = Ptr(FixedSizeArray(ITEM, 1))
ADTIIter = ADTInterface(None, {
'll_reset': (['self', DATA_PTR], Void),
'll_next': (['self'], Void),
})
ITER = Ptr(
GcStruct("array_iter",
("nd_m1", Signed), # number of dimensions - 1
("index", NPY_INTP),
("size", NPY_INTP),
("coordinates", INDEXARRAY),
("dims_m1", INDEXARRAY), # array of dimensions - 1
("strides", INDEXARRAY),
("backstrides", INDEXARRAY),
#("factors", INDEXARRAY),
#("ao", ARRAY), # not needed..
("dataptr", DATA_PTR), # pointer to current item
#("contiguous", Bool),
adtmeths = ADTIIter({
'll_next': ll_iter_next,
'll_reset': ll_iter_reset,
}),
))
return ITER
开发者ID:alkorzt,项目名称:pypy,代码行数:49,代码来源:rarray.py
示例4: postprocess_timeshifting
def postprocess_timeshifting(self):
annhelper = self.hrtyper.annhelper
convert_result = getattr(self.main, 'convert_result', str)
annotator = self.rtyper.annotator
args_s = [annmodel.lltype_to_annotation(v.concretetype)
for v in self.maingraph.getargs()]
retvar = self.maingraph.getreturnvar()
s_result = annmodel.lltype_to_annotation(retvar.concretetype)
main_fnptr = self.rtyper.type_system.getcallable(self.maingraph)
main = PseudoHighLevelCallable(main_fnptr, args_s, s_result)
if hasattr(self.main, 'convert_arguments'):
decoders = self.main.convert_arguments
assert len(decoders) == len(args_s)
else:
decoders = [int] * len(args_s)
decoders = unrolling_iterable(decoders)
def ll_main(argv):
args = ()
i = 1
for decoder in decoders:
args += (decoder(argv[i]),)
i = i + 1
try:
res = main(*args)
except Exception, e:
os.write(1, 'EXCEPTION: %s\n' % (e,))
return 0
os.write(1, convert_result(res) + '\n')
return 0
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:30,代码来源:test_genc_portal.py
示例5: gen_str_function
def gen_str_function(tuplerepr):
items_r = tuplerepr.items_r
str_funcs = [r_item.ll_str for r_item in items_r]
key = tuplerepr.rstr_ll, tuple(str_funcs)
try:
return _gen_str_function_cache[key]
except KeyError:
autounrolling_funclist = unrolling_iterable(enumerate(str_funcs))
constant = tuplerepr.rstr_ll.ll_constant
start = tuplerepr.rstr_ll.ll_build_start
push = tuplerepr.rstr_ll.ll_build_push
finish = tuplerepr.rstr_ll.ll_build_finish
length = len(items_r)
def ll_str(t):
if length == 0:
return constant("()")
buf = start(2 * length + 1)
push(buf, constant("("), 0)
for i, str_func in autounrolling_funclist:
attrname = 'item%d' % i
item = getattr(t, attrname)
if i > 0:
push(buf, constant(", "), 2 * i)
push(buf, str_func(item), 2 * i + 1)
if length == 1:
push(buf, constant(",)"), 2 * length)
else:
push(buf, constant(")"), 2 * length)
return finish(buf)
_gen_str_function_cache[key] = ll_str
return ll_str
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:34,代码来源:rtuple.py
示例6: make_arg_subclass
def make_arg_subclass(n, base):
rangen = unroll.unrolling_iterable(range(n))
class cls(base):
_immutable_fields_ = ["arg%s" % i for i in rangen]
def __init__(self, function, args):
base.__init__(self, function)
for i in rangen:
setattr(self, "arg%s" % i, args[i])
assert len(args) == n
def numargs(self):
return n
def getarg(self, i):
assert i < n
for j in rangen:
if i == j:
return getattr(self, "arg%s" % j)
assert 0
cls.__name__ = "%s%s" % (base.__name__, n)
return cls
开发者ID:khskrede,项目名称:mehh,代码行数:25,代码来源:haskell.py
示例7: get_operrcls2
def get_operrcls2(valuefmt):
strings, formats = decompose_valuefmt(valuefmt)
assert len(strings) == len(formats) + 1
try:
OpErrFmt = _fmtcache2[formats]
except KeyError:
from pypy.rlib.unroll import unrolling_iterable
attrs = ['x%d' % i for i in range(len(formats))]
entries = unrolling_iterable(enumerate(attrs))
#
class OpErrFmt(OperationError):
def __init__(self, w_type, strings, *args):
self.setup(w_type)
assert len(args) == len(strings) - 1
self.xstrings = strings
for i, attr in entries:
setattr(self, attr, args[i])
if not we_are_translated() and w_type is None:
from pypy.tool.error import FlowingError
raise FlowingError(self._compute_value())
def _compute_value(self):
lst = [None] * (len(formats) + len(formats) + 1)
for i, attr in entries:
string = self.xstrings[i]
value = getattr(self, attr)
lst[i+i] = string
lst[i+i+1] = str(value)
lst[-1] = self.xstrings[-1]
return ''.join(lst)
#
_fmtcache2[formats] = OpErrFmt
return OpErrFmt, strings
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:32,代码来源:error.py
示例8: proxymaker
def proxymaker(space, name, parentfn):
arity = nb_forcing_args[name]
indices = unrolling_iterable(range(arity))
if name in RegularMethods:
def proxy(*args_w):
newargs_w = ()
tainted = False
for i in indices:
w_arg = args_w[i]
if isinstance(w_arg, W_Tainted):
tainted = True
w_arg = w_arg.w_obj
elif isinstance(w_arg, W_TaintBomb):
return w_arg
newargs_w += (w_arg,)
newargs_w += args_w[arity:]
try:
w_res = parentfn(*newargs_w)
except OperationError, operr:
if not tainted:
raise
return W_TaintBomb(space, operr)
if tainted:
w_res = taint(w_res)
return w_res
开发者ID:gorakhargosh,项目名称:pypy,代码行数:26,代码来源:taint.py
示例9: gen_cmp_function
def gen_cmp_function(items_r, op_funcs, eq_funcs, strict):
"""generates <= and >= comparison ll_op for tuples
cmp_funcs is a tuple of (strict_comp, equality) functions
works for != with strict==True
"""
cmp_funcs = zip(op_funcs,eq_funcs)
autounrolling_funclist = unrolling_iterable(enumerate(cmp_funcs))
key = tuple(cmp_funcs), strict
try:
return _gen_cmp_function_cache[key]
except KeyError:
def ll_cmp(t1, t2):
cmp_res = True
for i, (cmpfn, eqfn) in autounrolling_funclist:
attrname = 'item%d' % i
item1 = getattr(t1, attrname)
item2 = getattr(t2, attrname)
cmp_res = cmpfn(item1, item2)
if cmp_res:
# a strict compare is true we shortcut
return True
eq_res = eqfn(item1, item2)
if not eq_res:
# not strict and not equal we fail
return False
# Everything's equal here
if strict:
return False
else:
return True
_gen_cmp_function_cache[key] = ll_cmp
return ll_cmp
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:32,代码来源:rtuple.py
示例10: _define_collect_residual_args
def _define_collect_residual_args(self):
my_redirected_names = unrolling_iterable(self.my_redirected_names)
TOPPTR = self.access_desc.PTRTYPE
if TOPPTR == self.PTRTYPE:
_super_collect = None
else:
_super_collect = self.firstsubstructdesc._collect_residual_args
def _collect_residual_args(v):
if _super_collect is None:
assert not v.vable_access # xxx need to use access ?
t = ()
else:
t = _super_collect(v.super)
for name in my_redirected_names:
t = t + (getattr(v, name),)
return t
self._collect_residual_args = _collect_residual_args
def collect_residual_args(v):
t = (v,) + _collect_residual_args(v)
return t
self.collect_residual_args = collect_residual_args
开发者ID:antoine1fr,项目名称:pygirl,代码行数:26,代码来源:rcontainer.py
示例11: insn
def insn(*encoding):
def encode(mc, *args):
rexbyte = 0
if mc.WORD == 8:
# compute the REX byte, if any
for encode_step, arg, extra, rex_step in encoding_steps:
if rex_step:
if arg is not None:
arg = args[arg-1]
rexbyte |= rex_step(mc, arg, extra)
args = (rexbyte,) + args
# emit the bytes of the instruction
orbyte = 0
for encode_step, arg, extra, rex_step in encoding_steps:
if arg is not None:
arg = args[arg]
orbyte = encode_step(mc, arg, extra, orbyte)
assert orbyte == 0
#
encoding_steps = []
for step in encoding:
if isinstance(step, str):
for c in step:
encoding_steps.append((encode_char, None, ord(c), None))
else:
assert type(step) is tuple and len(step) == 4
encoding_steps.append(step)
encoding_steps = unrolling_iterable(encoding_steps)
return encode
开发者ID:gorakhargosh,项目名称:pypy,代码行数:30,代码来源:rx86.py
示例12: make_interior_getter
def make_interior_getter(fielddescs, _cache={}):
# returns a 'getinterior(jitstate, argbox, *indexboxes)' function
key = tuple(fielddescs)
try:
return _cache[key]
except KeyError:
unroll_fielddescs = unrolling_iterable([
(fielddesc, isinstance(fielddesc, ArrayFieldDesc))
for fielddesc in fielddescs])
def getinterior(jitstate, argbox, *indexboxes):
i = 0
for fielddesc, is_array in unroll_fielddescs:
if is_array: # array substruct
indexbox = indexboxes[i]
i += 1
genvar = jitstate.curbuilder.genop_getarraysubstruct(
fielddesc.arraytoken,
argbox.getgenvar(jitstate),
indexbox.getgenvar(jitstate))
argbox = fielddesc.makebox(jitstate, genvar)
else: # getsubstruct
argbox = argbox.op_getsubstruct(jitstate, fielddesc)
assert isinstance(argbox, rvalue.PtrRedBox)
return argbox
_cache[key] = getinterior
return getinterior
开发者ID:antoine1fr,项目名称:pygirl,代码行数:28,代码来源:rcontainer.py
示例13: make_specialized_class
def make_specialized_class(n):
iter_n = unrolling_iterable(range(n))
class cls(W_SmallTupleObject):
def __init__(self, values):
assert len(values) == n
for i in iter_n:
setattr(self, 'w_value%s' % i, values[i])
def tolist(self):
l = [None] * n
for i in iter_n:
l[i] = getattr(self, 'w_value%s' % i)
return l
# same source code, but builds and returns a resizable list
getitems_copy = func_with_new_name(tolist, 'getitems_copy')
def length(self):
return n
def getitem(self, index):
for i in iter_n:
if index == i:
return getattr(self,'w_value%s' % i)
raise IndexError
def setitem(self, index, w_item):
for i in iter_n:
if index == i:
setattr(self, 'w_value%s' % i, w_item)
return
raise IndexError
def eq(self, space, w_other):
if n != w_other.length():
return space.w_False
for i in iter_n:
item1 = getattr(self,'w_value%s' % i)
item2 = w_other.getitem(i)
if not space.eq_w(item1, item2):
return space.w_False
return space.w_True
def hash(self, space):
mult = 1000003
x = 0x345678
z = n
for i in iter_n:
w_item = getattr(self, 'w_value%s' % i)
y = space.int_w(space.hash(w_item))
x = (x ^ y) * mult
z -= 1
mult += 82520 + z + z
x += 97531
return space.wrap(intmask(x))
cls.__name__ = "W_SmallTupleObject%s" % n
return cls
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:smalltupleobject.py
示例14: __init__
def __init__(self):
self.heap = Heap()
self.signature2function = {}
self.parser = None
self.operations = None
#XXX circular imports hack
from pypy.lang.prolog.builtin import builtins_list
globals()['unrolling_builtins'] = unrolling_iterable(builtins_list)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:engine.py
示例15: __init__
def __init__(self, ctype):
CTypeController.__init__(self, ctype)
# Map the field names to their controllers
controllers = []
fields = []
for name, field_ctype in ctype._fields_:
controller = getcontroller(field_ctype)
setattr(self, 'fieldcontroller_' + name, controller)
controllers.append((name, controller))
fields.append((name, controller.knowntype))
external = getattr(ctype, '_external_', False)
self.knowntype = rctypesobject.RStruct(ctype.__name__, fields,
c_external = external)
self.fieldcontrollers = controllers
# Build a custom new() method where the setting of the fields
# is unrolled
unrolled_controllers = unrolling_iterable(controllers)
def structnew(*args):
obj = self.knowntype.allocate()
if len(args) > len(fields):
raise ValueError("too many arguments for this structure")
for name, controller in unrolled_controllers:
if args:
value = args[0]
args = args[1:]
if controller.is_box(value):
structsetboxattr(obj, name, value)
else:
structsetattr(obj, name, value)
return obj
self.new = structnew
# Build custom getter and setter methods
def structgetattr(obj, attr):
controller = getattr(self, 'fieldcontroller_' + attr)
itemobj = getattr(obj, 'ref_' + attr)()
return controller.return_value(itemobj)
structgetattr._annspecialcase_ = 'specialize:arg(1)'
def structsetattr(obj, attr, value):
controller = getattr(self, 'fieldcontroller_' + attr)
itemobj = getattr(obj, 'ref_' + attr)()
controller.store_value(itemobj, value)
structsetattr._annspecialcase_ = 'specialize:arg(1)'
def structsetboxattr(obj, attr, valuebox):
controller = getattr(self, 'fieldcontroller_' + attr)
itemobj = getattr(obj, 'ref_' + attr)()
controller.store_box(itemobj, valuebox)
structsetboxattr._annspecialcase_ = 'specialize:arg(1)'
self.getattr = structgetattr
self.setattr = structsetattr
self.setboxattr = structsetboxattr
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:58,代码来源:rstruct.py
示例16: test_unroll_setattrs
def test_unroll_setattrs(self):
values_names = unrolling_iterable(enumerate(['a', 'b', 'c']))
def f(x):
for v, name in values_names:
setattr(x, name, v)
graph = self.codetest(f)
ops = self.all_operations(graph)
assert ops == {'setattr': 3}
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_unroll.py
示例17: gen_get_shape
def gen_get_shape(ndim):
unrolling_dims = unrolling_iterable(range(ndim))
def ll_get_shape(ARRAY, TUPLE, array):
shape = malloc(TUPLE)
for i in unrolling_dims:
size = array.shape[i]
attr = 'item%d'%i
setattr(shape, attr, size)
return shape
return ll_get_shape
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:rarray.py
示例18: test_unroller
def test_unroller(self):
l = unrolling_iterable(range(10))
def f(tot):
for v in l:
tot += v
return tot*3
assert f(0) == sum(l)*3
graph = self.codetest(f)
ops = self.all_operations(graph)
assert ops == {'inplace_add': 10, 'mul': 1}
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:test_unroll.py
示例19: decorator
def decorator(func):
assert code not in prim_table
func.func_name = "prim_" + name
if unwrap_spec is None:
def wrapped(interp, argument_count_m1):
w_result = func(interp, argument_count_m1)
if not no_result:
assert w_result is not None
interp.s_active_context().push(w_result)
return w_result
else:
len_unwrap_spec = len(unwrap_spec)
assert (len_unwrap_spec == len(inspect.getargspec(func)[0]) + 1,
"wrong number of arguments")
unrolling_unwrap_spec = unrolling_iterable(enumerate(unwrap_spec))
def wrapped(interp, argument_count_m1):
argument_count = argument_count_m1 + 1 # to account for the rcvr
frame = interp.w_active_context()
s_frame = frame.as_context_get_shadow(interp.space)
assert argument_count == len_unwrap_spec
if len(s_frame.stack()) < len_unwrap_spec:
raise PrimitiveFailedError()
args = ()
for i, spec in unrolling_unwrap_spec:
index = len_unwrap_spec - 1 - i
w_arg = s_frame.peek(index)
if spec is int:
args += (interp.space.unwrap_int(w_arg), )
elif spec is index1_0:
args += (interp.space.unwrap_int(w_arg)-1, )
elif spec is float:
args += (interp.space.unwrap_float(w_arg), )
elif spec is object:
args += (w_arg, )
elif spec is str:
assert isinstance(w_arg, model.W_BytesObject)
args += (w_arg.as_string(), )
elif spec is char:
args += (unwrap_char(w_arg), )
else:
raise NotImplementedError(
"unknown unwrap_spec %s" % (spec, ))
w_result = func(interp, *args)
# After calling primitive, reload context-shadow in case it
# needs to be updated
new_s_frame = interp.s_active_context()
frame.as_context_get_shadow(interp.space).pop_n(len_unwrap_spec) # only if no exception occurs!
if not no_result:
assert w_result is not None
new_s_frame.push(w_result)
wrapped.func_name = "wrap_prim_" + name
prim_table[code] = wrapped
prim_table_implemented_only.append((code, wrapped))
return func
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:54,代码来源:primitives.py
示例20: test_unroll_twice
def test_unroll_twice(self):
operations = unrolling_iterable([1, 2, 3])
def f(x):
for num1 in operations:
for num2 in operations:
x = x + (num1 + num2)
return x
graph = self.codetest(f)
ops = self.all_operations(graph)
assert ops['add'] == 9
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:test_unroll.py
注:本文中的pypy.rlib.unroll.unrolling_iterable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论