def test_copy_and_shape(self): space = DummySpace() args = ArgumentsForTranslation(space, ['a'], ['x'], [1], ['w1'], {'y': 'w2'}) args1 = args.copy() args.combine_if_necessary() assert rawshape(args1) == (1, ('x', ), True, True)
def callparse(rtyper, graph, hop, opname, r_self=None): """Parse the arguments of 'hop' when calling the given 'graph'. """ rinputs = getrinputs(rtyper, graph) space = RPythonCallsSpace() def args_h(start): return [VarHolder(i, hop.args_s[i]) for i in range(start, hop.nb_args)] if r_self is None: start = 1 else: start = 0 rinputs[0] = r_self if opname == "simple_call": arguments = ArgumentsForTranslation(space, args_h(start)) elif opname == "call_args": arguments = ArgumentsForTranslation.fromshape( space, hop.args_s[start].const, # shape args_h(start + 1)) # parse the arguments according to the function we are calling signature = graph.signature defs_h = [] if graph.defaults: for x in graph.defaults: defs_h.append(ConstHolder(x)) try: holders = arguments.match_signature(signature, defs_h) except ArgErr, e: raise TyperError, "signature mismatch: %s" % e.getmsg(graph.name)
def test_prepend(self): space = DummySpace() args = ArgumentsForTranslation(space, ["0"]) args1 = args.prepend("thingy") assert args1 is not args assert args1.arguments_w == ["thingy", "0"] assert args1.keywords is args.keywords assert args1.keywords_w is args.keywords_w
def make_arguments_for_translation(space, args_w, keywords_w={}, w_stararg=None, w_starstararg=None): return ArgumentsForTranslation(space, args_w, keywords_w.keys(), keywords_w.values(), w_stararg, w_starstararg)
def build_args(self, op, args_s): space = RPythonCallsSpace() if op == "simple_call": return ArgumentsForTranslation(space, list(args_s)) elif op == "call_args": return ArgumentsForTranslation.fromshape( space, args_s[0].const, # shape list(args_s[1:]))
def argument_factory(self, *args): return ArgumentsForTranslation(self.space, *args)
def make_arguments(self, nargs): return ArgumentsForTranslation(self.space, self.peekvalues(nargs))
def call_function(self, w_func, *args_w): from pypy.interpreter.argument import ArgumentsForTranslation nargs = len(args_w) args = ArgumentsForTranslation(self, list(args_w)) return self.call_args(w_func, args)