Author: Ronan Lamy <ronan.l...@gmail.com> Branch: kill-flowobjspace Changeset: r60572:4affc42b8dba Date: 2013-01-27 22:56 +0000 http://bitbucket.org/pypy/pypy/changeset/4affc42b8dba/
Log: Store CallSpec kwargs in a dict diff --git a/rpython/flowspace/argument.py b/rpython/flowspace/argument.py --- a/rpython/flowspace/argument.py +++ b/rpython/flowspace/argument.py @@ -378,21 +378,18 @@ """Represents the arguments passed into a function call, i.e. the `a, b, *c, **d` part in `return func(a, b, *c, **d)`. """ - def __init__(self, space, args_w, keywords=None, keywords_w=None, - w_stararg=None, w_starstararg=None): + def __init__(self, space, args_w, keywords=None, w_stararg=None, + 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 - self.keywords = keywords or [] - self.keywords_w = keywords_w or [] - self.keyword_names_w = None + self.keywords = keywords or {} def copy(self): - return CallSpec(self.space, self.arguments_w, - self.keywords, self.keywords_w, self.w_stararg) + return self def unpack(self): "Return a ([w1,w2...], {'kw':w3...}) pair." @@ -401,23 +398,21 @@ args_w = self.arguments_w + stargs_w else: args_w = self.arguments_w - kwds_w = dict(zip(self.keywords, self.keywords_w)) - return args_w, kwds_w + return args_w, self.keywords def combine_if_necessary(self): raise NotImplementedError - 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) - shape_keys.sort() - else: - shape_keys = [] + def flatten(self): + """ Argument <-> list of w_objects together with "shape" information """ + shape_cnt = len(self.arguments_w) # Number of positional args + shape_keys = tuple(sorted(self.keywords)) shape_star = self.w_stararg is not None # Flag: presence of *arg shape_stst = False # Flag: presence of **kwds - return shape_cnt, tuple(shape_keys), shape_star, shape_stst # shape_keys are sorted + data_w = self.arguments_w + [self.keywords[key] for key in shape_keys] + if shape_star: + data_w.append(self.w_stararg) + return (shape_cnt, shape_keys, shape_star, shape_stst), data_w # diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py --- a/rpython/flowspace/flowcontext.py +++ b/rpython/flowspace/flowcontext.py @@ -975,24 +975,14 @@ raise FlowingError(self, "Dict-unpacking is not RPython") n_arguments = oparg & 0xff n_keywords = (oparg>>8) & 0xff - if n_keywords: - keywords = [None] * n_keywords - keywords_w = [None] * n_keywords - while True: - n_keywords -= 1 - if n_keywords < 0: - break - w_value = self.popvalue() - w_key = self.popvalue() - key = self.space.str_w(w_key) - keywords[n_keywords] = key - keywords_w[n_keywords] = w_value - else: - keywords = None - keywords_w = None + keywords = {} + for _ in range(n_keywords): + w_value = self.popvalue() + w_key = self.popvalue() + key = self.space.str_w(w_key) + keywords[key] = w_value arguments = self.popvalues(n_arguments) - args = CallSpec(self.space, arguments, keywords, - keywords_w, w_star, w_starstar) + args = CallSpec(self.space, arguments, keywords, w_star, w_starstar) w_function = self.popvalue() w_result = self.space.call_args(w_function, args) self.pushvalue(w_result) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit