[pypy-svn] r70691 - in pypy/branch/cli-jit/pypy: annotation rpython/lltypesystem rpython/ootypesystem rpython/ootypesystem/test rpython/test translator/cli translator/jvm/test

antocuni at codespeak.net antocuni at codespeak.net
Mon Jan 18 21:04:23 CET 2010


Author: antocuni
Date: Mon Jan 18 21:04:21 2010
New Revision: 70691

Modified:
   pypy/branch/cli-jit/pypy/annotation/builtin.py
   pypy/branch/cli-jit/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/cli-jit/pypy/rpython/ootypesystem/ooopimpl.py
   pypy/branch/cli-jit/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/cli-jit/pypy/rpython/ootypesystem/rbuiltin.py
   pypy/branch/cli-jit/pypy/rpython/ootypesystem/test/test_ootype.py
   pypy/branch/cli-jit/pypy/rpython/test/test_rclass.py
   pypy/branch/cli-jit/pypy/translator/cli/opcodes.py
   pypy/branch/cli-jit/pypy/translator/jvm/test/test_class.py
Log:
add a new ootype operations 'getsuperclassof', the get the superclass of
objects of type ootype.Class



Modified: pypy/branch/cli-jit/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/cli-jit/pypy/annotation/builtin.py	(original)
+++ pypy/branch/cli-jit/pypy/annotation/builtin.py	Mon Jan 18 21:04:21 2010
@@ -562,6 +562,10 @@
     assert isinstance(class2, SomeOOClass) 
     return s_Bool
 
+def getsuperclassof(class_):
+    assert isinstance(class_, SomeOOClass)
+    return SomeOOClass(class_.ootype._superclass)
+
 def runtimenew(c):
     assert isinstance(c, SomeOOClass)
     if c.ootype is None:
@@ -609,6 +613,7 @@
 BUILTIN_ANALYZERS[ootype.runtimenew] = runtimenew
 BUILTIN_ANALYZERS[ootype.classof] = classof
 BUILTIN_ANALYZERS[ootype.subclassof] = subclassof
+BUILTIN_ANALYZERS[ootype.getsuperclassof] = getsuperclassof
 BUILTIN_ANALYZERS[ootype.ooupcast] = ooupcast
 BUILTIN_ANALYZERS[ootype.oodowncast] = oodowncast
 BUILTIN_ANALYZERS[ootype.cast_to_object] = cast_to_object

Modified: pypy/branch/cli-jit/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/cli-jit/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/cli-jit/pypy/rpython/lltypesystem/lloperation.py	Mon Jan 18 21:04:21 2010
@@ -557,6 +557,7 @@
     'instanceof':           LLOp(oo=True, canfold=True),
     'classof':              LLOp(oo=True, canfold=True),
     'subclassof':           LLOp(oo=True, canfold=True),
+    'getsuperclassof':      LLOp(oo=True, canfold=True),
     'oostring':             LLOp(oo=True, sideeffects=False),
     'ooparse_int':          LLOp(oo=True, canraise=(ValueError,)),
     'ooparse_float':        LLOp(oo=True, canraise=(ValueError,)),

Modified: pypy/branch/cli-jit/pypy/rpython/ootypesystem/ooopimpl.py
==============================================================================
--- pypy/branch/cli-jit/pypy/rpython/ootypesystem/ooopimpl.py	(original)
+++ pypy/branch/cli-jit/pypy/rpython/ootypesystem/ooopimpl.py	Mon Jan 18 21:04:21 2010
@@ -51,6 +51,9 @@
 def op_subclassof(class1, class2):
     return ootype.subclassof(class1, class2)
 
+def op_getsuperclassof(class_):
+    return ootype.getsuperclassof(class_)
+
 def op_oogetfield(inst, name):
     checkinst(inst)
     if not ootype.typeOf(inst)._hints.get('immutable'):

Modified: pypy/branch/cli-jit/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/cli-jit/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/cli-jit/pypy/rpython/ootypesystem/ootype.py	Mon Jan 18 21:04:21 2010
@@ -919,6 +919,10 @@
     def _cast_to_object(self):
         return make_object(self)
 
+    def _get_superclass(self):
+        SUPER = self._INSTANCE._superclass
+        return runtimeClass(SUPER)
+
     def __repr__(self):
         return '%s(%s)' % (self.__class__.__name__, self._INSTANCE)
 
@@ -1867,6 +1871,9 @@
     assert class2 is not nullruntimeclass
     return isSubclass(class1._INSTANCE, class2._INSTANCE)
 
+def getsuperclassof(class_):
+    return class_._get_superclass()
+
 def addFields(INSTANCE, fields, with_default=False):
     INSTANCE._add_fields(fields, with_default)
 

Modified: pypy/branch/cli-jit/pypy/rpython/ootypesystem/rbuiltin.py
==============================================================================
--- pypy/branch/cli-jit/pypy/rpython/ootypesystem/rbuiltin.py	(original)
+++ pypy/branch/cli-jit/pypy/rpython/ootypesystem/rbuiltin.py	Mon Jan 18 21:04:21 2010
@@ -36,6 +36,12 @@
     return hop.genop('subclassof', vlist,
                      resulttype = ootype.Bool)
 
+def rtype_getsuperclassof(hop):
+    assert isinstance(hop.args_s[0], annmodel.SomeOOClass)
+    vlist = hop.inputargs(hop.args_r[0])
+    return hop.genop('getsuperclassof', vlist,
+                     resulttype = ootype.Class)
+
 def rtype_instanceof(hop):
     INSTANCE = hop.args_v[1].value
     v_inst = hop.inputarg(hop.args_r[0], arg=0)
@@ -124,6 +130,7 @@
 BUILTIN_TYPER[ootype.null] = rtype_null
 BUILTIN_TYPER[ootype.classof] = rtype_classof
 BUILTIN_TYPER[ootype.subclassof] = rtype_subclassof
+BUILTIN_TYPER[ootype.getsuperclassof] = rtype_getsuperclassof
 BUILTIN_TYPER[ootype.instanceof] = rtype_instanceof
 BUILTIN_TYPER[ootype.runtimenew] = rtype_runtimenew
 BUILTIN_TYPER[ootype.ooupcast] = rtype_ooupcast

Modified: pypy/branch/cli-jit/pypy/rpython/ootypesystem/test/test_ootype.py
==============================================================================
--- pypy/branch/cli-jit/pypy/rpython/ootypesystem/test/test_ootype.py	(original)
+++ pypy/branch/cli-jit/pypy/rpython/ootypesystem/test/test_ootype.py	Mon Jan 18 21:04:21 2010
@@ -377,6 +377,17 @@
         1, 1, 1,
         ]
 
+def test_getsuperclassof():
+    A = Instance("A", ROOT)
+    B = Instance("B", A)
+    C = Instance("C", B)
+    clsA = runtimeClass(A)
+    clsB = runtimeClass(B)
+    clsC = runtimeClass(C)
+    assert getsuperclassof(clsC) is clsB
+    assert getsuperclassof(clsB) is clsA
+    assert getsuperclassof(clsA) is runtimeClass(ROOT)
+
 def test_static_method_equality():
     SM = StaticMethod([], Signed)
     SM1 = StaticMethod([], Signed)

Modified: pypy/branch/cli-jit/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/branch/cli-jit/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/branch/cli-jit/pypy/rpython/test/test_rclass.py	Mon Jan 18 21:04:21 2010
@@ -997,3 +997,16 @@
                 return ootype.NULL
         res = self.interpret(fn_mix_null, [False])
         assert res is ootype.NULL
+
+    def test_getsuperclassof(self):
+        A = ootype.Instance("A", ootype.ROOT)
+        B = ootype.Instance("B", A)
+        clsA = ootype.runtimeClass(A)
+        clsB = ootype.runtimeClass(B)
+
+        def fn(flag):
+            cls = flag and clsA or clsB
+            return ootype.getsuperclassof(cls) is clsA
+
+        res = self.interpret(fn, [False], backendopt=False)
+        assert res

Modified: pypy/branch/cli-jit/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/cli-jit/pypy/translator/cli/opcodes.py	(original)
+++ pypy/branch/cli-jit/pypy/translator/cli/opcodes.py	Mon Jan 18 21:04:21 2010
@@ -59,6 +59,7 @@
     'classof':                  [PushAllArgs, 'callvirt instance class [mscorlib]System.Type object::GetType()'],
     'instanceof':               [CastTo, 'ldnull', 'cgt.un'],
     'subclassof':               [PushAllArgs, 'call bool [pypylib]pypy.runtime.Utils::SubclassOf(class [mscorlib]System.Type, class[mscorlib]System.Type)'],
+    'getsuperclassof':          [PushAllArgs, 'callvirt instance class [mscorlib]System.Type class [mscorlib]System.Type::get_BaseType()'],
     'gc_id':                    [PushAllArgs, 'call int32 [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::GetHashCode(object)'],   # XXX not implemented
     'gc_identityhash':          [PushAllArgs, 'call int32 [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::GetHashCode(object)'],
     'oostring':                 [OOString],

Modified: pypy/branch/cli-jit/pypy/translator/jvm/test/test_class.py
==============================================================================
--- pypy/branch/cli-jit/pypy/translator/jvm/test/test_class.py	(original)
+++ pypy/branch/cli-jit/pypy/translator/jvm/test/test_class.py	Mon Jan 18 21:04:21 2010
@@ -27,5 +27,8 @@
     def test_specialize_methods(self):
         py.test.skip('ABSTRACT METHOD FIX: RE-TEST AFTER MERGE')
 
+    def test_getsuperclassof(self):
+        py.test.skip('fixme')
+
 class TestJvmSpecialCase(JvmTest, BaseTestSpecialcase):
     pass



More information about the Pypy-commit mailing list