[pypy-svn] r59043 - in pypy/dist/pypy/translator/backendopt: . test

arigo at codespeak.net arigo at codespeak.net
Sun Oct 12 19:03:36 CEST 2008


Author: arigo
Date: Sun Oct 12 19:03:35 2008
New Revision: 59043

Modified:
   pypy/dist/pypy/translator/backendopt/mallocv.py
   pypy/dist/pypy/translator/backendopt/test/test_mallocv.py
Log:
Support for ptr_{nonzero,iszero,eq,ne}.


Modified: pypy/dist/pypy/translator/backendopt/mallocv.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/mallocv.py	(original)
+++ pypy/dist/pypy/translator/backendopt/mallocv.py	Sun Oct 12 19:03:35 2008
@@ -767,6 +767,42 @@
         else:
             return self.handle_default(op)
 
+    def handle_op_ptr_nonzero(self, op):
+        node = self.getnode(op.args[0])
+        if isinstance(node, VirtualSpecNode):
+            self.make_const_rt_result(op.result, True)
+            return []
+        else:
+            return self.handle_default(op)
+
+    def handle_op_ptr_iszero(self, op):
+        node = self.getnode(op.args[0])
+        if isinstance(node, VirtualSpecNode):
+            self.make_const_rt_result(op.result, False)
+            return []
+        else:
+            return self.handle_default(op)
+
+    def handle_op_ptr_eq(self, op):
+        node0 = self.getnode(op.args[0])
+        node1 = self.getnode(op.args[1])
+        if (isinstance(node0, VirtualSpecNode) or
+            isinstance(node1, VirtualSpecNode)):
+            self.make_const_rt_result(op.result, node0 is node1)
+            return []
+        else:
+            return self.handle_default(op)
+
+    def handle_op_ptr_ne(self, op):
+        node0 = self.getnode(op.args[0])
+        node1 = self.getnode(op.args[1])
+        if (isinstance(node0, VirtualSpecNode) or
+            isinstance(node1, VirtualSpecNode)):
+            self.make_const_rt_result(op.result, node0 is not node1)
+            return []
+        else:
+            return self.handle_default(op)
+
     def handle_op_malloc(self, op):
         if op.result is self.v_expand_malloc:
             MALLOCTYPE = op.result.concretetype.TO

Modified: pypy/dist/pypy/translator/backendopt/test/test_mallocv.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_mallocv.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_mallocv.py	Sun Oct 12 19:03:35 2008
@@ -8,7 +8,7 @@
 from pypy.objspace.flow.model import checkgraph, flatten, Block, mkentrymap
 from pypy.objspace.flow.model import summary
 from pypy.rpython.llinterp import LLInterpreter, LLException
-from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem import lltype, llmemory, lloperation
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib import objectmodel
 from pypy.rlib.rarithmetic import ovfcheck
@@ -476,7 +476,6 @@
                    expected_mallocs=1)   # no support for interior arrays
 
     def test_wrapper_cannot_be_removed(self):
-        py.test.skip("redo me")
         SMALL = lltype.OpaqueType('SMALL')
         BIG = lltype.GcStruct('BIG', ('z', lltype.Signed), ('s', SMALL))
 
@@ -486,7 +485,9 @@
             b = lltype.malloc(BIG)
             g(b.s)
 
-        self.check(fn, [], [], None, must_be_removed=False)
+        self.check(fn, [], [], None,
+                   expected_mallocs=1,   # no support for interior opaques
+                   expected_calls=1)
 
     def test_direct_fieldptr(self):
         py.test.skip("redo me")
@@ -533,12 +534,80 @@
                 self.check(fn, [], [], 12)
 
     def test_ptr_nonzero(self):
-        py.test.skip("redo me")
         S = lltype.GcStruct('S')
         def fn():
             s = lltype.malloc(S)
-            return bool(s)
-        self.check(fn, [], [], True)
+            return lloperation.llop.ptr_nonzero(lltype.Bool, s)
+        self.check(fn, [], [], True, expected_mallocs=0)
+
+    def test_ptr_iszero(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s = lltype.malloc(S)
+            return lloperation.llop.ptr_iszero(lltype.Bool, s)
+        self.check(fn, [], [], False, expected_mallocs=0)
+
+    def test_ptr_eq_null_left(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s = lltype.malloc(S)
+            null = lltype.nullptr(S)
+            return lloperation.llop.ptr_eq(lltype.Bool, s, null)
+        self.check(fn, [], [], False, expected_mallocs=0)
+
+    def test_ptr_ne_null_left(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s = lltype.malloc(S)
+            null = lltype.nullptr(S)
+            return lloperation.llop.ptr_ne(lltype.Bool, s, null)
+        self.check(fn, [], [], True, expected_mallocs=0)
+
+    def test_ptr_eq_null_right(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s = lltype.malloc(S)
+            null = lltype.nullptr(S)
+            return lloperation.llop.ptr_eq(lltype.Bool, null, s)
+        self.check(fn, [], [], False, expected_mallocs=0)
+
+    def test_ptr_ne_null_right(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s = lltype.malloc(S)
+            null = lltype.nullptr(S)
+            return lloperation.llop.ptr_ne(lltype.Bool, null, s)
+        self.check(fn, [], [], True, expected_mallocs=0)
+
+    def test_ptr_eq_same_struct(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s1 = lltype.malloc(S)
+            return lloperation.llop.ptr_eq(lltype.Bool, s1, s1)
+        self.check(fn, [], [], True, expected_mallocs=0)
+
+    def test_ptr_ne_same_struct(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s1 = lltype.malloc(S)
+            return lloperation.llop.ptr_ne(lltype.Bool, s1, s1)
+        self.check(fn, [], [], False, expected_mallocs=0)
+
+    def test_ptr_eq_diff_struct(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s1 = lltype.malloc(S)
+            s2 = lltype.malloc(S)
+            return lloperation.llop.ptr_eq(lltype.Bool, s1, s2)
+        self.check(fn, [], [], False, expected_mallocs=0)
+
+    def test_ptr_ne_diff_struct(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            s1 = lltype.malloc(S)
+            s2 = lltype.malloc(S)
+            return lloperation.llop.ptr_ne(lltype.Bool, s1, s2)
+        self.check(fn, [], [], True, expected_mallocs=0)
 
     def test_substruct_not_accessed(self):
         py.test.skip("redo me")



More information about the Pypy-commit mailing list