[pypy-svn] r66553 - in pypy/branch/pyjitpl5-optimize4/pypy/jit: backend/llgraph metainterp/test

arigo at codespeak.net arigo at codespeak.net
Thu Jul 23 19:52:31 CEST 2009


Author: arigo
Date: Thu Jul 23 19:52:31 2009
New Revision: 66553

Modified:
   pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py
Log:
Progress; the next test passes (also on ootype).


Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py	Thu Jul 23 19:52:31 2009
@@ -462,9 +462,11 @@
         else:
             return ootype.NULL
 
-    def do_new_with_vtable(self, args, typedescr):
-        assert isinstance(typedescr, TypeDescr)
-        assert len(args) == 1 # but we don't need it, so ignore
+    def do_new_with_vtable(self, args, descr=None):
+        assert descr is None
+        assert len(args) == 1
+        cls = args[0].getobj()
+        typedescr = self.class_sizes[cls]
         return typedescr.create()
 
     def do_new_array(self, args, typedescr):

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	Thu Jul 23 19:52:31 2009
@@ -1,11 +1,13 @@
 import py
+from pypy.rpython.lltypesystem import rclass
+from pypy.rpython.ootypesystem import ootype
 from pypy.jit.metainterp.test.test_resume import MyMetaInterp
 from pypy.jit.metainterp.test.test_optimizefindnode import (LLtypeMixin,
                                                             OOtypeMixin,
                                                             BaseTest)
 from pypy.jit.metainterp.optimizeopt import optimize
-from pypy.jit.metainterp.history import AbstractDescr, ConstInt
-from pypy.jit.metainterp import resume
+from pypy.jit.metainterp.history import AbstractDescr, ConstInt, BoxPtr
+from pypy.jit.metainterp import resume, executor
 from pypy.jit.metainterp.resoperation import rop, opname
 from pypy.jit.metainterp.test.oparser import parse
 
@@ -591,22 +593,63 @@
         self.fdescr = fdescr
         self.namespace['fdescr'] = fdescr
 
-    def unpack_expected_fail_args(self, oparse, text):
+    def _verify_fail_args(self, boxes, oparse, text):
         import re
         r = re.compile(r"\bwhere\s+(\w+)\s+is a\s+(\w+)")
         parts = list(r.finditer(text))
-        if parts:
-            text = text[:parts[0].start()]
-            xxx
-        return [oparse.getvar(s.strip()) for s in text.split(',')]
+        ends = [match.start() for match in parts] + [len(text)]
+        #
+        virtuals = {}
+        for match, end in zip(parts, ends[1:]):
+            pvar = match.group(1)
+            cls_vtable = self.namespace[match.group(2)]
+            fieldstext = text[match.end():end]
+            virtuals[pvar] = (cls_vtable, None, fieldstext)
+        #
+        def _variables_equal(box, varname, strict):
+            if varname not in virtuals:
+                if strict:
+                    assert box == oparse.getvar(varname)
+                else:
+                    assert box.value == oparse.getvar(varname).value
+            else:
+                cls_vtable, resolved, fieldstext = virtuals[varname]
+                if not self.cpu.is_oo:
+                    assert box.getptr(rclass.OBJECTPTR).typeptr == cls_vtable
+                else:
+                    root = ootype.cast_from_object(ootype.ROOT, box.getobj())
+                    assert ootype.classof(root) == cls_vtable
+                if resolved is not None:
+                    assert resolved.value == box.value
+                else:
+                    virtuals[varname] = cls_vtable, box, fieldstext
+        #
+        basetext = text[:ends[0]]
+        varnames = [s.strip() for s in basetext.split(',')]
+        assert len(boxes) == len(varnames)
+        for box, varname in zip(boxes, varnames):
+            _variables_equal(box, varname, strict=True)
+        #
+        for cls_vtable, resolved, fieldstext in virtuals.values():
+            assert resolved is not None
+            for fieldtext in fieldstext.split(','):
+                fieldtext = fieldtext.strip()
+                if not fieldtext:
+                    continue
+                fieldname, fieldvalue = fieldtext.split('=')
+                fielddescr = self.namespace[fieldname.strip()]
+                fieldbox = executor.execute(self.cpu,
+                                            rop.GETFIELD_GC,
+                                            [resolved],
+                                            descr=fielddescr)
+                _variables_equal(fieldbox, fieldvalue.strip(), strict=False)
 
     def check_expanded_fail_descr(self, expectedtext):
         fdescr = self.fdescr
         args, oparse = fdescr.args_seen[-1]
-        reader = resume.ResumeDataReader(fdescr, args, MyMetaInterp())
+        reader = resume.ResumeDataReader(fdescr, args, MyMetaInterp(self.cpu))
         boxes = reader.consume_boxes()
-        expected = self.unpack_expected_fail_args(oparse, expectedtext)
-        assert boxes == expected
+        self._verify_fail_args(boxes, oparse, expectedtext)
 
     def test_expand_fail_1(self):
         self.make_fail_descr()
@@ -632,7 +675,6 @@
         self.check_expanded_fail_descr('15, i3')
 
     def test_expand_fail_2(self):
-        py.test.skip("in-progress")
         self.make_fail_descr()
         ops = """
         [i1, i2]

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py	Thu Jul 23 19:52:31 2009
@@ -57,8 +57,10 @@
 
 
 class MyMetaInterp:
+    def __init__(self, cpu):
+        self.cpu = cpu
     def execute_and_record(self, opnum, argboxes, descr=None):
-        return executor.execute(LLtypeMixin.cpu, opnum, argboxes, descr)
+        return executor.execute(self.cpu, opnum, argboxes, descr)
 
 demo55 = lltype.malloc(LLtypeMixin.NODE)
 demo55o = lltype.cast_opaque_ptr(llmemory.GCREF, demo55)
@@ -76,7 +78,8 @@
     assert liveboxes == [b1s, b2s, b3s]
     #
     b1t, b2t, b3t = [BoxInt(11), BoxPtr(demo55o), BoxInt(33)]
-    reader = ResumeDataReader(storage, [b1t, b2t, b3t], MyMetaInterp())
+    reader = ResumeDataReader(storage, [b1t, b2t, b3t],
+                              MyMetaInterp(LLtypeMixin.cpu))
     lst = reader.consume_boxes()
     assert lst == [b1t, ConstInt(1), b1t, b2t]
     lst = reader.consume_boxes()
@@ -121,7 +124,8 @@
                          b5s]
     #
     b1t, b3t, b5t = [BoxInt(11), BoxInt(33), BoxPtr(demo55o)]
-    reader = ResumeDataReader(storage, [b1t, b3t, b5t], MyMetaInterp())
+    reader = ResumeDataReader(storage, [b1t, b3t, b5t],
+                              MyMetaInterp(LLtypeMixin.cpu))
     lst = reader.consume_boxes()
     b2t = lst[-1]
     assert lst == [b1t, ConstInt(1), b1t, b2t]
@@ -161,7 +165,8 @@
         assert liveboxes == [b2s, b3s]
         #
         b2t, b3t = [BoxPtr(demo55o), BoxInt(33)]
-        reader = ResumeDataReader(storage, [b2t, b3t], MyMetaInterp())
+        reader = ResumeDataReader(storage, [b2t, b3t],
+                                  MyMetaInterp(LLtypeMixin.cpu))
         lst = reader.consume_boxes()
         c1t = ConstInt(111)
         assert lst == [c1t, ConstInt(1), c1t, b2t]



More information about the Pypy-commit mailing list