Example #1
0
def compile_app(self):
    args = [a.compile() for a in self.args]
    # handle action calls in rhs of assignment
    if expr_context and top_context and self.rep in top_context.actions:
        returns = top_context.actions[self.rep]
        if len(returns) != 1:
            raise IvyError(self, "wrong number of return values")
            # TODO: right now we can't do anything with multiple returns
            sorts = [find_sort(r.sort) for r in returns]
            ress = []
            for sort in sorts:
                res = ivy_logic.Symbol(
                    'loc:' + str(len(expr_context.local_syms)), sort)
                expr_context.local_syms.append(res)
                ress.append(res())
            expr_context.code.append(
                CallAction(*([ivy_ast.Atom(self.rep, args)] + ress)))
            return ivy_ast.Tuple(*ress)
        sort = find_sort(returns[0].sort)
        res = ivy_logic.Symbol('loc:' + str(len(expr_context.local_syms)),
                               sort)
        expr_context.local_syms.append(res)
        expr_context.code.append(CallAction(ivy_ast.Atom(self.rep, args), res))
        return res()
    return (ivy_logic.Equals if self.rep == '=' else
            ivy_logic.find_polymorphic_symbol(self.rep))(*args)
Example #2
0
def compile_app(self):
    args = [a.compile() for a in self.args]
    # handle action calls in rhs of assignment
    if expr_context and top_context and self.rep in top_context.actions:
        params, returns = top_context.actions[self.rep]
        if len(returns) != 1:
            raise IvyError(self, "wrong number of return values")
            # TODO: right now we can't do anything with multiple returns
            sorts = [cmpl_sort(r.sort) for r in returns]
            ress = []
            for sort in sorts:
                res = ivy_logic.Symbol(
                    'loc:' + str(len(expr_context.local_syms)), sort)
                expr_context.local_syms.append(res)
                ress.append(res())
            expr_context.code.append(
                CallAction(*([ivy_ast.Atom(self.rep, args)] + ress)))
            return ivy_ast.Tuple(*ress)
        sort = cmpl_sort(returns[0].sort)
        res = ivy_logic.Symbol('loc:' + str(len(expr_context.local_syms)),
                               sort)
        expr_context.local_syms.append(res)
        with ASTContext(self):
            if len(params) != len(args):
                raise iu.IvyError(
                    self,
                    "wrong number of input parameters (got {}, expecting {})".
                    format(len(args), len(params)))
            args = [
                sort_infer(a, cmpl_sort(p.sort)) for a, p in zip(args, params)
            ]
        expr_context.code.append(CallAction(ivy_ast.Atom(self.rep, args), res))
        return res()
    return (ivy_logic.Equals if self.rep == '=' else
            ivy_logic.find_polymorphic_symbol(self.rep))(*args)
Example #3
0
def compile_call(self):
    assert top_context
    ctx = ExprContext(lineno=self.lineno)
    name = self.args[0].rep
    if name not in top_context.actions:
        raise iu.IvyError(self, "call to unknown action: {}".format(name))
    with ctx:
        args = [a.cmpl() for a in self.args[0].args]
    params, returns = top_context.actions[name]
    if len(returns) != len(self.args) - 1:
        raise iu.IvyError(
            self,
            "wrong number of output parameters (got {}, expecting {})".format(
                len(self.args) - 1, len(returns)))
    if len(params) != len(args):
        raise iu.IvyError(
            self,
            "wrong number of input parameters (got {}, expecting {})".format(
                len(args), len(params)))
    with ASTContext(self):
        mas = [sort_infer(a, cmpl_sort(p.sort)) for a, p in zip(args, params)]


#        print self.args
    res = CallAction(*([ivy_ast.Atom(name, mas)] +
                       [a.cmpl() for a in self.args[1:]]))
    res.lineno = self.lineno
    ctx.code.append(res)
    res = ctx.extract()
    #    print "compiled call action: {}".format(res)
    return res
Example #4
0
def compile_inline_call(self, args):
    params, returns = top_context.actions[self.rep]
    if len(returns) != 1:
        raise IvyError(self, "wrong number of return values")
        # TODO: right now we can't do anything with multiple returns
        sorts = [cmpl_sort(r.sort) for r in returns]
        ress = []
        for sort in sorts:
            res = ivy_logic.Symbol('loc:' + str(len(expr_context.local_syms)),
                                   sort)
            expr_context.local_syms.append(res)
            ress.append(res())
        expr_context.code.append(
            CallAction(*([ivy_ast.Atom(self.rep, args)] + ress)))
        return ivy_ast.Tuple(*ress)
    sort = cmpl_sort(returns[0].sort)
    res = ivy_logic.Symbol('loc:' + str(len(expr_context.local_syms)), sort)
    expr_context.local_syms.append(res)
    with ASTContext(self):
        if len(params) != len(args):
            raise iu.IvyError(
                self,
                "wrong number of input parameters (got {}, expecting {})".
                format(len(args), len(params)))
        args = [
            sort_infer_contravariant(a, cmpl_sort(p.sort))
            for a, p in zip(args, params)
        ]
    expr_context.code.append(CallAction(ivy_ast.Atom(self.rep, args), res))
    return res()
Example #5
0
def compile_call(self):
    ctx = ExprContext(lineno = self.lineno)
    with ctx:
        mas = [a.cmpl() for a in self.args[0].args]
    n = self.args[0].rep
#        print self.args
    res = CallAction(*([ivy_ast.Atom(n,mas)] + [a.cmpl() for a in self.args[1:]]))
    res.lineno = self.lineno
    ctx.code.append(res)
    res = ctx.extract()
#    print "compiled call action: {}".format(res)
    return res
Example #6
0
def compile_call(self):
    ctx = ExprContext(lineno=self.lineno)
    with ctx:
        mas = [a.cmpl() for a in self.args[0].args]
    n = self.args[0].rep
    #        print self.args
    res = CallAction(*([ivy_ast.Atom(n, mas)] +
                       [a.cmpl() for a in self.args[1:]]))
    res.lineno = self.lineno
    ctx.code.append(res)
    res = ctx.extract()
    #    print "compiled call action: {}".format(res)
    return res
Example #7
0
def compile_call(self):
    assert top_context
    ctx = ExprContext(lineno = self.lineno)
    name = self.args[0].rep
    if name not in top_context.actions:
        raise iu.IvyError(self,"call to unknown action: {}".format(name))
    with ctx:
        args = [a.cmpl() for a in self.args[0].args]
    params,returns = top_context.actions[name]
    if len(returns) != len(self.args) - 1:
        raise iu.IvyError(self,"wrong number of output parameters (got {}, expecting {})".format(len(self.args) - 1,len(returns)))
    if len(params) != len(args):
        raise iu.IvyError(self,"wrong number of input parameters (got {}, expecting {})".format(len(args),len(params)))
    with ASTContext(self):
        mas = [sort_infer(a,cmpl_sort(p.sort)) for a,p in zip(args,params)]
#        print self.args
    res = CallAction(*([ivy_ast.Atom(name,mas)] + [a.cmpl() for a in self.args[1:]]))
    res.lineno = self.lineno
    ctx.code.append(res)
    res = ctx.extract()
#    print "compiled call action: {}".format(res)
    return res
Example #8
0
def p_action_call_callatom_assign_callatom(p):
    "action : CALL callatom ASSIGN callatom"
    p[0] = CallAction(p[4], p[2])
    p[0].lineno = get_lineno(p, 1)
Example #9
0
def p_action_call_callatom(p):
    "action : CALL callatom"
    p[0] = CallAction(p[2])
    p[0].lineno = get_lineno(p, 1)
Example #10
0
def p_action_termtuple_assign_fmla(p):
    "action : termtuple ASSIGN callatom"
    p[0] = CallAction(*([p[3]] + list(p[1].args)))
    p[0].lineno = get_lineno(p, 2)
Example #11
0
def p_action_call_callatom_assign_callatom(p):
    'action : CALL callatom ASSIGN callatom'
    p[0] = CallAction(p[4], p[2])
    p[0].lineno = get_lineno(p, 1)
Example #12
0
def p_action_call_callatom(p):
    'action : CALL callatom'
    p[0] = CallAction(p[2])
    p[0].lineno = get_lineno(p, 1)
Example #13
0
def p_action_termtuple_assign_fmla(p):
    'action : termtuple ASSIGN callatom'
    p[0] = CallAction(*([p[3]] + list(p[1].args)))
    p[0].lineno = get_lineno(p, 2)
Example #14
0
def p_action_call_callatom_assign_callatom(p):
    'action : CALL callatom ASSIGN callatom'
    p[0] = CallAction(p[4],p[2])
    p[0].lineno = p.lineno(1)
Example #15
0
def p_action_call_callatom(p):
    'action : CALL callatom'
    p[0] = CallAction(p[2])
    p[0].lineno = p.lineno(1)
Example #16
0
def p_action_termtuple_assign_fmla(p):
    'action : termtuple ASSIGN callatom'
    p[0] = CallAction(*([p[3]]+list(p[1].args)))
    p[0].lineno = p.lineno(2)