Skip to content

Commit 7d0e50a

Browse files
authored
Merge pull request #156 from LPCIC/api_set
ocaml_set_conv
2 parents 22119dc + 6959e9b commit 7d0e50a

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# v1.16.5 (July 2022)
2+
3+
Requires Menhir 20211230 and OCaml 4.08 or above.
4+
Camlp5 8.0 or above is optional.
5+
6+
- Apis in the Builtin module:
7+
- New `string_set`, `int_set` and `loc_set` conversions
8+
- New `ocaml_set_conv` giving both the declarations and the conversion for the
9+
provided OCaml `Set` module
10+
111
# v1.16.4 (July 2022)
212

313
Requires Menhir 20211230 and OCaml 4.08 or above.

src/API.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,8 @@ module Utils = struct
10131013
module type Show1 = Util.Show1
10141014
module Map = Util.Map
10151015
module Set = Util.Set
1016+
module IntSet = Util.IntSet
1017+
module LocSet : Util.Set.S with type elt = Ast.Loc.t = Util.Set.Make(Ast.Loc)
10161018

10171019
end
10181020

src/API.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,9 @@ module Utils : sig
11601160

11611161
end
11621162

1163+
module IntSet : Set.S with type elt = int
1164+
module LocSet : Set.S with type elt = Ast.Loc.t
1165+
11631166
end
11641167

11651168
module RawPp : sig

src/builtin.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,8 @@ let elpi_stdlib_src = let open BuiltIn in [
11961196

11971197
]
11981198

1199-
let ocaml_set ~name (type a)
1200-
(alpha : a Conversion.t) (module Set : Util.Set.S with type elt = a) =
1199+
let ocaml_set_conv ~name (type a) (type b)
1200+
(alpha : a Conversion.t) (module Set : Util.Set.S with type elt = a and type t = b) =
12011201

12021202
let set = OpaqueData.declare {
12031203
OpaqueData.name;
@@ -1213,6 +1213,7 @@ let set = { set with Conversion.ty = Conversion.(TyName name) } in
12131213

12141214
let open BuiltIn in let open BuiltInData in
12151215

1216+
set,
12161217
[
12171218
LPCode ("kind "^name^" type.");
12181219

@@ -1299,6 +1300,7 @@ let open BuiltIn in let open BuiltInData in
12991300
DocAbove);
13001301
]
13011302
;;
1303+
let ocaml_set ~name c m = snd (ocaml_set_conv ~name c m)
13021304

13031305
let ocaml_map ~name (type a)
13041306
(alpha : a Conversion.t) (module Map : Util.Map.S with type key = a) =
@@ -1376,7 +1378,6 @@ let open BuiltIn in let open BuiltInData in
13761378
;;
13771379

13781380
module LocMap : Util.Map.S with type key = Ast.Loc.t = Util.Map.Make(Ast.Loc)
1379-
module LocSet : Util.Set.S with type elt = Ast.Loc.t = Util.Set.Make(Ast.Loc)
13801381

13811382
let elpi_map = let open BuiltIn in [
13821383

@@ -1390,6 +1391,9 @@ let elpi_set = let open BuiltIn in [
13901391

13911392
]
13921393

1394+
let string_set, string_set_decl = ocaml_set_conv ~name:"std.string.set" BuiltInData.string (module API.Compile.StrSet)
1395+
let int_set, int_set_decl = ocaml_set_conv ~name:"std.int.set" BuiltInData.int (module API.Utils.IntSet)
1396+
let loc_set, loc_set_decl = ocaml_set_conv ~name:"std.loc.set" BuiltInData.loc (module API.Utils.LocSet)
13931397

13941398
let elpi_stdlib =
13951399
elpi_stdlib_src @
@@ -1406,9 +1410,9 @@ let elpi_stdlib =
14061410
ocaml_map ~name:"std.string.map" BuiltInData.string (module Util.StrMap) @
14071411
ocaml_map ~name:"std.int.map" BuiltInData.int (module Util.IntMap) @
14081412
ocaml_map ~name:"std.loc.map" BuiltInData.loc (module LocMap) @
1409-
ocaml_set ~name:"std.string.set" BuiltInData.string (module Util.StrSet) @
1410-
ocaml_set ~name:"std.int.set" BuiltInData.int (module Util.IntSet) @
1411-
ocaml_set ~name:"std.loc.set" BuiltInData.loc (module LocSet) @
1413+
string_set_decl @
1414+
int_set_decl @
1415+
loc_set_decl @
14121416
[]
14131417
;;
14141418

src/builtin.mli

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ val ocaml_map :
4040
declaration list
4141
val ocaml_set :
4242
name:string ->
43-
'a API.Conversion.t -> (module API.Utils.Set.S with type elt = 'a) ->
43+
'a API.Conversion.t -> (module API.Utils.Set.S with type elt = 'a and type t = 'b) ->
4444
declaration list
45+
val ocaml_set_conv :
46+
name:string ->
47+
'a API.Conversion.t -> (module API.Utils.Set.S with type elt = 'a and type t = 'b) ->
48+
'b API.Conversion.t * declaration list
49+
val int_set : API.Utils.IntSet.t API.Conversion.t
50+
val string_set : API.Compile.StrSet.t API.Conversion.t
51+
val loc_set : API.Utils.LocSet.t API.Conversion.t
4552

4653
(* All the above, to be used as a sane default in Setup.init *)
4754
val std_declarations : declaration list

0 commit comments

Comments
 (0)