[pypy-svn] r30326 - in pypy/dist/pypy: annotation objspace/cpy objspace/cpy/test

arigo at codespeak.net arigo at codespeak.net
Fri Jul 21 17:24:58 CEST 2006


Author: arigo
Date: Fri Jul 21 17:24:56 2006
New Revision: 30326

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/objspace/cpy/ann_policy.py
   pypy/dist/pypy/objspace/cpy/function.py
   pypy/dist/pypy/objspace/cpy/test/test_function.py
Log:
Test and hackish fix for 'args_w' arguments in the extension compiler.


Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Fri Jul 21 17:24:56 2006
@@ -787,7 +787,12 @@
     """
     w_tuple = SomeTuple
     def newtuple(self, items_s):
-        return SomeTuple(items_s)
+        if items_s == [Ellipsis]:
+            res = SomeObject()   # hack to get a SomeObject as the *arg
+            res.from_ellipsis = True
+            return res
+        else:
+            return SomeTuple(items_s)
 
     def newdict(self, stuff):
         raise CallPatternTooComplex, "'**' argument"
@@ -798,6 +803,9 @@
                 expected_length != len(s_obj.items)):
                 raise ValueError
             return s_obj.items
+        if (s_obj.__class__ is SomeObject and
+            getattr(s_obj, 'from_ellipsis', False)):    # see newtuple()
+            return [Ellipsis]
         raise CallPatternTooComplex, "'*' argument must be SomeTuple"
 
     def is_w(self, one, other):

Modified: pypy/dist/pypy/objspace/cpy/ann_policy.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/ann_policy.py	(original)
+++ pypy/dist/pypy/objspace/cpy/ann_policy.py	Fri Jul 21 17:24:56 2006
@@ -40,3 +40,6 @@
         s_pyerrchecker = bk.immutablevalue(rctypes_pyerrchecker)
         s_result = bk.emulate_pbc_call(uniquekey, s_pyerrchecker, [])
         assert annmodel.s_None.contains(s_result)
+
+    def specialize__all_someobjects(self, funcdesc, args_s):
+        return funcdesc.cachedgraph(None)

Modified: pypy/dist/pypy/objspace/cpy/function.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/function.py	(original)
+++ pypy/dist/pypy/objspace/cpy/function.py	Fri Jul 21 17:24:56 2006
@@ -64,6 +64,7 @@
         tramp.wrappings.append('    %s.append(___W_Object(%s[___i]))' % (
             argname, basename))
         tramp.passedargs.append(argname)
+        tramp.star_arg = True
 
 
 class TrampolineSignature(object):
@@ -73,6 +74,7 @@
         self.wrappings = []
         self.passedargs = []
         self.miniglobals = {}
+        self.star_arg = False
 
 
 def reraise(e):
@@ -139,7 +141,9 @@
         trampoline = miniglobals['trampoline']
         trampoline = func_with_new_name(trampoline, func.name)
         trampoline.nb_args = len(tramp.inputargs)
+        trampoline.star_arg = tramp.star_arg
         trampoline.allow_someobjects = True    # annotator hint
+        trampoline._annspecialcase_ = "specialize:all_someobjects"
         w_result = W_Object(trampoline)
         space.wrap_cache[id(w_result)] = w_result, func, follow_annotations
         return w_result
@@ -150,5 +154,7 @@
     trampoline = w_trampoline.value
     s_trampoline = bookkeeper.immutablevalue(trampoline)
     args_s = [annmodel.SomeObject()] * trampoline.nb_args
+    if trampoline.star_arg:
+        args_s[-1] = Ellipsis   # hack, see bookkeeper.RPythonCallsSpace
     uniquekey = trampoline
     bookkeeper.emulate_pbc_call(uniquekey, s_trampoline, args_s)

Modified: pypy/dist/pypy/objspace/cpy/test/test_function.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/test/test_function.py	(original)
+++ pypy/dist/pypy/objspace/cpy/test/test_function.py	Fri Jul 21 17:24:56 2006
@@ -3,6 +3,8 @@
 from pypy.interpreter.function import BuiltinFunction
 from pypy.interpreter.gateway import interp2app, ObjSpace, W_Root
 from pypy.interpreter.argument import Arguments
+from pypy.objspace.cpy.ann_policy import CPyAnnotatorPolicy
+from pypy.translator.c.test.test_genc import compile
 
 
 def entrypoint1(space, w_x):
@@ -76,3 +78,24 @@
     w_result = space.call_function(w_entrypoint, space.wrap(-2))
     result = space.int_w(w_result)
     assert result == 0
+
+def test_compile_star_args():
+    space = CPyObjSpace()
+    func = interp2app(entrypoint3).__spacebind__(space)
+    bltin = BuiltinFunction(func)
+    w_entrypoint = space.wrap(bltin)
+
+    def entry_point():
+        w_result_1 = space.call_function(w_entrypoint, space.wrap(-200),
+                                                       space.wrap("hello"),
+                                                       space.wrap("world"))
+        w_result_2 = space.call_function(w_entrypoint, space.wrap(-20))
+        return space.int_w(space.add(w_result_1, w_result_2))
+
+    assert entry_point() == -400
+
+    fn = compile(entry_point, [],
+                 annotatorpolicy = CPyAnnotatorPolicy(space))
+
+    res = fn()
+    assert res == -400



More information about the Pypy-commit mailing list