[pypy-svn] r28889 - in pypy/dist/pypy/rpython: lltypesystem ootypesystem test

ac at codespeak.net ac at codespeak.net
Fri Jun 16 17:05:40 CEST 2006


Author: ac
Date: Fri Jun 16 17:05:40 2006
New Revision: 28889

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rclass.py
   pypy/dist/pypy/rpython/ootypesystem/rclass.py
   pypy/dist/pypy/rpython/test/test_rclass.py
Log:
(pedronis, arre) Support type() on constants. => Raising a prebuilt
exception works.



Modified: pypy/dist/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rclass.py	Fri Jun 16 17:05:40 2006
@@ -520,6 +520,8 @@
         return vptr
 
     def rtype_type(self, hop):
+	if hop.s_result.is_constant():
+            return hop.inputconst(hop.r_result, hop.s_result.const)
         instance_repr = self.common_repr()
         vinst, = hop.inputargs(instance_repr)
         if hop.args_s[0].can_be_none():

Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py	Fri Jun 16 17:05:40 2006
@@ -402,6 +402,8 @@
         return ootype.oostring(instance, self.ll_const(-1))
 
     def rtype_type(self, hop):
+	if hop.s_result.is_constant():
+            return hop.inputconst(hop.r_result, hop.s_result.const)
         vinst, = hop.inputargs(self)
         if hop.args_s[0].can_be_none():
             return hop.gendirectcall(ll_inst_type, vinst)

Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py	Fri Jun 16 17:05:40 2006
@@ -382,6 +382,17 @@
         res = self.interpret(f, [0])
         assert res is False
 
+    def test_type_of_constant(self):
+        class A:
+            pass
+        a = A()
+
+        def f():
+            return type(a) is A
+        
+        res = self.interpret(f, [])
+        
+        
     def test_void_fnptr(self):
         def g():
             return 42



More information about the Pypy-commit mailing list