本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.typeOf函数的典型用法代码示例。如果您正苦于以下问题:Python typeOf函数的具体用法?Python typeOf怎么用?Python typeOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了typeOf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrap
def wrap(cpu, value, in_const_box=False):
if isinstance(lltype.typeOf(value), lltype.Ptr):
if lltype.typeOf(value).TO._gckind == 'gc':
value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
if in_const_box:
return history.ConstPtr(value)
else:
return history.BoxPtr(value)
else:
adr = llmemory.cast_ptr_to_adr(value)
value = cpu.cast_adr_to_int(adr)
# fall through to the end of the function
elif isinstance(lltype.typeOf(value), ootype.OOType):
value = ootype.cast_to_object(value)
if in_const_box:
return history.ConstObj(value)
else:
return history.BoxObj(value)
elif isinstance(value, float):
if in_const_box:
return history.ConstFloat(value)
else:
return history.BoxFloat(value)
else:
value = intmask(value)
if in_const_box:
return history.ConstInt(value)
else:
return history.BoxInt(value)
示例2: __init__
def __init__(self, hrtyper, DICT):
RGenOp = hrtyper.RGenOp
rtyper = hrtyper.rtyper
bk = rtyper.annotator.bookkeeper
self.DICT = DICT
self.DICTPTR = lltype.Ptr(DICT)
self.ptrkind = RGenOp.kindToken(self.DICTPTR)
argtypes = [bk.immutablevalue(DICT)]
ll_newdict_ptr = rtyper.annotate_helper_fn(rdict.ll_newdict,
argtypes)
self.gv_ll_newdict = RGenOp.constPrebuiltGlobal(ll_newdict_ptr)
self.tok_ll_newdict = RGenOp.sigToken(lltype.typeOf(ll_newdict_ptr).TO)
argtypes = [self.DICTPTR, DICT.KEY, DICT.VALUE, HASH]
ll_insertclean = rtyper.annotate_helper_fn(rdict.ll_dict_insertclean,
argtypes)
self.gv_ll_insertclean = RGenOp.constPrebuiltGlobal(ll_insertclean)
self.tok_ll_insertclean = RGenOp.sigToken(
lltype.typeOf(ll_insertclean).TO)
# XXX some fishing that only works if the DICT does not come from
# an r_dict
if DICT.keyeq is None:
keyeq = operator.eq
else:
assert isinstance(DICT.keyeq, lltype.staticAdtMethod)
keyeq = DICT.keyeq.__get__(42)
assert isinstance(DICT.keyhash, lltype.staticAdtMethod)
keyhash = DICT.keyhash.__get__(42)
keydesc = LLEqDesc(DICT.KEY, keyeq, keyhash)
self.VirtualDict = keydesc.VirtualDict
示例3: foo
def foo():
# a bit hard to test, really
a = llop.get_exception_addr(llmemory.Address)
assert lltype.typeOf(a) is llmemory.Address
a = llop.get_exc_value_addr(llmemory.Address)
assert lltype.typeOf(a) is llmemory.Address
return 42
示例4: generic_initializationexpr
def generic_initializationexpr(db, value, access_expr, decoration):
if isinstance(typeOf(value), ContainerType):
node = db.getcontainernode(value)
lines = list(node.initializationexpr(decoration + "."))
lines[-1] += ","
return lines
else:
comma = ","
if typeOf(value) == Ptr(PyObject) and value:
# cannot just write 'gxxx' as a constant in a structure :-(
node = db.getcontainernode(value._obj)
expr = "NULL /*%s*/" % node.name
node.where_to_copy_me.append("&%s" % access_expr)
elif typeOf(value) == Float and not isfinite(value):
db.late_initializations.append(("%s" % access_expr, db.get(value)))
expr = "0.0 /* patched later by %sinfinity */" % ("-+"[value > 0])
else:
expr = db.get(value)
if typeOf(value) is Void:
comma = ""
expr += comma
i = expr.find("\n")
if i < 0:
i = len(expr)
expr = "%s\t/* %s */%s" % (expr[:i], decoration, expr[i:])
return expr.split("\n")
示例5: wrap
def wrap(cpu, value, in_const_box=False):
if isinstance(lltype.typeOf(value), lltype.Ptr):
if lltype.typeOf(value).TO._gckind == 'gc':
value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
if in_const_box:
return history.ConstPtr(value)
else:
return history.BoxPtr(value)
else:
adr = llmemory.cast_ptr_to_adr(value)
value = heaptracker.adr2int(adr)
# fall through to the end of the function
elif isinstance(lltype.typeOf(value), ootype.OOType):
value = ootype.cast_to_object(value)
if in_const_box:
return history.ConstObj(value)
else:
return history.BoxObj(value)
elif isinstance(value, float):
value = longlong.getfloatstorage(value)
if in_const_box:
return history.ConstFloat(value)
else:
return history.BoxFloat(value)
elif isinstance(value, str) or isinstance(value, unicode):
assert len(value) == 1 # must be a character
value = ord(value)
else:
value = intmask(value)
if in_const_box:
return history.ConstInt(value)
else:
return history.BoxInt(value)
示例6: generic_initializationexpr
def generic_initializationexpr(db, value, access_expr, decoration):
if isinstance(typeOf(value), ContainerType):
node = db.getcontainernode(value)
lines = list(node.initializationexpr(decoration+'.'))
lines[-1] += ','
return lines
else:
comma = ','
if typeOf(value) == Ptr(PyObject) and value:
# cannot just write 'gxxx' as a constant in a structure :-(
node = db.getcontainernode(value._obj)
expr = 'NULL /*%s*/' % node.name
node.where_to_copy_me.append('&%s' % access_expr)
elif typeOf(value) == Float and (isinf(value) or isnan(value)):
db.late_initializations.append(('%s' % access_expr, db.get(value)))
expr = '0.0 /* patched later by %sinfinity */' % (
'-+'[value > 0])
else:
expr = db.get(value)
if typeOf(value) is Void:
comma = ''
expr += comma
i = expr.find('\n')
if i<0: i = len(expr)
expr = '%s\t/* %s */%s' % (expr[:i], decoration, expr[i:])
return expr.split('\n')
示例7: ll_arraycopy
def ll_arraycopy(source, dest, source_start, dest_start, length):
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rlib.objectmodel import keepalive_until_here
# supports non-overlapping copies only
if not we_are_translated():
if source == dest:
assert (source_start + length <= dest_start or
dest_start + length <= source_start)
TP = lltype.typeOf(source).TO
assert TP == lltype.typeOf(dest).TO
if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
# perform a write barrier that copies necessary flags from
# source to dest
if not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest):
# if the write barrier is not supported, copy by hand
for i in range(length):
dest[i + dest_start] = source[i + source_start]
return
source_addr = llmemory.cast_ptr_to_adr(source)
dest_addr = llmemory.cast_ptr_to_adr(dest)
cp_source_addr = (source_addr + llmemory.itemoffsetof(TP, 0) +
llmemory.sizeof(TP.OF) * source_start)
cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
llmemory.sizeof(TP.OF) * dest_start)
llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
llmemory.sizeof(TP.OF) * length)
keepalive_until_here(source)
keepalive_until_here(dest)
示例8: setup
def setup(self):
for value in self._getvalues():
self.db.prepare_constant(lltype.typeOf(value), value)
p, c = lltype.parentlink(self.value)
if p is not None:
self.db.prepare_constant(lltype.typeOf(p), p)
示例9: finish_rtype
def finish_rtype(self):
rtyper = self.rtyper
translator = rtyper.annotator.translator
original_graph_count = len(translator.graphs)
rtyper.type_system.perform_normalizations(rtyper)
for r in self.delayedreprs:
r.set_setup_delayed(False)
rtyper.call_all_setups()
for p, repr, obj in self.delayedconsts:
p._become(repr.convert_const(obj))
rtyper.call_all_setups()
for p, graph in self.delayedfuncs:
self.newgraphs[graph] = True
real_p = rtyper.getcallable(graph)
REAL = get_functype(lltype.typeOf(real_p))
FUNCTYPE = get_functype(lltype.typeOf(p))
if isinstance(FUNCTYPE, (lltype.ForwardReference, ootype.ForwardReference)):
FUNCTYPE.become(REAL)
assert FUNCTYPE == REAL
p._become(real_p)
rtyper.specialize_more_blocks()
self.delayedreprs.clear()
del self.delayedconsts[:]
del self.delayedfuncs[:]
for graph in translator.graphs[original_graph_count:]:
self.newgraphs[graph] = True
示例10: enum_content
def enum_content(self, o, name='', with_header=True):
# XXX clean up
T = lltype.typeOf(o)
if (self.size_gc_header is not None and with_header
and isinstance(T, lltype.ContainerType) and T._gckind == 'gc'):
adr = llmemory.cast_ptr_to_adr(o._as_ptr())
adr -= self.size_gc_header
o = adr.get()._obj
T = lltype.typeOf(o)
if isinstance(T, lltype.Struct):
try:
gcobjptr = header2obj[o]
fmt = '(%s)'
except KeyError:
gcobjptr = None
fmt = '%s'
for name in T._names:
for name, value in self.enum_content(getattr(o, name), name,
with_header=False):
yield fmt % (name,), value
if gcobjptr:
GCT = lltype.typeOf(gcobjptr)
if self.size_gc_header is not None:
for sub in self.enum_content(gcobjptr._obj,
with_header=False):
yield sub
else:
# display as a link to avoid the same data showing up
# twice in the graph
yield 'header of', gcobjptr._obj
elif isinstance(T, lltype.Array):
for index, o1 in enumerate(o.items):
for sub in self.enum_content(o1, str(index)):
yield sub
elif isinstance(T, lltype.Ptr):
if not o:
yield name, 'null'
else:
yield name, self.normalize(lltype.normalizeptr(o)._obj)
elif isinstance(T, lltype.OpaqueType) and hasattr(o, 'container'):
T = lltype.typeOf(o.container)
yield 'container', '<%s>' % (shorttypename(T),)
for sub in self.enum_content(o.container, name, with_header=False):
yield sub
elif T == llmemory.Address:
if not o:
yield name, 'NULL'
else:
addrof = o.ref()
T1 = lltype.typeOf(addrof)
if (isinstance(T1, lltype.Ptr) and
isinstance(T1.TO, lltype.Struct) and
addrof._obj in header2obj):
yield name + ' @hdr', self.normalize(addrof._obj)
else:
yield name + ' @', self.normalize(o.ptr._obj)
## if o.offset:
## yield '... offset', str(o.offset)
else:
yield name, str(o)
示例11: _get_offset
def _get_offset(self, cppinstance):
if cppinstance:
assert lltype.typeOf(cppinstance.cppclass.handle) == lltype.typeOf(self.scope.handle)
offset = self.offset + capi.c_base_offset(cppinstance.cppclass, self.scope, cppinstance.get_rawobject(), 1)
else:
offset = self.offset
return offset
示例12: op_gc_writebarrier_before_copy
def op_gc_writebarrier_before_copy(source, dest):
A = lltype.typeOf(source)
assert A == lltype.typeOf(dest)
assert isinstance(A.TO, lltype.GcArray)
assert isinstance(A.TO.OF, lltype.Ptr)
assert A.TO.OF.TO._gckind == 'gc'
return True
示例13: dispatcher
def dispatcher(self, shape, index, argtypes, resulttype):
key = shape, index, tuple(argtypes), resulttype
if key in self._dispatch_cache:
return self._dispatch_cache[key]
from pypy.translator.unsimplify import varoftype
from pypy.objspace.flow.model import FunctionGraph, Link, Block, SpaceOperation
inputargs = [varoftype(t) for t in [Char] + argtypes]
startblock = Block(inputargs)
startblock.exitswitch = inputargs[0]
graph = FunctionGraph("dispatcher", startblock, varoftype(resulttype))
row_of_graphs = self.callfamily.calltables[shape][index]
links = []
descs = list(self.s_pbc.descriptions)
if self.s_pbc.can_be_None:
descs.insert(0, None)
for desc in descs:
if desc is None:
continue
args_v = [varoftype(t) for t in argtypes]
b = Block(args_v)
llfn = self.rtyper.getcallable(row_of_graphs[desc])
v_fn = inputconst(typeOf(llfn), llfn)
v_result = varoftype(resulttype)
b.operations.append(
SpaceOperation("direct_call", [v_fn] + args_v, v_result))
b.closeblock(Link([v_result], graph.returnblock))
i = self.descriptions.index(desc)
links.append(Link(inputargs[1:], b, chr(i)))
links[-1].llexitcase = chr(i)
startblock.closeblock(*links)
self.rtyper.annotator.translator.graphs.append(graph)
ll_ret = self.rtyper.type_system.getcallable(graph)
#FTYPE = FuncType
c_ret = self._dispatch_cache[key] = inputconst(typeOf(ll_ret), ll_ret)
return c_ret
示例14: setup_externs
def setup_externs(c_db, db):
rtyper = db.translator.rtyper
from pypy.translator.c.extfunc import predeclare_all
# hacks to make predeclare_all work
decls = list(predeclare_all(c_db, rtyper))
for c_name, obj in decls:
if isinstance(obj, lltype.LowLevelType):
db.prepare_type(obj)
elif isinstance(obj, FunctionGraph):
funcptr = rtyper.getcallable(obj)
c = inputconst(lltype.typeOf(funcptr), funcptr)
db.prepare_arg_value(c)
elif isinstance(lltype.typeOf(obj), lltype.Ptr):
db.prepare_constant(lltype.typeOf(obj), obj)
elif type(c_name) is str and type(obj) is int:
pass #define c_name obj
else:
assert False, "unhandled predeclare %s %s %s" % (c_name, type(obj), obj)
def annotatehelper(func, *argtypes):
graph = db.translator.rtyper.annotate_helper(func, argtypes)
fptr = rtyper.getcallable(graph)
c = inputconst(lltype.typeOf(fptr), fptr)
db.prepare_arg_value(c)
decls.append(("ll_" + func.func_name, graph))
return graph.name
return decls
示例15: gendirectcall
def gendirectcall(self, ll_function, *args_v):
rtyper = self.rtyper
args_s = []
newargs_v = []
for v in args_v:
if v.concretetype is Void:
s_value = rtyper.binding(v, default=annmodel.s_None)
if not s_value.is_constant():
raise TyperError("non-constant variable of type Void")
if not isinstance(s_value, annmodel.SomePBC):
raise TyperError("non-PBC Void argument: %r", (s_value,))
args_s.append(s_value)
else:
args_s.append(annmodel.lltype_to_annotation(v.concretetype))
newargs_v.append(v)
self.rtyper.call_all_setups() # compute ForwardReferences now
# hack for bound methods
if hasattr(ll_function, 'im_func'):
bk = rtyper.annotator.bookkeeper
args_s.insert(0, bk.immutablevalue(ll_function.im_self))
newargs_v.insert(0, inputconst(Void, ll_function.im_self))
ll_function = ll_function.im_func
graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s,
rtyper.lowlevel_ann_policy)
self.record_extra_call(graph)
# build the 'direct_call' operation
f = self.rtyper.getcallable(graph)
c = inputconst(typeOf(f), f)
fobj = self.rtyper.type_system_deref(f)
return self.genop('direct_call', [c]+newargs_v,
resulttype = typeOf(fobj).RESULT)