[880] | 1 | |
---|
| 2 | include "Clight/Csyntax.ma". |
---|
[1515] | 3 | include "utilities/extranat.ma". |
---|
[880] | 4 | |
---|
| 5 | axiom TypeMismatch : String. |
---|
| 6 | |
---|
| 7 | definition sz_eq_dec : ∀s1,s2:intsize. (s1 = s2) + (s1 ≠ s2). |
---|
| 8 | #s1 cases s1; #s2 cases s2; /2/; %2 ; % #H destruct; qed. |
---|
| 9 | definition sg_eq_dec : ∀s1,s2:signedness. (s1 = s2) + (s1 ≠ s2). |
---|
| 10 | #s1 cases s1; #s2 cases s2; /2/; %2 ; % #H destruct; qed. |
---|
| 11 | definition fs_eq_dec : ∀s1,s2:floatsize. (s1 = s2) + (s1 ≠ s2). |
---|
| 12 | #s1 cases s1; #s2 cases s2; /2/; %2 ; % #H destruct; qed. |
---|
| 13 | |
---|
| 14 | let rec type_eq_dec (t1,t2:type) : Sum (t1 = t2) (t1 ≠ t2) ≝ |
---|
[891] | 15 | match t1 return λt'. Sum (t' = t2) (t' ≠ t2) with |
---|
| 16 | [ Tvoid ⇒ match t2 return λt'. Sum (Tvoid = t') (Tvoid ≠ t') with [ Tvoid ⇒ inl ?? (refl ??) | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
| 17 | | Tint sz sg ⇒ match t2 return λt'. Sum (Tint ?? = t') (Tint ?? ≠ t') with [ Tint sz' sg' ⇒ |
---|
[880] | 18 | match sz_eq_dec sz sz' with [ inl e1 ⇒ |
---|
| 19 | match sg_eq_dec sg sg' with [ inl e2 ⇒ inl ??? |
---|
| 20 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 21 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 22 | | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
[891] | 23 | | Tfloat f ⇒ match t2 return λt'. Sum (Tfloat ? = t') (Tfloat ? ≠ t') with [ Tfloat f' ⇒ |
---|
[880] | 24 | match fs_eq_dec f f' with [ inl e1 ⇒ inl ??? |
---|
| 25 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 26 | | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
[891] | 27 | | Tpointer s t ⇒ match t2 return λt'. Sum (Tpointer ?? = t') (Tpointer ?? ≠ t') with [ Tpointer s' t' ⇒ |
---|
[880] | 28 | match eq_region_dec s s' with [ inl e1 ⇒ |
---|
| 29 | match type_eq_dec t t' with [ inl e2 ⇒ inl ??? |
---|
| 30 | | inr e2 ⇒ inr ?? (nmk ? (λH.match e2 with [ nmk e' ⇒ e' ? ])) ] |
---|
| 31 | | inr e1 ⇒ inr ?? (nmk ? (λH.match e1 with [ nmk e' ⇒ e' ? ])) ] | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
[891] | 32 | | Tarray s t n ⇒ match t2 return λt'. Sum (Tarray ??? = t') (Tarray ??? ≠ t') with [ Tarray s' t' n' ⇒ |
---|
[880] | 33 | match eq_region_dec s s' with [ inl e1 ⇒ |
---|
| 34 | match type_eq_dec t t' with [ inl e2 ⇒ |
---|
| 35 | match eq_nat_dec n n' with [ inl e3 ⇒ inl ??? |
---|
| 36 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 37 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 38 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 39 | | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
[891] | 40 | | Tfunction tl t ⇒ match t2 return λt'. Sum (Tfunction ?? = t') (Tfunction ?? ≠ t') with [ Tfunction tl' t' ⇒ |
---|
[880] | 41 | match typelist_eq_dec tl tl' with [ inl e1 ⇒ |
---|
| 42 | match type_eq_dec t t' with [ inl e2 ⇒ inl ??? |
---|
| 43 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 44 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 45 | | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
| 46 | | Tstruct i fl ⇒ |
---|
[891] | 47 | match t2 return λt'. Sum (Tstruct ?? = t') (Tstruct ?? ≠ t') with [ Tstruct i' fl' ⇒ |
---|
[880] | 48 | match ident_eq i i' with [ inl e1 ⇒ |
---|
| 49 | match fieldlist_eq_dec fl fl' with [ inl e2 ⇒ inl ??? |
---|
| 50 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 51 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 52 | | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
| 53 | | Tunion i fl ⇒ |
---|
[891] | 54 | match t2 return λt'. Sum (Tunion ?? = t') (Tunion ?? ≠ t') with [ Tunion i' fl' ⇒ |
---|
[880] | 55 | match ident_eq i i' with [ inl e1 ⇒ |
---|
| 56 | match fieldlist_eq_dec fl fl' with [ inl e2 ⇒ inl ??? |
---|
| 57 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 58 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 59 | | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
[891] | 60 | | Tcomp_ptr r i ⇒ match t2 return λt'. Sum (Tcomp_ptr ? ? = t') (Tcomp_ptr ? ? ≠ t') with [ Tcomp_ptr r' i' ⇒ |
---|
[880] | 61 | match eq_region_dec r r' with [ inl e1 ⇒ |
---|
| 62 | match ident_eq i i' 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 | ] |
---|
[891] | 67 | and typelist_eq_dec (tl1,tl2:typelist) : Sum (tl1 = tl2) (tl1 ≠ tl2) ≝ |
---|
| 68 | match tl1 return λtl'. Sum (tl' = tl2) (tl' ≠ tl2) with |
---|
| 69 | [ Tnil ⇒ match tl2 return λtl'. Sum (Tnil = tl') (Tnil ≠ tl') with [ Tnil ⇒ inl ?? (refl ??) | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
| 70 | | Tcons t1 ts1 ⇒ match tl2 return λtl'. Sum (Tcons ?? = tl') (Tcons ?? ≠ tl') with [ Tnil ⇒ inr ?? (nmk ? (λH.?)) | Tcons t2 ts2 ⇒ |
---|
[880] | 71 | match type_eq_dec t1 t2 with [ inl e1 ⇒ |
---|
| 72 | match typelist_eq_dec ts1 ts2 with [ inl e2 ⇒ inl ??? |
---|
| 73 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 74 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] ] |
---|
| 75 | ] |
---|
[891] | 76 | and fieldlist_eq_dec (fl1,fl2:fieldlist) : Sum (fl1 = fl2) (fl1 ≠ fl2) ≝ |
---|
| 77 | match fl1 return λfl'. Sum (fl' = fl2) (fl' ≠ fl2) with |
---|
| 78 | [ Fnil ⇒ match fl2 return λfl'. Sum (Fnil = fl') (Fnil ≠ fl') with [ Fnil ⇒ inl ?? (refl ??) | _ ⇒ inr ?? (nmk ? (λH.?)) ] |
---|
| 79 | | Fcons i1 t1 fs1 ⇒ match fl2 return λfl'. Sum (Fcons ??? = fl') (Fcons ??? ≠ fl') with [ Fnil ⇒ inr ?? (nmk ? (λH.?)) | Fcons i2 t2 fs2 ⇒ |
---|
[880] | 80 | match ident_eq i1 i2 with [ inl e1 ⇒ |
---|
| 81 | match type_eq_dec t1 t2 with [ inl e2 ⇒ |
---|
| 82 | match fieldlist_eq_dec fs1 fs2 with [ inl e3 ⇒ inl ??? |
---|
| 83 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 84 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] |
---|
| 85 | | inr e ⇒ inr ?? (nmk ? (λH.match e with [ nmk e' ⇒ e' ? ])) ] ] |
---|
[1401] | 86 | ]. try destruct; // |
---|
| 87 | qed. |
---|
[880] | 88 | |
---|
| 89 | definition assert_type_eq : ∀t1,t2:type. res (t1 = t2) ≝ |
---|
| 90 | λt1,t2. match type_eq_dec t1 t2 with [ inl p ⇒ OK ? p | inr _ ⇒ Error ? (msg TypeMismatch)]. |
---|
[1198] | 91 | |
---|
| 92 | definition type_eq : type → type → bool ≝ |
---|
| 93 | λt1,t2. match type_eq_dec t1 t2 with [ inl _ ⇒ true | inr _ ⇒ false ]. |
---|
| 94 | |
---|