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

ale at codespeak.net ale at codespeak.net
Sat Jun 25 20:32:24 CEST 2005


Author: ale
Date: Sat Jun 25 20:32:23 2005
New Revision: 13903

Modified:
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
Log:
Done is_true for PBC's

Fixed a bug in MultipleFrozenPBCRepr thanks to Armin

Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Sat Jun 25 20:32:23 2005
@@ -60,8 +60,10 @@
         lst = self.prebuiltinstances.items()
         lst.sort()
         return tuple(lst)
-
-
+    
+    def rtype_is_true(self,hop):
+        return Constant(True,Bool)
+    
 # ____________________________________________________________
 
 
@@ -100,7 +102,9 @@
 
 # __ None ____________________________________________________
 class NoneFrozenPBCRepr(SingleFrozenPBCRepr):
-    pass
+    
+    def rtype_is_true(self,hop):
+        return Constant(False,Bool)
 
 none_frozen_pbc_repr = NoneFrozenPBCRepr()
 
@@ -161,8 +165,10 @@
     def convert_const(self, pbc):
         if pbc is None:
             return nullptr(self.pbc_type)
-        if pbc not in self.access_set.objects:
-            raise TyperError("not found in PBC set: %r" % (pbc,))
+        if isinstance(pbc, types.MethodType) and pbc.im_self is None:
+            value = pbc.im_func   # unbound method -> bare function
+##        if pbc not in self.access_set.objects:
+##            raise TyperError("not found in PBC set: %r" % (pbc,))
         try:
             return self.pbc_cache[pbc]
         except KeyError:

Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py	Sat Jun 25 20:32:23 2005
@@ -63,15 +63,22 @@
             rv = 1000 * float(i-10) 
             ry = 100 * float(i-10) +0.1
             assert math.fmod(rv,ry) == ev_fun(rv,ry)        
-##import time
-##def test_time_time():            
-##    def f(neg):
-##        if neg:
-##            return time.time()
-##        else:
-##            return time.clock()
-##    ev_fn = make_interpreter(f,[True])
-##    assert isinstance(ev_fn(True),float)
-##    assert isinstance(ev_fn(False),float)
-    
+
+def test_pbc_isTrue():
+    class C:
+        def f(self):
+            pass
+        
+    def g(obj):
+        return bool(obj)
+    def fn(neg):    
+        c = C.f
+        return g(c)
+    ev_fun = make_interpreter(fn, [True])
+    assert ev_fun(True)
+    def fn(neg):    
+        c = None
+        return g(c)
+    ev_fun = make_interpreter(fn, [True])
+    assert not ev_fun(True)
     
\ No newline at end of file



More information about the Pypy-commit mailing list