[pypy-svn] r65095 - in pypy/branch/pyjitpl5/pypy/rpython: . lltypesystem lltypesystem/test ootypesystem test

antocuni at codespeak.net antocuni at codespeak.net
Wed May 6 14:54:29 CEST 2009


Author: antocuni
Date: Wed May  6 14:54:28 2009
New Revision: 65095

Added:
   pypy/branch/pyjitpl5/pypy/rpython/rvirtualizable2.py
      - copied unchanged from r65092, pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py
   pypy/branch/pyjitpl5/pypy/rpython/test/test_rvirtualizable2.py
      - copied, changed from r65079, pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/test/test_rvirtualizable2.py
Removed:
   pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py
   pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/test/test_rvirtualizable2.py
Modified:
   pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py
   pypy/branch/pyjitpl5/pypy/rpython/rclass.py
Log:
(in-progress) port rvirtualizable2.py to ootype, part 1: move
rvirtualizable2.py and the logic to select it one level up, and write a proper
unit test



Modified: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py	Wed May  6 14:54:28 2009
@@ -19,7 +19,6 @@
 from pypy.rpython.robject import PyObjRepr, pyobj_repr
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.annotation import model as annmodel
-from pypy.rlib.objectmodel import UnboxedValue
 from pypy.rlib.rarithmetic import intmask
 
 #
@@ -606,41 +605,6 @@
             return hop.gendirectcall(ll_isinstance, v_obj, v_cls)
 
 
-def buildinstancerepr(rtyper, classdef, gcflavor='gc'):
-    if classdef is None:
-        unboxed = []
-        virtualizable = False
-        virtualizable2 = False
-    else:
-        unboxed = [subdef for subdef in classdef.getallsubdefs()
-                          if subdef.classdesc.pyobj is not None and
-                             issubclass(subdef.classdesc.pyobj, UnboxedValue)]
-        virtualizable = classdef.classdesc.read_attribute('_virtualizable_',
-                                                          Constant(False)).value
-        virtualizable2 = classdef.classdesc.read_attribute('_virtualizable2_',
-                                                           Constant(False)).value
-    if virtualizable:
-        assert len(unboxed) == 0
-        assert gcflavor == 'gc'
-        from pypy.rpython.lltypesystem import rvirtualizable
-        return rvirtualizable.VirtualizableInstanceRepr(rtyper, classdef)
-    elif virtualizable2:
-        assert len(unboxed) == 0
-        assert gcflavor == 'gc'
-        from pypy.rpython.lltypesystem import rvirtualizable2
-        return rvirtualizable2.Virtualizable2InstanceRepr(rtyper, classdef)
-    elif len(unboxed) == 0:
-        return InstanceRepr(rtyper, classdef, gcflavor)
-    else:
-        # the UnboxedValue class and its parent classes need a
-        # special repr for their instances
-        if len(unboxed) != 1:
-            raise TyperError("%r has several UnboxedValue subclasses" % (
-                classdef,))
-        assert gcflavor == 'gc'
-        from pypy.rpython.lltypesystem import rtagged
-        return rtagged.TaggedInstanceRepr(rtyper, classdef, unboxed[0])
-
 
 class __extend__(pairtype(InstanceRepr, InstanceRepr)):
     def convert_from_to((r_ins1, r_ins2), v, llops):

Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py	Wed May  6 14:54:28 2009
@@ -524,8 +524,6 @@
         if '_hash_cache_' in self.lowleveltype._allfields():
             result._hash_cache_ = hash(value)
 
-buildinstancerepr = InstanceRepr
-
 
 class __extend__(pairtype(InstanceRepr, InstanceRepr)):
     def convert_from_to((r_ins1, r_ins2), v, llops):

Modified: pypy/branch/pyjitpl5/pypy/rpython/rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/rclass.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/rclass.py	Wed May  6 14:54:28 2009
@@ -22,13 +22,55 @@
     try:
         result = rtyper.instance_reprs[classdef, flavor]
     except KeyError:
-        result = rtyper.type_system.rclass.buildinstancerepr(
-                        rtyper, classdef, gcflavor=flavor)
+        result = buildinstancerepr(rtyper, classdef, gcflavor=flavor)
 
         rtyper.instance_reprs[classdef, flavor] = result
         rtyper.add_pendingsetup(result)
     return result
 
+
+def buildinstancerepr(rtyper, classdef, gcflavor='gc'):
+    from pypy.rlib.objectmodel import UnboxedValue
+    from pypy.objspace.flow.model import Constant
+    
+    if classdef is None:
+        unboxed = []
+        virtualizable = False
+        virtualizable2 = False
+    else:
+        unboxed = [subdef for subdef in classdef.getallsubdefs()
+                          if subdef.classdesc.pyobj is not None and
+                             issubclass(subdef.classdesc.pyobj, UnboxedValue)]
+        virtualizable = classdef.classdesc.read_attribute('_virtualizable_',
+                                                          Constant(False)).value
+        virtualizable2 = classdef.classdesc.read_attribute('_virtualizable2_',
+                                                           Constant(False)).value
+    if virtualizable:
+        assert rtyper.type_system.name == 'lltypesystem'
+        assert len(unboxed) == 0
+        assert gcflavor == 'gc'
+        from pypy.rpython.lltypesystem import rvirtualizable
+        return rvirtualizable.VirtualizableInstanceRepr(rtyper, classdef)
+    elif virtualizable2:
+        assert rtyper.type_system.name == 'lltypesystem'
+        assert len(unboxed) == 0
+        assert gcflavor == 'gc'
+        from pypy.rpython import rvirtualizable2
+        return rvirtualizable2.Virtualizable2InstanceRepr(rtyper, classdef)
+    elif len(unboxed) == 0:
+        return rtyper.type_system.rclass.InstanceRepr(rtyper, classdef, gcflavor)
+    else:
+        assert rtyper.type_system.name == 'lltypesystem'
+        # the UnboxedValue class and its parent classes need a
+        # special repr for their instances
+        if len(unboxed) != 1:
+            raise TyperError("%r has several UnboxedValue subclasses" % (
+                classdef,))
+        assert gcflavor == 'gc'
+        from pypy.rpython.lltypesystem import rtagged
+        return rtagged.TaggedInstanceRepr(rtyper, classdef, unboxed[0])
+
+
 class MissingRTypeAttribute(TyperError):
     pass
 

Copied: pypy/branch/pyjitpl5/pypy/rpython/test/test_rvirtualizable2.py (from r65079, pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/test/test_rvirtualizable2.py)
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/test/test_rvirtualizable2.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/test/test_rvirtualizable2.py	Wed May  6 14:54:28 2009
@@ -1,6 +1,6 @@
 import py
 from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 
 
 class V(object):
@@ -9,12 +9,31 @@
     def __init__(self, v):
         self.v = v
 
-def test_simple():
-    def f(v):
-        vinst = V(v)
-        return vinst, vinst.v
-    res = interpret(f, [42])
-    assert res.item1 == 42
-    res = lltype.normalizeptr(res.item0)
-    assert res.inst_v == 42
-    assert not res.vable_rti
+class BaseTest(BaseRtypingTest):
+    def test_generate_promote_virtualizable(self):
+        def fn(n):
+            vinst = V(n)
+            return vinst.v
+        _, _, graph = self.gengraph(fn, [int])
+        block = graph.startblock
+        op_getfield = block.operations[-1]
+        op_promote = block.operations[-2]
+        assert op_getfield.opname in ('getfield', 'oogetfield')
+        v_inst = op_getfield.args[0]
+        assert op_promote.opname == 'promote_virtualizable'
+        assert op_promote.args[0] is v_inst
+
+class TestLLtype(LLRtypeMixin, BaseTest):
+
+    def test_simple(self):
+        def f(v):
+            vinst = V(v)
+            return vinst, vinst.v
+        res = self.interpret(f, [42])
+        assert res.item1 == 42
+        res = lltype.normalizeptr(res.item0)
+        assert res.inst_v == 42
+        assert not res.vable_rti
+
+## class TestOOtype(OORtypeMixin, BaseTest):
+##     pass



More information about the Pypy-commit mailing list