예제 #1
0
def print_module(mod):
    print ivy_logic.sig
    thing = ''
    for kwd, lst in [
        ('axiom', mod.labeled_axioms),
        ('property', mod.labeled_props),
        ('init', mod.labeled_inits),
        ('conjecture', mod.labeled_conjs),
        ('definition', mod.definitions),
    ]:

        thing += labeled_fmlas_to_str(kwd, lst)

    for tn in sorted(mod.sig.interp):
        thing += "interp {} -> {}\n".format(tn, mod.sig.interp[tn])
    print thing

    for name, action in mod.initializers:
        print iu.pretty("after init {" + str(action) + "}")

    for x, y in mod.actions.iteritems():
        print iu.pretty(ia.action_def_to_str(x, y))

    for x in sorted(mod.public_actions):
        print 'export {}'.format(x)
예제 #2
0
def ivy_compile(ag, decls):
    with ag.domain.sig:
        ag.init_cond = true_clauses()
        for name in decls.defined:
            ag.domain.add_to_hierarchy(name)
        with TopContext(collect_actions(decls.decls)):
            IvyDomainSetup(ag.domain)(decls)
            IvyARGSetup(ag)(decls)
        ag.domain.macros = decls.macros
        if not ag.states:
            ac = ag.context
            with ac:
                if ag.predicates:
                    if not ag.init_cond.is_true():
                        raise IvyError(
                            None,
                            "init and state declarations are not compatible")
                    for n, p in ag.predicates.iteritems():
                        s = eval_state_facts(p)
                        if s is not None:
                            s.label = n
                else:
                    ac.new_state(ag.init_cond)
        ag.domain.type_check()
        # try instantiating all the actions to type check them
        for name, action in ag.actions.iteritems():
            #            print "checking: {} = {}".format(name,action)
            type_check_action(action, ag.domain, ag.states[0].in_scope)
            if not hasattr(action, 'lineno'):
                print "no lineno: {}".format(name)
            assert hasattr(action, 'formal_params'), action
        iso = isolate.get()
        if iso:
            isolate_component(ag, iso)
        else:
            # apply all the mixins in no particular order
            for name, mixins in ag.mixins.iteritems():
                for mixin in mixins:
                    action1, action2 = (lookup_action(mixin, ag, a.relname)
                                        for a in mixin.args)
                    mixed = ivy_actions.mixin_before(mixin, action1, action2)
                    ag.actions[mixin.args[1].relname] = mixed
            # find the globally exported actions (all if none specified, for compat)
            if ag.exports:
                ag.public_actions = set()
                for e in ag.exports:
                    if not e.scope():  # global export
                        ag.public_actions.add(e.exported())
            else:
                for a in ag.actions:
                    ag.public_actions.add(a)

            print "actions:"
            for x, y in ag.actions.iteritems():
                print iu.pretty("action {} = {}".format(x, y))

    ivy_logic.sig = ag.domain.sig  # TODO: make this an environment
예제 #3
0
파일: ivy_printer.py 프로젝트: odedp/ivy
def print_module(mod):
    print ivy_logic.sig
    thing = ''
    for kwd,lst in [('axiom',mod.labeled_axioms),
                    ('property',mod.labeled_props),
                    ('init',mod.labeled_inits),
                    ('conjecture',mod.labeled_conjs),
                    ('definition',mod.definitions),]:
        
        thing += labeled_fmlas_to_str(kwd,lst)

    for tn in sorted(mod.sig.interp):
        thing += "interp {} -> {}\n".format(tn,mod.sig.interp[tn])
    print thing

    for name,action in mod.initializers:
        print iu.pretty("after init {" + str(action) + "}")

    for x,y in mod.actions.iteritems():
        print iu.pretty(ia.action_def_to_str(x,y))

    for x in sorted(mod.public_actions):
        print 'export {}'.format(x)
예제 #4
0
def create_isolate(iso,mod = None,**kwargs):

        mod = mod or im.module

        # check all mixin declarations

        for name,mixins in mod.mixins.iteritems():
            for mixin in mixins:
                with ASTContext(mixins):
                    action1,action2 = (lookup_action(mixin,mod,a.relname) for a in mixin.args)

        # check all the delagate declarations

        for dl in mod.delegates:
            lookup_action(dl.args[0],mod,dl.delegated())
            if dl.delegee() and dl.delegee() not in mod.hierarchy:
                raise iu.IvyError(dl.args[1],"{} is not a module instance".format(name))

        # Determine the mixin order (as a side effect on module.mixins)

        get_mixin_order(iso,mod)

        # Construct an isolate

        if iso:
            isolate_component(mod,iso)
        else:
            # apply all the mixins in no particular order
            for name,mixins in mod.mixins.iteritems():
                for mixin in mixins:
                    action1,action2 = (lookup_action(mixin,mod,a.relname) for a in mixin.args)
                    mixed = ia.apply_mixin(mixin,action1,action2)
                    mod.actions[mixin.args[1].relname] = mixed
            # find the globally exported actions (all if none specified, for compat)
            if mod.exports:
                mod.public_actions.clear()
                for e in mod.exports:
                    if not e.scope(): # global export
                        mod.public_actions.add(e.exported())
            else:
                for a in mod.actions:
                    mod.public_actions.add(a)

        # Create one big external action if requested


        ext = kwargs['ext'] if 'ext' in kwargs else ext_action.get()
        if ext is not None:
            ext_acts = [mod.actions[x] for x in sorted(mod.public_actions)]
            ext_act = ia.EnvAction(*ext_acts)
            mod.public_actions.add(ext);
            mod.actions[ext] = ext_act;

        # Check native interpretations of symbols

        slv.check_compat()

        # Make concept spaces from the conjecture

        for i,cax in enumerate(mod.labeled_conjs):
            fmla = cax.formula
            csname = 'conjecture:'+ str(i)
            variables = list(lu.used_variables_ast(fmla))
            sort = ivy_logic.RelationSort([v.sort for v in variables])
            sym = ivy_logic.Symbol(csname,sort)
            space = ics.NamedSpace(ivy_logic.Literal(0,fmla))
            mod.concept_spaces.append((sym(*variables),space))

        # ith.check_theory()

        if show_compiled.get():
            for x,y in mod.actions.iteritems():
                print iu.pretty("action {} = {}".format(x,y))
예제 #5
0
파일: ivy_art.py 프로젝트: asyaf/ivy
def label_from_action(action):
    return iu.pretty(str(action), max_lines=4)
예제 #6
0
파일: ivy_art.py 프로젝트: jamella/ivy
def label_from_action(action):
    if hasattr(action,'label'):
        return action.label
    return iu.pretty(str(action),max_lines=4)
예제 #7
0
파일: ivy_compiler.py 프로젝트: JJTRX/ivy
def ivy_compile(ag,decls):
    ag.actions = {}
    ag.predicates = {}
    ag.assertions = []
    ag.mixins = defaultdict(list)
    ag.domain.clear()
    ag.public_actions = set()
    ag.isolates = {}
    ag.exports = []
    ag.delegates = []
    with ag.domain.sig:
        ag.init_cond = true_clauses()
        for name in decls.defined:
            ag.domain.add_to_hierarchy(name)
        with TopContext(collect_actions(decls.decls)):
            IvyDomainSetup(ag.domain)(decls)
            IvyARGSetup(ag)(decls)
        ag.domain.macros = decls.macros
        if not ag.states:
            ac = ag.context
            with ac:
                if ag.predicates:
                    if not ag.init_cond.is_true():
                        raise IvyError(None,"init and state declarations are not compatible");
                    for n,p in ag.predicates.iteritems():
                        s = eval_state_facts(p)
                        if s is not None:
                            s.label = n
                else:
                    ac.new_state(ag.init_cond)
        ag.domain.type_check()
        # try instantiating all the actions to type check them
        for name,action in ag.actions.iteritems():
#            print "checking: {} = {}".format(name,action)
            type_check_action(action,ag.domain,ag.states[0].in_scope)
            if not hasattr(action,'lineno'):
                print "no lineno: {}".format(name)
        iso = isolate.get()
        if iso:
            isolate_component(ag,iso)
        else:
            # apply all the mixins in no particular order
            for name,mixins in ag.mixins.iteritems():
                for mixin in mixins:
                    action1,action2 = (lookup_action(mixin,ag,a.relname) for a in mixin.args)
                    mixed = ivy_actions.mixin_before(mixin,action1,action2)
                    ag.actions[mixin.args[1].relname] = mixed
            # find the globally exported actions (all if none specified, for compat)
            if ag.exports:
                ag.public_actions = set()
                for e in ag.exports:
                    if not e.scope(): # global export
                        ag.public_actions.add(e.exported())
            else:
                for a in ag.actions:
                    ag.public_actions.add(a)

            print "actions:"
            for x,y in ag.actions.iteritems():
                print iu.pretty("action {} = {}".format(x,y))


    ivy_logic.sig = ag.domain.sig # TODO: make this an environment
예제 #8
0
파일: ivy_compiler.py 프로젝트: JJTRX/ivy
def isolate_component(ag,isolate_name):
    domain = ag.domain
    if isolate_name not in ag.isolates:
        raise IvyError(None,"undefined isolate: {}".format(isolate_name))
    isolate = ag.isolates[isolate_name]
    verified = set(a.relname for a in isolate.verified())
    present = set(a.relname for a in isolate.present())
    present.update(verified)
    delegates = set(s.delegated() for s in ag.delegates)
    for name in present:
        if name not in domain.hierarchy:
            raise IvyError(None,"{} is not a module instance".format(name))
    
    new_actions = {}
    use_mixin = lambda name: startswith_some(name,present)
    mod_mixin = lambda m: m if startswith_some(name,verified) else m.prefix_calls('ext:')
    for actname,action in ag.actions.iteritems():
        ver = startswith_some(actname,verified)
        pre = startswith_some(actname,present)
        if pre: 
            if not ver:
                assert hasattr(action,'lineno')
                ext_action = action.assert_to_assume().prefix_calls('ext:')
                assert hasattr(ext_action,'lineno')
                if actname in delegates:
                    int_action = action.prefix_calls('ext:')
                    assert hasattr(int_action,'lineno')
                else:
                    int_action = ext_action
                    assert hasattr(int_action,'lineno')
            else:
                int_action = ext_action = action
                assert hasattr(int_action,'lineno')
            # internal version of the action has mixins checked
            new_actions[actname] = add_mixins(ag,actname,int_action,False,use_mixin,mod_mixin)
            # external version of the action assumes mixins are ok
            new_action = add_mixins(ag,actname,ext_action,True,use_mixin,mod_mixin)
            new_actions['ext:'+actname] = new_action
            # TODO: external version is public if action public *or* called from opaque
            # public_actions.add('ext:'+actname)
        else:
            # TODO: here must check that summarized action does not
            # have a call dependency on the isolated module
            action = summarize_action(action)
            new_actions[actname] = add_mixins(ag,actname,action,False,use_mixin,mod_mixin)
            new_actions['ext:'+actname] = add_mixins(ag,actname,action,True,use_mixin,mod_mixin)


    # figure out what is exported:
    exported = set()
    for e in ag.exports:
        if not e.scope() and startswith_some(e.exported(),present): # global scope
            exported.add('ext:' + e.exported())
    for actname,action in ag.actions.iteritems():
        if not startswith_some(actname,present):
            for c in action.iter_calls():
                if startswith_some(c,present):
                    exported.add('ext:' + c)
#    print "exported: {}".format(exported)

    ag.public_actions = exported
    ag.actions = new_actions

    ext_act = ia.ChoiceAction(*[ag.actions[x] for x in sorted(exported)])
    exported.add('ext');
    ag.actions['ext'] = ext_act;

    print "actions:"
    for x,y in ag.actions.iteritems():
        print iu.pretty("action {} = {}".format(x,y))
예제 #9
0
def label_from_action(action):
    if hasattr(action, 'label'):
        return action.label
    return iu.pretty(str(action), max_lines=4)
예제 #10
0
파일: ivy_art.py 프로젝트: pbnj-io/ivy
def label_from_action(action):
    return iu.pretty(str(action),max_lines=4)
예제 #11
0
 def construct_transitions_from_expressions(self):
     for state in self.states:
         if hasattr(state,'expr') and is_action_app(state.expr):
             expr = state.expr
             prestate,op,label,poststate = expr.args[0],expr.rep,iu.pretty(str(expr.rep),max_lines=4),state
             self.transitions.append((prestate,op,label,poststate))
예제 #12
0
def isolate_component(ag, isolate_name):
    domain = ag.domain
    if isolate_name not in ag.isolates:
        raise IvyError(None, "undefined isolate: {}".format(isolate_name))
    isolate = ag.isolates[isolate_name]
    verified = set(a.relname for a in isolate.verified())
    present = set(a.relname for a in isolate.present())
    present.update(verified)
    delegates = set(s.delegated() for s in ag.delegates)
    for name in present:
        if name not in domain.hierarchy:
            raise IvyError(None, "{} is not a module instance".format(name))

    new_actions = {}
    use_mixin = lambda name: startswith_some(name, present)
    mod_mixin = lambda m: m if startswith_some(name, verified
                                               ) else m.prefix_calls('ext:')
    for actname, action in ag.actions.iteritems():
        ver = startswith_some(actname, verified)
        pre = startswith_some(actname, present)
        if pre:
            if not ver:
                assert hasattr(action, 'lineno')
                assert hasattr(action, 'formal_params'), action
                ext_action = action.assert_to_assume().prefix_calls('ext:')
                assert hasattr(ext_action, 'lineno')
                assert hasattr(ext_action, 'formal_params'), ext_action
                if actname in delegates:
                    int_action = action.prefix_calls('ext:')
                    assert hasattr(int_action, 'lineno')
                    assert hasattr(int_action, 'formal_params'), int_action
                else:
                    int_action = ext_action
                    assert hasattr(int_action, 'lineno')
                    assert hasattr(int_action, 'formal_params'), int_action
            else:
                int_action = ext_action = action
                assert hasattr(int_action, 'lineno')
                assert hasattr(int_action, 'formal_params'), int_action
            # internal version of the action has mixins checked
            new_actions[actname] = add_mixins(ag, actname, int_action, False,
                                              use_mixin, lambda m: m)
            # external version of the action assumes mixins are ok
            new_action = add_mixins(ag, actname, ext_action, True, use_mixin,
                                    mod_mixin)
            new_actions['ext:' + actname] = new_action
            # TODO: external version is public if action public *or* called from opaque
            # public_actions.add('ext:'+actname)
        else:
            # TODO: here must check that summarized action does not
            # have a call dependency on the isolated module
            action = summarize_action(action)
            new_actions[actname] = add_mixins(ag, actname, action, False,
                                              use_mixin, mod_mixin)
            new_actions['ext:' + actname] = add_mixins(ag, actname, action,
                                                       True, use_mixin,
                                                       mod_mixin)

    # figure out what is exported:
    exported = set()
    for e in ag.exports:
        if not e.scope() and startswith_some(e.exported(),
                                             present):  # global scope
            exported.add('ext:' + e.exported())
    for actname, action in ag.actions.iteritems():
        if not startswith_some(actname, present):
            for c in action.iter_calls():
                if startswith_some(c, present):
                    exported.add('ext:' + c)
#    print "exported: {}".format(exported)

    ext_act = ia.ChoiceAction(*[new_actions[x] for x in sorted(exported)])
    exported.add('ext')
    new_actions['ext'] = ext_act

    ag.public_actions.clear()
    ag.public_actions.update(exported)
    ag.actions.clear()
    ag.actions.update(new_actions)

    print "actions:"
    for x, y in ag.actions.iteritems():
        print iu.pretty("action {} = {}".format(x, y))
예제 #13
0
파일: ivy_isolate.py 프로젝트: xornand/ivy
def create_isolate(iso,mod = None,**kwargs):

        mod = mod or im.module

        # check all mixin declarations

        for name,mixins in mod.mixins.iteritems():
            for mixin in mixins:
                with ASTContext(mixins):
                    action1,action2 = (lookup_action(mixin,mod,a.relname) for a in mixin.args)

        # check all the delagate declarations

        for dl in mod.delegates:
            lookup_action(dl.args[0],mod,dl.delegated())
            if dl.delegee() and dl.delegee() not in mod.hierarchy:
                raise iu.IvyError(dl.args[1],"{} is not a module instance".format(name))

        # Determine the mixin order (as a side effect on module.mixins)

        get_mixin_order(iso,mod)

        # Construct an isolate

        if iso:
            isolate_component(mod,iso)
        else:
            if mod.isolates:
                raise iu.IvyError(None,'no isolate specified on command line')
            # apply all the mixins in no particular order
            for name,mixins in mod.mixins.iteritems():
                for mixin in mixins:
                    action1,action2 = (lookup_action(mixin,mod,a.relname) for a in mixin.args)
                    mixed = ia.apply_mixin(mixin,action1,action2)
                    mod.actions[mixin.args[1].relname] = mixed
            # find the globally exported actions (all if none specified, for compat)
            if mod.exports:
                mod.public_actions.clear()
                for e in mod.exports:
                    if not e.scope(): # global export
                        mod.public_actions.add(e.exported())
            else:
                for a in mod.actions:
                    mod.public_actions.add(a)

        # Create one big external action if requested


        ext = kwargs['ext'] if 'ext' in kwargs else ext_action.get()
        if ext is not None:
            ext_acts = [mod.actions[x] for x in sorted(mod.public_actions)]
            ext_act = ia.EnvAction(*ext_acts)
            mod.public_actions.add(ext);
            mod.actions[ext] = ext_act;

        # Check native interpretations of symbols

        slv.check_compat()

        # Make concept spaces from the conjecture

        for i,cax in enumerate(mod.labeled_conjs):
            fmla = cax.formula
            csname = 'conjecture:'+ str(i)
            variables = list(lu.used_variables_ast(fmla))
            sort = ivy_logic.RelationSort([v.sort for v in variables])
            sym = ivy_logic.Symbol(csname,sort)
            space = ics.NamedSpace(ivy_logic.Literal(0,fmla))
            mod.concept_spaces.append((sym(*variables),space))

        ith.check_theory()

        if show_compiled.get():
            for x,y in mod.actions.iteritems():
                print iu.pretty("action {} = {}".format(x,y))
예제 #14
0
 def label_from_action(self, action):
     if hasattr(action, 'label'):
         return action.label + '\n'
     lineno = str(action.lineno) if hasattr(action, 'lineno') else ''
     return lineno + iu.pretty(str(action), max_lines=4)