source: src/Clight/TypeComparison.ma @ 2468

Last change on this file since 2468 was 2468, checked in by garnier, 7 years ago

Floats are gone from the front-end. Some trace amount might remain in RTL/RTLabs, but this should be easily fixable.
Also, work-in-progress in Clight/memoryInjections.ma

File size: 6.4 KB
Line 
1
2include "Clight/Csyntax.ma".
3include "utilities/extranat.ma".
4
5axiom TypeMismatch : String.
6
7definition sz_eq_dec : ∀s1,s2:intsize. (s1 = s2) + (s1 ≠ s2).
8#s1 cases s1; #s2 cases s2; /2/; %2 ; % #H destruct; qed.
9definition sg_eq_dec : ∀s1,s2:signedness. (s1 = s2) + (s1 ≠ s2).
10#s1 cases s1; #s2 cases s2; /2/; %2 ; % #H destruct; qed.
11
12let rec type_eq_dec (t1,t2:type) : Sum (t1 = t2) (t1 ≠ t2) ≝
13match t1 return λt'. Sum (t' = t2) (t' ≠ t2) with
14[ Tvoid ⇒ match t2 return λt'. Sum (Tvoid = t') (Tvoid ≠ t') with [ Tvoid ⇒ inl ?? (refl ??) | _ ⇒ inr ?? (nmk ? (λH.?)) ]
15| Tint sz sg ⇒ match t2 return λt'. Sum (Tint ?? = t') (Tint ?? ≠ t')  with [ Tint sz' sg' ⇒
16    match sz_eq_dec sz sz' with [ inl e1 ⇒
17    match sg_eq_dec sg sg' with [ inl e2 ⇒ inl ???
18    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
19    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
20    | _ ⇒ inr ?? (nmk ? (λH.?)) ]
21| Tpointer t ⇒ match t2 return λt'. Sum (Tpointer ? = t') (Tpointer ? ≠ t')  with [ Tpointer t' ⇒
22      match type_eq_dec t t' with [ inl e2 ⇒ inl ???
23      | inr e2 ⇒ inr ?? (nmk ? (λH.match e2 with [ nmk e' ⇒ e' ? ])) ]
24    | _ ⇒ inr ?? (nmk ? (λH.?)) ]
25| Tarray t n ⇒ match t2 return λt'. Sum (Tarray ?? = t') (Tarray ?? ≠ t')  with [ Tarray t' n' ⇒
26      match type_eq_dec t t' with [ inl e2 ⇒
27        match eq_nat_dec n n' with [ inl e3 ⇒ inl ???
28        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
29        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
30        | _ ⇒ inr ?? (nmk ? (λH.?)) ]
31(*
32| Tpointer s t ⇒ match t2 return λt'. Sum (Tpointer ?? = t') (Tpointer ?? ≠ t')  with [ Tpointer s' t' ⇒
33    match eq_region_dec s s' with [ inl e1 ⇒
34      match type_eq_dec t t' with [ inl e2 ⇒ inl ???
35      | inr e2 ⇒ inr ?? (nmk ? (λH.match e2 with [ nmk e' ⇒ e' ? ])) ]
36    | inr e1 ⇒ inr ?? (nmk ? (λH.match e1 with [ nmk e' ⇒ e' ? ])) ] | _ ⇒ inr ?? (nmk ? (λH.?)) ]
37| Tarray s t n ⇒ match t2 return λt'. Sum (Tarray ??? = t') (Tarray ??? ≠ t')  with [ Tarray s' t' n' ⇒
38    match eq_region_dec s s' with [ inl e1 ⇒
39      match type_eq_dec t t' with [ inl e2 ⇒
40        match eq_nat_dec n n' with [ inl e3 ⇒ inl ???
41        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
42        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
43        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
44        | _ ⇒ inr ?? (nmk ? (λH.?)) ]
45*)
46| Tfunction tl t ⇒ match t2 return λt'. Sum (Tfunction ?? = t') (Tfunction ?? ≠ t')  with [ Tfunction tl' t' ⇒
47    match typelist_eq_dec tl tl' with [ inl e1 ⇒
48    match type_eq_dec t t' with [ inl e2 ⇒ inl ???
49    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
50    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
51  | _ ⇒ inr ?? (nmk ? (λH.?)) ]
52| Tstruct i fl ⇒
53    match t2 return λt'. Sum (Tstruct ?? = t') (Tstruct ?? ≠ t')  with [ Tstruct i' fl' ⇒
54    match ident_eq i i' with [ inl e1 ⇒
55    match fieldlist_eq_dec fl fl' with [ inl e2 ⇒ inl ???
56    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
57    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
58    | _ ⇒ inr ?? (nmk ? (λH.?)) ]
59| Tunion i fl ⇒
60    match t2 return λt'. Sum (Tunion ?? = t') (Tunion ?? ≠ t')  with [ Tunion i' fl' ⇒
61    match ident_eq i i' with [ inl e1 ⇒
62    match fieldlist_eq_dec fl fl' with [ inl e2 ⇒ inl ???
63    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
64    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
65    |  _ ⇒ inr ?? (nmk ? (λH.?)) ]
66| Tcomp_ptr i ⇒ match t2 return λt'. Sum (Tcomp_ptr ? = t') (Tcomp_ptr ? ≠ t')  with [ Tcomp_ptr i' ⇒
67      match ident_eq i i' with [ inl e2 ⇒ inl ???
68      | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
69    | _ ⇒ inr ?? (nmk ? (λH.?)) ]
70(*
71| Tcomp_ptr r i ⇒ match t2 return λt'. Sum (Tcomp_ptr ? ? = t') (Tcomp_ptr ? ? ≠ t')  with [ Tcomp_ptr r' i' ⇒
72    match eq_region_dec r r' with [ inl e1 ⇒
73      match ident_eq i i' with [ inl e2 ⇒ inl ???
74      | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
75    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
76    | _ ⇒ inr ?? (nmk ? (λH.?)) ]
77*)
78]
79and typelist_eq_dec (tl1,tl2:typelist) : Sum (tl1 = tl2) (tl1 ≠ tl2) ≝
80match tl1 return λtl'. Sum (tl' = tl2) (tl' ≠ tl2) with
81[ Tnil ⇒ match tl2 return λtl'. Sum (Tnil = tl') (Tnil ≠ tl') with [ Tnil ⇒ inl ?? (refl ??) | _ ⇒ inr ?? (nmk ? (λH.?)) ]
82| Tcons t1 ts1 ⇒ match tl2 return λtl'. Sum (Tcons ?? = tl') (Tcons ?? ≠ tl') with [ Tnil ⇒ inr ?? (nmk ? (λH.?)) | Tcons t2 ts2 ⇒
83    match type_eq_dec t1 t2 with [ inl e1 ⇒
84    match typelist_eq_dec ts1 ts2 with [ inl e2 ⇒ inl ???
85    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
86    | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] ]
87]
88and fieldlist_eq_dec (fl1,fl2:fieldlist) : Sum (fl1 = fl2) (fl1 ≠ fl2) ≝
89match fl1 return λfl'. Sum (fl' = fl2) (fl' ≠ fl2) with
90[ Fnil ⇒ match fl2 return λfl'. Sum (Fnil = fl') (Fnil ≠ fl') with [ Fnil ⇒ inl ?? (refl ??) | _ ⇒ inr ?? (nmk ? (λH.?)) ]
91| Fcons i1 t1 fs1 ⇒ match fl2 return λfl'. Sum (Fcons ??? = fl') (Fcons ??? ≠ fl') with [ Fnil ⇒ inr ?? (nmk ? (λH.?)) | Fcons i2 t2 fs2 ⇒
92    match ident_eq i1 i2 with [ inl e1 ⇒
93      match type_eq_dec t1 t2 with [ inl e2 ⇒
94        match fieldlist_eq_dec fs1 fs2 with [ inl e3 ⇒ inl ???
95        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
96        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ]
97        | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] ]
98]. try destruct; //
99qed.
100
101definition assert_type_eq : ∀t1,t2:type. res (t1 = t2) ≝
102λt1,t2. match type_eq_dec t1 t2 with [ inl p ⇒ OK ? p | inr _ ⇒ Error ? (msg TypeMismatch)].
103
104definition type_eq : type → type → bool ≝
105λt1,t2. match type_eq_dec t1 t2 with [ inl _ ⇒ true | inr _ ⇒ false ].
106
107
108definition if_type_eq : ∀t1,t2:type. ∀P:type → type → Type[0]. P t1 t1 → P t1 t2 → P t1 t2 ≝
109λt1,t2,P. match type_eq_dec t1 t2 return λ_. P t1 t1 → P t1 t2 → P t1 t2 with [ inl E ⇒ λx,d. x⌈P t1 t1 ↦ P t1 t2⌉ | inr _ ⇒ λx,d. d ].
110// qed.
Note: See TracBrowser for help on using the repository browser.