本文整理汇总了Python中pypy.rpython.rclass.getclassrepr函数的典型用法代码示例。如果您正苦于以下问题:Python getclassrepr函数的具体用法?Python getclassrepr怎么用?Python getclassrepr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getclassrepr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkfunction
def checkfunction(translator):
# make sure that there is a sensible comparison defined on the
# symbolics
bk = translator.annotator.bookkeeper
rtyper = translator.rtyper
base_classdef = bk.getuniqueclassdef(PBase)
base_vtable = rclass.getclassrepr(rtyper, base_classdef).getruntime(CLASSTYPE)
sub3_classdef = bk.getuniqueclassdef(Sub3)
sub3_vtable = rclass.getclassrepr(rtyper, sub3_classdef).getruntime(CLASSTYPE)
assert ll_issubclass(sub3_vtable, base_vtable)
assert not ll_issubclass(base_vtable, sub3_vtable)
示例2: initialize_prebuilt_instance
def initialize_prebuilt_instance(self, value, classdef, result):
if self.classdef is not None:
# recursively build the parent part of the instance
self.rbase.initialize_prebuilt_instance(value, classdef,
result.super)
# then add instance attributes from this level
for name, (mangled_name, r) in self.fields.items():
if r.lowleveltype is Void:
llattrvalue = None
elif name == '_hash_cache_': # hash() support
llattrvalue = hash(value)
else:
try:
attrvalue = getattr(value, name)
except AttributeError:
attrvalue = self.classdef.classdesc.read_attribute(name, None)
if attrvalue is None:
warning("prebuilt instance %r has no attribute %r" % (
value, name))
llattrvalue = r.lowleveltype._defl()
else:
llattrvalue = r.convert_desc_or_const(attrvalue)
else:
llattrvalue = r.convert_const(attrvalue)
setattr(result, mangled_name, llattrvalue)
else:
# OBJECT part
rclass = getclassrepr(self.rtyper, classdef)
result.typeptr = rclass.getvtable()
示例3: __init__
def __init__(self, rtyper, classdef):
AbstractClassRepr.__init__(self, rtyper, classdef)
# This is the Repr for a reference to the class 'classdef' or
# any subclass. In the simple case, the lowleveltype is just
# ootype.Class. If we need to store class attributes, we use a
# "meta" class where the attributes are defined, and the class
# reference is a reference to an instance of this meta class.
extra_access_sets = self.rtyper.class_pbc_attributes.get(
classdef, {})
has_class_attributes = bool(extra_access_sets)
if self.classdef is not None:
self.rbase = getclassrepr(self.rtyper, self.classdef.basedef)
meta_base_type = self.rbase.lowleveltype
baseclass_has_meta = meta_base_type != ootype.Class
else:
baseclass_has_meta = False
if not has_class_attributes and not baseclass_has_meta:
self.lowleveltype = ootype.Class # simple case
else:
if self.classdef is None:
raise TyperError("the root 'object' class should not have"
" class attributes")
if self.classdef.classdesc.pyobj in standardexceptions:
raise TyperError("Standard exception class %r should not have"
" class attributes" % (self.classdef.name,))
if not baseclass_has_meta:
meta_base_type = META
self.lowleveltype = ootype.Instance(
self.classdef.name + "_meta", meta_base_type)
示例4: gettype_from_unboxed
def gettype_from_unboxed(self, llops, vinst, can_be_none=False):
unboxedclass_repr = getclassrepr(self.rtyper, self.unboxedclassdef)
cunboxedcls = inputconst(CLASSTYPE, unboxedclass_repr.getvtable())
if self.is_parent:
# If the lltype of vinst shows that it cannot be a tagged value,
# we can directly read the typeptr. Otherwise, call a helper that
# checks if the tag bit is set in the pointer.
unboxedinstance_repr = getinstancerepr(self.rtyper,
self.unboxedclassdef)
try:
lltype.castable(unboxedinstance_repr.lowleveltype,
vinst.concretetype)
except lltype.InvalidCast:
can_be_tagged = False
else:
can_be_tagged = True
vinst = llops.genop('cast_pointer', [vinst],
resulttype=self.common_repr())
if can_be_tagged:
if can_be_none:
func = ll_unboxed_getclass_canbenone
else:
func = ll_unboxed_getclass
return llops.gendirectcall(func, vinst,
cunboxedcls)
elif can_be_none:
return llops.gendirectcall(ll_inst_type, vinst)
else:
ctypeptr = inputconst(lltype.Void, 'typeptr')
return llops.genop('getfield', [vinst, ctypeptr],
resulttype = CLASSTYPE)
else:
return cunboxedcls
示例5: convert_desc
def convert_desc(self, desc):
if desc not in self.s_pbc.descriptions:
raise TyperError("%r not in %r" % (cls, self))
if self.lowleveltype is Void:
return None
subclassdef = desc.getuniqueclassdef()
r_subclass = rclass.getclassrepr(self.rtyper, subclassdef)
return r_subclass.getruntime(self.lowleveltype)
示例6: _setup_repr
def _setup_repr(self, llfields=None, hints=None, adtmeths=None):
# NOTE: don't store mutable objects like the dicts below on 'self'
# before they are fully built, to avoid strange bugs in case
# of recursion where other code would uses these
# partially-initialized dicts.
self.rclass = getclassrepr(self.rtyper, self.classdef)
fields = {}
allinstancefields = {}
if self.classdef is None:
fields['__class__'] = 'typeptr', get_type_repr(self.rtyper)
else:
# instance attributes
if llfields is None:
llfields = []
attrs = self.classdef.attrs.items()
attrs.sort()
for name, attrdef in attrs:
if not attrdef.readonly:
r = self.rtyper.getrepr(attrdef.s_value)
mangled_name = 'inst_' + name
fields[name] = mangled_name, r
llfields.append((mangled_name, r.lowleveltype))
#
# hash() support
if self.rtyper.needs_hash_support(self.classdef):
from pypy.rpython import rint
fields['_hash_cache_'] = 'hash_cache', rint.signed_repr
llfields.append(('hash_cache', Signed))
self.rbase = getinstancerepr(self.rtyper, self.classdef.basedef,
self.gcflavor)
self.rbase.setup()
#
# PyObject wrapper support
if self.has_wrapper and '_wrapper_' not in self.rbase.allinstancefields:
fields['_wrapper_'] = 'wrapper', pyobj_repr
llfields.append(('wrapper', Ptr(PyObject)))
MkStruct = lltype.STRUCT_BY_FLAVOR[LLFLAVOR[self.gcflavor]]
if adtmeths is None:
adtmeths = {}
if hints is None:
hints = {}
if '_immutable_' in self.classdef.classdesc.classdict:
hints = hints.copy()
hints['immutable'] = True
object_type = MkStruct(self.classdef.name,
('super', self.rbase.object_type),
hints=hints,
adtmeths=adtmeths,
*llfields)
self.object_type.become(object_type)
allinstancefields.update(self.rbase.allinstancefields)
allinstancefields.update(fields)
self.fields = fields
self.allinstancefields = allinstancefields
if self.gcflavor in RTTIFLAVORS:
attachRuntimeTypeInfo(self.object_type)
示例7: new_instance
def new_instance(self, llops, classcallhop=None):
"""Build a new instance, without calling __init__."""
classrepr = getclassrepr(self.rtyper, self.classdef)
v_instance = llops.genop("new",
[inputconst(ootype.Void, self.lowleveltype)], self.lowleveltype)
cmeta = inputconst(ootype.Void, "meta")
cmeta_instance = inputconst(CLASSTYPE, classrepr.get_meta_instance())
llops.genop("oosetfield", [v_instance, cmeta, cmeta_instance],
resulttype=ootype.Void)
return v_instance
示例8: specialize_call
def specialize_call(self, hop):
from pypy.rpython.rclass import getclassrepr
from pypy.objspace.flow.model import Constant
from pypy.rpython.lltypesystem import rclass
Class = hop.args_s[0].const
classdef = hop.rtyper.annotator.bookkeeper.getuniqueclassdef(Class)
classrepr = getclassrepr(hop.rtyper, classdef)
vtable = classrepr.getvtable()
assert lltype.typeOf(vtable) == rclass.CLASSTYPE
return Constant(vtable, concretetype=rclass.CLASSTYPE)
示例9: __init__
def __init__(self, rtyper, classdef):
AbstractClassRepr.__init__(self, rtyper, classdef)
if self.classdef is not None:
self.rbase = getclassrepr(self.rtyper, self.classdef.basedef)
base_type = self.rbase.lowleveltype
self.lowleveltype = ootype.Instance(
self.classdef.name + "_meta", base_type)
else:
# we are ROOT
self.lowleveltype = CLASSTYPE
示例10: __init__
def __init__(self, rtyper):
self.make_standard_exceptions(rtyper)
# (NB. rclass identifies 'Exception' and 'object')
r_type = rclass.getclassrepr(rtyper, None)
r_instance = rclass.getinstancerepr(rtyper, None)
r_type.setup()
r_instance.setup()
self.r_exception_type = r_type
self.r_exception_value = r_instance
self.lltype_of_exception_type = r_type.lowleveltype
self.lltype_of_exception_value = r_instance.lowleveltype
示例11: getlowleveltype
def getlowleveltype(self):
classdescs = list(self.s_pbc.descriptions)
# if any of the classdefs get the lowleveltype ootype.Class,
# we can only pick ootype.Class for us too. Otherwise META.
for classdesc in classdescs:
for classdef in classdesc.getallclassdefs():
r_class = getclassrepr(self.rtyper, classdef)
if r_class.lowleveltype == ootype.Class:
return ootype.Class
else:
return META
示例12: get_access_set
def get_access_set(self, attrname):
"""Return the ClassAttrFamily corresponding to accesses to 'attrname'
and the ClassRepr of the class which stores this attribute in
its vtable.
"""
classdescs = self.s_pbc.descriptions.keys()
access = classdescs[0].queryattrfamily(attrname)
for classdesc in classdescs[1:]:
access1 = classdesc.queryattrfamily(attrname)
assert access1 is access # XXX not implemented
if access is None:
raise rclass.MissingRTypeAttribute(attrname)
commonbase = access.commonbase
class_repr = rclass.getclassrepr(self.rtyper, commonbase)
return access, class_repr
示例13: _setup_repr
def _setup_repr(self, llfields=None, hints=None, adtmeths=None):
# NOTE: don't store mutable objects like the dicts below on 'self'
# before they are fully built, to avoid strange bugs in case
# of recursion where other code would uses these
# partially-initialized dicts.
self.rclass = getclassrepr(self.rtyper, self.classdef)
fields = {}
allinstancefields = {}
if self.classdef is None:
fields['__class__'] = 'typeptr', get_type_repr(self.rtyper)
else:
# instance attributes
if llfields is None:
llfields = []
attrs = self.classdef.attrs.items()
attrs.sort()
for name, attrdef in attrs:
if not attrdef.readonly:
r = self.rtyper.getrepr(attrdef.s_value)
mangled_name = 'inst_' + name
fields[name] = mangled_name, r
llfields.append((mangled_name, r.lowleveltype))
self.rbase = getinstancerepr(self.rtyper, self.classdef.basedef,
self.gcflavor)
self.rbase.setup()
MkStruct = lltype.STRUCT_BY_FLAVOR[LLFLAVOR[self.gcflavor]]
if adtmeths is None:
adtmeths = {}
if hints is None:
hints = {}
hints = self._check_for_immutable_hints(hints)
object_type = MkStruct(self.classdef.name,
('super', self.rbase.object_type),
hints=hints,
adtmeths=adtmeths,
*llfields)
self.object_type.become(object_type)
allinstancefields.update(self.rbase.allinstancefields)
allinstancefields.update(fields)
self.fields = fields
self.allinstancefields = allinstancefields
if self.gcflavor == 'gc':
attachRuntimeTypeInfo(self.object_type)
示例14: initialize_prebuilt_data
def initialize_prebuilt_data(self, value, classdef, result):
# then add instance attributes from this level
classrepr = getclassrepr(self.rtyper, self.classdef)
for mangled, (oot, default) in self.lowleveltype._allfields().items():
if oot is ootype.Void:
llattrvalue = None
elif mangled == 'meta':
llattrvalue = classrepr.get_meta_instance()
else:
name = unmangle(mangled, self.rtyper.getconfig())
try:
attrvalue = getattr(value, name)
except AttributeError:
attrvalue = self.classdef.classdesc.read_attribute(name, None)
if attrvalue is None:
warning("prebuilt instance %r has no attribute %r" % (
value, name))
continue
llattrvalue = self.allfields[mangled].convert_desc_or_const(attrvalue)
else:
llattrvalue = self.allfields[mangled].convert_const(attrvalue)
setattr(result, mangled, llattrvalue)
示例15: new_instance
def new_instance(self, llops, classcallhop=None):
"""Build a new instance, without calling __init__."""
classrepr = getclassrepr(self.rtyper, self.classdef)
v_instance = llops.genop("new",
[inputconst(ootype.Void, self.lowleveltype)], self.lowleveltype)
return v_instance