[pypy-svn] r68284 - in pypy/branch/improve-kwd-args/pypy: annotation interpreter objspace/flow rpython

pedronis at codespeak.net pedronis at codespeak.net
Fri Oct 9 17:52:30 CEST 2009


Author: pedronis
Date: Fri Oct  9 17:52:29 2009
New Revision: 68284

Modified:
   pypy/branch/improve-kwd-args/pypy/annotation/bookkeeper.py
   pypy/branch/improve-kwd-args/pypy/interpreter/argument.py
   pypy/branch/improve-kwd-args/pypy/interpreter/pyframe.py
   pypy/branch/improve-kwd-args/pypy/interpreter/pyopcode.py
   pypy/branch/improve-kwd-args/pypy/objspace/flow/flowcontext.py
   pypy/branch/improve-kwd-args/pypy/rpython/callparse.py
Log:
(pedronis, cfbolz): make a subclass of Arguments, ArgumentsForTranslation,
which is used only in the translation toolchain (flow space, annotator, rtyper
to be precise).


Modified: pypy/branch/improve-kwd-args/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/annotation/bookkeeper.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/annotation/bookkeeper.py	Fri Oct  9 17:52:29 2009
@@ -16,7 +16,7 @@
 from pypy.annotation.dictdef import DictDef
 from pypy.annotation import description
 from pypy.annotation.signature import annotationoftype
-from pypy.interpreter.argument import Arguments
+from pypy.interpreter.argument import ArgumentsForTranslation
 from pypy.rlib.objectmodel import r_dict, Symbolic
 from pypy.tool.algo.unionfind import UnionFind
 from pypy.rpython.lltypesystem import lltype, llmemory
@@ -695,10 +695,11 @@
     def build_args(self, op, args_s):
         space = RPythonCallsSpace()
         if op == "simple_call":
-            return Arguments(space, list(args_s))
+            return ArgumentsForTranslation(space, list(args_s))
         elif op == "call_args":
-            return Arguments.fromshape(space, args_s[0].const, # shape
-                                       list(args_s[1:]))
+            return ArgumentsForTranslation.fromshape(
+                    space, args_s[0].const, # shape
+                    list(args_s[1:]))
 
     def ondegenerated(self, what, s_value, where=None, called_from_graph=None):
         self.annotator.ondegenerated(what, s_value, where=where,

Modified: pypy/branch/improve-kwd-args/pypy/interpreter/argument.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/interpreter/argument.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/interpreter/argument.py	Fri Oct  9 17:52:29 2009
@@ -24,6 +24,12 @@
         self.w_stararg = w_stararg
         self.w_starstararg = w_starstararg
 
+    @staticmethod
+    def factory(space, args_w, kwds_w=None,
+                w_stararg=None, w_starstararg=None):
+        return Argument(space, args_w, kwds_w,
+                        w_stararg, w_starstararg)
+
     def num_args(self): # only used in module/__builtin__/interp_classobj.py
         self._unpack()
         return len(self.arguments_w)
@@ -33,20 +39,22 @@
         return len(self.kwds_w)
         
     def __repr__(self):
+        """ NOT_RPYTHON """
         if self.w_starstararg is not None:
-            return 'Arguments(%s, %s, %s, %s)' % (self.arguments_w,
-                                                  self.kwds_w,
-                                                  self.w_stararg,
-                                                  self.w_starstararg)
+            return '%s(%s, %s, %s, %s)' % (self.__class__,
+                                           self.arguments_w,
+                                           self.kwds_w,
+                                           self.w_stararg,
+                                           self.w_starstararg)
         if self.w_stararg is None:
             if not self.kwds_w:
-                return 'Arguments(%s)' % (self.arguments_w,)
+                return '%s(%s)' % (self.__class__, self.arguments_w,)
             else:
-                return 'Arguments(%s, %s)' % (self.arguments_w, self.kwds_w)
+                return '%s(%s, %s)' % (self.__class__, self.arguments_w,
+                                       self.kwds_w)
         else:
-            return 'Arguments(%s, %s, %s)' % (self.arguments_w,
-                                              self.kwds_w,
-                                              self.w_stararg)
+            return '%s(%s, %s, %s)' % (self.__class__, self.arguments_w,
+                                       self.kwds_w, self.w_stararg)
 
 
     ###  Manipulation  ###
@@ -58,8 +66,8 @@
 
     def prepend(self, w_firstarg): # used often
         "Return a new Arguments with a new argument inserted first."
-        return Arguments(self.space, [w_firstarg] + self.arguments_w,
-                         self.kwds_w, self.w_stararg, self.w_starstararg)
+        return self.factory(self.space, [w_firstarg] + self.arguments_w,
+                            self.kwds_w, self.w_stararg, self.w_starstararg)
             
     def _unpack(self):
         "unpack the *arg and **kwd into w_arguments and kwds_w"
@@ -336,7 +344,7 @@
         # ./interpreter/baseobjspace.py
         """Convenience static method to build an Arguments
            from a wrapped sequence and a wrapped dictionary."""
-        return Arguments(space, [], w_stararg=w_args, w_starstararg=w_kwds)
+        return self.factory(space, [], w_stararg=w_args, w_starstararg=w_kwds)
     frompacked = staticmethod(frompacked)
 
     def topacked(self):
@@ -351,11 +359,7 @@
         return w_args, w_kwds
 
     def fromshape(space, (shape_cnt,shape_keys,shape_star,shape_stst), data_w):
-        # used by
-        # geninterped code
-        # ./rpython/callparse.py
-        # ./rpython/rbuiltin.py
-        # ./annotation/bookkeeper.py
+        # used by geninterped code
         args_w = data_w[:shape_cnt]
         p = shape_cnt
         kwds_w = {}
@@ -385,7 +389,13 @@
         args_w, kwds_w = self.unpack()
         return Arguments(self.space, args_w, kwds_w)
 
-    # ------------- used only by the translation toolchain -------------------
+
+class ArgumentsForTranslation(Arguments):
+    @staticmethod
+    def factory(space, args_w, kwds_w=None,
+                w_stararg=None, w_starstararg=None):
+        return ArgumentsForTranslation(space, args_w, kwds_w,
+                                       w_stararg, w_starstararg)
 
     def match_signature(self, signature, defaults_w):
         """Parse args and kwargs according to the signature of a code object,
@@ -438,7 +448,31 @@
         for key in need_kwds:
             kwds_w[key] = unfiltered_kwds_w[key]
                     
-        return Arguments(self.space, args_w, kwds_w)
+        return ArgumentsForTranslation(self.space, args_w, kwds_w)
+
+    def fromshape(space, (shape_cnt,shape_keys,shape_star,shape_stst), data_w):
+        # used by
+        # ./rpython/callparse.py
+        # ./rpython/rbuiltin.py
+        # ./annotation/bookkeeper.py
+        args_w = data_w[:shape_cnt]
+        p = shape_cnt
+        kwds_w = {}
+        for i in range(len(shape_keys)):
+            kwds_w[shape_keys[i]] = data_w[p]
+            p += 1
+        if shape_star:
+            w_star = data_w[p]
+            p += 1
+        else:
+            w_star = None
+        if shape_stst:
+            w_starstar = data_w[p]
+            p += 1
+        else:
+            w_starstar = None
+        return ArgumentsForTranslation(space, args_w, kwds_w, w_star, w_starstar)
+    fromshape = staticmethod(fromshape)
 
     def flatten(self):
         # used by ./objspace/flow/objspace.py

Modified: pypy/branch/improve-kwd-args/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/interpreter/pyframe.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/interpreter/pyframe.py	Fri Oct  9 17:52:29 2009
@@ -282,6 +282,9 @@
     def make_arguments(self, nargs):
         return Arguments(self.space, self.peekvalues(nargs))
 
+    def argument_factory(self, arguments, keywords, w_star, w_starstar):
+        return Arguments(self.space, arguments, keywords, w_star, w_starstar)
+
     @jit.dont_look_inside
     def descr__reduce__(self, space):
         from pypy.interpreter.mixedmodule import MixedModule

Modified: pypy/branch/improve-kwd-args/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/interpreter/pyopcode.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/interpreter/pyopcode.py	Fri Oct  9 17:52:29 2009
@@ -900,7 +900,7 @@
         if n_keywords:
             keywords = f.popstrdictvalues(n_keywords)
         arguments = f.popvalues(n_arguments)
-        args = Arguments(f.space, arguments, keywords, w_star, w_starstar)
+        args = f.argument_factory(arguments, keywords, w_star, w_starstar)
         w_function  = f.popvalue()
         if we_are_jitted():
             w_result = f.space.call_args(w_function, args)

Modified: pypy/branch/improve-kwd-args/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/objspace/flow/flowcontext.py	Fri Oct  9 17:52:29 2009
@@ -2,6 +2,7 @@
 from pypy.interpreter.executioncontext import ExecutionContext
 from pypy.interpreter.error import OperationError
 from pypy.interpreter import pyframe
+from pypy.interpreter.argument import ArgumentsForTranslation
 from pypy.objspace.flow.model import *
 from pypy.objspace.flow.framestate import FrameState
 
@@ -219,8 +220,8 @@
         # create an empty frame suitable for the code object
         # while ignoring any operation like the creation of the locals dict
         self.recorder = []
-        frame = pyframe.PyFrame(self.space, self.code,
-                                self.w_globals, self.closure)
+        frame = FlowSpaceFrame(self.space, self.code,
+                               self.w_globals, self.closure)
         frame.last_instr = 0
         return frame
 
@@ -392,3 +393,9 @@
             if isinstance(w_v, Constant):
                 if w_v.value is oldvalue:
                     stack_items_w[i] = w_new
+
+class FlowSpaceFrame(pyframe.PyFrame):
+    def make_arguments(self, nargs):
+        return ArgumentsForTranslation(self.space, self.peekvalues(nargs))
+    def argument_factory(self, arguments, keywords, w_star, w_starstar):
+        return ArgumentsForTranslation(self.space, arguments, keywords, w_star, w_starstar)

Modified: pypy/branch/improve-kwd-args/pypy/rpython/callparse.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/rpython/callparse.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/rpython/callparse.py	Fri Oct  9 17:52:29 2009
@@ -1,4 +1,4 @@
-from pypy.interpreter.argument import Arguments, ArgErr
+from pypy.interpreter.argument import ArgumentsForTranslation, ArgErr
 from pypy.annotation import model as annmodel
 from pypy.rpython import rtuple
 from pypy.rpython.error import TyperError
@@ -40,9 +40,9 @@
         start = 0
         rinputs[0] = r_self
     if opname == "simple_call":
-        arguments =  Arguments(space, args_h(start))
+        arguments =  ArgumentsForTranslation(space, args_h(start))
     elif opname == "call_args":
-        arguments = Arguments.fromshape(space,
+        arguments = ArgumentsForTranslation.fromshape(space,
                 hop.args_s[start].const, # shape
                 args_h(start+1))
     # parse the arguments according to the function we are calling



More information about the Pypy-commit mailing list