[pypy-commit] pypy kill-flowobjspace: make .flatten() and .match_signature() nondestructive
rlamy
noreply at buildbot.pypy.org
Sat Feb 2 18:21:27 CET 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: kill-flowobjspace
Changeset: r60820:5cce25c6328c
Date: 2013-01-31 05:39 +0000
http://bitbucket.org/pypy/pypy/changeset/5cce25c6328c/
Log: make .flatten() and .match_signature() nondestructive
diff --git a/rpython/annotator/argument.py b/rpython/annotator/argument.py
--- a/rpython/annotator/argument.py
+++ b/rpython/annotator/argument.py
@@ -33,11 +33,11 @@
pass
class ArgumentsForTranslation(object):
+ w_starstararg = None
def __init__(self, space, args_w, keywords=None, keywords_w=None,
w_stararg=None, w_starstararg=None):
self.w_stararg = w_stararg
- self.w_starstararg = w_starstararg
- self.combine_has_happened = False
+ assert w_starstararg is None
self.space = space
assert isinstance(args_w, list)
self.arguments_w = args_w
@@ -54,17 +54,13 @@
return '%s(%s, %s, %s)' % (name, self.arguments_w,
self.keywords, self.keywords_w)
- def _combine_wrapped(self, w_stararg, w_starstararg):
- "unpack the *arg and **kwd into arguments_w and keywords_w"
- if w_stararg is not None:
- self._combine_starargs_wrapped(w_stararg)
- assert w_starstararg is None
-
- def _combine_starargs_wrapped(self, w_stararg):
- # unpack the * arguments
- space = self.space
- args_w = space.unpackiterable(w_stararg)
- self.arguments_w = self.arguments_w + args_w
+ @property
+ def positional_args(self):
+ if self.w_stararg is not None:
+ args_w = self.space.unpackiterable(self.w_stararg)
+ return self.arguments_w + args_w
+ else:
+ return self.arguments_w
def fixedunpack(self, argcount):
"""The simplest argument parsing: get the 'argcount' arguments,
@@ -77,12 +73,6 @@
raise ValueError, "not enough arguments (%d expected)" % argcount
return self.arguments_w
- def combine_if_necessary(self):
- if self.combine_has_happened:
- return
- self._combine_wrapped(self.w_stararg, self.w_starstararg)
- self.combine_has_happened = True
-
def prepend(self, w_firstarg): # used often
"Return a new Arguments with a new argument inserted first."
return ArgumentsForTranslation(self.space, [w_firstarg] + self.arguments_w,
@@ -101,10 +91,9 @@
# args_w = list of the normal actual parameters, wrapped
# scope_w = resulting list of wrapped values
#
- self.combine_if_necessary()
co_argcount = signature.num_argnames() # expected formal arguments, without */**
- args_w = self.arguments_w
+ args_w = self.positional_args
num_args = len(args_w)
keywords = self.keywords or []
num_kwds = len(keywords)
@@ -186,12 +175,11 @@
def unpack(self):
"Return a ([w1,w2...], {'kw':w3...}) pair."
- self.combine_if_necessary()
kwds_w = {}
if self.keywords:
for i in range(len(self.keywords)):
kwds_w[self.keywords[i]] = self.keywords_w[i]
- return self.arguments_w, kwds_w
+ return self.positional_args, kwds_w
def match_signature(self, signature, defaults_w):
@@ -282,7 +270,6 @@
return (shape_cnt, shape_keys, shape_star, shape_stst), data_w
def _rawshape(self, nextra=0):
- assert not self.combine_has_happened
shape_cnt = len(self.arguments_w)+nextra # Number of positional args
if self.keywords:
shape_keys = self.keywords[:] # List of keywords (strings)
diff --git a/rpython/annotator/test/test_argument.py b/rpython/annotator/test/test_argument.py
--- a/rpython/annotator/test/test_argument.py
+++ b/rpython/annotator/test/test_argument.py
@@ -104,16 +104,6 @@
args = make_arguments_for_translation(space, [1,2,3,4,5], {'e': 5, 'd': 7})
assert rawshape(args) == (5, ('d', 'e'), False, False)
- args = make_arguments_for_translation(space, [], {},
- w_stararg=[1],
- w_starstararg={'c': 5, 'd': 7})
- assert rawshape(args) == (0, (), True, True)
-
- args = make_arguments_for_translation(space, [1,2], {'g': 9},
- w_stararg=[3,4,5],
- w_starstararg={'e': 5, 'd': 7})
- assert rawshape(args) == (2, ('g', ), True, True)
-
def test_flatten(self):
space = DummySpace()
@@ -138,16 +128,6 @@
args = make_arguments_for_translation(space, [1,2,3,4,5], {'e': 5, 'd': 7})
assert args.flatten() == ((5, ('d', 'e'), False, False), [1, 2, 3, 4, 5, 7, 5])
- args = make_arguments_for_translation(space, [], {},
- w_stararg=[1],
- w_starstararg={'c': 5, 'd': 7})
- assert args.flatten() == ((0, (), True, True), [[1], {'c': 5, 'd': 7}])
-
- args = make_arguments_for_translation(space, [1,2], {'g': 9},
- w_stararg=[3,4,5],
- w_starstararg={'e': 5, 'd': 7})
- assert args.flatten() == ((2, ('g', ), True, True), [1, 2, 9, [3, 4, 5], {'e': 5, 'd': 7}])
-
def test_stararg_flowspace_variable(self):
space = DummySpace()
var = object()
@@ -189,12 +169,3 @@
shape = ((5, ('d', 'e'), False, False), [1, 2, 3, 4, 5, 7, 5])
args = ArgumentsForTranslation.fromshape(space, *shape)
assert args.flatten() == shape
-
- shape = ((0, (), True, True), [[1], {'c': 5, 'd': 7}])
- args = ArgumentsForTranslation.fromshape(space, *shape)
- assert args.flatten() == shape
-
- shape = ((2, ('g', ), True, True), [1, 2, 9, [3, 4, 5], {'e': 5, 'd': 7}])
- args = ArgumentsForTranslation.fromshape(space, *shape)
- assert args.flatten() == shape
-
diff --git a/rpython/flowspace/argument.py b/rpython/flowspace/argument.py
--- a/rpython/flowspace/argument.py
+++ b/rpython/flowspace/argument.py
@@ -81,7 +81,6 @@
w_starstararg=None):
self.w_stararg = w_stararg
assert w_starstararg is None, "No **-unpacking in RPython"
- self.combine_has_happened = False
self.space = space
assert isinstance(args_w, list)
self.arguments_w = args_w
More information about the pypy-commit
mailing list