-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.v
84 lines (69 loc) · 2.04 KB
/
example.v
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
78
79
80
81
82
(*
A nice example of λ-Pallene code:
let A:tbl[tbl[int]] = {} : tbl[tbl[int]] in
let B:tbl[int] = (A as tbl[int]) in
A[1] = B; B[2] = 10; A[1][2]
It types and reduces to 10.
*)
Require Import Coq.Logic.Decidable.
Require Import PeanoNat.
Require Import Coq.Strings.String.
Require Import Ascii.
Require Import Bool.
Require Import Nat.
Require Import Coq.Program.Equality.
Require Import LIR.maps.
Require Import LIR.pallene.
Require Import LIR.lir.
(* Variable names *)
Definition A := "A":string.
Definition B := "B":string.
(* Sequence 'operator' e1 ; e2 *)
Definition PESeq (e1 e2 : PE) : PE := PELet ("":string) PTNil e1 e2.
Definition example : PE :=
PELet A (PTArr (PTArr PTInt)) (PENew (PTArr PTInt))
(PELet B (PTArr PTInt)
(PECast (PEVar A) (PTArr PTInt))
(PESeq
(PESet (PEVar A) (PENum 1) (PEVar B))
(PESeq
(PESet (PEVar B) (PENum 2) (PENum 10))
(PEGet (PEGet (PEVar A) (PENum 1)) (PENum 2))))).
(*
** Example is well typed with type int
*)
Goal PtypeOf MEmpty example = Some PTInt.
Proof. trivial. Qed.
(*
** Example evaluates to 10
*)
Lemma run : exists m, PEmptyMem / example -p->* m / (PENum 10).
Proof with eauto 10 using pstep, PValue.
eexists.
unfold example.
eapply PMStMStep.
{ eapply PStLet1. eapply PStNew. unfold PfreshT. simpl. eauto. }
eapply PMStMStep... (* Let *)
eapply PMStMStep.
{ eapply PStLet1. simpl. eapply PStCast; eauto using PValue.
discriminate. simpl. trivial. }
simpl.
eapply PMStMStep... (* Let *)
eapply PMStMStep.
{ eapply PStLet1. simpl. eapply PStSet. auto using PValue. }
simpl.
eapply PMStMStep... (* Let *)
eapply PMStMStep.
{ eapply PStLet1. eapply PStSet. auto using PValue. }
eapply PMStMStep... (* Let *)
eapply PMStMStep... (* Get *)
simpl.
eapply PMStMStep.
{ eapply PStGet1. eapply PStCast; auto using PValue; easy. }
eapply PMStMStep... (* Get *)
simpl.
eapply PMStMStep.
{ eapply PStCast; auto using PValue; easy. }
eauto using Pmultistep.
Unshelve. all: auto using PValue.
Qed.