Skip to content

Commit e8a4b0e

Browse files
committed
rebased
1 parent 0a1bf49 commit e8a4b0e

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

ppx_elpi/ppx_elpi.ml

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ let conversion_of (module B : Ast_builder.S) ty = let open B in
723723
| [%type: string] -> [%expr Elpi.API.BuiltInData.string]
724724
| [%type: int] -> [%expr Elpi.API.BuiltInData.int]
725725
| [%type: float] -> [%expr Elpi.API.BuiltInData.float]
726-
| [%type: bool] -> [%expr Elpi.Builtin.bool]
727-
| [%type: char] -> [%expr Elpi.Builtin.char]
726+
| [%type: bool] -> [%expr Elpi.API.BuiltInData.bool]
727+
| [%type: char] -> [%expr Elpi.API.BuiltInData.char]
728728
| [%type: [%t? typ] list] -> [%expr Elpi.API.BuiltInData.list [%e aux typ ]]
729729
| [%type: [%t? typ] option] -> [%expr Elpi.Builtin.option [%e aux typ ]]
730730
| [%type: [%t? typ1] * [%t? typ2]] -> [%expr Elpi.Builtin.pair [%e aux typ1 ] [%e aux typ2 ]]
@@ -747,8 +747,8 @@ let rec find_embed_of (module B : Ast_builder.S) current_mutrec_block ty = let
747747
| [%type: string] -> [%expr Elpi.API.PPX.embed_string]
748748
| [%type: int] -> [%expr Elpi.API.PPX.embed_int]
749749
| [%type: float] -> [%expr Elpi.API.PPX.embed_float]
750-
| [%type: bool] -> [%expr Elpi.Builtin.PPX.embed_bool]
751-
| [%type: char] -> [%expr Elpi.Builtin.PPX.embed_char]
750+
| [%type: bool] -> [%expr Elpi.API.PPX.embed_bool]
751+
| [%type: char] -> [%expr Elpi.API.PPX.embed_char]
752752
| [%type: [%t? typ] list] -> [%expr Elpi.API.PPX.embed_list [%e aux typ ]]
753753
| [%type: [%t? typ] option] -> [%expr Elpi.Builtin.PPX.embed_option [%e aux typ ]]
754754
| [%type: [%t? typ1] * [%t? typ2]] -> [%expr Elpi.Builtin.PPX.embed_pair [%e aux typ1 ] [%e aux typ2 ]]
@@ -768,8 +768,8 @@ let rec find_readback_of (module B : Ast_builder.S) current_mutrec_block ty = l
768768
| [%type: string] -> [%expr Elpi.API.PPX.readback_string]
769769
| [%type: int] -> [%expr Elpi.API.PPX.readback_int]
770770
| [%type: float] -> [%expr Elpi.API.PPX.readback_float]
771-
| [%type: bool] -> [%expr Elpi.Builtin.PPX.readback_bool]
772-
| [%type: char] -> [%expr Elpi.Builtin.PPX.readback_char]
771+
| [%type: bool] -> [%expr Elpi.API.PPX.readback_bool]
772+
| [%type: char] -> [%expr Elpi.API.PPX.readback_char]
773773
| [%type: [%t? typ] list] -> [%expr Elpi.API.PPX.readback_list [%e aux typ ]]
774774
| [%type: [%t? typ] option] -> [%expr Elpi.Builtin.PPX.readback_option [%e aux typ ]]
775775
| [%type: [%t? typ1] * [%t? typ2]] -> [%expr Elpi.Builtin.PPX.readback_pair [%e aux typ1 ] [%e aux typ2 ]]
@@ -1108,32 +1108,12 @@ let coversion_for_opaque (module B : Ast_builder.S) elpi_name name = let open B
11081108
[%type: ( [%t ptyp_constr (Located.lident name) []] , #Elpi.API.Conversion.ctx as 'c) Elpi.API.Conversion.t]))
11091109
~expr:[%expr
11101110

1111-
let name = [%e elpi_name ] in
1112-
let { Elpi.API.RawOpaqueData.cin; isc; cout; name=c }, constants_map, doc = [%e evar @@ elpi_cdata_name name ] in
1113-
1114-
let ty = Elpi.API.Conversion.TyName name in
1115-
let embed ~depth:_ _ _ state x =
1116-
state, Elpi.API.RawData.mkCData (cin x), [] in
1117-
let readback ~depth _ _ state t =
1118-
match Elpi.API.RawData.look ~depth t with
1119-
| Elpi.API.RawData.CData c when isc c -> state, cout c, []
1120-
| Elpi.API.RawData.Const i when i < 0 ->
1121-
begin try state, snd @@ Elpi.API.RawData.Constants.Map.find i constants_map, []
1122-
with Not_found -> raise (Elpi.API.Conversion.TypeErr(ty,depth,t)) end
1123-
| _ -> raise (Elpi.API.Conversion.TypeErr(ty,depth,t)) in
1124-
let pp_doc fmt () =
1125-
if doc <> "" then begin
1126-
Elpi.API.PPX.Doc.comment fmt ("% " ^ doc);
1127-
Format.fprintf fmt "@\n";
1128-
end;
1129-
Format.fprintf fmt "@[<hov 2>typeabbrev %s (ctype \"%s\").@]@\n@\n" name c;
1130-
Elpi.API.RawData.Constants.Map.iter (fun _ (c,_) ->
1131-
Format.fprintf fmt "@[<hov 2>type %s %s.@]@\n" c name)
1132-
constants_map
1133-
in
1134-
{ Elpi.API.Conversion.embed; readback; ty; pp_doc; pp = (fun fmt x -> Elpi.API.RawOpaqueData.pp fmt (cin x)) }
1135-
1136-
]
1111+
let ty, pp, pp_doc, cdata = [%e evar @@ elpi_cdata_name name ] in {
1112+
Elpi.API.Conversion.ty; pp_doc; pp;
1113+
embed = (fun ~depth -> Elpi.API.OpaqueData.embed cdata ~depth);
1114+
readback = (fun ~depth -> Elpi.API.OpaqueData.readback cdata ~depth);
1115+
}
1116+
]
11371117

11381118
let abstract_expr_over_params (module B : Ast_builder.S) vl f e = let open B in
11391119
let rec aux = function
@@ -1276,7 +1256,7 @@ let constants_of_tyd (module B : Ast_builder.S) { type_decl ; elpi_name; name; _
12761256
| Opaque opaque_data ->
12771257
[pstr_value Nonrecursive [
12781258
value_binding ~pat:(pvar @@ elpi_cdata_name name)
1279-
~expr:[%expr Elpi.API.RawOpaqueData.declare [%e opaque_data]]]]
1259+
~expr:[%expr Elpi.API.OpaqueData.declare [%e opaque_data]]]]
12801260
| Algebraic (csts,_) -> List.flatten @@ List.map (fun x -> x.declaration) @@ drop_skip csts
12811261

12821262
let elpi_declaration_of_tyd (module B : Ast_builder.S) tyd = let open B in

ppx_elpi/tests/test_opaque_type.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
let elpi_stuff = ref []
22

33
let pp_simple _ _ = ()
4-
type simple [@@elpi.opaque {Elpi.API.OpaqueData.name = "simple"; doc = ""; pp = (fun fmt _ -> Format.fprintf fmt "<simple>"); compare = Pervasives.compare; hash = Hashtbl.hash; hconsed = false; constants = []; } ]
4+
type simple [@@elpi.opaque { Elpi.API.OpaqueData.
5+
name = "simple";
6+
cname = "simple";
7+
doc = "a simple opaque data type";
8+
pp = (fun fmt _ -> Format.fprintf fmt "<simple>");
9+
compare = Pervasives.compare;
10+
hash = Hashtbl.hash;
11+
hconsed = false;
12+
constants = [];
13+
}]
514
[@@deriving elpi { declaration = elpi_stuff }]
615

716
open Elpi.API

0 commit comments

Comments
 (0)