[pypy-svn] r22398 - pypy/branch/arre-experiments/pypy/interpreter

ac at codespeak.net ac at codespeak.net
Wed Jan 18 17:24:29 CET 2006


Author: ac
Date: Wed Jan 18 17:24:29 2006
New Revision: 22398

Modified:
   pypy/branch/arre-experiments/pypy/interpreter/argument.py
   pypy/branch/arre-experiments/pypy/interpreter/function.py
   pypy/branch/arre-experiments/pypy/interpreter/nestedscope.py
   pypy/branch/arre-experiments/pypy/interpreter/pyframe.py
   pypy/branch/arre-experiments/pypy/interpreter/pyopcode.py
Log:
Some more tweeking. Possibly a regression performance-wise.



Modified: pypy/branch/arre-experiments/pypy/interpreter/argument.py
==============================================================================
--- pypy/branch/arre-experiments/pypy/interpreter/argument.py	(original)
+++ pypy/branch/arre-experiments/pypy/interpreter/argument.py	Wed Jan 18 17:24:29 2006
@@ -27,8 +27,8 @@
         has_vararg = varargname is not None
         has_kwarg = kwargname is not None
         try:
-            self._match_signature(scope_w, argnames, has_vararg, has_kwarg,
-                                  defaults_w, 0, [])
+            return self._match_signature(scope_w, argnames, has_vararg,
+                                         has_kwarg, defaults_w, 0, None)
         except ArgErr, e:
             raise OperationError(self.space.w_TypeError,
                                  self.space.wrap(e.getmsg(fnname)))
@@ -76,7 +76,7 @@
         if has_kwarg:
             scopelen += 1
         scope_w = [None] * scopelen
-        self._match_signature(scope_w, argnames, has_vararg, has_kwarg, defaults_w, 0, [])
+        self._match_signature(scope_w, argnames, has_vararg, has_kwarg, defaults_w, 0, None)
         return scope_w
     
 class ArgumentsPrepended(AbstractArguments):
@@ -107,13 +107,21 @@
     def _rawshape(self, nextra=0):
         return self.args._rawshape(nextra + 1)
 
-    def _match_signature(self, scope_w, argnames, has_vararg=False, has_kwarg=False, defaults_w=[], blindargs=0, extravarargs=[]):
+    def _match_signature(self, scope_w, argnames, has_vararg=False, has_kwarg=False, defaults_w=[], blindargs=0, extravarargs=None):
+        """Parse args and kwargs according to the signature of a code object,
+        or raise an ArgErr in case of failure.
+        Return the number of arguments filled in.
+        """
         if blindargs < len(argnames):
             scope_w[blindargs] = self.w_firstarg
         else:
-            extravarargs.append(self.w_firstarg)
-        self.args._match_signature(scope_w, argnames, has_vararg, has_kwarg,
-                                   defaults_w, blindargs + 1, extravarargs)
+            if extravarargs is None:
+                extravarargs = [ self.w_firstarg ]
+            else:
+                extravarargs.append(self.w_firstarg)
+        return self.args._match_signature(scope_w, argnames, has_vararg,
+                                          has_kwarg, defaults_w,
+                                          blindargs + 1, extravarargs)
     
     def flatten(self):
         (shape_cnt, shape_keys, shape_star, shape_stst), data_w = self.args.flatten()
@@ -168,7 +176,11 @@
     def _rawshape(self, nextra=0):
         return nextra + self.nargs, (), False, False
 
-    def _match_signature(self, scope_w, argnames, has_vararg=False, has_kwarg=False, defaults_w=[], blindargs=0, extravarargs=[]):
+    def _match_signature(self, scope_w, argnames, has_vararg=False, has_kwarg=False, defaults_w=[], blindargs=0, extravarargs=None):
+        """Parse args and kwargs according to the signature of a code object,
+        or raise an ArgErr in case of failure.
+        Return the number of arguments filled in.
+        """
         co_argcount = len(argnames)
         if blindargs + self.nargs + len(defaults_w) < co_argcount:
             raise ArgErrCount(blindargs + self.nargs , 0,
@@ -185,7 +197,7 @@
                 scope_w[i + blindargs] = self.valuestack.top(self.nargs - 1 - i)
             if has_vararg:
                 if blindargs > co_argcount:
-                    startarg_w = extravararg
+                    startarg_w = extravarargs
                     for i in range(self.nargs):
                         startarg_w.append(self.valuestack.top(self.nargs - 1 - i))
                 else:
@@ -208,7 +220,9 @@
 
         if has_kwarg:
             scope_w[co_argcount] = self.space.newdict([])
-
+            co_argcount += 1
+        return co_argcount
+    
     def flatten(self):
         data_w = [None] * self.nargs
         for i in range(self.nargs):
@@ -343,11 +357,11 @@
 
     def _match_signature(self, scope_w, argnames, has_vararg=False,
                          has_kwarg=False, defaults_w=[], blindargs=0,
-                         extravarargs=[]):
+                         extravarargs=None):
         """Parse args and kwargs according to the signature of a code object,
         or raise an ArgErr in case of failure.
+        Return the number of arguments filled in.
         """
-
         #
         #   args_w = list of the normal actual parameters, wrapped
         #   kwds_w = real dictionary {'keyword': wrapped parameter}
@@ -455,7 +469,8 @@
                               (co_argcount, has_vararg, has_kwarg),
                               defaults_w, missing)
 
-
+        return co_argcount + has_vararg + has_kwarg
+    
     ### Argument <-> list of w_objects together with "shape" information
 
     def _rawshape(self, nextra=0):

Modified: pypy/branch/arre-experiments/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/arre-experiments/pypy/interpreter/function.py	(original)
+++ pypy/branch/arre-experiments/pypy/interpreter/function.py	Wed Jan 18 17:24:29 2006
@@ -33,10 +33,18 @@
         return "<Function %s>" % self.name
 
     def call_args(self, args):
-        scope_w = args.parse(self.name, self.code.signature(), self.defs_w)
         frame = self.code.create_frame(self.space, self.w_func_globals,
                                        self.closure)
-        frame.setfastscope(scope_w)
+        sig = self.code.signature()
+        if (isinstance(frame, PyFrame) and
+            frame.setfastscope is PyFrame.setfastscope):
+            # XXX: Performance hack!
+            args_matched = args.parse_into_scope(frame.fastlocals_w, self.name,
+                                                 sig, self.defs_w)
+            frame.init_cells(args_matched)
+        else:
+            scope_w = args.parse(self.name, sig, self.defs_w)
+            frame.setfastscope(scope_w)
         return frame.run()
 
     def getdict(self):

Modified: pypy/branch/arre-experiments/pypy/interpreter/nestedscope.py
==============================================================================
--- pypy/branch/arre-experiments/pypy/interpreter/nestedscope.py	(original)
+++ pypy/branch/arre-experiments/pypy/interpreter/nestedscope.py	Wed Jan 18 17:24:29 2006
@@ -99,8 +99,7 @@
             else:
                 cell.set(w_value)
 
-    def setfastscope(self, scope_w):
-        PyInterpFrame.setfastscope(self, scope_w)
+    def init_cells(self, num_vars):
         if self.pycode.co_cellvars:
             # the first few cell vars could shadow already-set arguments,
             # in the same order as they appear in co_varnames
@@ -109,10 +108,10 @@
             cellvars = code.co_cellvars
             next     = 0
             nextname = cellvars[0]
-            for i in range(len(scope_w)):
+            for i in range(num_vars):
                 if argvars[i] == nextname:
                     # argument i has the same name as the next cell var
-                    w_value = scope_w[i]
+                    w_value = self.fastlocals_w[i]
                     self.cells[next] = Cell(w_value)
                     next += 1
                     try:

Modified: pypy/branch/arre-experiments/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/arre-experiments/pypy/interpreter/pyframe.py	(original)
+++ pypy/branch/arre-experiments/pypy/interpreter/pyframe.py	Wed Jan 18 17:24:29 2006
@@ -80,7 +80,13 @@
         if len(scope_w) > len(self.fastlocals_w):
             raise ValueError, "new fastscope is longer than the allocated area"
         self.fastlocals_w[:len(scope_w)] = scope_w
-        
+        self.init_cells(len(scope_w))
+
+    def init_cells(self, numvars):
+        """Initialize cellvars from self.fastlocals_w
+        This is overridden in PyNestedScopeFrame"""
+        pass
+    
     def getclosure(self):
         return None
 

Modified: pypy/branch/arre-experiments/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/arre-experiments/pypy/interpreter/pyopcode.py	(original)
+++ pypy/branch/arre-experiments/pypy/interpreter/pyopcode.py	Wed Jan 18 17:24:29 2006
@@ -647,13 +647,14 @@
                 w_key   = f.valuestack.pop()
                 key = f.space.str_w(w_key)
                 keywords[key] = w_value
-        arguments = [f.valuestack.pop() for i in range(n_arguments)]
-        arguments.reverse()
+        arguments = [None] * n_arguments
+        for i in range(n_arguments - 1, -1, -1):
+            arguments[i] = f.valuestack.pop()
         args = Arguments(f.space, arguments, keywords, w_star, w_starstar)
         w_function  = f.valuestack.pop()
         w_result = f.space.call_args(w_function, args)
         f.valuestack.push(w_result)
-
+        
     def CALL_FUNCTION(f, oparg):
         # XXX start of hack for performance
         if oparg == 0:      # 0 arg, 0 keyword arg



More information about the Pypy-commit mailing list