[pypy-svn] r7794 - in pypy/trunk/src/pypy: annotation objspace/std

arigo at codespeak.net arigo at codespeak.net
Thu Dec 9 21:50:06 CET 2004


Author: arigo
Date: Thu Dec  9 21:50:05 2004
New Revision: 7794

Modified:
   pypy/trunk/src/pypy/annotation/bookkeeper.py
   pypy/trunk/src/pypy/objspace/std/multimethod.py
   pypy/trunk/src/pypy/objspace/std/stdtypedef.py
Log:
- fixed the specialization of functions taking a *arg based on the
  number of actual arguments provided, which was disabled after the
  recent extension of the Arguments class.

- replaced a regular args with a *args in multimethod.py to trigger
  the above specialization.
  But this kind of rewrite isn't enough e.g. for BuiltinFrame.run()...



Modified: pypy/trunk/src/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/bookkeeper.py	(original)
+++ pypy/trunk/src/pypy/annotation/bookkeeper.py	Thu Dec  9 21:50:05 2004
@@ -8,6 +8,7 @@
 from pypy.annotation.classdef import ClassDef
 from pypy.interpreter.miscutils import getthreadlocals
 from pypy.tool.hack import func_with_new_name
+from pypy.interpreter.pycode import CO_VARARGS
 
 class Bookkeeper:
     """The log of choices that have been made while analysing the operations.
@@ -221,11 +222,18 @@
             else:
                 raise Exception, "unsupported specialization type '%s'"%(x,)
 
-##        elif func.func_code.co_flags & CO_VARARGS:
-##            # calls to *arg functions: create one version per number of args
-##            func = self.specialize_by_key(func, len(args),
-##                                          name='%s__%d' % (func.func_name,
-##                                                           len(args)))
+        elif func.func_code.co_flags & CO_VARARGS:
+            # calls to *arg functions: create one version per number of args
+            assert not args.kwds_w, (
+                "keyword forbidden in calls to *arg functions")
+            nbargs = len(args.arguments_w)
+            if args.w_stararg is not None:
+                s_len = args.w_stararg.len()
+                assert s_len.is_constant(), "calls require known number of args"
+                nbargs += s_len.const
+            func = self.specialize_by_key(func, nbargs,
+                                          name='%s__%d' % (func.func_name,
+                                                           nbargs))
         return self.annotator.recursivecall(func, self.position_key, args)
 
     def specialize_by_key(self, thing, key, name=None):

Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/multimethod.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/multimethod.py	Thu Dec  9 21:50:05 2004
@@ -466,7 +466,7 @@
             raise TypeError, ("multimethod needs at least %d arguments" %
                               self.multimethod.arity)
         try:
-            return self.perform_call(args)
+            return self.perform_call(*args)
         except FailedToImplement, e:
             if e.args:
                 raise OperationError(e.args[0], e.args[1])
@@ -485,7 +485,7 @@
                 w_value = self.space.wrap(message)
                 raise OperationError(self.space.w_TypeError, w_value)
 
-    def perform_call(self, args):
+    def perform_call(self, *args):
         for a in args:
             assert isinstance(a, self.ASSERT_BASE_TYPE), (
                 "'%s' multimethod got a non-wrapped argument: %r" % (

Modified: pypy/trunk/src/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stdtypedef.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stdtypedef.py	Thu Dec  9 21:50:05 2004
@@ -176,7 +176,7 @@
         args = list(self.fastlocals_w)
         args.insert(0, args.pop(self.code.bound_position))
         try:
-            return self.code.mm.perform_call(args)
+            return self.code.mm.perform_call(*args)
         except FailedToImplement, e:
             if e.args:
                 raise OperationError(e.args[0], e.args[1])



More information about the Pypy-commit mailing list