本文整理汇总了Python中pypy.rlib.unroll.unrolling_iterable函数的典型用法代码示例。如果您正苦于以下问题:Python unrolling_iterable函数的具体用法?Python unrolling_iterable怎么用?Python unrolling_iterable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unrolling_iterable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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