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

arigo at codespeak.net arigo at codespeak.net
Sat Apr 11 12:41:08 CEST 2009


Author: arigo
Date: Sat Apr 11 12:41:05 2009
New Revision: 63978

Modified:
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/policy.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
Log:
Handle 'indirect_call' where the policy returns None for
the called graphs.


Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py	Sat Apr 11 12:41:05 2009
@@ -748,10 +748,14 @@
                            if x.concretetype is not lltype.Void])
         self.register_var(op.result)
 
-    def handle_residual_call(self, op):
+    def handle_residual_call(self, op, skip_last=False):
         self.minimize_variables()
+        if skip_last:
+            args = op.args[1:-1]
+        else:
+            args = op.args[1:]
         calldescr, non_void_args = self.codewriter.getcalldescr(op.args[0],
-                                                                op.args[1:],
+                                                                args,
                                                                 op.result)
         self.emit('residual_call')
         self.emit(self.get_position(calldescr))
@@ -918,8 +922,11 @@
         self.register_var(op.result)
 
     def serialize_op_indirect_call(self, op):
-        self.minimize_variables()
         targets = self.codewriter.policy.graphs_from(op)
+        if targets is None:      # this is a residual call
+            self.handle_residual_call(op, skip_last=True)
+            return
+        self.minimize_variables()
         indirectcallset = self.codewriter.get_indirectcallset(targets)
         self.emit('indirect_call')
         self.emit(self.get_position(indirectcallset))

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/policy.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/policy.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/policy.py	Sat Apr 11 12:41:05 2009
@@ -31,9 +31,11 @@
         else:
             assert op.opname == 'indirect_call'
             graphs = op.args[-1].value
-            for graph in graphs:
-                if self.look_inside_graph(graph):
-                    return graphs  # common case: look inside at least 1 graph
+            if graphs is not None:
+                for graph in graphs:
+                    if self.look_inside_graph(graph):
+                        return graphs  # common case: look inside at
+                                       # least one of the graphs
         # residual call case: we don't need to look into any graph
         return None
 

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py	Sat Apr 11 12:41:05 2009
@@ -467,17 +467,35 @@
         assert self.interp_operations(f, [x, x]) == expected
         lltype.free(x, flavor='raw')
 
+    def test_instantiate_classes(self):
+        class Base: pass
+        class A(Base): foo = 72
+        class B(Base): foo = 8
+        def f(n):
+            if n > 5:
+                cls = A
+            else:
+                cls = B
+            return cls().foo
+        res = self.interp_operations(f, [3])
+        assert res == 8
+        res = self.interp_operations(f, [13])
+        assert res == 72
+
+
 class TestOOtype(BasicTests, OOJitMixin):
     def skip(self):
         py.test.skip('in-progress')
 
     test_chr2str = skip
+    test_string = skip
     test_unicode = skip
     test_residual_call = skip
     test_format = skip
     test_getfield = skip
     test_getfield_immutable = skip
     test_oops_on_nongc = skip
+    test_instantiate_classes = skip
 
 
 class TestLLtype(BasicTests, LLJitMixin):



More information about the Pypy-commit mailing list