[pypy-svn] r64981 - pypy/branch/pyjitpl5/pypy/jit/backend/test

fijal at codespeak.net fijal at codespeak.net
Sat May 2 20:21:48 CEST 2009


Author: fijal
Date: Sat May  2 20:21:47 2009
New Revision: 64981

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py
   pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
Log:
non-raising calls


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py	Sat May  2 20:21:47 2009
@@ -3,7 +3,8 @@
 from pypy.jit.backend.test import test_random
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 from pypy.jit.metainterp.history import ConstInt, ConstPtr, ConstAddr
-
+from pypy.rpython.annlowlevel import llhelper
+from pypy.rlib.rarithmetic import intmask
 
 class LLtypeOperationBuilder(test_random.OperationBuilder):
 
@@ -151,6 +152,33 @@
         v_ptr = builder.do(self.opnum, args, self.size_descr(builder, S))
         builder.ptrvars.append((v_ptr, S))
 
+class CallOperation(test_random.AbstractOperation):
+    def produce_into(self, builder, r):
+        subset = builder.subset_of_intvars(r)
+        if len(subset) == 0:
+            sum = ""
+            funcargs = ""
+        else:
+            funcargs = ", ".join(['arg_%d' % i for i in range(len(subset))])
+            sum = "intmask(%s)" % " + ".join(['arg_%d' % i for i in range(len(subset))])
+        code = py.code.Source("""
+        def f(%s):
+           return %s
+        """ % (funcargs, sum)).compile()
+        d = {'intmask' : intmask}
+        exec code in d
+
+        if len(subset) == 0:
+            RES = lltype.Void
+        else:
+            RES = lltype.Signed
+        TP = lltype.FuncType([lltype.Signed] * len(subset), RES)
+        ptr = llhelper(lltype.Ptr(TP), d['f'])
+        c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr), builder.cpu)
+        args = [c_addr] + subset
+        descr = builder.cpu.calldescrof(TP, TP.ARGS, TP.RESULT)
+        self.put(builder, args, descr)
+
 # ____________________________________________________________
 
 OPERATIONS = test_random.OPERATIONS[:]
@@ -163,6 +191,7 @@
     OPERATIONS.append(NewOperation(rop.NEW_WITH_VTABLE))
 
     OPERATIONS.append(GuardClassOperation(rop.GUARD_CLASS))
+    OPERATIONS.append(CallOperation(rop.CALL))
 
 LLtypeOperationBuilder.OPERATIONS = OPERATIONS
 

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py	Sat May  2 20:21:47 2009
@@ -47,6 +47,15 @@
             v = self.do(rop.INT_IS_TRUE, [v])
         return v
 
+    def subset_of_intvars(self, r):
+        subset = []
+        k = r.random()
+        num = int(k * len(self.intvars))
+        for i in range(num):
+            subset.append(r.choice(self.intvars))
+        r.shuffle(subset)
+        return subset
+
     def process_operation(self, s, op, names, subops):
         args = []
         for v in op.args:
@@ -152,9 +161,10 @@
         self.boolres = boolres
     def put(self, builder, args, descr=None):
         v_result = builder.do(self.opnum, args, descr=descr)
-        builder.intvars.append(v_result)
-        if self.boolres:
-            builder.boolvars.append(v_result)
+        if v_result is not None:
+            builder.intvars.append(v_result)
+            if self.boolres:
+                builder.boolvars.append(v_result)
 
 class UnaryOperation(AbstractOperation):
     def produce_into(self, builder, r):
@@ -199,12 +209,7 @@
     def produce_into(self, builder, r):
         op, passing = self.gen_guard(builder, r)
         builder.loop.operations.append(op)
-        k = r.random()
-        subset = []
-        num = int(k * len(builder.intvars))
-        for i in range(num):
-            subset.append(r.choice(builder.intvars))
-        r.shuffle(subset)
+        subset = builder.subset_of_intvars(r)        
         op.suboperations = [ResOperation(rop.FAIL, subset, None)]
         if not passing:
             builder.should_fail_by = op.suboperations[0]
@@ -405,12 +410,7 @@
                                                 op.args[:])
         self.generate_ops(bridge_builder, r, subloop, op.args[:])
         if r.random() < 0.1:
-            k = r.random()
-            subset = []
-            num = int(k * len(bridge_builder.intvars))
-            for i in range(num):
-                subset.append(r.choice(bridge_builder.intvars))
-            r.shuffle(subset)
+            subset = bridge_builder.subset_of_intvars(r)
             if len(subset) == 0:
                 return False
             args = [x.clonebox() for x in subset]



More information about the Pypy-commit mailing list