[pypy-svn] r65885 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jun 23 14:05:19 CEST 2009


Author: arigo
Date: Tue Jun 23 14:05:18 2009
New Revision: 65885

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
Log:
Subclasses of virtualizable.


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	Tue Jun 23 14:05:18 2009
@@ -292,6 +292,35 @@
         self.check_loops(getarrayitem_gc=0)
 
 
+    def test_subclass_of_virtualizable(self):
+        myjitdriver = JitDriver(greens = [], reds = ['frame'],
+                                virtualizables = ['frame'])
+
+        class Frame(object):
+            _virtualizable2_ = ['x', 'y']
+
+            def __init__(self, x, y):
+                self.x = x
+                self.y = y
+
+        class SubFrame(Frame):
+            pass
+
+        def f(n):
+            Frame(0, 0)    # hack: make sure x and y are attached to Frame
+            frame = SubFrame(n, 0)
+            while frame.x > 0:
+                myjitdriver.can_enter_jit(frame=frame)
+                myjitdriver.jit_merge_point(frame=frame)
+                frame.y += frame.x
+                frame.x -= 1
+            return frame.y
+
+        res = self.meta_interp(f, [10])
+        assert res == 55
+        self.check_loops(getfield_gc=0, setfield_gc=0)
+
+
     def test_virtualizable_with_list(self):
         py.test.skip("redo or fix")
         myjitdriver = JitDriver(greens = [], reds = ['n', 'frame', 'x'],

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	Tue Jun 23 14:05:18 2009
@@ -473,6 +473,8 @@
         index = len(jitdriver.greens) + jitdriver.reds.index(vname)
         self.index_of_virtualizable = index
         VTYPEPTR = warmrunnerdesc.JIT_ENTER_FUNCTYPE.ARGS[index]
+        while 'virtualizable2_accessor' not in VTYPEPTR.TO._hints:
+            VTYPEPTR = lltype.Ptr(VTYPEPTR.TO._first_struct()[1])
         self.VTYPEPTR = VTYPEPTR
         #
         accessor = VTYPEPTR.TO._hints['virtualizable2_accessor']



More information about the Pypy-commit mailing list