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

pedronis at codespeak.net pedronis at codespeak.net
Tue Jul 19 23:32:49 CEST 2005


Author: pedronis
Date: Tue Jul 19 23:32:48 2005
New Revision: 14794

Modified:
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
more needed call_args support



Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Tue Jul 19 23:32:48 2005
@@ -299,18 +299,33 @@
         return self.r_im_self.convert_const(method.im_self)
 
     def rtype_simple_call(self, hop):
+        return self.redispatch_call(hop, call_args=False)
+
+    def rtype_call_args(self, hop):
+        return self.redispatch_call(hop, call_args=True)
+
+    def redispatch_call(self, hop, call_args):
         s_function = annmodel.SomePBC({self.function: True})
         hop2 = hop.copy()
         hop2.args_s[0] = self.s_im_self   # make the 1st arg stand for 'im_self'
         hop2.args_r[0] = self.r_im_self   # (same lowleveltype as 'self')
         if isinstance(hop2.args_v[0], Constant):
             hop2.args_v[0] = hop.inputarg(self, 0)
+        if call_args:
+            hop2.swap_fst_snd_args()
+            _, s_shape = hop2.r_s_popfirstarg() # temporarely remove shape
+            adjust_shape(hop2, s_shape)
         c = Constant(self.function)
         hop2.v_s_insertfirstarg(c, s_function)   # insert 'function'
         # now hop2 looks like simple_call(function, self, args...)
         return hop2.dispatch()
 
-
+def adjust_shape(hop2, s_shape):
+    new_shape = (s_shape.const[0]+1,) + s_shape.const[1:]
+    c_shape = Constant(new_shape)
+    s_shape = hop2.rtyper.annotator.bookkeeper.immutablevalue(new_shape)
+    hop2.v_s_insertfirstarg(c_shape, s_shape) # reinsert adjusted shape
+    
 # ____________________________________________________________
 
 
@@ -531,6 +546,12 @@
         return rclass.get_type_repr(self.rtyper).convert_const(cls)
 
     def rtype_simple_call(self, hop):
+        return self.redispatch_call(hop, call_args=False)
+
+    def rtype_call_args(self, hop):
+        return self.redispatch_call(hop, call_args=True)
+
+    def redispatch_call(self, hop, call_args):
         if self.lowleveltype != Void:
             # instantiating a class from multiple possible classes
             vcls = hop.inputarg(self, arg=0)
@@ -556,7 +577,12 @@
             s_init = self.rtyper.annotator.bookkeeper.immutablevalue(initfunc)
             hop2 = hop.copy()
             hop2.r_s_popfirstarg()   # discard the class pointer argument
-            hop2.v_s_insertfirstarg(v_instance, s_instance)  # add 'instance'
+            if call_args:
+                _, s_shape = hop2.r_s_popfirstarg() # temporarely remove shape
+                hop2.v_s_insertfirstarg(v_instance, s_instance)  # add 'instance'
+                adjust_shape(hop2, s_shape)
+            else:
+                hop2.v_s_insertfirstarg(v_instance, s_instance)  # add 'instance'
             c = Constant(initfunc)
             hop2.v_s_insertfirstarg(c, s_init)   # add 'initfunc'
             hop2.s_result = annmodel.SomePBC({None: True})

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Tue Jul 19 23:32:48 2005
@@ -554,6 +554,11 @@
         self.args_s.insert(0, s_newfirstarg)
         self.nb_args += 1
 
+    def swap_fst_snd_args(self):
+        self.args_v[0], self.args_v[1] = self.args_v[1], self.args_v[0]
+        self.args_s[0], self.args_s[1] = self.args_s[1], self.args_s[0]
+        self.args_r[0], self.args_r[1] = self.args_r[1], self.args_r[0]
+
     def has_implicit_exception(self, exc_cls):
         for link in self.exceptionlinks:
             if issubclass(exc_cls, link.exitcase):

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Tue Jul 19 23:32:48 2005
@@ -94,12 +94,24 @@
         return instance.a1
     assert interpret(f, [5]) == 5
 
+def test_class_init_w_kwds():
+    def f(a):
+        instance = MyBaseWithInit(a=a)
+        return instance.a1
+    assert interpret(f, [5]) == 5
+
 def test_class_init_2():
     def f(a, b):
         instance = MySubclassWithInit(a, b)
         return instance.a1 * instance.b1
     assert interpret(f, [6, 7]) == 42
 
+def test_class_init_2_w_kwds():
+    def f(a, b):
+        instance = MySubclassWithInit(a, b=b)
+        return instance.a1 * instance.b1
+    assert interpret(f, [6, 7]) == 42
+
 def test_class_calling_init():
     def f():
         instance = MySubclassWithInit(1, 2)
@@ -142,6 +154,14 @@
     res = interpret(f, [6])
     assert res == 11
 
+def test_call_frozen_pbc_simple_w_kwds():
+    fr1 = Freezing()
+    fr1.x = 5
+    def f(n):
+        return fr1.mymethod(y=n)
+    res = interpret(f, [6])
+    assert res == 11
+
 def test_call_frozen_pbc_multiple():
     fr1 = Freezing()
     fr2 = Freezing()
@@ -158,6 +178,22 @@
     res = interpret(f, [-1])
     assert res == 5
 
+def test_call_frozen_pbc_multiple_w_kwds():
+    fr1 = Freezing()
+    fr2 = Freezing()
+    fr1.x = 5
+    fr2.x = 6
+    def f(n):
+        if n > 0:
+            fr = fr1
+        else:
+            fr = fr2
+        return fr.mymethod(y=n)
+    res = interpret(f, [1])
+    assert res == 6
+    res = interpret(f, [-1])
+    assert res == 5
+
 def test_is_among_frozen():
     fr1 = Freezing()
     fr2 = Freezing()
@@ -310,6 +346,18 @@
     res = interpret(fn, [])
     assert res == 0
 
+def test_rpbc_bound_method_static_call_w_kwds():
+    class R:
+        def meth(self, x):
+            return x
+    r = R()
+    m = r.meth
+    def fn():
+        return m(x=3)
+    res = interpret(fn, [])
+    assert res == 3
+
+
 def test_constant_return_disagreement():
     class R:
         def meth(self):



More information about the Pypy-commit mailing list