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

arigo at codespeak.net arigo at codespeak.net
Sun Apr 23 12:10:12 CEST 2006


Author: arigo
Date: Sun Apr 23 12:10:11 2006
New Revision: 26175

Modified:
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/rctypes/test/test_rarray.py
   pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py
Log:
Some hacks to allow *arg calls to rtyped built-in functions.
Not very clean.


Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Sun Apr 23 12:10:11 2006
@@ -86,7 +86,27 @@
         from pypy.interpreter.argument import Arguments
         arguments = Arguments.fromshape(None, hop.args_s[1].const, # shape
                                         range(hop.nb_args-2))
-        args_s, kwds = arguments.unpack()
+        if arguments.w_starstararg is not None:
+            raise TyperError("**kwds call not implemented")
+        if arguments.w_stararg is not None:
+            # expand the *arg in-place -- it must be a tuple
+            from pypy.rpython.rtuple import AbstractTupleRepr
+            if arguments.w_stararg != hop.nb_args - 3:
+                raise TyperError("call pattern too complex")
+            hop.nb_args -= 1
+            v_tuple = hop.args_v.pop()
+            s_tuple = hop.args_s.pop()
+            r_tuple = hop.args_r.pop()
+            if not isinstance(r_tuple, AbstractTupleRepr):
+                raise TyperError("*arg must be a tuple")
+            for i in range(len(r_tuple.items_r)):
+                v_item = r_tuple.getitem(hop.llops, v_tuple, i)
+                hop.nb_args += 1
+                hop.args_v.append(v_item)
+                hop.args_s.append(s_tuple.items[i])
+                hop.args_r.append(r_tuple.items_r[i])
+
+        kwds = arguments.kwds_w or {}
         # prefix keyword arguments with 'i_'
         kwds_i = {}
         for key, index in kwds.items():

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rarray.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rarray.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rarray.py	Sun Apr 23 12:10:11 2006
@@ -268,6 +268,18 @@
         assert res.c_data[3] == 0
         assert res.c_data[4] == 0
 
+    def test_specialize_constructor_stararg(self):
+        A = c_int * 5
+        def func(x, y):
+            args = (x, y)
+            return A(*args)
+        res = interpret(func, [123, 456])
+        assert res.c_data[0] == 123
+        assert res.c_data[1] == 456
+        assert res.c_data[2] == 0
+        assert res.c_data[3] == 0
+        assert res.c_data[4] == 0
+
 class Test_compilation:
     def test_compile_array_access(self):
         def access_array():

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py	Sun Apr 23 12:10:11 2006
@@ -225,3 +225,15 @@
         s1 = time.ctime(N)
         s2 = fn(N)
         assert s1.strip() == s2.strip()
+
+    def test_compile_ctime_vararg(self):
+        import time
+        N = 101010101
+        def func(n):
+            args = (byref(c_long(n)),)
+            return ctime(*args)
+
+        fn = compile(func, [int])
+        s1 = time.ctime(N)
+        s2 = fn(N)
+        assert s1.strip() == s2.strip()



More information about the Pypy-commit mailing list