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

arigo at codespeak.net arigo at codespeak.net
Sun Jun 26 20:52:57 CEST 2005


Author: arigo
Date: Sun Jun 26 20:52:54 2005
New Revision: 13990

Modified:
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
is_true for SomePBCs that can contain None in their set.


Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Sun Jun 26 20:52:54 2005
@@ -60,10 +60,7 @@
         lst = self.prebuiltinstances.items()
         lst.sort()
         return tuple(lst)
-    
-    def rtype_is_true(self, hop):
-        return Constant(True, Bool)
-    
+
 # ____________________________________________________________
 
 
@@ -184,6 +181,15 @@
                 setattr(result, mangled_name, llvalue)
             return result
 
+    def rtype_is_true(self, hop):
+        if hop.s_result.is_constant():
+            assert hop.s_result.const is True    # custom __nonzero__ on PBCs?
+            return hop.inputconst(Bool, hop.s_result.const)
+        else:
+            # None is a nullptr, which is false; everything else is true.
+            vlist = hop.inputargs(self)
+            return hop.genop('ptr_nonzero', vlist, resulttype=Bool)
+
     def rtype_getattr(self, hop):
         attr = hop.args_s[1].const
         vpbc, vattr = hop.inputargs(self, Void)

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Sun Jun 26 20:52:54 2005
@@ -232,3 +232,24 @@
         return r.meth()
     res = interpret(fn, [])
     assert res == 0
+
+def test_None_is_false():
+    def fn(i):
+        return bool([None, fn][i])
+    res = interpret(fn, [1])
+    assert res is True
+    res = interpret(fn, [0])
+    assert res is False
+
+def INPROGRESS_test_classpbc_getattr():
+    class A:
+        myvalue = 123
+    class B(A):
+        myvalue = 456
+    def f(i):
+        B()      # force B and A to have a ClassDef
+        return [A,B][i].myvalue
+    res = interpret(f, [0], view=True)
+    assert res == 123
+    res = interpret(f, [1])
+    assert res == 456



More information about the Pypy-commit mailing list