aboutsummaryrefslogtreecommitdiffstats
path: root/lib/extraction/prelude.v
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extraction/prelude.v')
-rw-r--r--lib/extraction/prelude.v52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/extraction/prelude.v b/lib/extraction/prelude.v
new file mode 100644
index 0000000..ef35bcb
--- /dev/null
+++ b/lib/extraction/prelude.v
@@ -0,0 +1,52 @@
1Require Import Coq.Numbers.DecimalString ExtrOcamlBasic ExtrOcamlString.
2From stdpp Require Import strings stringmap gmap.
3From mininix Require Import nix.interp.
4
5Definition attr_set_insert (x : string) (α : attr) (αs : gmap string attr) : gmap string attr :=
6 <[x:=α]> αs.
7
8Definition attr_set_contains (x : string) (αs : gmap string attr) : bool :=
9 bool_decide (x ∈ dom αs).
10
11Definition attr_set_fold {A} (f : string → attr → A → A) (init : A) (αs : gmap string attr) : A :=
12 map_fold f init αs.
13
14Definition attr_set_empty : gmap string attr := ∅.
15
16Definition env_fold {A} (f : string → (kind * thunk) → A → A) (init : A) (E : env) : A :=
17 map_fold f init E.
18
19Definition env_insert_abs (x : string) (t : thunk) (E : env) : env :=
20 <[x:=(ABS,t)]> E.
21
22Definition thunk_map_fold {A} (f : string → thunk → A → A) (init : A) (bs : gmap string thunk) : A :=
23 map_fold f init bs.
24
25Definition thunk_map_insert (x : string) (t : thunk) (bs : gmap string thunk) : gmap string thunk :=
26 <[x:=t]> bs.
27
28Definition thunk_map_empty : gmap string thunk := ∅.
29
30Definition matcher := gmap string (option expr).
31
32Definition matcher_empty : matcher := ∅.
33
34Definition matcher_insert (x : string) (me : option expr) (ms : matcher) : matcher :=
35 <[x:=me]> ms.
36
37Definition matcher_fold {A} (f : string → option expr → A → A) (init : A) (ms : matcher) : A :=
38 map_fold f init ms.
39
40Definition env_empty : env := ∅.
41
42Definition string_of_Z (x : Z) : string :=
43 NilZero.string_of_int (Z.to_int x).
44
45Definition string_to_Z (s : string) : option Z :=
46 Z.of_int <$> NilZero.int_of_string s.
47
48Separate Extraction
49 attr_set_insert env_insert_abs matcher_insert thunk_map_insert
50 attr_set_contains attr_set_fold env_fold matcher_fold thunk_map_fold
51 env_empty attr_set_empty matcher_empty thunk_map_empty string_of_Z
52 string_to_Z interp' forallb.