diff options
author | Rutger Broekhoff | 2025-07-07 21:52:08 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2025-07-07 21:52:08 +0200 |
commit | ba61dfd69504ec6263a9dee9931d93adeb6f3142 (patch) | |
tree | d6c9b78e50eeab24e0c1c09ab45909a6ae3fd5db /theories/nix/tests.v | |
download | verified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.tar.gz verified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.zip |
Initialize repository
Diffstat (limited to 'theories/nix/tests.v')
-rw-r--r-- | theories/nix/tests.v | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/theories/nix/tests.v b/theories/nix/tests.v new file mode 100644 index 0000000..cbce874 --- /dev/null +++ b/theories/nix/tests.v | |||
@@ -0,0 +1,185 @@ | |||
1 | From mininix Require Export nix.interp nix.notations. | ||
2 | From stdpp Require Import options. | ||
3 | Open Scope Z_scope. | ||
4 | |||
5 | (** Compare base vals without comparing the proofs. Since we do not have | ||
6 | definitional proof irrelevance, comparing the proofs would fail (and in practice | ||
7 | make Coq loop). *) | ||
8 | Definition res_eq (rv : res val) (bl2 : base_lit) := | ||
9 | match rv with | ||
10 | | Res (Some (VLit bl1 _)) => bl1 = bl2 | ||
11 | | _ => False | ||
12 | end. | ||
13 | Infix "=?" := res_eq. | ||
14 | |||
15 | Definition float_1 := | ||
16 | ceil: (Float.of_Z 20 /: 3). | ||
17 | Goal interp 100 ∅ float_1 =? 7. | ||
18 | Proof. by vm_compute. Qed. | ||
19 | |||
20 | Definition float_2 := | ||
21 | Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *: | ||
22 | Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *: | ||
23 | Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *: | ||
24 | Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000 *: | ||
25 | Float.of_Z 100000000000000000000000000000000000000000000000000000000000000000000000000000. | ||
26 | Goal interp 100 ∅ float_2 =? NFloat (Binary.B754_infinity false). | ||
27 | Proof. by vm_compute. Qed. | ||
28 | |||
29 | Definition float_3 := float_2 /: float_2. | ||
30 | Goal interp 100 ∅ float_3 =? NFloat (`Float.indef_nan). | ||
31 | Proof. by vm_compute. Qed. | ||
32 | |||
33 | Definition let_let := | ||
34 | let: "x" := 1 in let: "x" := 2 in "x". | ||
35 | Goal interp 100 ∅ let_let =? 2. | ||
36 | Proof. by vm_compute. Qed. | ||
37 | |||
38 | Definition with_let := | ||
39 | with: EAttr {[ "x" := AttrN 1 ]} in let: "x" := 2 in "x". | ||
40 | Goal interp 100 ∅ with_let =? 2. | ||
41 | Proof. by vm_compute. Qed. | ||
42 | |||
43 | Definition let_with := | ||
44 | let: "x" := 1 in with: EAttr {[ "x" := AttrN 2 ]} in "x". | ||
45 | Goal interp 100 ∅ let_with =? 1. | ||
46 | Proof. by vm_compute. Qed. | ||
47 | |||
48 | Definition with_with := | ||
49 | with: EAttr {[ "x" := AttrN 1 ]} in with: EAttr {[ "x" := AttrN 2 ]} in "x". | ||
50 | Goal interp 100 ∅ with_with =? 2. | ||
51 | Proof. by vm_compute. Qed. | ||
52 | |||
53 | Definition with_with_inherit := | ||
54 | with: EAttr {[ "x" := AttrN 1 ]} in with: EAttr {[ "x" := AttrN "x" ]} in "x". | ||
55 | Goal interp 100 ∅ with_with_inherit =? 1. | ||
56 | Proof. by vm_compute. Qed. | ||
57 | |||
58 | Definition with_loop := | ||
59 | with: EAttr {[ "x" := AttrR "x" ]} in "x". | ||
60 | Goal interp 100 ∅ with_loop = NoFuel. | ||
61 | Proof. by vm_compute. Qed. | ||
62 | |||
63 | Definition rec_attr_shadow_1 := | ||
64 | let: "foo" := EAttr {[ "bar" := AttrN 10 ]} in | ||
65 | EAttr {[ | ||
66 | "bar" := AttrR ("foo" .: "bar"); | ||
67 | "foo" := AttrR (EAttr {[ "bar" := AttrN 20 ]}) | ||
68 | ]} .: "bar". | ||
69 | Goal interp 100 ∅ rec_attr_shadow_1 =? 20. | ||
70 | Proof. by vm_compute. Qed. | ||
71 | |||
72 | Definition rec_attr_shadow_2 := | ||
73 | EAttr {[ | ||
74 | "y" := AttrR (EAttr {[ "y" := AttrN "z" ]} .: "y"); | ||
75 | "z" := AttrR 20 | ||
76 | ]} .: "y". | ||
77 | Goal interp 100 ∅ rec_attr_shadow_2 =? 20. | ||
78 | Proof. by vm_compute. Qed. | ||
79 | |||
80 | Definition nested_functor_1 := | ||
81 | EAttr {[ "__functor" := AttrN $ λ: "self", | ||
82 | EAttr {[ "__functor" := AttrN $ λ: "self" "x", 10 ]} ]} 10. | ||
83 | Goal interp 100 ∅ nested_functor_1 =? 10. | ||
84 | Proof. by vm_compute. Qed. | ||
85 | |||
86 | Definition nested_functor_2 := | ||
87 | EAttr {[ "__functor" := AttrN $ | ||
88 | EAttr {[ "__functor" := AttrN $ λ: "self" "self" "x", 10 ]} ]} 10. | ||
89 | Goal interp 100 ∅ nested_functor_2 =? 10. | ||
90 | Proof. by vm_compute. Qed. | ||
91 | |||
92 | Definition functor_loop_1 := | ||
93 | EAttr {[ "__functor" := AttrN $ | ||
94 | λ: "self", "self" "self" | ||
95 | ]} 10. | ||
96 | Goal interp 1000 ∅ functor_loop_1 = NoFuel. | ||
97 | Proof. by vm_compute. Qed. | ||
98 | |||
99 | Definition functor_loop_2 := | ||
100 | EAttr {[ "__functor" := AttrN $ | ||
101 | λ: "self" "f", "f" ("self" "f") | ||
102 | ]} (λ: "go" "x", "go" "x") 10. | ||
103 | Goal interp 1000 ∅ functor_loop_2 = NoFuel. | ||
104 | Proof. by vm_compute. Qed. | ||
105 | |||
106 | Fixpoint many_lets (i : nat) (e : expr) : expr := | ||
107 | match i with | ||
108 | | O => e | ||
109 | | S i => let: "x" +:+ pretty i := 0 in many_lets i e | ||
110 | end. | ||
111 | |||
112 | Fixpoint many_adds (i : nat) : expr := | ||
113 | match i with | ||
114 | | O => 0 | ||
115 | | S i => ("x" +:+ pretty i) +: many_adds i | ||
116 | end. | ||
117 | |||
118 | Definition big_prog (i : nat) : expr := many_lets i $ many_adds i. | ||
119 | |||
120 | Definition big := big_prog 1000. | ||
121 | |||
122 | Goal interp 5000 ∅ big =? 0. | ||
123 | Proof. by vm_compute. Qed. | ||
124 | |||
125 | Definition matching_1 := | ||
126 | (λattr: {[ "x" := None; "y" := None ]}, "x" +: "y") | ||
127 | (EAttr {[ "x" := AttrN 10; "y" := AttrN 11 ]}). | ||
128 | Goal interp 1000 ∅ matching_1 =? 21. | ||
129 | Proof. by vm_compute. Qed. | ||
130 | |||
131 | Definition matching_2 := | ||
132 | (λattr: {[ "x" := None; "y" := Some (EId' "x") ]}, "x" +: "y") | ||
133 | (EAttr {[ "x" := AttrN 10 ]}). | ||
134 | Goal interp 1000 ∅ matching_2 =? 20. | ||
135 | Proof. by vm_compute. Qed. | ||
136 | |||
137 | Definition matching_3 := | ||
138 | (λattr: {[ "x" := None; "y" := None ]}, "x" +: "y") | ||
139 | (EAttr {[ "x" := AttrN 10 ]}). | ||
140 | Goal interp 1000 ∅ matching_3 = mfail. | ||
141 | Proof. by vm_compute. Qed. | ||
142 | |||
143 | Definition matching_4 := | ||
144 | (λattr: {[ "x" := None; "y" := None ]}, "x" +: "y") | ||
145 | (EAttr {[ "x" := AttrN 10; "y" := AttrN 11; "z" := AttrN 12 ]}). | ||
146 | Goal interp 1000 ∅ matching_4 = mfail. | ||
147 | Proof. by vm_compute. Qed. | ||
148 | |||
149 | Definition matching_5 := | ||
150 | (λattr: {[ "x" := None; "y" := None ]} .., "x" +: "y") | ||
151 | (EAttr {[ "x" := AttrN 10; "y" := AttrN 11; "z" := AttrN 12 ]}). | ||
152 | Goal interp 1000 ∅ matching_5 =? 21. | ||
153 | Proof. by vm_compute. Qed. | ||
154 | |||
155 | Definition matching_6 := | ||
156 | (λattr: {[ "y" := Some (EId' "y") ]}, "y") | ||
157 | (EAttr {[ "y" := AttrN 10 ]}). | ||
158 | Goal interp 1000 ∅ matching_6 =? 10. | ||
159 | Proof. by vm_compute. Qed. | ||
160 | |||
161 | Definition matching_7 := | ||
162 | (λattr: {[ "y" := Some (EId' "y") ]}, "y") (EAttr ∅). | ||
163 | Goal interp 1000 ∅ matching_7 = NoFuel. | ||
164 | Proof. by vm_compute. Qed. | ||
165 | |||
166 | Definition matching_8 := | ||
167 | (λattr: {[ "y" := Some (EId' "y") ]}.., "y") | ||
168 | (EAttr {[ "x" := AttrN 10 ]}). | ||
169 | Goal interp 1000 ∅ matching_8 = NoFuel. | ||
170 | Proof. by vm_compute. Qed. | ||
171 | |||
172 | Definition list_lt_1 := | ||
173 | EList [ELit 2; ELit 3] <: EList [ELit 3]. | ||
174 | Goal interp 1000 ∅ list_lt_1 =? true. | ||
175 | Proof. by vm_compute. Qed. | ||
176 | |||
177 | Definition list_lt_2 := | ||
178 | EList [ELit 2; ELit 3] <: EList [ELit 2]. | ||
179 | Goal interp 1000 ∅ list_lt_2 =? false. | ||
180 | Proof. by vm_compute. Qed. | ||
181 | |||
182 | Definition list_lt_3 := | ||
183 | EList [ELit 2] <: EList [ELit 2; ELit 3]. | ||
184 | Goal interp 1000 ∅ list_lt_3 =? true. | ||
185 | Proof. by vm_compute. Qed. | ||