本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.typeOf函数的典型用法代码示例。如果您正苦于以下问题:Python typeOf函数的具体用法?Python typeOf怎么用?Python typeOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了typeOf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:enyst,项目名称:plexnet,代码行数:29,代码来源:warmstate.py
示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:32,代码来源:vdict.py
示例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
开发者ID:enyst,项目名称:plexnet,代码行数:7,代码来源:test_exceptiontransform.py
示例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")
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:26,代码来源:node.py
示例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)
开发者ID:ieure,项目名称:pypy,代码行数:33,代码来源:warmstate.py
示例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')
开发者ID:enyst,项目名称:plexnet,代码行数:26,代码来源:node.py
示例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)
开发者ID:ieure,项目名称:pypy,代码行数:31,代码来源:rgc.py
示例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)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:structnode.py
示例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
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:26,代码来源:annlowlevel.py
示例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)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:60,代码来源:lltracker.py
示例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
开发者ID:MichaelBlume,项目名称:pypy,代码行数:7,代码来源:interp_cppyy.py
示例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
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:opimpl.py
示例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
开发者ID:ieure,项目名称:pypy,代码行数:35,代码来源:rpbc.py
示例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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:30,代码来源:externs2ll.py
示例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)
开发者ID:ieure,项目名称:pypy,代码行数:35,代码来源:rtyper.py
示例16: reccopy
def reccopy(source, dest):
# copy recursively a structure or array onto another.
T = lltype.typeOf(source).TO
assert T == lltype.typeOf(dest).TO
if isinstance(T, (lltype.Array, lltype.FixedSizeArray)):
assert source._obj.getlength() == dest._obj.getlength()
ITEMTYPE = T.OF
for i in range(source._obj.getlength()):
if isinstance(ITEMTYPE, lltype.ContainerType):
subsrc = source[i]
subdst = dest[i]
reccopy(subsrc, subdst)
else:
# this is a hack XXX de-hack this
llvalue = source._obj.getitem(i, uninitialized_ok=True)
dest._obj.setitem(i, llvalue)
elif isinstance(T, lltype.Struct):
for name in T._names:
FIELDTYPE = getattr(T, name)
if isinstance(FIELDTYPE, lltype.ContainerType):
subsrc = getattr(source, name)
subdst = getattr(dest, name)
reccopy(subsrc, subdst)
else:
# this is a hack XXX de-hack this
llvalue = source._obj._getattr(name, uninitialized_ok=True)
setattr(dest._obj, name, llvalue)
else:
raise TypeError(T)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:rmodel.py
示例17: ref
def ref(self, firstitemptr):
A = lltype.typeOf(firstitemptr).TO
if A == self.TYPE:
# for array of containers
parent, index = lltype.parentlink(firstitemptr._obj)
assert parent, "%r is not within a container" % (firstitemptr,)
assert isinstance(lltype.typeOf(parent),
(lltype.Array, lltype.FixedSizeArray)), (
"%r is not within an array" % (firstitemptr,))
if isinstance(index, str):
assert index.startswith('item') # itemN => N
index = int(index[4:])
index += self.repeat
if index == parent.getlength():
# for references exactly to the end of the array
try:
endmarker = _end_markers[parent]
except KeyError:
endmarker = _endmarker_struct(A, parent=parent,
parentindex=index)
_end_markers[parent] = endmarker
return endmarker._as_ptr()
else:
return parent.getitem(index)._as_ptr()
elif (isinstance(A, lltype.FixedSizeArray) and
array_item_type_match(A.OF, self.TYPE)):
# for array of primitives or pointers
return lltype.direct_ptradd(firstitemptr, self.repeat)
else:
raise TypeError('got %r, expected %r' % (A, self.TYPE))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:30,代码来源:llmemory.py
示例18: get
def get(self, obj, funcgen=None):
if isinstance(obj, CConstant):
return obj.c_name # without further checks
T = typeOf(obj)
if isinstance(T, Primitive) or T == GCREF:
return PrimitiveName[T](obj, self)
elif isinstance(T, Ptr):
if (isinstance(T.TO, OpaqueType) and
T.TO.hints.get('c_pointer_typedef') is not None):
if obj._obj is not None:
value = rffi.cast(rffi.SSIZE_T, obj)
return '((%s) %s)' % (cdecl(self.gettype(T), ''),
self.get(value))
if obj: # test if the ptr is non-NULL
try:
container = obj._obj
except lltype.DelayedPointer:
# hack hack hack
name = obj._obj0
assert name.startswith('delayed!')
n = len('delayed!')
if len(name) == n:
raise
if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
if obj in self.idelayedfunctionnames:
return self.idelayedfunctionnames[obj][0]
funcname = name[n:]
funcname = self.namespace.uniquename('g_'+funcname)
self.idelayedfunctionnames[obj] = funcname, obj
else:
funcname = None # can't use the name of a
# delayed non-function ptr
self.delayedfunctionptrs.append(obj)
return funcname
# /hack hack hack
else:
# hack hack hack
if obj in self.idelayedfunctionnames:
# this used to be a delayed function,
# make sure we use the same name
forcename = self.idelayedfunctionnames[obj][0]
node = self.getcontainernode(container,
forcename=forcename)
assert node.getptrname() == forcename
return forcename
# /hack hack hack
if isinstance(container, int):
# special case for tagged odd-valued pointers
return '((%s) %d)' % (cdecl(self.gettype(T), ''),
obj._obj)
node = self.getcontainernode(container)
if node._funccodegen_owner is None:
node._funccodegen_owner = funcgen
return node.getptrname()
else:
return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
else:
raise Exception("don't know about %r" % (obj,))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:database.py
示例19: __init__
def __init__(self, db, value):
assert isinstance(lltype.typeOf(value), lltype.Array)
self.db = db
self.value = value
self.arraytype = lltype.typeOf(value).OF
name = '' #str(value).split()[1]
self.make_name(name)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:arraynode.py
示例20: op_check_and_clear_exc
def op_check_and_clear_exc(self):
exc_data = self.llinterpreter.get_transformed_exc_data(self.graph)
assert exc_data
etype = exc_data.exc_type
evalue = exc_data.exc_value
exc_data.exc_type = lltype.typeOf(etype )._defl()
exc_data.exc_value = lltype.typeOf(evalue)._defl()
return bool(etype)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:llinterp.py
注:本文中的pypy.rpython.lltypesystem.lltype.typeOf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论