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

arigo at codespeak.net arigo at codespeak.net
Fri Jan 18 15:46:43 CET 2008


Author: arigo
Date: Fri Jan 18 15:46:41 2008
New Revision: 50749

Added:
   pypy/dist/pypy/jit/timeshifter/test/support.py   (contents, props changed)
   pypy/dist/pypy/jit/timeshifter/test/test_rcontainer.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/timeshifter/test/test_rvalue.py
Log:
(cfbolz, fijal, arigo)
Another test.  Amazing: 6 JIT tests that run in a small fraction of a second!


Added: pypy/dist/pypy/jit/timeshifter/test/support.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/timeshifter/test/support.py	Fri Jan 18 15:46:41 2008
@@ -0,0 +1,74 @@
+# Fake stuff for the tests.
+
+from pypy.jit.codegen.model import GenVar, GenConst
+
+
+class FakeJITState(object):
+    def __init__(self):
+        self.curbuilder = FakeBuilder()
+
+class FakeRGenOp(object):
+    def genzeroconst(self, kind):
+        if kind == "dummy pointer":
+            return FakeGenConst("NULL")
+        return FakeGenConst(0)
+
+    @staticmethod
+    def kindToken(TYPE):
+        return ("kind", TYPE)
+
+    @staticmethod
+    def fieldToken(TYPE, name):
+        return ("field", TYPE, name)
+
+    @staticmethod
+    def allocToken(TYPE):
+        return ("alloc", TYPE)
+
+    @staticmethod
+    def constPrebuiltGlobal(value):
+        return FakeGenConst(value)
+
+
+class FakeBuilder(object):
+    ops_with_no_retval = set(['setfield'])
+    
+    def __init__(self):
+        self.ops = []
+        self.varcount = 1
+        self.rgenop = FakeRGenOp()
+
+    def __getattr__(self, name):
+        if name.startswith('genop_'):
+            opname = name[len('genop_'):]            
+            def genop_(*args):
+                if opname in self.ops_with_no_retval:
+                    v = None
+                else:
+                    v = FakeGenVar(self.varcount)
+                    self.varcount += 1
+                self.ops.append((opname, args, v))
+                return v
+            genop_.func_name = name
+            return genop_
+        else:
+            raise AttributeError, name
+
+
+class FakeHRTyper(object):
+    RGenOp = FakeRGenOp
+
+class FakeGenVar(GenVar):
+    def __init__(self, count=0):
+        self.count=count
+    
+    def __repr__(self):
+        return "V%d" % self.count
+
+    def __eq__(self, other):
+        return self.count == other.count
+
+
+class FakeGenConst(GenConst):
+    def __init__(self, _value=None):
+        self._value = _value

Added: pypy/dist/pypy/jit/timeshifter/test/test_rcontainer.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/timeshifter/test/test_rcontainer.py	Fri Jan 18 15:46:41 2008
@@ -0,0 +1,22 @@
+from pypy.rpython.lltypesystem import lltype
+from pypy.jit.timeshifter import rvalue, rcontainer
+from pypy.jit.timeshifter.test.support import *
+
+
+def test_virtualstruct_get_set_field():
+    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()
+    assert box.known_nonzero
+
+    V42 = FakeGenVar(42)
+    valuebox = rvalue.IntRedBox("dummy kind", V42)
+    box.op_setfield(jitstate, desc, valuebox)
+    assert jitstate.curbuilder.ops == []
+
+    box2 = box.op_getfield(jitstate, desc)
+    assert box2.genvar is V42
+    assert jitstate.curbuilder.ops == []

Modified: pypy/dist/pypy/jit/timeshifter/test/test_rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_rvalue.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_rvalue.py	Fri Jan 18 15:46:41 2008
@@ -2,73 +2,7 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.jit.timeshifter import rvalue
 from pypy.jit.timeshifter import rcontainer
-from pypy.jit.codegen.model import GenVar, GenConst
-
-class FakeJITState(object):
-    def __init__(self):
-        self.curbuilder = FakeBuilder()
-
-class FakeRGenOp(object):
-    def genzeroconst(self, kind):
-        if kind == "dummy pointer":
-            return FakeGenConst("NULL")
-        return FakeGenConst(0)
-
-    @staticmethod
-    def kindToken(TYPE):
-        return TYPE
-
-    @staticmethod
-    def fieldToken(TYPE, name):
-        return TYPE, name
-
-    @staticmethod
-    def constPrebuiltGlobal(value):
-        return FakeGenConst(value)
-
-
-class FakeBuilder(object):
-    ops_with_no_retval = set(['setfield'])
-    
-    def __init__(self):
-        self.ops = []
-        self.varcount = 1
-        self.rgenop = FakeRGenOp()
-
-    def __getattr__(self, name):
-        if name.startswith('genop_'):
-            opname = name[len('genop_'):]            
-            def genop_(*args):
-                if opname in self.ops_with_no_retval:
-                    v = None
-                else:
-                    v = FakeGenVar(self.varcount)
-                    self.varcount += 1
-                self.ops.append((opname, args, v))
-                return v
-            genop_.func_name = name
-            return genop_
-        else:
-            raise AttributeError, name
-
-
-class FakeHRTyper(object):
-    RGenOp = FakeRGenOp
-
-class FakeGenVar(GenVar):
-    def __init__(self, count=0):
-        self.count=count
-    
-    def __repr__(self):
-        return "V%d" % self.count
-
-    def __eq__(self, other):
-        return self.count == other.count
-
-
-class FakeGenConst(GenConst):
-    def __init__(self, _value=None):
-        self._value = _value
+from pypy.jit.timeshifter.test.support import *
 
 
 def test_create_int_redbox_var():
@@ -130,10 +64,10 @@
     box2 = box.op_getfield(jitstate, desc)
     V1 = box2.genvar
     assert box.known_nonzero
-    assert jitstate.curbuilder.ops == [('getfield', ((STRUCT, 'foo'), V0), V1)]
+    assert jitstate.curbuilder.ops == [('getfield', (('field', STRUCT, 'foo'), V0), V1)]
 
     jitstate.curbuilder.ops = []
     V42 = FakeGenVar(42)
     valuebox = rvalue.IntRedBox("dummy kind", V42)
     box.op_setfield(jitstate, desc, valuebox)
-    assert jitstate.curbuilder.ops == [('setfield', ((STRUCT, 'foo'), V0, V42), None)]
+    assert jitstate.curbuilder.ops == [('setfield', (('field', STRUCT, 'foo'), V0, V42), None)]



More information about the Pypy-commit mailing list