Debian Codegraph @

pretyping/geninterp.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Names
12 open Genarg
13
14 module TacStore = Store.Make ()
15
16 (** Dynamic toplevel values *)
17
18 module ValT = Dyn.Make ()
19
20 module Val =
21 struct
22
23 type 'a typ = 'a ValT.tag
24
25 type _ tag =
26 | Base : 'a typ -> 'a tag
27 | List : 'a tag -> 'a list tag
28 | Opt : 'a tag -> 'a option tag
29 | Pair : 'a tag * 'b tag -> ('a * 'b) tag
30
31 type t = Dyn : 'a typ * 'a -> t
32
33 let eq = ValT.eq
34 let repr = ValT.repr
35 let create = ValT.create
36
37 let pr : type a. a typ -> Pp.t = fun t -> Pp.str (repr t)
38
39 let typ_list = ValT.create "list"
40 let typ_opt = ValT.create "option"
41 let typ_pair = ValT.create "pair"
42
43 let rec inject : type a. a tag -> a -> t = fun tag x -> match tag with
44 | Base t -> Dyn (t, x)
45 | List tag -> Dyn (typ_list, List.map (fun x -> inject tag x) x)
46 | Opt tag -> Dyn (typ_opt, Option.map (fun x -> inject tag x) x)
47 | Pair (tag1, tag2) ->
48 Dyn (typ_pair, (inject tag1 (fst x), inject tag2 (snd x)))
49
50 end
51
52 module ValTMap = ValT.Map
53
54 module ValReprObj =
55 struct
56 type ('raw, 'glb, 'top) obj = 'top Val.tag
57 let name = "valrepr"
58 let default _ = None
59 end
60
61 module ValRepr = Register(ValReprObj)
62
63 let rec val_tag : type a b c. (a, b, c) genarg_type -> c Val.tag = function
64 | ListArg t -> Val.List (val_tag t)
65 | OptArg t -> Val.Opt (val_tag t)
66 | PairArg (t1, t2) -> Val.Pair (val_tag t1, val_tag t2)
67 | ExtraArg s -> ValRepr.obj (ExtraArg s)
68
69 let val_tag = function Topwit t -> val_tag t
70
71 let register_val0 wit tag =
72 let tag = match tag with
73 | None ->
74 let name = match wit with
75 | ExtraArg s -> ArgT.repr s
76 | _ -> assert false
77 in
78 Val.Base (Val.create name)
79 | Some tag -> tag
80 in
81 ValRepr.register0 wit tag
82
83 (** Interpretation functions *)
84
85 type interp_sign =
86 { lfun : Val.t Id.Map.t
87 ; poly : PolyFlags.t
88 ; extra : TacStore.t }
89
90 type ('glb, 'top) interp_fun = interp_sign -> 'glb -> 'top Ftactic.t
91
92 module InterpObj =
93 struct
94 type ('raw, 'glb, 'top) obj = ('glb, Val.t) interp_fun
95 let name = "interp"
96 let default _ = None
97 end
98
99 module Interp = Register(InterpObj)
100
101 let interp = Interp.obj
102
103 let generic_interp ist (GenArg (Glbwit wit, v)) = interp wit ist v
104
105 let register_interp0 = Interp.register0