Esempio n. 1
0
 def decompose(self, pre, post, fail=False):
     v = self.get_callee()
     if not isinstance(v, Action):
         return []
     actual_params = self.args[0].args
     actual_returns = self.args[1:]
     vocab = list(symbols_asts(actual_params + actual_returns))
     formals = v.formal_params + v.formal_returns
     premap, pre = hide_state_map(formals, pre)
     postmap, post = hide_state_map(formals, post)
     actual_params = [rename_ast(p, premap) for p in actual_params]
     actual_returns = [rename_ast(p, postmap) for p in actual_returns]
     pre = constrain_state(
         pre,
         And(*
             [Equals(x, y)
              for x, y in zip(actual_params, v.formal_params)]))
     if not fail:
         post = constrain_state(
             post,
             And(*[
                 Equals(x, y)
                 for x, y in zip(actual_returns, v.formal_returns)
             ]))
     ren = dict((x, x.prefix('__hide:')) for x in actual_returns)
     post = (post[0], rename_clauses(post[1], ren), post[2])
     callee = v.clone(v.args)  # drop the formals
     res = [(pre, [callee], post)]
     print "decompose call:"
     print "pre = {}".format(pre)
     print "callee = {}".format(callee)
     print "post = {}".format(post)
     return res
Esempio n. 2
0
 def apply_actuals(self, domain, pvars, v):
     actual_params = self.args[0].args
     actual_returns = self.args[1:]
     #        formal_params = [s.prefix('_') for s in v.formal_params] # rename to prevent capture
     #        formal_returns = [s.prefix('_') for s in v.formal_returns] # rename to prevent capture
     #        subst = dict(zip(v.formal_params+v.formal_returns, formal_params+formal_returns))
     vocab = list(symbols_asts(actual_params + actual_returns))
     subst = distinct_obj_renaming(v.formal_params + v.formal_returns, vocab)
     #        print "apply_actuals: subst: {}".format(subst)
     formal_params = [subst[s] for s in v.formal_params]  # rename to prevent capture
     formal_returns = [subst[s] for s in v.formal_returns]  # rename to prevent capture
     v = substitute_constants_ast(v, subst)
     #        print "formal_params: {}".format(formal_params)
     #        print "formal_returns: {}".format(formal_returns)
     #        print "substituted called action: {}".format(v)
     if len(formal_params) != len(actual_params):
         raise IvyError(self, "wrong number of input parameters")
     if len(formal_returns) != len(actual_returns):
         raise IvyError(self, "wrong number of output parameters")
     for x, y in zip(formal_params, actual_params):
         if x.sort != y.sort:
             raise IvyError(self, "value for input parameter {} has wrong sort".format(x))
     for x, y in zip(formal_returns, actual_returns):
         if x.sort != y.sort:
             raise IvyError(self, "value for output parameter {} has wrong sort".format(x))
     input_asgns = [AssignAction(x, y) for x, y in zip(formal_params, actual_params)]
     output_asgns = [AssignAction(y, x) for x, y in zip(formal_returns, actual_returns)]
     res = Sequence(*(input_asgns + [v] + output_asgns))
     #        print "with parameter assigns: {}".format(res)
     res = res.int_update(domain, pvars)
     #        print "call update: {}".format(res)
     res = hide(formal_params + formal_returns, res)
     #        print "after hide: {}".format(res)
     return res
Esempio n. 3
0
    def apply_actuals(self, domain, pvars, v):
        assert hasattr(v, 'formal_params'), v
        actual_params = self.args[0].args
        actual_returns = self.args[1:]
        #        formal_params = [s.prefix('_') for s in v.formal_params] # rename to prevent capture
        #        formal_returns = [s.prefix('_') for s in v.formal_returns] # rename to prevent capture
        #        subst = dict(zip(v.formal_params+v.formal_returns, formal_params+formal_returns))
        vocab = list(symbols_asts(actual_params + actual_returns))
        subst = distinct_obj_renaming(v.formal_params + v.formal_returns,
                                      vocab)
        for s, t in list(subst.iteritems()):
            subst[old(s)] = old(t)


#        print "apply_actuals: subst: {}".format(subst)
        formal_params = [subst[s]
                         for s in v.formal_params]  # rename to prevent capture
        formal_returns = [subst[s] for s in v.formal_returns
                          ]  # rename to prevent capture
        v = substitute_constants_ast(v, subst)
        #        print "formal_params: {}".format(formal_params)
        #        print "formal_returns: {}".format(formal_returns)
        #        print "substituted called action: {}".format(v)
        if len(formal_params) != len(actual_params):
            raise IvyError(self, "wrong number of input parameters")
        if len(formal_returns) != len(actual_returns):
            raise IvyError(self, "wrong number of output parameters")
        for x, y in zip(formal_params, actual_params):
            if x.sort != y.sort and not domain.is_variant(x.sort, y.sort):
                raise IvyError(
                    self,
                    "value for input parameter {} has wrong sort".format(x))
        for x, y in zip(formal_returns, actual_returns):
            if x.sort != y.sort and not domain.is_variant(y.sort, x.sort):
                raise IvyError(
                    self,
                    "value for output parameter {} has wrong sort".format(x))
        input_asgns = [
            AssignAction(x, y) for x, y in zip(formal_params, actual_params)
        ]
        output_asgns = [
            AssignAction(y, x) for x, y in zip(formal_returns, actual_returns)
        ]
        res = Sequence(*(input_asgns + [BindOldsAction(v)] + output_asgns))
        res = res.int_update(domain, pvars)
        #        print "call update: {}".format(res)
        res = hide(formal_params + formal_returns, res)
        #        print "after hide: {}".format(res)
        return res
Esempio n. 4
0
 def decompose(self, pre, post):
     v = self.get_callee()
     if not isinstance(v, Action):
         return []
     actual_params = self.args[0].args
     actual_returns = self.args[1:]
     vocab = list(symbols_asts(actual_params + actual_returns))
     formals = v.formal_params + v.formal_returns
     premap, pre = hide_state_map(formals, pre)
     postmap, post = hide_state_map(formals, post)
     actual_params = [rename_ast(p, premap) for p in actual_params]
     actual_returns = [rename_ast(p, postmap) for p in actual_returns]
     pre = constrain_state(pre, And(*[Equals(x, y) for x, y in zip(actual_params, v.formal_params)]))
     post = constrain_state(post, And(*[Equals(x, y) for x, y in zip(actual_returns, v.formal_returns)]))
     ren = dict((x, x.prefix("__hide:")) for x in actual_returns)
     post = (post[0], rename_clauses(post[1], ren), post[2])
     callee = v.clone(v.args)  # drop the formals
     return [(pre, [callee], post)]