[pypy-svn] r50753 - pypy/dist/pypy/jit/timeshifter/test

arigo at codespeak.net arigo at codespeak.net
Fri Jan 18 16:39:43 CET 2008


Author: arigo
Date: Fri Jan 18 16:39:42 2008
New Revision: 50753

Modified:
   pypy/dist/pypy/jit/timeshifter/test/test_rcontainer.py
Log:
(cfbolz, arigo)
Simple test about merging virtual structures.


Modified: pypy/dist/pypy/jit/timeshifter/test/test_rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_rcontainer.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_rcontainer.py	Fri Jan 18 16:39:42 2008
@@ -5,23 +5,25 @@
 
 class TestVirtualStruct:
 
+    def setup_class(cls):
+        cls.STRUCT = lltype.Struct("dummy", ("foo", lltype.Signed))
+        cls.structdesc = rcontainer.StructTypeDesc(FakeHRTyper(), cls.STRUCT)
+        cls.fielddesc = rcontainer.StructFieldDesc(FakeHRTyper(),
+                                                   lltype.Ptr(cls.STRUCT),
+                                                   "foo", 0)
+
     def make_virtual_struct(self):
         jitstate = FakeJITState()
-        STRUCT = lltype.Struct("dummy", ("foo", lltype.Signed))
-        structdesc = rcontainer.StructTypeDesc(FakeHRTyper(), STRUCT)
-        desc = rcontainer.StructFieldDesc(FakeHRTyper(), lltype.Ptr(STRUCT), "foo", 0)
 
-        box = structdesc.factory()
+        box = self.structdesc.factory()
         assert box.known_nonzero
 
         V42 = FakeGenVar(42)
         valuebox = rvalue.IntRedBox("dummy kind", V42)
-        box.op_setfield(jitstate, desc, valuebox)
+        box.op_setfield(jitstate, self.fielddesc, valuebox)
         assert jitstate.curbuilder.ops == []
         self.jitstate = jitstate
         self.V42 = V42
-        self.STRUCT = STRUCT
-        self.fielddesc = desc
         return box
 
     def test_virtualstruct_get_set_field(self):
@@ -38,3 +40,22 @@
         assert jitstate.curbuilder.ops == [
             ('malloc_fixedsize', (('alloc', self.STRUCT),), V1),
             ('setfield', (('field', self.STRUCT, 'foo'), V1, self.V42), None)]
+
+    def test_simple_merge(self):
+        oldbox = self.make_virtual_struct()
+        frozenbox = oldbox.freeze(rvalue.freeze_memo())
+        outgoingvarboxes = []
+        res = frozenbox.exactmatch(oldbox, outgoingvarboxes,
+                                   rvalue.exactmatch_memo())
+        assert res
+        fieldbox = oldbox.content.op_getfield(self.jitstate, self.fielddesc)
+        assert outgoingvarboxes == [fieldbox]
+
+        newbox = self.make_virtual_struct()
+        constbox = rvalue.IntRedBox("dummy kind", FakeGenConst(23))
+        newbox.content.op_setfield(self.jitstate, self.fielddesc, constbox)
+        outgoingvarboxes = []
+        res = frozenbox.exactmatch(newbox, outgoingvarboxes,
+                                   rvalue.exactmatch_memo())
+        assert res
+        assert outgoingvarboxes == [constbox]



More information about the Pypy-commit mailing list