[pypy-svn] r60315 - in pypy/branch/oo-jit/pypy/jit/tl: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Dec 4 09:31:03 CET 2008


Author: antocuni
Date: Thu Dec  4 09:31:01 2008
New Revision: 60315

Modified:
   pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py
   pypy/branch/oo-jit/pypy/jit/tl/tlc.py
Log:
implement truth value and equality for objects



Modified: pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py	Thu Dec  4 09:31:01 2008
@@ -157,3 +157,31 @@
         """, pool)
         res = interp_eval(bytecode, 0, nil, pool)
         assert res.int_o() == 42
+
+    def test_obj_truth(self):
+        from pypy.jit.tl.tlc import interp_eval, nil
+        pool = ConstantPool()
+        bytecode = compile("""
+            NEW foo,bar
+            BR_COND true
+            PUSH 12
+            PUSH 1
+            BR_COND exit
+        true:
+            PUSH 42
+        exit:
+            RETURN
+        """, pool)
+        res = interp_eval(bytecode, 0, nil, pool)
+        assert res.int_o() == 42
+
+    def test_obj_equality(self):
+        from pypy.jit.tl.tlc import interp_eval, nil
+        pool = ConstantPool()
+        bytecode = compile("""
+            NEW foo,bar
+            NEW foo,bar
+            EQ
+        """, pool)
+        res = interp_eval(bytecode, 0, nil, pool)
+        assert res.int_o() == 0

Modified: pypy/branch/oo-jit/pypy/jit/tl/tlc.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/tl/tlc.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/tl/tlc.py	Thu Dec  4 09:31:01 2008
@@ -73,6 +73,12 @@
         cls = hint(self.cls, promote=True)
         return hint(cls, deepfreeze=True)
 
+    def t(self):
+        return True
+
+    def eq(self, other):
+        return self is other
+
     def getattr(self, name):
         i = self.getclass().attributes[name]
         return self.values[i]



More information about the Pypy-commit mailing list