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

pedronis at codespeak.net pedronis at codespeak.net
Mon Jul 18 16:39:10 CEST 2005


Author: pedronis
Date: Mon Jul 18 16:39:08 2005
New Revision: 14732

Modified:
   pypy/dist/pypy/rpython/rspecialcase.py
   pypy/dist/pypy/rpython/test/test_rspecialcase.py
Log:
override:ignore support for methods too



Modified: pypy/dist/pypy/rpython/rspecialcase.py
==============================================================================
--- pypy/dist/pypy/rpython/rspecialcase.py	(original)
+++ pypy/dist/pypy/rpython/rspecialcase.py	Mon Jul 18 16:39:08 2005
@@ -6,10 +6,10 @@
 
 
 def rtype_call_specialcase(hop):
-    v_function = hop.args_v[0]
-    if not isinstance(v_function, Constant):
-        raise TyperError("call_specialcase on a variable function")
-    func = v_function.value
+    s_function = hop.args_s[0]
+    if len(s_function.prebuiltinstances) != 1:
+        raise TyperError("not monomorphic call_specialcase")
+    func, clsdef = s_function.prebuiltinstances.items()[0]
     tag = func._annspecialcase_
     if not tag.startswith("override:"):
         raise TyperError("call_specialcase only supports 'override:' functions")
@@ -20,11 +20,9 @@
         raise TyperError("call_specialcase: unknown tag override:" + tag)
     hop2 = hop.copy()
     hop2.r_s_popfirstarg()
-    return rtype_override_fn(hop2)
+    return rtype_override_fn(hop2, clsdef)
 
 
-# def rtype_override_XXX to be added later
 
-
-def rtype_override_ignore(hop):
+def rtype_override_ignore(hop, clsdef): # ignore works for methods too
     return inputconst(hop.r_result, None)

Modified: pypy/dist/pypy/rpython/test/test_rspecialcase.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rspecialcase.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rspecialcase.py	Mon Jul 18 16:39:08 2005
@@ -20,3 +20,19 @@
     assert ''.join(res.chars) == "ab"
     
         
+def test_meth_override_ignore():
+    class X:
+        def f(self):
+            pass
+        f._annspecialcase_ = "override:ignore"
+    def g(i):
+        x = X()
+        if i == 1:
+            return "ab"
+        else:
+            return x.f()
+
+    res = interpret(g, [0])
+    assert not res
+    res = interpret(g, [1])
+    assert ''.join(res.chars) == "ab"



More information about the Pypy-commit mailing list