예제 #1
0
 def fromclasstype(self, vclass, llops):
     assert ootype.isSubclass(vclass.concretetype, META)
     if self.lowleveltype == ootype.Class:
         c_class_ = inputconst(ootype.Void, 'class_')
         return llops.genop('oogetfield', [vclass, c_class_],
                            resulttype=ootype.Class)
     else:
         assert ootype.isSubclass(self.lowleveltype, vclass.concretetype)
         return llops.genop('oodowncast', [vclass],
                            resulttype=self.lowleveltype)
예제 #2
0
파일: rclass.py 프로젝트: sota/pypy
 def fromclasstype(self, vclass, llops):
     assert ootype.isSubclass(vclass.concretetype, META)
     if self.lowleveltype == ootype.Class:
         c_class_ = inputconst(ootype.Void, 'class_')
         return llops.genop('oogetfield', [vclass, c_class_],
                 resulttype=ootype.Class)
     else:
         assert ootype.isSubclass(self.lowleveltype, vclass.concretetype)
         return llops.genop('oodowncast', [vclass],
                 resulttype=self.lowleveltype)
예제 #3
0
def match_virtualizable_type(TYPE, VTYPEPTR):
    if isinstance(TYPE, ootype.Instance):
        # ootype only: any subtype may be used
        return ootype.isSubclass(TYPE, VTYPEPTR)
    else:
        # lltype, or ootype with a TYPE that is e.g. an ootype.Record
        return TYPE == VTYPEPTR
예제 #4
0
 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)
예제 #5
0
 def compute_result_annotation(self, s_value, s_type):
     if isinstance(s_type.const, ootype.OOType):
         TYPE = s_type.const
     else:
         cliClass = s_type.const
         TYPE = cliClass._INSTANCE
     assert ootype.isSubclass(s_value.ootype, TYPE)
     return SomeOOInstance(TYPE)
예제 #6
0
파일: rclass.py 프로젝트: sota/pypy
 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)
예제 #7
0
파일: dotnet.py 프로젝트: sota/pypy
 def compute_result_annotation(self, s_value, s_type):
     if isinstance(s_type.const, ootype.OOType):
         TYPE = s_type.const
     else:
         cliClass = s_type.const
         TYPE = cliClass._INSTANCE
     assert ootype.isSubclass(s_value.ootype, TYPE)
     return SomeOOInstance(TYPE)
예제 #8
0
 def simple_call(self, *s_args):
     from rpython.translator.cli.query import get_cli_class
     DELEGATE = get_cli_class('System.Delegate')._INSTANCE
     if ootype.isSubclass(self.ootype, DELEGATE):
         s_invoke = self.getattr(immutablevalue('Invoke'))
         return s_invoke.simple_call(*s_args)
     else:
         # cannot call a non-delegate
         return SomeObject.simple_call(self, *s_args)
예제 #9
0
파일: dotnet.py 프로젝트: sota/pypy
 def simple_call(self, *s_args):
     from rpython.translator.cli.query import get_cli_class
     DELEGATE = get_cli_class('System.Delegate')._INSTANCE
     if ootype.isSubclass(self.ootype, DELEGATE):
         s_invoke = self.getattr(immutablevalue('Invoke'))
         return s_invoke.simple_call(*s_args)
     else:
         # cannot call a non-delegate
         return SomeObject.simple_call(self, *s_args)
예제 #10
0
 def _toString(self):
     if ootype.isSubclass(self.INSTANCE, self.db.genoo.EXCEPTION):
         return  # don't override the default ToString, which prints a traceback
     self.ilasm.begin_function('ToString', [], 'string', False, 'virtual',
                               'instance', 'default')
     self.ilasm.opcode('ldarg.0')
     self.ilasm.call(
         'string class [pypylib]pypy.test.Result::InstanceToPython(object)')
     self.ilasm.ret()
     self.ilasm.end_function()
예제 #11
0
class __extend__(pairtype(SomeOOInstance, SomeInteger)):
    def getitem((ooinst, index)):
        if ooinst.ootype._isArray:
            return SomeOOInstance(ooinst.ootype._ELEMENT)
        return s_ImpossibleValue

    def setitem((ooinst, index), s_value):
        if ooinst.ootype._isArray:
            if s_value is annmodel.s_None:
                return s_None
            ELEMENT = ooinst.ootype._ELEMENT
            VALUE = s_value.ootype
            assert ootype.isSubclass(VALUE, ELEMENT)
            return s_None
        return s_ImpossibleValue
예제 #12
0
파일: exceptiondata.py 프로젝트: sota/pypy
 def is_exception_instance(self, INSTANCE):
     return ootype.isSubclass(INSTANCE, self._EXCEPTION_INST)
예제 #13
0
 def is_exception_instance(self, INSTANCE):
     return ootype.isSubclass(INSTANCE, self._EXCEPTION_INST)
예제 #14
0
파일: database.py 프로젝트: sota/pypy-old
    def _translate_instance(self, OOTYPE):
        assert isinstance(OOTYPE, ootype.Instance)
        assert OOTYPE is not ootype.ROOT

        # Create class object if it does not already exist:
        if OOTYPE in self._classes:
            return self._classes[OOTYPE]

        # Create the class object first
        clsnm = self._pkg(self._uniq(OOTYPE._name))
        clsobj = node.Class(clsnm)
        self._classes[OOTYPE] = clsobj

        # Resolve super class 
        assert OOTYPE._superclass
        supercls = self._translate_superclass_of(OOTYPE)
        clsobj.set_super_class(supercls)

        # TODO --- mangle field and method names?  Must be
        # deterministic, or use hashtable to avoid conflicts between
        # classes?
        
        # Add fields:
        self._translate_class_fields(clsobj, OOTYPE)
            
        # Add methods:
        for mname, mimpl in OOTYPE._methods.iteritems():
            if not hasattr(mimpl, 'graph'):
                # Abstract method
                METH = mimpl._TYPE
                arglist = [self.lltype_to_cts(ARG) for ARG in METH.ARGS
                           if ARG is not ootype.Void]
                returntype = self.lltype_to_cts(METH.RESULT)
                clsobj.add_abstract_method(jvm.Method.v(
                    clsobj, mname, arglist, returntype))
            else:
                # if the first argument's type is not a supertype of
                # this class it means that this method this method is
                # not really used by the class: don't render it, else
                # there would be a type mismatch.
                args =  mimpl.graph.getargs()
                SELF = args[0].concretetype
                if not ootype.isSubclass(OOTYPE, SELF): continue
                mobj = self._function_for_graph(
                    clsobj, mname, False, mimpl.graph)
                # XXX: this logic is broken: it might happen that there are
                # ootype.Instance which contains a meth whose graph is exactly
                # the same as the meth in the superclass: in this case,
                # len(graphs) == 1 but we cannot just mark the method as final
                # (or we can, but we should avoid to emit the method in the
                # subclass, then)
                ## graphs = OOTYPE._lookup_graphs(mname)
                ## if len(graphs) == 1:
                ##     mobj.is_final = True
                clsobj.add_method(mobj)

        # currently, we always include a special "dump" method for debugging
        # purposes
        dump_method = node.InstanceDumpMethod(self, OOTYPE, clsobj)
        clsobj.add_method(dump_method)

        self.pending_node(clsobj)
        return clsobj