Ejemplo n.º 1
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
Ejemplo n.º 2
0
    def int_update(self,domain,pvars):
        update = self.args[-1].int_update(domain,pvars)
#        syms = used_symbols_asts(self.args[0:-1])
        syms = self.args[0:-1]
#        print "hiding locals : {}".format(syms)
        res =  hide(syms,update)
#        print "local res: {}".format(res)
        return res
Ejemplo n.º 3
0
 def int_update(self, domain, pvars):
     update = self.args[-1].int_update(domain, pvars)
     #        syms = used_symbols_asts(self.args[0:-1])
     syms = self.args[0:-1]
     #        print "hiding locals : {}".format(syms)
     res = hide(syms, update)
     #        print "local res: {}".format(res)
     return res
Ejemplo n.º 4
0
 def hide_formals(self,update):
     to_hide = []
     if hasattr(self,'formal_params'):
         to_hide += self.formal_params
     if hasattr(self,'formal_returns'):
         to_hide += self.formal_returns
     if to_hide:
          update = hide(to_hide,update)
     return update
Ejemplo n.º 5
0
 def hide_formals(self, update):
     to_hide = []
     if hasattr(self, "formal_params"):
         to_hide += self.formal_params
     if hasattr(self, "formal_returns"):
         to_hide += self.formal_returns
     if to_hide:
         update = hide(to_hide, update)
     return update
Ejemplo n.º 6
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