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

arigo at codespeak.net arigo at codespeak.net
Mon Jun 20 13:42:56 CEST 2005


Author: arigo
Date: Mon Jun 20 13:42:53 2005
New Revision: 13613

Modified:
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
   pypy/dist/pypy/rpython/test/test_rlist.py
Log:
- fix SomeBuiltin.rtyper_makekey()
- don't hack the 'hop' object but a copy in
    BuiltinMethodRepr.rtype_simple_call()
- keyword arg 'viewbefore' in interpret() to see the flow graph
    before the typer modifies it -- useful to debug the typer
- support bound methods of prebuilt objects of built-in types
    (list and str for now)


Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Mon Jun 20 13:42:53 2005
@@ -24,10 +24,12 @@
             return BuiltinMethodRepr(rtyper.getrepr(self.s_self),
                                      self.methodname)
     def rtyper_makekey(self):
-        key = (getattr(self, 'const', None), self.methodname)
-        if self.s_self is not None:
-            key += (self.s_self.rtyper_makekey(),)
-        return key
+        if self.s_self is None:
+            # built-in function case
+            return getattr(self, 'const', None)
+        else:
+            # built-in method case
+            return (self.methodname, self.s_self.rtyper_makekey())
 
 
 class BuiltinFunctionRepr(Repr):
@@ -64,9 +66,10 @@
             raise TyperError("missing %s.%s" % (
                 self.self_repr.__class__.__name__, name))
         # hack based on the fact that 'lowleveltype == self_repr.lowleveltype'
-        assert hop.args_r[0] is self
-        hop.args_r[0] = self.self_repr
-        return bltintyper(hop)
+        hop2 = hop.copy()
+        assert hop2.args_r[0] is self
+        hop2.args_r[0] = self.self_repr
+        return bltintyper(hop2)
 
 
 ##class __extend__(pairtype(SomeBuiltin, SomeObject)):

Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Mon Jun 20 13:42:53 2005
@@ -56,6 +56,7 @@
             self.LIST.become(GcStruct("list", ("items", Ptr(ITEMARRAY))))
 
     def convert_const(self, listobj):
+        listobj = getattr(listobj, '__self__', listobj) # for bound list methods
         if not isinstance(listobj, list):
             raise TyperError("expected a list: %r" % (listobj,))
         try:

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Mon Jun 20 13:42:53 2005
@@ -44,6 +44,7 @@
     def convert_const(self, value):
         if value is None:
             return nullptr(STR)
+        value = getattr(value, '__self__', value)  # for bound string methods
         if not isinstance(value, str):
             raise TyperError("not a str: %r" % (value,))
         try:

Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py	Mon Jun 20 13:42:53 2005
@@ -26,10 +26,11 @@
             if func(pyobjectptr(cls)).typeptr == klass:
                 return cls
 
-def gengraph(func, argtypes=[]):
+def gengraph(func, argtypes=[], viewbefore=False):
     t = Translator(func)
     t.annotate(argtypes)
-    #t.view()
+    if viewbefore:
+        t.view()
     global typer # we need it for find_exception
     typer = RPythonTyper(t.annotator)
     typer.specialize()
@@ -37,8 +38,9 @@
     t.checkgraphs()
     return t, typer
 
-def interpret(func, values, view=False):
-    t, typer = gengraph(func, [lltype_to_annotation(typeOf(x)) for x in values])
+def interpret(func, values, view=False, viewbefore=False):
+    t, typer = gengraph(func, [lltype_to_annotation(typeOf(x)) for x in values],
+                        viewbefore)
     if view:
         t.view()
     interp = LLInterpreter(t.flowgraphs, typer)

Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py	Mon Jun 20 13:42:53 2005
@@ -163,3 +163,10 @@
     assert res == 'k'
     res = interpret(dummyfn, [-2])
     assert res == 'z'
+
+def test_bound_list_method():
+    klist = [1,2,3]
+    # for testing constant methods without actually mutating the constant
+    def dummyfn(n):
+        klist.extend([])
+    interpret(dummyfn, [7])



More information about the Pypy-commit mailing list