当前位置: 首页>>代码示例>>Python>>正文


Python rclass.getinstancerepr函数代码示例

本文整理汇总了Python中pypy.rpython.rclass.getinstancerepr函数的典型用法代码示例。如果您正苦于以下问题:Python getinstancerepr函数的具体用法?Python getinstancerepr怎么用?Python getinstancerepr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getinstancerepr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: externalvsinternal

def externalvsinternal(rtyper, item_repr): # -> external_item_repr, (internal_)item_repr
    from pypy.rpython import rclass
    if (isinstance(item_repr, rclass.AbstractInstanceRepr) and
        getattr(item_repr, 'gcflavor', 'gc') == 'gc'):
        return item_repr, rclass.getinstancerepr(rtyper, None)
    else:
        return item_repr, item_repr
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:rmodel.py

示例2: __init__

    def __init__(self, rtyper, s_pbc):
        self.rtyper = rtyper
        self.s_pbc = s_pbc
        if s_pbc.isNone():
            raise TyperError("unsupported: variable of type "
                             "bound-method-object or None")
        mdescs = s_pbc.descriptions.keys()
        methodname = mdescs[0].name
        classdef = mdescs[0].selfclassdef
        flags    = mdescs[0].flags
        for mdesc in mdescs[1:]:
            if mdesc.name != methodname:
                raise TyperError("cannot find a unique name under which the "
                                 "methods can be found: %r" % (
                        mdescs,))
            if mdesc.flags != flags:
                raise TyperError("inconsistent 'flags': %r versus %r" % (
                    mdesc.flags, flags))
            classdef = classdef.commonbase(mdesc.selfclassdef)
            if classdef is None:
                raise TyperError("mixing methods coming from instances of "
                                 "classes with no common base: %r" % (mdescs,))

        self.methodname = methodname
        self.classdef = classdef.locate_attribute(methodname)
        # the low-level representation is just the bound 'self' argument.
        self.s_im_self = annmodel.SomeInstance(self.classdef, flags=flags)
        self.r_im_self = rclass.getinstancerepr(rtyper, self.classdef)
        self.lowleveltype = self.r_im_self.lowleveltype
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:rpbc.py

示例3: 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
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:rtagged.py

示例4: get_ll_pyobjectptr

 def get_ll_pyobjectptr(self, rtyper):
     from pypy.rpython.rclass import getinstancerepr
     emulated_cls = self.instance
     rpython_cls = emulated_cls._rpython_class_
     classdef = rtyper.annotator.bookkeeper.getuniqueclassdef(rpython_cls)
     r_inst = getinstancerepr(rtyper, classdef)
     return build_pytypeobject(r_inst)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:rcpy.py

示例5: setup_meta_instance

    def setup_meta_instance(self, meta_instance, rsubcls):
        if self.classdef is None:
            rinstance = getinstancerepr(self.rtyper, rsubcls.classdef)
            meta_instance.class_ = ootype.runtimeClass(rinstance.lowleveltype)
        else:
            # setup class attributes: for each attribute name at the level
            # of 'self', look up its value in the subclass rsubcls
            def assign(mangled_name, value):
                if isinstance(value, flowmodel.Constant) and isinstance(value.value, staticmethod):
                    value = flowmodel.Constant(value.value.__get__(42))   # staticmethod => bare function
                llvalue = r.convert_desc_or_const(value)
                setattr(meta_instance, mangled_name, llvalue)

            # extra PBC attributes
            for (access_set, attr), (mangled_name, r) in self.pbcfields.items():
                if rsubcls.classdef.classdesc not in access_set.descs:
                    continue   # only for the classes in the same pbc access set
                if r.lowleveltype is ootype.Void:
                    continue
                attrvalue = rsubcls.classdef.classdesc.read_attribute(attr, None)
                if attrvalue is not None:
                    assign(mangled_name, attrvalue)

            # then initialize the 'super' portion of the vtable
            self.rbase.setup_meta_instance(meta_instance, rsubcls)
开发者ID:alkorzt,项目名称:pypy,代码行数:25,代码来源:rclass.py

示例6: rtype_method_set

 def rtype_method_set(self, hop):
     r_object = getinstancerepr(self.rtyper, None)
     v_d, v_key, v_value = hop.inputargs(self, r_object, r_object)
     hop.exception_cannot_occur()
     if hop.args_s[2].is_constant() and hop.args_s[2].const is None:
         hop.gendirectcall(ll_set_null, v_d, v_key)
     else:
         hop.gendirectcall(ll_set, v_d, v_key, v_value)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:_rweakkeydict.py

示例7: getruntime

 def getruntime(self, expected_type):
     if expected_type == ootype.Class:
         rinstance = getinstancerepr(self.rtyper, self.classdef)
         return ootype.runtimeClass(rinstance.lowleveltype)
     else:
         assert ootype.isSubclass(expected_type, META)
         meta = self.get_meta_instance(cast_to_root_meta=False)
         return ootype.ooupcast(expected_type, meta)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:rclass.py

示例8: rtype_method_get

 def rtype_method_get(self, hop):
     r_object = getinstancerepr(self.rtyper, None)
     v_d, v_key = hop.inputargs(self, r_object)
     hop.exception_cannot_occur()
     v_result = hop.gendirectcall(ll_get, v_d, v_key)
     v_result = hop.genop("cast_pointer", [v_result],
                          resulttype=hop.r_result.lowleveltype)
     return v_result
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:_rweakkeydict.py

示例9: setup_vtable

    def setup_vtable(self, vtable, rsubcls):
        """Initialize the 'self' portion of the 'vtable' belonging to the
        given subclass."""
        if self.classdef is None:
            # initialize the 'subclassrange_*' and 'name' fields
            if rsubcls.classdef is not None:
                #vtable.parenttypeptr = rsubcls.rbase.getvtable()
                vtable.subclassrange_min = rsubcls.classdef.minid
                vtable.subclassrange_max = rsubcls.classdef.maxid
            else: #for the root class
                vtable.subclassrange_min = 0
                vtable.subclassrange_max = sys.maxint
            rinstance = getinstancerepr(self.rtyper, rsubcls.classdef)
            rinstance.setup()
            if rinstance.gcflavor in RTTIFLAVORS:
                vtable.rtti = getRuntimeTypeInfo(rinstance.object_type)
            if rsubcls.classdef is None:
                name = 'object'
            else:
                name = rsubcls.classdef.shortname
            vtable.name = malloc(Array(Char), len(name)+1, immortal=True)
            for i in range(len(name)):
                vtable.name[i] = name[i]
            vtable.name[len(name)] = '\x00'
            if hasattr(rsubcls.classdef, 'my_instantiate_graph'):
                graph = rsubcls.classdef.my_instantiate_graph
                vtable.instantiate = self.rtyper.getcallable(graph)
            #else: the classdef was created recently, so no instantiate()
            #      could reach it
        else:
            # setup class attributes: for each attribute name at the level
            # of 'self', look up its value in the subclass rsubcls
            def assign(mangled_name, value):
                if isinstance(value, Constant) and isinstance(value.value, staticmethod):
                    value = Constant(value.value.__get__(42))   # staticmethod => bare function
                llvalue = r.convert_desc_or_const(value)
                setattr(vtable, mangled_name, llvalue)

            mro = list(rsubcls.classdef.getmro())
            for fldname in self.clsfields:
                mangled_name, r = self.clsfields[fldname]
                if r.lowleveltype is Void:
                    continue
                value = rsubcls.classdef.classdesc.read_attribute(fldname, None)
                if value is not None:
                    assign(mangled_name, value)
            # extra PBC attributes
            for (access_set, attr), (mangled_name, r) in self.pbcfields.items():
                if rsubcls.classdef.classdesc not in access_set.descs:
                    continue   # only for the classes in the same pbc access set
                if r.lowleveltype is Void:
                    continue
                attrvalue = rsubcls.classdef.classdesc.read_attribute(attr, None)
                if attrvalue is not None:
                    assign(mangled_name, attrvalue)

            # then initialize the 'super' portion of the vtable
            self.rbase.setup_vtable(vtable.super, rsubcls)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:58,代码来源:rclass.py

示例10: _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)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:58,代码来源:rclass.py

示例11: specialize_call

 def specialize_call(self, hop):
     from pypy.rpython.rclass import getinstancerepr
     s_cls = hop.args_s[1]
     assert s_cls.is_constant()
     [classdesc] = s_cls.descriptions
     classdef = classdesc.getuniqueclassdef()
     r_inst = getinstancerepr(hop.rtyper, classdef)
     cpytype = build_pytypeobject(r_inst)
     return hop.inputconst(PyObjPtr, cpytype)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:rcpy.py

示例12: redispatch_call

    def redispatch_call(self, hop, call_args):
        s_instance = hop.s_result
        r_instance = hop.r_result

        if len(self.s_pbc.descriptions) == 1:
            # instantiating a single class
            if self.lowleveltype is not Void:
                assert 0, "XXX None-or-1-class instantation not implemented"
            assert isinstance(s_instance, annmodel.SomeInstance)
            classdef = s_instance.classdef
            s_init = classdef.classdesc.s_read_attribute('__init__')
            v_init = Constant("init-func-dummy")   # this value not really used

            if (isinstance(s_init, annmodel.SomeImpossibleValue) and 
                classdef.classdesc.is_exception_class() and
                classdef.has_no_attrs()):
                # special case for instanciating simple built-in
                # exceptions: always return the same prebuilt instance,
                # and ignore any arguments passed to the contructor.
                r_instance = rclass.getinstancerepr(hop.rtyper, classdef)
                example = r_instance.get_reusable_prebuilt_instance()
                hop.exception_cannot_occur()
                return hop.inputconst(r_instance.lowleveltype, example)

            v_instance = rclass.rtype_new_instance(hop.rtyper, classdef,
                                                   hop.llops, hop)
            if isinstance(v_instance, tuple):
                v_instance, must_call_init = v_instance
                if not must_call_init:
                    return v_instance
        else:
            # instantiating a class from multiple possible classes
            vtypeptr = hop.inputarg(self, arg=0)
            try:
                access_set, r_class = self.get_access_set('__init__')
            except rclass.MissingRTypeAttribute:
                s_init = annmodel.s_ImpossibleValue
            else:
                s_init = access_set.s_value
                v_init = r_class.getpbcfield(vtypeptr, access_set, '__init__',
                                             hop.llops)                
            v_instance = self._instantiate_runtime_class(hop, vtypeptr, r_instance)

        if isinstance(s_init, annmodel.SomeImpossibleValue):
            assert hop.nb_args == 1, ("arguments passed to __init__, "
                                      "but no __init__!")
            hop.exception_cannot_occur()
        else:
            hop2 = self.replace_class_with_inst_arg(
                    hop, v_instance, s_instance, call_args)
            hop2.v_s_insertfirstarg(v_init, s_init)   # add 'initfunc'
            hop2.s_result = annmodel.s_None
            hop2.r_result = self.rtyper.getrepr(hop2.s_result)
            # now hop2 looks like simple_call(initfunc, instance, args...)
            hop2.dispatch()
        return v_instance
开发者ID:enyst,项目名称:plexnet,代码行数:56,代码来源:rpbc.py

示例13: __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
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:exceptiondata.py

示例14: _instantiate_runtime_class

 def _instantiate_runtime_class(self, hop, v_meta, r_instance):
     classdef = hop.s_result.classdef            
     c_class_ = hop.inputconst(ootype.Void, "class_")
     v_class = hop.genop('oogetfield', [v_meta, c_class_],
             resulttype=ootype.Class)
     resulttype = getinstancerepr(hop.rtyper, classdef).lowleveltype
     v_instance = hop.genop('runtimenew', [v_class], resulttype=resulttype)
     c_meta = hop.inputconst(ootype.Void, "meta")
     hop.genop('oosetfield', [v_instance, c_meta, v_meta],
             resulttype=ootype.Void)
     return v_instance
开发者ID:antoine1fr,项目名称:pygirl,代码行数:11,代码来源:rpbc.py

示例15: _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)
开发者ID:alkorzt,项目名称:pypy,代码行数:45,代码来源:rclass.py


注:本文中的pypy.rpython.rclass.getinstancerepr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。