[pypy-svn] r16149 - in pypy/dist/pypy/rpython: . memory/test

pedronis at codespeak.net pedronis at codespeak.net
Thu Aug 18 18:29:00 CEST 2005


Author: pedronis
Date: Thu Aug 18 18:28:58 2005
New Revision: 16149

Modified:
   pypy/dist/pypy/rpython/memory/test/test_address.py
   pypy/dist/pypy/rpython/raddress.py
Log:
rtyping of is_true for addresses



Modified: pypy/dist/pypy/rpython/memory/test/test_address.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_address.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_address.py	Thu Aug 18 18:28:58 2005
@@ -157,6 +157,21 @@
         rtyper = RPythonTyper(a)
         rtyper.specialize() #does not raise
 
+    def test_addr_as_bool(self):
+        def f(addr1, addr2):
+            if addr1:
+                return 1
+            else:
+                if not addr2:
+                    return 0
+                else:
+                    return -1
+        a = RPythonAnnotator()
+        #does not raise:
+        s = a.build_types(f, [annmodel.SomeAddress(), annmodel.SomeAddress()])
+        rtyper = RPythonTyper(a)
+        rtyper.specialize() #does not raise
+
     def test_address_arithmetic(self):
         def f(offset, char):
             addr = raw_malloc(10000)

Modified: pypy/dist/pypy/rpython/raddress.py
==============================================================================
--- pypy/dist/pypy/rpython/raddress.py	(original)
+++ pypy/dist/pypy/rpython/raddress.py	Thu Aug 18 18:28:58 2005
@@ -30,6 +30,12 @@
         v_access = hop.inputarg(address_repr, 0)
         return v_access
 
+    def rtype_is_true(self, hop):
+        v_addr, = hop.inputargs(address_repr)
+        c_null = hop.inputconst(address_repr, NULL)
+        return hop.genop('adr_ne', [v_addr, c_null],
+                         resulttype=lltype.Bool)
+
 
 address_repr = AddressRepr()
 



More information about the Pypy-commit mailing list