[pypy-svn] r17784 - pypy/dist/pypy/interpreter/astcompiler

ac at codespeak.net ac at codespeak.net
Fri Sep 23 12:42:40 CEST 2005


Author: ac
Date: Fri Sep 23 12:42:40 2005
New Revision: 17784

Modified:
   pypy/dist/pypy/interpreter/astcompiler/pyassem.py
   pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
Log:
Refactor processing of tuple-arguments.

Modified: pypy/dist/pypy/interpreter/astcompiler/pyassem.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pyassem.py	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/pyassem.py	Fri Sep 23 12:42:40 2005
@@ -442,8 +442,7 @@
         self.name = name
         self.filename = filename
         self.docstring = space.w_None
-        self.args = args # XXX
-        self.argcount = getArgCount(args)
+        self.argcount = len(args)
         self.klass = klass
         self.flags = 0
         if optimized:
@@ -463,21 +462,12 @@
         # kinds of variables.
         self.closure = []
         self.varnames = []
-        for var in args:
+        for i in range(len(args)):
+            var = args[i]
             if isinstance(var, ast.AssName):
-                _name = var.name
-                assert isinstance(_name,str)
-                self.varnames.append( _name )
-            elif isinstance(var, TupleArg):
-                _name = var.getName()
-                assert isinstance(_name,str)
-                self.varnames.append( _name )
+                self.varnames.append(var.name )
             elif isinstance(var, ast.AssTuple):
-                for n in var.flatten():
-                    assert isinstance(n, ast.AssName)
-                    _name = n.name
-                    assert isinstance(_name,str)
-                    self.varnames.append( _name )
+                self.varnames.append('.%d' % (2 * i))
         self.stage = RAW
         self.orderedblocks = []
 
@@ -844,26 +834,6 @@
     if opname[:4] == 'JUMP':
         return 1
 
-class TupleArg(ast.Node):
-    """Helper for marking func defs with nested tuples in arglist"""
-    def __init__(self, count, names):
-        self.count = count
-        self.names = names
-    def __repr__(self):
-        return "TupleArg(%s, %s)" % (self.count, self.names)
-    def getName(self):
-        return ".%d" % self.count
-
-def getArgCount(args):
-    argcount = len(args)
-    if args:
-        for arg in args:
-            if isinstance(arg, TupleArg):
-                numNames = len(arg.names.getArgNames())
-                # numNames = len(misc.flatten(arg.names))
-                argcount = argcount - numNames
-    return argcount
-
 def twobyte(val):
     """Convert an int argument into high and low bytes"""
     assert isinstance(val,int)

Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	Fri Sep 23 12:42:40 2005
@@ -12,7 +12,6 @@
     SC_FREE, SC_CELL, SC_DEFAULT
 from pypy.interpreter.astcompiler.consts import CO_VARARGS, CO_VARKEYWORDS, \
     CO_NEWLOCALS, CO_NESTED, CO_GENERATOR, CO_GENERATOR_ALLOWED, CO_FUTURE_DIVISION
-from pypy.interpreter.astcompiler.pyassem import TupleArg
 from pypy.interpreter.pyparser.error import SyntaxError
 
 # drop VERSION dependency since it the ast transformer for 2.4 doesn't work with 2.3 anyway
@@ -1243,9 +1242,7 @@
         if 'None' in argnames:
             raise SyntaxError('assignment to None is not allowed')
 
-        args, hasTupleArg = generateArgList(func.argnames)
-
-        graph = pyassem.PyFlowGraph(space, name, func.filename, args,
+        graph = pyassem.PyFlowGraph(space, name, func.filename, func.argnames,
                                     optimized=self.localsfullyknown,
                                     newlocals=1)
         self.isLambda = isLambda
@@ -1261,8 +1258,7 @@
         if func.kwargs:
             self.graph.setFlag(CO_VARKEYWORDS)
         self.set_lineno(func)
-        if hasTupleArg:
-            self.generateArgUnpack(func.argnames)
+        self.generateArgUnpack(func.argnames)
 
     def get_module(self):
         return self.module
@@ -1361,23 +1357,6 @@
             self.emitop_obj("LOAD_CONST", klass.doc)
             self.storeName('__doc__')
 
-def generateArgList(arglist):
-    """Generate an arg list marking TupleArgs"""
-    args = []
-    extra = []
-    count = 0
-    for i in range(len(arglist)):
-        elt = arglist[i]
-        if isinstance(elt, ast.AssName):
-            args.append(elt)
-        elif isinstance(elt, ast.AssTuple):
-            args.append(TupleArg(i * 2, elt))
-            extra.extend(elt.getChildNodes())
-            count = count + 1
-        else:
-            raise ValueError( "unexpect argument type:" + str(elt) )
-    return args + extra, count
-
 def findOp(node):
     """Find the op (DELETE, LOAD, STORE) in an AssTuple tree"""
     v = OpFinder()



More information about the Pypy-commit mailing list