示例#1
0
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 = Arguments(space, args_h(start))
    elif opname == "call_args":
        arguments = Arguments.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)
示例#2
0
 def build_args(self, op, args_s):
     space = RPythonCallsSpace()
     if op == "simple_call":
         return Arguments(space, list(args_s))
     elif op == "call_args":
         return Arguments.fromshape(space, args_s[0].const, # shape
                                    list(args_s[1:]))
示例#3
0
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 = Arguments(space, args_h(start))
    elif opname == "call_args":
        arguments = Arguments.fromshape(space, hop.args_s[start].const, args_h(start + 1))  # shape
    # 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)
示例#4
0
def call_args_expand(hop, takes_kwds = True):
    hop = hop.copy()
    from pypy.interpreter.argument import Arguments
    arguments = Arguments.fromshape(None, hop.args_s[1].const, # shape
                                    range(hop.nb_args-2))
    if arguments.w_starstararg is not None:
        raise TyperError("**kwds call not implemented")
    if arguments.w_stararg is not None:
        # expand the *arg in-place -- it must be a tuple
        from pypy.rpython.rtuple import AbstractTupleRepr
        if arguments.w_stararg != hop.nb_args - 3:
            raise TyperError("call pattern too complex")
        hop.nb_args -= 1
        v_tuple = hop.args_v.pop()
        s_tuple = hop.args_s.pop()
        r_tuple = hop.args_r.pop()
        if not isinstance(r_tuple, AbstractTupleRepr):
            raise TyperError("*arg must be a tuple")
        for i in range(len(r_tuple.items_r)):
            v_item = r_tuple.getitem_internal(hop.llops, v_tuple, i)
            hop.nb_args += 1
            hop.args_v.append(v_item)
            hop.args_s.append(s_tuple.items[i])
            hop.args_r.append(r_tuple.items_r[i])

    kwds = arguments.kwds_w or {}
    if not takes_kwds and kwds:
        raise TyperError("kwds args not supported")
    # prefix keyword arguments with 'i_'
    kwds_i = {}
    for key, index in kwds.items():
        kwds_i['i_'+key] = index

    return hop, kwds_i
示例#5
0
 def build_args(self, op, args_s):
     space = RPythonCallsSpace()
     if op == "simple_call":
         return Arguments(space, list(args_s))
     elif op == "call_args":
         return Arguments.fromshape(space, args_s[0].const, # shape
                                    list(args_s[1:]))
示例#6
0
 def op_call_args(self):
     a = self.argnames
     shape = self.op.args[1].value
     args = Arguments.fromshape(None, shape, a[2:])
     lst = args.arguments_w[:]
     for key, value in args.kwds_w.items():
         lst.append("%s=%s" % (key, value))
     if args.w_stararg is not None:
         lst.append("*%s" % args.w_stararg)
     if args.w_starstararg is not None:
         lst.append("**%s" % args.w_starstararg)
     return "%s = %s(%s)" % (self.resultname, a[0], ", ".join(lst))