summaryrefslogtreecommitdiff
path: root/Test/irondafny0/xrefine1.dfy
blob: 4b085e6ba3130b72945bd244dcab1c8a8b7a24b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// RUN: %dafny /ironDafny /compile:3 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

abstract module ProtocolSpec {
    type ProtoT

    predicate Init(p:ProtoT)
}

abstract module HostSpec {
    type HostT
    import P as ProtocolSpec

    function method foo(h:HostT) : P.ProtoT
}

module ProtocolImpl exclusively refines ProtocolSpec {
    type ProtoT = bool    

    predicate Init(p:ProtoT) { !p }

    method orange(i:nat) returns (j:nat)
    {
        j := i + 1;
    }
}

module HostImpl exclusively refines HostSpec {
    import P = ProtocolImpl

    type HostT = int

    function method foo(h:HostT) : P.ProtoT
    {
        h > 0
    }

    method apple(i:nat) returns (j:nat)
    {
        j := i + 1;
    }
}

abstract module MainSpec {
    import HI as HostSpec
    import PI as ProtocolSpec

    method Test(h1:HI.HostT, h2:HI.HostT) 
        requires HI.foo(h1) == HI.foo(h2);
        requires PI.Init(HI.foo(h1))
}

module MainImpl exclusively refines MainSpec {
    import HI = HostImpl
    import PI = ProtocolImpl
    
    method Test(h1:HI.HostT, h2:HI.HostT) 
    {
        var a := HI.foo(h1);
        print "HI.foo(h1) => ", a, "\n";
        var b := HI.foo(h2);
        print "HI.foo(h2) => ", b, "\n";
        var i := PI.orange(1);
        print "PI.orange(1) => ", i, "\n";
        var j := HI.apple(2);
        print "PI.apple(2) => ", j, "\n";
    }

    method Main()
    {
        Test(-1, 1);
    }
}