Gentoo Archives: gentoo-commits

From: Alexis Ballier <aballier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-ml/js_of_ocaml/, dev-ml/js_of_ocaml/files/
Date: Tue, 03 May 2016 09:14:46
Message-Id: 1462266832.fde940cd10dd7ac97fa741dc85fcdc5a2e4b5c1f.aballier@gentoo
1 commit: fde940cd10dd7ac97fa741dc85fcdc5a2e4b5c1f
2 Author: Alexis Ballier <aballier <AT> gentoo <DOT> org>
3 AuthorDate: Sun May 1 18:46:12 2016 +0000
4 Commit: Alexis Ballier <aballier <AT> gentoo <DOT> org>
5 CommitDate: Tue May 3 09:13:52 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fde940cd
7
8 dev-ml/js_of_ocaml: fix build with ocaml 4.03
9
10 Package-Manager: portage-2.2.28
11 Signed-off-by: Alexis Ballier <aballier <AT> gentoo.org>
12
13 dev-ml/js_of_ocaml/files/oc43.patch | 1418 +++++++++++++++++++++++++++++
14 dev-ml/js_of_ocaml/js_of_ocaml-2.7.ebuild | 4 +
15 2 files changed, 1422 insertions(+)
16
17 diff --git a/dev-ml/js_of_ocaml/files/oc43.patch b/dev-ml/js_of_ocaml/files/oc43.patch
18 new file mode 100644
19 index 0000000..face810
20 --- /dev/null
21 +++ b/dev-ml/js_of_ocaml/files/oc43.patch
22 @@ -0,0 +1,1418 @@
23 +commit 3e4d39ece5a67bfc17f47c3da8a95ccca789abd5
24 +Author: Hugo Heuzard <hugo.heuzard@×××××.com>
25 +Date: Mon Mar 28 23:35:47 2016 +0100
26 +
27 + Deriving_json for ocaml 4.03
28 +
29 + move
30 +
31 +diff --git a/.gitignore b/.gitignore
32 +index 71e4ccf..ccbb796 100644
33 +--- a/.gitignore
34 ++++ b/.gitignore
35 +@@ -58,6 +58,7 @@ benchmarks/results
36 + benchmarks/config
37 + lib/deriving_json/deriving_Json_lexer.ml
38 + lib/ppx/ppx_js.ml
39 ++lib/ppx/ppx_deriving_json.ml
40 + lib/ppx/ppx_js
41 + Makefile.local
42 +
43 +diff --git a/lib/ppx/ppx_deriving_json.cppo.ml b/lib/ppx/ppx_deriving_json.cppo.ml
44 +new file mode 100644
45 +index 0000000..814ed99
46 +--- /dev/null
47 ++++ b/lib/ppx/ppx_deriving_json.cppo.ml
48 +@@ -0,0 +1,711 @@
49 ++(* Js_of_ocaml
50 ++ * http://www.ocsigen.org
51 ++ * Copyright Vasilis Papavasileiou 2015
52 ++ *
53 ++ * This program is free software; you can redistribute it and/or modify
54 ++ * it under the terms of the GNU Lesser General Public License as published by
55 ++ * the Free Software Foundation, with linking exception;
56 ++ * either version 2.1 of the License, or (at your option) any later version.
57 ++ *
58 ++ * This program is distributed in the hope that it will be useful,
59 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
60 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61 ++ * GNU Lesser General Public License for more details.
62 ++ *
63 ++ * You should have received a copy of the GNU Lesser General Public License
64 ++ * along with this program; if not, write to the Free Software
65 ++ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
66 ++ *)
67 ++
68 ++let deriver = "json"
69 ++
70 ++(* Copied (and adapted) this from ppx_deriving repo (commit
71 ++ e2079fa8f3460055bf990461f295c6c4b391fafc) ; we get an empty set of
72 ++ let bindings with ppx_deriving 3.0 *)
73 ++let sanitize expr = [%expr
74 ++ (let open! Ppx_deriving_runtime in [%e expr]) [@ocaml.warning "-A"]]
75 ++
76 ++let var_ptuple l =
77 ++ List.map Ast_convenience.pvar l |> Ast_helper.Pat.tuple
78 ++
79 ++let map_loc f {Location.txt; loc} =
80 ++ {Location.txt = f txt; loc}
81 ++
82 ++let suffix_lid {Location.txt; loc} ~suffix =
83 ++ let txt = Ppx_deriving.mangle_lid (`Suffix suffix) txt in
84 ++ Ast_helper.Exp.ident {txt; loc} ~loc
85 ++
86 ++let suffix_decl ({Parsetree.ptype_loc = loc} as d) ~suffix =
87 ++ (let s =
88 ++ Ppx_deriving.mangle_type_decl (`Suffix suffix) d |>
89 ++ Longident.parse
90 ++ in
91 ++ Location.mkloc s loc) |> Ast_helper.Exp.ident ~loc
92 ++
93 ++let suffix_decl_p ({Parsetree.ptype_loc = loc} as d) ~suffix =
94 ++ (let s = Ppx_deriving.mangle_type_decl (`Suffix suffix) d in
95 ++ Location.mkloc s loc) |> Ast_helper.Pat.var ~loc
96 ++
97 ++let rec fresh_vars ?(acc = []) n =
98 ++ if n <= 0 then
99 ++ List.rev acc
100 ++ else
101 ++ let acc = Ppx_deriving.fresh_var acc :: acc in
102 ++ fresh_vars ~acc (n - 1)
103 ++
104 ++let unreachable_case () =
105 ++ Ast_helper.Exp.case [%pat? _ ] [%expr assert false]
106 ++
107 ++let label_of_constructor = map_loc (fun c -> Longident.Lident c)
108 ++
109 ++let wrap_write r ~pattern = [%expr fun buf [%p pattern] -> [%e r]]
110 ++
111 ++let buf_expand r = [%expr fun buf -> [%e r]]
112 ++
113 ++let seqlist = function
114 ++ | h :: l ->
115 ++ let f acc e = [%expr [%e acc]; [%e e]] in
116 ++ List.fold_left f h l
117 ++ | [] ->
118 ++ [%expr ()]
119 ++
120 ++let check_record_fields =
121 ++ List.iter @@ function
122 ++ | {Parsetree.pld_mutable = Mutable} ->
123 ++ Location.raise_errorf
124 ++ "%s cannot be derived for mutable records" deriver
125 ++ | {pld_type = {ptyp_desc = Ptyp_poly _}} ->
126 ++ Location.raise_errorf
127 ++ "%s cannot be derived for polymorphic records" deriver
128 ++ | _ ->
129 ++ ()
130 ++
131 ++let maybe_tuple_type = function
132 ++ | [y] -> y
133 ++ | l -> Ast_helper.Typ.tuple l
134 ++
135 ++let rec write_tuple_contents l ly ~tag ~poly =
136 ++ let e =
137 ++ let f v y =
138 ++ let arg = Ast_convenience.evar v in
139 ++ let e = write_body_of_type y ~arg ~poly in
140 ++ [%expr Buffer.add_string buf ","; [%e e]]
141 ++ in
142 ++ List.map2 f l ly |> seqlist
143 ++ and s = Ast_convenience.str ("[" ^ string_of_int tag) in [%expr
144 ++ Buffer.add_string buf [%e s];
145 ++ [%e e];
146 ++ Buffer.add_string buf "]"]
147 ++
148 ++and write_body_of_tuple_type l ~arg ~poly ~tag =
149 ++ let n = List.length l in
150 ++ let vars = fresh_vars n in
151 ++ let e = write_tuple_contents vars l ~tag ~poly
152 ++ and p = var_ptuple vars in
153 ++ [%expr let [%p p] = [%e arg] in [%e e]]
154 ++
155 ++and write_poly_case r ~arg ~poly =
156 ++ match r with
157 ++ | Parsetree.Rtag (label, _, _, l) ->
158 ++ let i = Ppx_deriving.hash_variant label
159 ++ and n = List.length l in
160 ++ let v = Ppx_deriving.fresh_var [] in
161 ++ let lhs =
162 ++ (if n = 0 then None else Some (Ast_convenience.pvar v)) |>
163 ++ Ast_helper.Pat.variant label
164 ++ and rhs =
165 ++ match l with
166 ++ | [] ->
167 ++ let e = Ast_convenience.int i in
168 ++ [%expr Deriving_Json.Json_int.write buf [%e e]]
169 ++ | _ ->
170 ++ let l = [[%type: int]; maybe_tuple_type l]
171 ++ and arg = Ast_helper.Exp.tuple Ast_convenience.[int i; evar v] in
172 ++ write_body_of_tuple_type l ~arg ~poly ~tag:0
173 ++ in
174 ++ Ast_helper.Exp.case lhs rhs
175 ++ | Rinherit ({ptyp_desc = Ptyp_constr (lid, _)} as y) ->
176 ++ Ast_helper.Exp.case (Ast_helper.Pat.type_ lid)
177 ++ (write_body_of_type y ~arg ~poly)
178 ++ | Rinherit {ptyp_loc} ->
179 ++ Location.raise_errorf ~loc:ptyp_loc
180 ++ "%s write case cannot be derived" deriver
181 ++
182 ++and write_body_of_type y ~arg ~poly =
183 ++ match y with
184 ++ | [%type: unit] ->
185 ++ [%expr Deriving_Json.Json_unit.write buf [%e arg]]
186 ++ | [%type: int] ->
187 ++ [%expr Deriving_Json.Json_int.write buf [%e arg]]
188 ++ | [%type: int32] | [%type: Int32.t] ->
189 ++ [%expr Deriving_Json.Json_int32.write buf [%e arg]]
190 ++ | [%type: int64] | [%type: Int64.t] ->
191 ++ [%expr Deriving_Json.Json_int64.write buf [%e arg]]
192 ++ | [%type: nativeint] | [%type: Nativeint.t] ->
193 ++ [%expr Deriving_Json.Json_nativeint.write buf [%e arg]]
194 ++ | [%type: float] ->
195 ++ [%expr Deriving_Json.Json_float.write buf [%e arg]]
196 ++ | [%type: bool] ->
197 ++ [%expr Deriving_Json.Json_bool.write buf [%e arg]]
198 ++ | [%type: char] ->
199 ++ [%expr Deriving_Json.Json_char.write buf [%e arg]]
200 ++ | [%type: string] ->
201 ++ [%expr Deriving_Json.Json_string.write buf [%e arg]]
202 ++ | [%type: bytes] ->
203 ++ [%expr Deriving_Json.Json_bytes.write buf [%e arg]]
204 ++ | [%type: [%t? y] list] ->
205 ++ let e = write_of_type y ~poly in
206 ++ [%expr Deriving_Json.write_list [%e e] buf [%e arg]]
207 ++ | [%type: [%t? y] ref] ->
208 ++ let e = write_of_type y ~poly in
209 ++ [%expr Deriving_Json.write_ref [%e e] buf [%e arg]]
210 ++ | [%type: [%t? y] option] ->
211 ++ let e = write_of_type y ~poly in
212 ++ [%expr Deriving_Json.write_option [%e e] buf [%e arg]]
213 ++ | [%type: [%t? y] array] ->
214 ++ let e = write_of_type y ~poly in
215 ++ [%expr Deriving_Json.write_array [%e e] buf [%e arg]]
216 ++ | { Parsetree.ptyp_desc = Ptyp_var v } when poly ->
217 ++ [%expr [%e Ast_convenience.evar ("poly_" ^ v)] buf [%e arg]]
218 ++ | { Parsetree.ptyp_desc = Ptyp_tuple l } ->
219 ++ write_body_of_tuple_type l ~arg ~poly ~tag:0
220 ++ | { Parsetree.ptyp_desc = Ptyp_variant (l, _, _); ptyp_loc = loc } ->
221 ++ List.map (write_poly_case ~arg ~poly) l @ [unreachable_case ()] |>
222 ++ Ast_helper.Exp.match_ arg
223 ++ | { Parsetree.ptyp_desc = Ptyp_constr (lid, l) } ->
224 ++ let e = suffix_lid lid ~suffix:"to_json"
225 ++ and l = List.map (write_of_type ~poly) l in
226 ++ [%expr [%e Ast_convenience.app e l] buf [%e arg]]
227 ++ | { Parsetree.ptyp_loc } ->
228 ++ Location.raise_errorf ~loc:ptyp_loc
229 ++ "%s_write cannot be derived for %s"
230 ++ deriver (Ppx_deriving.string_of_core_type y)
231 ++
232 ++and write_of_type y ~poly =
233 ++ let v = "a" in
234 ++ let arg = Ast_convenience.evar v
235 ++ and pattern = Ast_convenience.pvar v in
236 ++ wrap_write (write_body_of_type y ~arg ~poly) ~pattern
237 ++
238 ++and write_of_record ?(tag=0) d l =
239 ++ let pattern =
240 ++ let l =
241 ++ let f {Parsetree.pld_name} =
242 ++ label_of_constructor pld_name,
243 ++ Ast_helper.Pat.var pld_name
244 ++ in
245 ++ List.map f l
246 ++ in
247 ++ Ast_helper.Pat.record l Asttypes.Closed
248 ++ and e =
249 ++ let l =
250 ++ let f {Parsetree.pld_name = {txt}} = txt in
251 ++ List.map f l
252 ++ and ly =
253 ++ let f {Parsetree.pld_type} = pld_type in
254 ++ List.map f l
255 ++ in
256 ++ write_tuple_contents l ly ~tag ~poly:true
257 ++ in
258 ++ wrap_write e ~pattern
259 ++
260 ++let recognize_case_of_constructor i l =
261 ++ let lhs =
262 ++ match l with
263 ++ | [] -> [%pat? `Cst [%p Ast_convenience.pint i]]
264 ++ | _ -> [%pat? `NCst [%p Ast_convenience.pint i]]
265 ++ in
266 ++ Ast_helper.Exp.case lhs [%expr true]
267 ++
268 ++let recognize_body_of_poly_variant l ~loc =
269 ++ let l =
270 ++ let f = function
271 ++ | Parsetree.Rtag (label, _, _, l) ->
272 ++ let i = Ppx_deriving.hash_variant label in
273 ++ recognize_case_of_constructor i l
274 ++ | Rinherit {ptyp_desc = Ptyp_constr (lid, _)} ->
275 ++ let guard = [%expr [%e suffix_lid lid ~suffix:"recognize"] x] in
276 ++ Ast_helper.Exp.case ~guard [%pat? x] [%expr true]
277 ++ | _ ->
278 ++ Location.raise_errorf ~loc
279 ++ "%s_recognize cannot be derived" deriver
280 ++ and default = Ast_helper.Exp.case [%pat? _] [%expr false] in
281 ++ List.map f l @ [default]
282 ++ in
283 ++ Ast_helper.Exp.function_ l
284 ++
285 ++let tag_error_case ?(typename="") () =
286 ++ let y = Ast_convenience.str typename in
287 ++ Ast_helper.Exp.case
288 ++ [%pat? _]
289 ++ [%expr Deriving_Json_lexer.tag_error ~typename:[%e y] buf]
290 ++
291 ++let maybe_tuple_type = function
292 ++ | [y] -> y
293 ++ | l -> Ast_helper.Typ.tuple l
294 ++
295 ++let rec read_poly_case ?decl y = function
296 ++ | Parsetree.Rtag (label, _, _, l) ->
297 ++ let i = Ppx_deriving.hash_variant label |> Ast_convenience.pint in
298 ++ (match l with
299 ++ | [] ->
300 ++ Ast_helper.Exp.case [%pat? `Cst [%p i]]
301 ++ (Ast_helper.Exp.variant label None)
302 ++ | l ->
303 ++ Ast_helper.Exp.case [%pat? `NCst [%p i]] [%expr
304 ++ Deriving_Json_lexer.read_comma buf;
305 ++ let v = [%e read_body_of_type ?decl (maybe_tuple_type l)] in
306 ++ Deriving_Json_lexer.read_rbracket buf;
307 ++ [%e Ast_helper.Exp.variant label (Some [%expr v])]])
308 ++ | Rinherit {ptyp_desc = Ptyp_constr (lid, l)} ->
309 ++ let guard = [%expr [%e suffix_lid lid ~suffix:"recognize"] x]
310 ++ and e =
311 ++ let e = suffix_lid lid ~suffix:"of_json_with_tag"
312 ++ and l = List.map (read_of_type ?decl) l in
313 ++ [%expr ([%e Ast_convenience.app e l] buf x :> [%t y])]
314 ++ in
315 ++ Ast_helper.Exp.case ~guard [%pat? x] e
316 ++ | Rinherit {ptyp_loc} ->
317 ++ Location.raise_errorf ~loc:ptyp_loc
318 ++ "%s read case cannot be derived" deriver
319 ++
320 ++and read_of_poly_variant ?decl l y ~loc =
321 ++ List.map (read_poly_case ?decl y) l @ [tag_error_case ()] |>
322 ++ Ast_helper.Exp.function_ |>
323 ++ buf_expand
324 ++
325 ++and read_tuple_contents ?decl l ~f =
326 ++ let n = List.length l in
327 ++ let lv = fresh_vars n in
328 ++ let f v y acc =
329 ++ let e = read_body_of_type ?decl y in [%expr
330 ++ Deriving_Json_lexer.read_comma buf;
331 ++ let [%p Ast_convenience.pvar v] = [%e e] in
332 ++ [%e acc]]
333 ++ and acc = List.map Ast_convenience.evar lv |> f in
334 ++ let acc = [%expr Deriving_Json_lexer.read_rbracket buf; [%e acc]] in
335 ++ List.fold_right2 f lv l acc
336 ++
337 ++and read_body_of_tuple_type ?decl l = [%expr
338 ++ Deriving_Json_lexer.read_lbracket buf;
339 ++ ignore (Deriving_Json_lexer.read_tag_1 0 buf);
340 ++ [%e read_tuple_contents ?decl l ~f:Ast_helper.Exp.tuple]]
341 ++
342 ++and read_of_record_raw ?decl l =
343 ++ let f =
344 ++ let f {Parsetree.pld_name} e = label_of_constructor pld_name, e in
345 ++ fun l' -> Ast_helper.Exp.record (List.map2 f l l') None
346 ++ and l =
347 ++ let f {Parsetree.pld_type} = pld_type in
348 ++ List.map f l
349 ++ in
350 ++ read_tuple_contents l ?decl ~f
351 ++
352 ++and read_of_record decl l =
353 ++ let e = read_of_record_raw ~decl l in
354 ++ [%expr
355 ++ Deriving_Json_lexer.read_lbracket buf;
356 ++ ignore (Deriving_Json_lexer.read_tag_2 0 254 buf);
357 ++ [%e e]] |> buf_expand
358 ++
359 ++and read_body_of_type ?decl y =
360 ++ let poly = match decl with Some _ -> true | _ -> false in
361 ++ match y with
362 ++ | [%type: unit] ->
363 ++ [%expr Deriving_Json.Json_unit.read buf]
364 ++ | [%type: int] ->
365 ++ [%expr Deriving_Json.Json_int.read buf]
366 ++ | [%type: int32] | [%type: Int32.t] ->
367 ++ [%expr Deriving_Json.Json_int32.read buf]
368 ++ | [%type: int64] | [%type: Int64.t] ->
369 ++ [%expr Deriving_Json.Json_int64.read buf]
370 ++ | [%type: nativeint] | [%type: Nativeint.t] ->
371 ++ [%expr Deriving_Json.Json_nativeint.read buf]
372 ++ | [%type: float] ->
373 ++ [%expr Deriving_Json.Json_float.read buf]
374 ++ | [%type: bool] ->
375 ++ [%expr Deriving_Json.Json_bool.read buf]
376 ++ | [%type: char] ->
377 ++ [%expr Deriving_Json.Json_char.read buf]
378 ++ | [%type: string] ->
379 ++ [%expr Deriving_Json.Json_string.read buf]
380 ++ | [%type: bytes] ->
381 ++ [%expr Deriving_Json.Json_bytes.read buf]
382 ++ | [%type: [%t? y] list] ->
383 ++ [%expr Deriving_Json.read_list [%e read_of_type ?decl y] buf]
384 ++ | [%type: [%t? y] ref] ->
385 ++ [%expr Deriving_Json.read_ref [%e read_of_type ?decl y] buf]
386 ++ | [%type: [%t? y] option] ->
387 ++ [%expr Deriving_Json.read_option [%e read_of_type ?decl y] buf]
388 ++ | [%type: [%t? y] array] ->
389 ++ [%expr Deriving_Json.read_array [%e read_of_type ?decl y] buf]
390 ++ | { Parsetree.ptyp_desc = Ptyp_tuple l } ->
391 ++ read_body_of_tuple_type l ?decl
392 ++ | { Parsetree.ptyp_desc = Ptyp_variant (l, _, _); ptyp_loc = loc } ->
393 ++ let e =
394 ++ (match decl with
395 ++ | Some decl ->
396 ++ let e = suffix_decl decl ~suffix:"of_json_with_tag"
397 ++ and l =
398 ++ let {Parsetree.ptype_params = l} = decl
399 ++ and f (y, _) = read_of_type y ~decl in
400 ++ List.map f l
401 ++ in
402 ++ Ast_convenience.app e l
403 ++ | None ->
404 ++ read_of_poly_variant l y ~loc)
405 ++ and tag = [%expr Deriving_Json_lexer.read_vcase buf] in
406 ++ [%expr [%e e] buf [%e tag]]
407 ++ | { Parsetree.ptyp_desc = Ptyp_var v } when poly ->
408 ++ [%expr [%e Ast_convenience.evar ("poly_" ^ v)] buf]
409 ++ | { Parsetree.ptyp_desc = Ptyp_constr (lid, l) } ->
410 ++ let e = suffix_lid lid ~suffix:"of_json"
411 ++ and l = List.map (read_of_type ?decl) l in
412 ++ [%expr [%e Ast_convenience.app e l] buf]
413 ++ | { Parsetree.ptyp_loc } ->
414 ++ Location.raise_errorf ~loc:ptyp_loc
415 ++ "%s_read cannot be derived for %s" deriver
416 ++ (Ppx_deriving.string_of_core_type y)
417 ++
418 ++and read_of_type ?decl y =
419 ++ read_body_of_type ?decl y |> buf_expand
420 ++
421 ++let json_of_type ?decl y =
422 ++ let read = read_of_type ?decl y
423 ++ and write =
424 ++ let poly = match decl with Some _ -> true | _ -> false in
425 ++ write_of_type y ~poly in
426 ++ [%expr Deriving_Json.make [%e write] [%e read]]
427 ++
428 ++let fun_str_wrap d e y ~f ~suffix =
429 ++ let e = Ppx_deriving.poly_fun_of_type_decl d e |> sanitize
430 ++ and v = suffix_decl_p d ~suffix
431 ++ and y = Ppx_deriving.poly_arrow_of_type_decl f d y in
432 ++ Ast_helper.(Vb.mk (Pat.constraint_ v y) e)
433 ++
434 ++let read_str_wrap d e =
435 ++ let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]]
436 ++ and suffix = "of_json" in
437 ++ let y = f (Ppx_deriving.core_type_of_type_decl d) in
438 ++ fun_str_wrap d e y ~f ~suffix
439 ++
440 ++let read_tag_str_wrap d e =
441 ++ let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]]
442 ++ and suffix = "of_json_with_tag"
443 ++ and y =
444 ++ let y = Ppx_deriving.core_type_of_type_decl d in
445 ++ [%type: Deriving_Json_lexer.lexbuf ->
446 ++ [`NCst of int | `Cst of int] -> [%t y]]
447 ++ in
448 ++ fun_str_wrap d e y ~f ~suffix
449 ++
450 ++let write_str_wrap d e =
451 ++ let f y = [%type: Buffer.t -> [%t y] -> unit]
452 ++ and suffix = "to_json" in
453 ++ let y =
454 ++ let y = Ppx_deriving.core_type_of_type_decl d in
455 ++ (match d with
456 ++ | {ptype_manifest =
457 ++ Some {ptyp_desc = Parsetree.Ptyp_variant (_, _, _)}} ->
458 ++ [%type: [> [%t y]]]
459 ++ | _ ->
460 ++ y) |> f
461 ++ in
462 ++ fun_str_wrap d e y ~f ~suffix
463 ++
464 ++let recognize_str_wrap d e =
465 ++ let v = suffix_decl_p d ~suffix:"recognize"
466 ++ and y = [%type: [`NCst of int | `Cst of int] -> bool] in
467 ++ Ast_helper.(Vb.mk (Pat.constraint_ v y) e)
468 ++
469 ++let json_poly_type d =
470 ++ let f y = [%type: [%t y] Deriving_Json.t] in
471 ++ let y = f (Ppx_deriving.core_type_of_type_decl d) in
472 ++ Ppx_deriving.poly_arrow_of_type_decl f d y
473 ++
474 ++let json_str_wrap d e =
475 ++ let v = suffix_decl_p d ~suffix:"json"
476 ++ and e = Ppx_deriving.(poly_fun_of_type_decl d e)
477 ++ and y = json_poly_type d in
478 ++ Ast_helper.(Vb.mk (Pat.constraint_ v y) e)
479 ++
480 ++let json_str d =
481 ++ let write =
482 ++ let f acc id =
483 ++ let poly = Ast_convenience.evar ("poly_" ^ id) in
484 ++ [%expr [%e acc] (Deriving_Json.write [%e poly])]
485 ++ and acc = suffix_decl d ~suffix:"to_json" in
486 ++ Ppx_deriving.fold_left_type_decl f acc d
487 ++ and read =
488 ++ let f acc id =
489 ++ let poly = Ast_convenience.evar ("poly_" ^ id) in
490 ++ [%expr [%e acc] (Deriving_Json.read [%e poly])]
491 ++ and acc = suffix_decl d ~suffix:"of_json" in
492 ++ Ppx_deriving.fold_left_type_decl f acc d
493 ++ in
494 ++ [%expr Deriving_Json.make [%e write] [%e read]] |>
495 ++ json_str_wrap d
496 ++
497 ++let write_decl_of_type d y =
498 ++ (let e =
499 ++ let arg = Ast_convenience.evar "a" in
500 ++ write_body_of_type y ~arg ~poly:true
501 ++ in
502 ++ [%expr fun buf a -> [%e e]]) |> write_str_wrap d
503 ++
504 ++let read_decl_of_type decl y =
505 ++ read_body_of_type y ~decl |> buf_expand |> read_str_wrap decl
506 ++
507 ++let json_decls_of_type decl y =
508 ++ let recognize, read_tag =
509 ++ match y with
510 ++ | { Parsetree.ptyp_desc = Ptyp_variant (l, _, _);
511 ++ ptyp_loc = loc } ->
512 ++ Some (recognize_body_of_poly_variant l ~loc
513 ++ |> recognize_str_wrap decl),
514 ++ Some (read_of_poly_variant l y ~decl ~loc
515 ++ |> read_tag_str_wrap decl)
516 ++ | _ ->
517 ++ None, None
518 ++ in
519 ++ write_decl_of_type decl y,
520 ++ read_decl_of_type decl y,
521 ++ json_str decl,
522 ++ recognize, read_tag
523 ++
524 ++let write_case (i, i', l) {Parsetree.pcd_name; pcd_args; pcd_loc} =
525 ++ let i, i', lhs, rhs =
526 ++ match pcd_args with
527 ++#if OCAML_VERSION >= (4, 03, 0)
528 ++ | Pcstr_tuple [] | Pcstr_record [] ->
529 ++#else
530 ++ | [] ->
531 ++#endif
532 ++ i + 1,
533 ++ i',
534 ++ None,
535 ++ [%expr Deriving_Json.Json_int.write buf
536 ++ [%e Ast_convenience.int i]]
537 ++#if OCAML_VERSION >= (4, 03, 0)
538 ++ | Pcstr_tuple ([ _ ] as args) ->
539 ++#else
540 ++ | [ _ ] as args ->
541 ++#endif
542 ++ let v = Ppx_deriving.fresh_var [] in
543 ++ i,
544 ++ i' + 1,
545 ++ Some (Ast_convenience.pvar v),
546 ++ write_tuple_contents [v] args ~tag:i' ~poly:true
547 ++#if OCAML_VERSION >= (4, 03, 0)
548 ++ | Pcstr_tuple args ->
549 ++#else
550 ++ | args ->
551 ++#endif
552 ++ let vars = fresh_vars (List.length args) in
553 ++ i,
554 ++ i' + 1,
555 ++ Some (var_ptuple vars),
556 ++ write_tuple_contents vars args ~tag:i' ~poly:true
557 ++#if OCAML_VERSION >= (4, 03, 0)
558 ++ | Pcstr_record args ->
559 ++ let vars = fresh_vars (List.length args) in
560 ++ i,
561 ++ i' + 1,
562 ++ Some (var_ptuple vars),
563 ++ write_of_record vars args ~tag:i'
564 ++#endif
565 ++ in
566 ++ i, i',
567 ++ Ast_helper.
568 ++ (Exp.case (Pat.construct (label_of_constructor pcd_name) lhs)
569 ++ rhs) :: l
570 ++
571 ++let write_decl_of_variant d l =
572 ++ (let _, _, l = List.fold_left write_case (0, 0, []) l in
573 ++ Ast_helper.Exp.function_ l) |> buf_expand |>
574 ++ write_str_wrap d
575 ++
576 ++let read_case ?decl (i, i', l)
577 ++ {Parsetree.pcd_name; pcd_args; pcd_loc} =
578 ++ match pcd_args with
579 ++#if OCAML_VERSION >= (4, 03, 0)
580 ++ | Pcstr_tuple [] | Pcstr_record [] ->
581 ++#else
582 ++ | [] ->
583 ++#endif
584 ++ i + 1, i',
585 ++ Ast_helper.Exp.case
586 ++ [%pat? `Cst [%p Ast_convenience.pint i]]
587 ++ (Ast_helper.Exp.construct (label_of_constructor pcd_name) None)
588 ++ :: l
589 ++#if OCAML_VERSION >= (4, 03, 0)
590 ++ | Pcstr_tuple pcd_args ->
591 ++#else
592 ++ | pcd_args ->
593 ++#endif
594 ++ let f l =
595 ++ let args =
596 ++ match l with
597 ++ | [] -> None
598 ++ | [e] -> Some e
599 ++ | l -> Some (Ast_helper.Exp.tuple l)
600 ++ in Ast_helper.Exp.construct (label_of_constructor pcd_name) args
601 ++ in
602 ++ let expr = read_tuple_contents ?decl pcd_args ~f in
603 ++ let case = Ast_helper.Exp.case [%pat? `NCst [%p Ast_convenience.pint i']] expr in
604 ++ i, i' + 1, case :: l
605 ++#if OCAML_VERSION >= (4, 03, 0)
606 ++ | Pcstr_record pcd_args ->
607 ++ let expr = read_of_record_raw ?decl pcd_args in
608 ++ let case = Ast_helper.Exp.case [%pat? `NCst [%p Ast_convenience.pint i']] expr in
609 ++ i, i' + 1, case :: l
610 ++#endif
611 ++
612 ++let read_decl_of_variant decl l =
613 ++ (let _, _, l = List.fold_left (read_case ~decl) (0, 0, []) l
614 ++ and e = [%expr Deriving_Json_lexer.read_case buf] in
615 ++ Ast_helper.Exp.match_ e (l @ [tag_error_case ()])) |>
616 ++ buf_expand |>
617 ++ read_str_wrap decl
618 ++
619 ++let json_decls_of_variant d l =
620 ++ write_decl_of_variant d l, read_decl_of_variant d l, json_str d,
621 ++ None, None
622 ++
623 ++let write_decl_of_record d l =
624 ++ write_of_record d l |> write_str_wrap d
625 ++
626 ++let read_decl_of_record d l =
627 ++ read_of_record d l |> read_str_wrap d
628 ++
629 ++let json_decls_of_record d l =
630 ++ check_record_fields l;
631 ++ write_decl_of_record d l, read_decl_of_record d l, json_str d,
632 ++ None, None
633 ++
634 ++let json_str_of_decl ({Parsetree.ptype_loc} as d) =
635 ++ Ast_helper.with_default_loc ptype_loc @@ fun () ->
636 ++ match d with
637 ++ | { Parsetree.ptype_manifest = Some y } ->
638 ++ json_decls_of_type d y
639 ++ | { ptype_kind = Ptype_variant l } ->
640 ++ json_decls_of_variant d l
641 ++ | { ptype_kind = Ptype_record l } ->
642 ++ json_decls_of_record d l
643 ++ | _ ->
644 ++ Location.raise_errorf "%s cannot be derived for %s" deriver
645 ++ (Ppx_deriving.mangle_type_decl (`Suffix "") d)
646 ++
647 ++let read_sig_of_decl ({Parsetree.ptype_loc} as d) =
648 ++ (let s =
649 ++ let s = Ppx_deriving.mangle_type_decl (`Suffix "of_json") d in
650 ++ Location.mkloc s ptype_loc
651 ++ and y =
652 ++ let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]] in
653 ++ let y = f (Ppx_deriving.core_type_of_type_decl d) in
654 ++ Ppx_deriving.poly_arrow_of_type_decl f d y
655 ++ in
656 ++ Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
657 ++
658 ++let recognize_sig_of_decl ({Parsetree.ptype_loc} as d) =
659 ++ (let s =
660 ++ let s = Ppx_deriving.mangle_type_decl (`Suffix "recognize") d in
661 ++ Location.mkloc s ptype_loc
662 ++ and y = [%type: [ `NCst of int | `Cst of int ] -> bool] in
663 ++ Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
664 ++
665 ++let read_with_tag_sig_of_decl ({Parsetree.ptype_loc} as d) =
666 ++ (let s =
667 ++ let s =
668 ++ Ppx_deriving.mangle_type_decl (`Suffix "of_json_with_tag") d
669 ++ in
670 ++ Location.mkloc s ptype_loc
671 ++ and y =
672 ++ let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]] in
673 ++ let y =
674 ++ let y = Ppx_deriving.core_type_of_type_decl d in
675 ++ f [%type: [ `NCst of int | `Cst of int ] -> [%t y]]
676 ++ in
677 ++ Ppx_deriving.poly_arrow_of_type_decl f d y
678 ++ in
679 ++ Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
680 ++
681 ++let write_sig_of_decl ({Parsetree.ptype_loc} as d) =
682 ++ (let s =
683 ++ let s = Ppx_deriving.mangle_type_decl (`Suffix "to_json") d in
684 ++ Location.mkloc s ptype_loc
685 ++ and y =
686 ++ let f y = [%type: Buffer.t -> [%t y] -> unit] in
687 ++ let y = f (Ppx_deriving.core_type_of_type_decl d) in
688 ++ Ppx_deriving.poly_arrow_of_type_decl f d y
689 ++ in
690 ++ Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
691 ++
692 ++let json_sig_of_decl ({Parsetree.ptype_loc} as d) =
693 ++ (let s =
694 ++ let s = Ppx_deriving.mangle_type_decl (`Suffix "json") d in
695 ++ Location.mkloc s ptype_loc
696 ++ and y =
697 ++ let f y = [%type: [%t y] Deriving_Json.t] in
698 ++ let y = f (Ppx_deriving.core_type_of_type_decl d) in
699 ++ Ppx_deriving.poly_arrow_of_type_decl f d y
700 ++ in
701 ++ Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
702 ++
703 ++let sigs_of_decl ({Parsetree.ptype_loc} as d) =
704 ++ Ast_helper.with_default_loc ptype_loc @@ fun () ->
705 ++ let l = [
706 ++ read_sig_of_decl d;
707 ++ write_sig_of_decl d;
708 ++ json_sig_of_decl d
709 ++ ] in
710 ++ match d with
711 ++ | { Parsetree.ptype_manifest =
712 ++ Some {Parsetree.ptyp_desc = Parsetree.Ptyp_variant _}} ->
713 ++ read_with_tag_sig_of_decl d :: recognize_sig_of_decl d :: l
714 ++ | _ ->
715 ++ l
716 ++
717 ++let register_for_expr s f =
718 ++ let core_type ({Parsetree.ptyp_loc} as y) =
719 ++ let f () = f y |> sanitize in
720 ++ Ast_helper.with_default_loc ptyp_loc f
721 ++ in
722 ++ Ppx_deriving.(create s ~core_type () |> register)
723 ++
724 ++let _ =
725 ++ register_for_expr "of_json" @@ fun y -> [%expr
726 ++ fun s ->
727 ++ [%e read_of_type y]
728 ++ (Deriving_Json_lexer.init_lexer (Lexing.from_string s))]
729 ++
730 ++let _ =
731 ++ register_for_expr "to_json" @@ fun y -> [%expr
732 ++ fun x ->
733 ++ let buf = Buffer.create 50 in
734 ++ [%e write_of_type y ~poly:false] buf x;
735 ++ Buffer.contents buf]
736 ++
737 ++let _ =
738 ++ let core_type ({Parsetree.ptyp_loc} as y) =
739 ++ let f () = json_of_type y |> sanitize in
740 ++ Ast_helper.with_default_loc ptyp_loc f
741 ++ and type_decl_str ~options ~path l =
742 ++ let lw, lr, lj, lp, lrv =
743 ++ let f d (lw, lr, lj, lp, lrv) =
744 ++ let w, r, j, p, rv = json_str_of_decl d in
745 ++ w :: lw, r :: lr, j :: lj,
746 ++ (match p with Some p -> p :: lp | None -> lp),
747 ++ (match rv with Some rv -> rv :: lrv | None -> lrv)
748 ++ and acc = [], [], [], [], [] in
749 ++ List.fold_right f l acc
750 ++ and f = Ast_helper.Str.value Asttypes.Recursive
751 ++ and f' = Ast_helper.Str.value Asttypes.Nonrecursive in
752 ++ let l = [f (lrv @ lr); f lw; f' lj] in
753 ++ match lp with [] -> l | _ -> f lp :: l
754 ++ and type_decl_sig ~options ~path l =
755 ++ List.map sigs_of_decl l |> List.flatten
756 ++ in
757 ++ Ppx_deriving.
758 ++ (create "json" ~core_type ~type_decl_str ~type_decl_sig ()
759 ++ |> register)
760 +diff --git a/lib/ppx/ppx_deriving_json.ml b/lib/ppx/ppx_deriving_json.ml
761 +deleted file mode 100644
762 +index e96ce3f..0000000
763 +--- a/lib/ppx/ppx_deriving_json.ml
764 ++++ /dev/null
765 +@@ -1,675 +0,0 @@
766 +-(* Js_of_ocaml
767 +- * http://www.ocsigen.org
768 +- * Copyright Vasilis Papavasileiou 2015
769 +- *
770 +- * This program is free software; you can redistribute it and/or modify
771 +- * it under the terms of the GNU Lesser General Public License as published by
772 +- * the Free Software Foundation, with linking exception;
773 +- * either version 2.1 of the License, or (at your option) any later version.
774 +- *
775 +- * This program is distributed in the hope that it will be useful,
776 +- * but WITHOUT ANY WARRANTY; without even the implied warranty of
777 +- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
778 +- * GNU Lesser General Public License for more details.
779 +- *
780 +- * You should have received a copy of the GNU Lesser General Public License
781 +- * along with this program; if not, write to the Free Software
782 +- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
783 +- *)
784 +-
785 +-let deriver = "json"
786 +-
787 +-(* Copied (and adapted) this from ppx_deriving repo (commit
788 +- e2079fa8f3460055bf990461f295c6c4b391fafc) ; we get an empty set of
789 +- let bindings with ppx_deriving 3.0 *)
790 +-let sanitize expr = [%expr
791 +- (let open! Ppx_deriving_runtime in [%e expr]) [@ocaml.warning "-A"]]
792 +-
793 +-let var_ptuple l =
794 +- List.map Ast_convenience.pvar l |> Ast_helper.Pat.tuple
795 +-
796 +-let map_loc f {Location.txt; loc} =
797 +- {Location.txt = f txt; loc}
798 +-
799 +-let suffix_lid {Location.txt; loc} ~suffix =
800 +- let txt = Ppx_deriving.mangle_lid (`Suffix suffix) txt in
801 +- Ast_helper.Exp.ident {txt; loc} ~loc
802 +-
803 +-let suffix_decl ({Parsetree.ptype_loc = loc} as d) ~suffix =
804 +- (let s =
805 +- Ppx_deriving.mangle_type_decl (`Suffix suffix) d |>
806 +- Longident.parse
807 +- in
808 +- Location.mkloc s loc) |> Ast_helper.Exp.ident ~loc
809 +-
810 +-let suffix_decl_p ({Parsetree.ptype_loc = loc} as d) ~suffix =
811 +- (let s = Ppx_deriving.mangle_type_decl (`Suffix suffix) d in
812 +- Location.mkloc s loc) |> Ast_helper.Pat.var ~loc
813 +-
814 +-let rec fresh_vars ?(acc = []) n =
815 +- if n <= 0 then
816 +- List.rev acc
817 +- else
818 +- let acc = Ppx_deriving.fresh_var acc :: acc in
819 +- fresh_vars ~acc (n - 1)
820 +-
821 +-let unreachable_case () =
822 +- Ast_helper.Exp.case [%pat? _ ] [%expr assert false]
823 +-
824 +-let label_of_constructor = map_loc (fun c -> Longident.Lident c)
825 +-
826 +-let wrap_write r ~pattern = [%expr fun buf [%p pattern] -> [%e r]]
827 +-
828 +-let buf_expand r = [%expr fun buf -> [%e r]]
829 +-
830 +-let seqlist = function
831 +- | h :: l ->
832 +- let f acc e = [%expr [%e acc]; [%e e]] in
833 +- List.fold_left f h l
834 +- | [] ->
835 +- [%expr ()]
836 +-
837 +-let check_record_fields =
838 +- List.iter @@ function
839 +- | {Parsetree.pld_mutable = Mutable} ->
840 +- Location.raise_errorf
841 +- "%s cannot be derived for mutable records" deriver
842 +- | {pld_type = {ptyp_desc = Ptyp_poly _}} ->
843 +- Location.raise_errorf
844 +- "%s cannot be derived for polymorphic records" deriver
845 +- | _ ->
846 +- ()
847 +-
848 +-let maybe_tuple_type = function
849 +- | [y] -> y
850 +- | l -> Ast_helper.Typ.tuple l
851 +-
852 +-let rec write_tuple_contents l ly tag ~poly =
853 +- let e =
854 +- let f v y =
855 +- let arg = Ast_convenience.evar v in
856 +- let e = write_body_of_type y ~arg ~poly in
857 +- [%expr Buffer.add_string buf ","; [%e e]]
858 +- in
859 +- List.map2 f l ly |> seqlist
860 +- and s = Ast_convenience.str ("[" ^ string_of_int tag) in [%expr
861 +- Buffer.add_string buf [%e s];
862 +- [%e e];
863 +- Buffer.add_string buf "]"]
864 +-
865 +-and write_body_of_tuple_type l ~arg ~poly ~tag =
866 +- let n = List.length l in
867 +- let vars = fresh_vars n in
868 +- let e = write_tuple_contents vars l tag ~poly
869 +- and p = var_ptuple vars in
870 +- [%expr let [%p p] = [%e arg] in [%e e]]
871 +-
872 +-and write_poly_case r ~arg ~poly =
873 +- match r with
874 +- | Parsetree.Rtag (label, _, _, l) ->
875 +- let i = Ppx_deriving.hash_variant label
876 +- and n = List.length l in
877 +- let v = Ppx_deriving.fresh_var [] in
878 +- let lhs =
879 +- (if n = 0 then None else Some (Ast_convenience.pvar v)) |>
880 +- Ast_helper.Pat.variant label
881 +- and rhs =
882 +- match l with
883 +- | [] ->
884 +- let e = Ast_convenience.int i in
885 +- [%expr Deriving_Json.Json_int.write buf [%e e]]
886 +- | _ ->
887 +- let l = [[%type: int]; maybe_tuple_type l]
888 +- and arg = Ast_helper.Exp.tuple Ast_convenience.[int i; evar v] in
889 +- write_body_of_tuple_type l ~arg ~poly ~tag:0
890 +- in
891 +- Ast_helper.Exp.case lhs rhs
892 +- | Rinherit ({ptyp_desc = Ptyp_constr (lid, _)} as y) ->
893 +- Ast_helper.Exp.case (Ast_helper.Pat.type_ lid)
894 +- (write_body_of_type y ~arg ~poly)
895 +- | Rinherit {ptyp_loc} ->
896 +- Location.raise_errorf ~loc:ptyp_loc
897 +- "%s write case cannot be derived" deriver
898 +-
899 +-and write_body_of_type y ~arg ~poly =
900 +- match y with
901 +- | [%type: unit] ->
902 +- [%expr Deriving_Json.Json_unit.write buf [%e arg]]
903 +- | [%type: int] ->
904 +- [%expr Deriving_Json.Json_int.write buf [%e arg]]
905 +- | [%type: int32] | [%type: Int32.t] ->
906 +- [%expr Deriving_Json.Json_int32.write buf [%e arg]]
907 +- | [%type: int64] | [%type: Int64.t] ->
908 +- [%expr Deriving_Json.Json_int64.write buf [%e arg]]
909 +- | [%type: nativeint] | [%type: Nativeint.t] ->
910 +- [%expr Deriving_Json.Json_nativeint.write buf [%e arg]]
911 +- | [%type: float] ->
912 +- [%expr Deriving_Json.Json_float.write buf [%e arg]]
913 +- | [%type: bool] ->
914 +- [%expr Deriving_Json.Json_bool.write buf [%e arg]]
915 +- | [%type: char] ->
916 +- [%expr Deriving_Json.Json_char.write buf [%e arg]]
917 +- | [%type: string] ->
918 +- [%expr Deriving_Json.Json_string.write buf [%e arg]]
919 +- | [%type: bytes] ->
920 +- [%expr Deriving_Json.Json_bytes.write buf [%e arg]]
921 +- | [%type: [%t? y] list] ->
922 +- let e = write_of_type y ~poly in
923 +- [%expr Deriving_Json.write_list [%e e] buf [%e arg]]
924 +- | [%type: [%t? y] ref] ->
925 +- let e = write_of_type y ~poly in
926 +- [%expr Deriving_Json.write_ref [%e e] buf [%e arg]]
927 +- | [%type: [%t? y] option] ->
928 +- let e = write_of_type y ~poly in
929 +- [%expr Deriving_Json.write_option [%e e] buf [%e arg]]
930 +- | [%type: [%t? y] array] ->
931 +- let e = write_of_type y ~poly in
932 +- [%expr Deriving_Json.write_array [%e e] buf [%e arg]]
933 +- | { Parsetree.ptyp_desc = Ptyp_var v } when poly ->
934 +- [%expr [%e Ast_convenience.evar ("poly_" ^ v)] buf [%e arg]]
935 +- | { Parsetree.ptyp_desc = Ptyp_tuple l } ->
936 +- write_body_of_tuple_type l ~arg ~poly ~tag:0
937 +- | { Parsetree.ptyp_desc = Ptyp_variant (l, _, _); ptyp_loc = loc } ->
938 +- List.map (write_poly_case ~arg ~poly) l @ [unreachable_case ()] |>
939 +- Ast_helper.Exp.match_ arg
940 +- | { Parsetree.ptyp_desc = Ptyp_constr (lid, l) } ->
941 +- let e = suffix_lid lid ~suffix:"to_json"
942 +- and l = List.map (write_of_type ~poly) l in
943 +- [%expr [%e Ast_convenience.app e l] buf [%e arg]]
944 +- | { Parsetree.ptyp_loc } ->
945 +- Location.raise_errorf ~loc:ptyp_loc
946 +- "%s_write cannot be derived for %s"
947 +- deriver (Ppx_deriving.string_of_core_type y)
948 +-
949 +-and write_of_type y ~poly =
950 +- let v = "a" in
951 +- let arg = Ast_convenience.evar v
952 +- and pattern = Ast_convenience.pvar v in
953 +- wrap_write (write_body_of_type y ~arg ~poly) ~pattern
954 +-
955 +-and write_of_record d l =
956 +- let pattern =
957 +- let l =
958 +- let f {Parsetree.pld_name} =
959 +- label_of_constructor pld_name,
960 +- Ast_helper.Pat.var pld_name
961 +- in
962 +- List.map f l
963 +- in
964 +- Ast_helper.Pat.record l Asttypes.Closed
965 +- and e =
966 +- let l =
967 +- let f {Parsetree.pld_name = {txt}} = txt in
968 +- List.map f l
969 +- and ly =
970 +- let f {Parsetree.pld_type} = pld_type in
971 +- List.map f l
972 +- in
973 +- write_tuple_contents l ly 0 ~poly:true
974 +- in
975 +- wrap_write e ~pattern
976 +-
977 +-let recognize_case_of_constructor i l =
978 +- let lhs =
979 +- match l with
980 +- | [] -> [%pat? `Cst [%p Ast_convenience.pint i]]
981 +- | _ -> [%pat? `NCst [%p Ast_convenience.pint i]]
982 +- in
983 +- Ast_helper.Exp.case lhs [%expr true]
984 +-
985 +-let recognize_body_of_poly_variant l ~loc =
986 +- let l =
987 +- let f = function
988 +- | Parsetree.Rtag (label, _, _, l) ->
989 +- let i = Ppx_deriving.hash_variant label in
990 +- recognize_case_of_constructor i l
991 +- | Rinherit {ptyp_desc = Ptyp_constr (lid, _)} ->
992 +- let guard = [%expr [%e suffix_lid lid ~suffix:"recognize"] x] in
993 +- Ast_helper.Exp.case ~guard [%pat? x] [%expr true]
994 +- | _ ->
995 +- Location.raise_errorf ~loc
996 +- "%s_recognize cannot be derived" deriver
997 +- and default = Ast_helper.Exp.case [%pat? _] [%expr false] in
998 +- List.map f l @ [default]
999 +- in
1000 +- Ast_helper.Exp.function_ l
1001 +-
1002 +-let tag_error_case ?(typename="") () =
1003 +- let y = Ast_convenience.str typename in
1004 +- Ast_helper.Exp.case
1005 +- [%pat? _]
1006 +- [%expr Deriving_Json_lexer.tag_error ~typename:[%e y] buf]
1007 +-
1008 +-let maybe_tuple_type = function
1009 +- | [y] -> y
1010 +- | l -> Ast_helper.Typ.tuple l
1011 +-
1012 +-let rec read_poly_case ?decl y = function
1013 +- | Parsetree.Rtag (label, _, _, l) ->
1014 +- let i = Ppx_deriving.hash_variant label |> Ast_convenience.pint in
1015 +- (match l with
1016 +- | [] ->
1017 +- Ast_helper.Exp.case [%pat? `Cst [%p i]]
1018 +- (Ast_helper.Exp.variant label None)
1019 +- | l ->
1020 +- Ast_helper.Exp.case [%pat? `NCst [%p i]] [%expr
1021 +- Deriving_Json_lexer.read_comma buf;
1022 +- let v = [%e read_body_of_type ?decl (maybe_tuple_type l)] in
1023 +- Deriving_Json_lexer.read_rbracket buf;
1024 +- [%e Ast_helper.Exp.variant label (Some [%expr v])]])
1025 +- | Rinherit {ptyp_desc = Ptyp_constr (lid, l)} ->
1026 +- let guard = [%expr [%e suffix_lid lid ~suffix:"recognize"] x]
1027 +- and e =
1028 +- let e = suffix_lid lid ~suffix:"of_json_with_tag"
1029 +- and l = List.map (read_of_type ?decl) l in
1030 +- [%expr ([%e Ast_convenience.app e l] buf x :> [%t y])]
1031 +- in
1032 +- Ast_helper.Exp.case ~guard [%pat? x] e
1033 +- | Rinherit {ptyp_loc} ->
1034 +- Location.raise_errorf ~loc:ptyp_loc
1035 +- "%s read case cannot be derived" deriver
1036 +-
1037 +-and read_of_poly_variant ?decl l y ~loc =
1038 +- List.map (read_poly_case ?decl y) l @ [tag_error_case ()] |>
1039 +- Ast_helper.Exp.function_ |>
1040 +- buf_expand
1041 +-
1042 +-and read_tuple_contents ?decl l ~f =
1043 +- let n = List.length l in
1044 +- let lv = fresh_vars n in
1045 +- let f v y acc =
1046 +- let e = read_body_of_type ?decl y in [%expr
1047 +- Deriving_Json_lexer.read_comma buf;
1048 +- let [%p Ast_convenience.pvar v] = [%e e] in
1049 +- [%e acc]]
1050 +- and acc = List.map Ast_convenience.evar lv |> f in
1051 +- let acc = [%expr Deriving_Json_lexer.read_rbracket buf; [%e acc]] in
1052 +- List.fold_right2 f lv l acc
1053 +-
1054 +-and read_body_of_tuple_type ?decl l = [%expr
1055 +- Deriving_Json_lexer.read_lbracket buf;
1056 +- ignore (Deriving_Json_lexer.read_tag_1 0 buf);
1057 +- [%e read_tuple_contents ?decl l ~f:Ast_helper.Exp.tuple]]
1058 +-
1059 +-and read_of_record decl l =
1060 +- let e =
1061 +- let f =
1062 +- let f {Parsetree.pld_name} e = label_of_constructor pld_name, e in
1063 +- fun l' -> Ast_helper.Exp.record (List.map2 f l l') None
1064 +- and l =
1065 +- let f {Parsetree.pld_type} = pld_type in
1066 +- List.map f l
1067 +- in
1068 +- read_tuple_contents l ~decl ~f
1069 +- in [%expr
1070 +- Deriving_Json_lexer.read_lbracket buf;
1071 +- ignore (Deriving_Json_lexer.read_tag_2 0 254 buf);
1072 +- [%e e]] |> buf_expand
1073 +-
1074 +-and read_body_of_type ?decl y =
1075 +- let poly = match decl with Some _ -> true | _ -> false in
1076 +- match y with
1077 +- | [%type: unit] ->
1078 +- [%expr Deriving_Json.Json_unit.read buf]
1079 +- | [%type: int] ->
1080 +- [%expr Deriving_Json.Json_int.read buf]
1081 +- | [%type: int32] | [%type: Int32.t] ->
1082 +- [%expr Deriving_Json.Json_int32.read buf]
1083 +- | [%type: int64] | [%type: Int64.t] ->
1084 +- [%expr Deriving_Json.Json_int64.read buf]
1085 +- | [%type: nativeint] | [%type: Nativeint.t] ->
1086 +- [%expr Deriving_Json.Json_nativeint.read buf]
1087 +- | [%type: float] ->
1088 +- [%expr Deriving_Json.Json_float.read buf]
1089 +- | [%type: bool] ->
1090 +- [%expr Deriving_Json.Json_bool.read buf]
1091 +- | [%type: char] ->
1092 +- [%expr Deriving_Json.Json_char.read buf]
1093 +- | [%type: string] ->
1094 +- [%expr Deriving_Json.Json_string.read buf]
1095 +- | [%type: bytes] ->
1096 +- [%expr Deriving_Json.Json_bytes.read buf]
1097 +- | [%type: [%t? y] list] ->
1098 +- [%expr Deriving_Json.read_list [%e read_of_type ?decl y] buf]
1099 +- | [%type: [%t? y] ref] ->
1100 +- [%expr Deriving_Json.read_ref [%e read_of_type ?decl y] buf]
1101 +- | [%type: [%t? y] option] ->
1102 +- [%expr Deriving_Json.read_option [%e read_of_type ?decl y] buf]
1103 +- | [%type: [%t? y] array] ->
1104 +- [%expr Deriving_Json.read_array [%e read_of_type ?decl y] buf]
1105 +- | { Parsetree.ptyp_desc = Ptyp_tuple l } ->
1106 +- read_body_of_tuple_type l ?decl
1107 +- | { Parsetree.ptyp_desc = Ptyp_variant (l, _, _); ptyp_loc = loc } ->
1108 +- let e =
1109 +- (match decl with
1110 +- | Some decl ->
1111 +- let e = suffix_decl decl ~suffix:"of_json_with_tag"
1112 +- and l =
1113 +- let {Parsetree.ptype_params = l} = decl
1114 +- and f (y, _) = read_of_type y ~decl in
1115 +- List.map f l
1116 +- in
1117 +- Ast_convenience.app e l
1118 +- | None ->
1119 +- read_of_poly_variant l y ~loc)
1120 +- and tag = [%expr Deriving_Json_lexer.read_vcase buf] in
1121 +- [%expr [%e e] buf [%e tag]]
1122 +- | { Parsetree.ptyp_desc = Ptyp_var v } when poly ->
1123 +- [%expr [%e Ast_convenience.evar ("poly_" ^ v)] buf]
1124 +- | { Parsetree.ptyp_desc = Ptyp_constr (lid, l) } ->
1125 +- let e = suffix_lid lid ~suffix:"of_json"
1126 +- and l = List.map (read_of_type ?decl) l in
1127 +- [%expr [%e Ast_convenience.app e l] buf]
1128 +- | { Parsetree.ptyp_loc } ->
1129 +- Location.raise_errorf ~loc:ptyp_loc
1130 +- "%s_read cannot be derived for %s" deriver
1131 +- (Ppx_deriving.string_of_core_type y)
1132 +-
1133 +-and read_of_type ?decl y =
1134 +- read_body_of_type ?decl y |> buf_expand
1135 +-
1136 +-let json_of_type ?decl y =
1137 +- let read = read_of_type ?decl y
1138 +- and write =
1139 +- let poly = match decl with Some _ -> true | _ -> false in
1140 +- write_of_type y ~poly in
1141 +- [%expr Deriving_Json.make [%e write] [%e read]]
1142 +-
1143 +-let fun_str_wrap d e y ~f ~suffix =
1144 +- let e = Ppx_deriving.poly_fun_of_type_decl d e |> sanitize
1145 +- and v = suffix_decl_p d ~suffix
1146 +- and y = Ppx_deriving.poly_arrow_of_type_decl f d y in
1147 +- Ast_helper.(Vb.mk (Pat.constraint_ v y) e)
1148 +-
1149 +-let read_str_wrap d e =
1150 +- let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]]
1151 +- and suffix = "of_json" in
1152 +- let y = f (Ppx_deriving.core_type_of_type_decl d) in
1153 +- fun_str_wrap d e y ~f ~suffix
1154 +-
1155 +-let read_tag_str_wrap d e =
1156 +- let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]]
1157 +- and suffix = "of_json_with_tag"
1158 +- and y =
1159 +- let y = Ppx_deriving.core_type_of_type_decl d in
1160 +- [%type: Deriving_Json_lexer.lexbuf ->
1161 +- [`NCst of int | `Cst of int] -> [%t y]]
1162 +- in
1163 +- fun_str_wrap d e y ~f ~suffix
1164 +-
1165 +-let write_str_wrap d e =
1166 +- let f y = [%type: Buffer.t -> [%t y] -> unit]
1167 +- and suffix = "to_json" in
1168 +- let y =
1169 +- let y = Ppx_deriving.core_type_of_type_decl d in
1170 +- (match d with
1171 +- | {ptype_manifest =
1172 +- Some {ptyp_desc = Parsetree.Ptyp_variant (_, _, _)}} ->
1173 +- [%type: [> [%t y]]]
1174 +- | _ ->
1175 +- y) |> f
1176 +- in
1177 +- fun_str_wrap d e y ~f ~suffix
1178 +-
1179 +-let recognize_str_wrap d e =
1180 +- let v = suffix_decl_p d ~suffix:"recognize"
1181 +- and y = [%type: [`NCst of int | `Cst of int] -> bool] in
1182 +- Ast_helper.(Vb.mk (Pat.constraint_ v y) e)
1183 +-
1184 +-let json_poly_type d =
1185 +- let f y = [%type: [%t y] Deriving_Json.t] in
1186 +- let y = f (Ppx_deriving.core_type_of_type_decl d) in
1187 +- Ppx_deriving.poly_arrow_of_type_decl f d y
1188 +-
1189 +-let json_str_wrap d e =
1190 +- let v = suffix_decl_p d ~suffix:"json"
1191 +- and e = Ppx_deriving.(poly_fun_of_type_decl d e)
1192 +- and y = json_poly_type d in
1193 +- Ast_helper.(Vb.mk (Pat.constraint_ v y) e)
1194 +-
1195 +-let json_str d =
1196 +- let write =
1197 +- let f acc id =
1198 +- let poly = Ast_convenience.evar ("poly_" ^ id) in
1199 +- [%expr [%e acc] (Deriving_Json.write [%e poly])]
1200 +- and acc = suffix_decl d ~suffix:"to_json" in
1201 +- Ppx_deriving.fold_left_type_decl f acc d
1202 +- and read =
1203 +- let f acc id =
1204 +- let poly = Ast_convenience.evar ("poly_" ^ id) in
1205 +- [%expr [%e acc] (Deriving_Json.read [%e poly])]
1206 +- and acc = suffix_decl d ~suffix:"of_json" in
1207 +- Ppx_deriving.fold_left_type_decl f acc d
1208 +- in
1209 +- [%expr Deriving_Json.make [%e write] [%e read]] |>
1210 +- json_str_wrap d
1211 +-
1212 +-let write_decl_of_type d y =
1213 +- (let e =
1214 +- let arg = Ast_convenience.evar "a" in
1215 +- write_body_of_type y ~arg ~poly:true
1216 +- in
1217 +- [%expr fun buf a -> [%e e]]) |> write_str_wrap d
1218 +-
1219 +-let read_decl_of_type decl y =
1220 +- read_body_of_type y ~decl |> buf_expand |> read_str_wrap decl
1221 +-
1222 +-let json_decls_of_type decl y =
1223 +- let recognize, read_tag =
1224 +- match y with
1225 +- | { Parsetree.ptyp_desc = Ptyp_variant (l, _, _);
1226 +- ptyp_loc = loc } ->
1227 +- Some (recognize_body_of_poly_variant l ~loc
1228 +- |> recognize_str_wrap decl),
1229 +- Some (read_of_poly_variant l y ~decl ~loc
1230 +- |> read_tag_str_wrap decl)
1231 +- | _ ->
1232 +- None, None
1233 +- in
1234 +- write_decl_of_type decl y,
1235 +- read_decl_of_type decl y,
1236 +- json_str decl,
1237 +- recognize, read_tag
1238 +-
1239 +-let write_case (i, i', l) {Parsetree.pcd_name; pcd_args; pcd_loc} =
1240 +- let n = List.length pcd_args in
1241 +- let vars = fresh_vars n in
1242 +- let i, i', lhs, rhs =
1243 +- match vars with
1244 +- | [] ->
1245 +- i + 1,
1246 +- i',
1247 +- None,
1248 +- [%expr Deriving_Json.Json_int.write buf
1249 +- [%e Ast_convenience.int i]]
1250 +- | [v] ->
1251 +- i,
1252 +- i' + 1,
1253 +- Some (Ast_convenience.pvar v),
1254 +- write_tuple_contents vars pcd_args i' ~poly:true
1255 +- | _ ->
1256 +- i,
1257 +- i' + 1,
1258 +- Some (var_ptuple vars),
1259 +- write_tuple_contents vars pcd_args i' ~poly:true
1260 +- in
1261 +- i, i',
1262 +- Ast_helper.
1263 +- (Exp.case (Pat.construct (label_of_constructor pcd_name) lhs)
1264 +- rhs) :: l
1265 +-
1266 +-let write_decl_of_variant d l =
1267 +- (let _, _, l = List.fold_left write_case (0, 0, []) l in
1268 +- Ast_helper.Exp.function_ l) |> buf_expand |>
1269 +- write_str_wrap d
1270 +-
1271 +-let read_case ?decl (i, i', l)
1272 +- {Parsetree.pcd_name; pcd_args; pcd_loc} =
1273 +- match pcd_args with
1274 +- | [] ->
1275 +- i + 1, i',
1276 +- Ast_helper.Exp.case
1277 +- [%pat? `Cst [%p Ast_convenience.pint i]]
1278 +- (Ast_helper.Exp.construct (label_of_constructor pcd_name) None)
1279 +- :: l
1280 +- | _ ->
1281 +- i, i' + 1,
1282 +- ((let f l =
1283 +- (match l with
1284 +- | [] -> None
1285 +- | [e] -> Some e
1286 +- | l -> Some (Ast_helper.Exp.tuple l)) |>
1287 +- Ast_helper.Exp.construct (label_of_constructor pcd_name)
1288 +- in
1289 +- read_tuple_contents ?decl pcd_args ~f) |>
1290 +- Ast_helper.Exp.case [%pat? `NCst [%p Ast_convenience.pint i']])
1291 +- :: l
1292 +-
1293 +-let read_decl_of_variant decl l =
1294 +- (let _, _, l = List.fold_left (read_case ~decl) (0, 0, []) l
1295 +- and e = [%expr Deriving_Json_lexer.read_case buf] in
1296 +- Ast_helper.Exp.match_ e (l @ [tag_error_case ()])) |>
1297 +- buf_expand |>
1298 +- read_str_wrap decl
1299 +-
1300 +-let json_decls_of_variant d l =
1301 +- write_decl_of_variant d l, read_decl_of_variant d l, json_str d,
1302 +- None, None
1303 +-
1304 +-let write_decl_of_record d l =
1305 +- write_of_record d l |> write_str_wrap d
1306 +-
1307 +-let read_decl_of_record d l =
1308 +- read_of_record d l |> read_str_wrap d
1309 +-
1310 +-let json_decls_of_record d l =
1311 +- check_record_fields l;
1312 +- write_decl_of_record d l, read_decl_of_record d l, json_str d,
1313 +- None, None
1314 +-
1315 +-let json_str_of_decl ({Parsetree.ptype_loc} as d) =
1316 +- Ast_helper.with_default_loc ptype_loc @@ fun () ->
1317 +- match d with
1318 +- | { Parsetree.ptype_manifest = Some y } ->
1319 +- json_decls_of_type d y
1320 +- | { ptype_kind = Ptype_variant l } ->
1321 +- json_decls_of_variant d l
1322 +- | { ptype_kind = Ptype_record l } ->
1323 +- json_decls_of_record d l
1324 +- | _ ->
1325 +- Location.raise_errorf "%s cannot be derived for %s" deriver
1326 +- (Ppx_deriving.mangle_type_decl (`Suffix "") d)
1327 +-
1328 +-let read_sig_of_decl ({Parsetree.ptype_loc} as d) =
1329 +- (let s =
1330 +- let s = Ppx_deriving.mangle_type_decl (`Suffix "of_json") d in
1331 +- Location.mkloc s ptype_loc
1332 +- and y =
1333 +- let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]] in
1334 +- let y = f (Ppx_deriving.core_type_of_type_decl d) in
1335 +- Ppx_deriving.poly_arrow_of_type_decl f d y
1336 +- in
1337 +- Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
1338 +-
1339 +-let recognize_sig_of_decl ({Parsetree.ptype_loc} as d) =
1340 +- (let s =
1341 +- let s = Ppx_deriving.mangle_type_decl (`Suffix "recognize") d in
1342 +- Location.mkloc s ptype_loc
1343 +- and y = [%type: [ `NCst of int | `Cst of int ] -> bool] in
1344 +- Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
1345 +-
1346 +-let read_with_tag_sig_of_decl ({Parsetree.ptype_loc} as d) =
1347 +- (let s =
1348 +- let s =
1349 +- Ppx_deriving.mangle_type_decl (`Suffix "of_json_with_tag") d
1350 +- in
1351 +- Location.mkloc s ptype_loc
1352 +- and y =
1353 +- let f y = [%type: Deriving_Json_lexer.lexbuf -> [%t y]] in
1354 +- let y =
1355 +- let y = Ppx_deriving.core_type_of_type_decl d in
1356 +- f [%type: [ `NCst of int | `Cst of int ] -> [%t y]]
1357 +- in
1358 +- Ppx_deriving.poly_arrow_of_type_decl f d y
1359 +- in
1360 +- Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
1361 +-
1362 +-let write_sig_of_decl ({Parsetree.ptype_loc} as d) =
1363 +- (let s =
1364 +- let s = Ppx_deriving.mangle_type_decl (`Suffix "to_json") d in
1365 +- Location.mkloc s ptype_loc
1366 +- and y =
1367 +- let f y = [%type: Buffer.t -> [%t y] -> unit] in
1368 +- let y = f (Ppx_deriving.core_type_of_type_decl d) in
1369 +- Ppx_deriving.poly_arrow_of_type_decl f d y
1370 +- in
1371 +- Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
1372 +-
1373 +-let json_sig_of_decl ({Parsetree.ptype_loc} as d) =
1374 +- (let s =
1375 +- let s = Ppx_deriving.mangle_type_decl (`Suffix "json") d in
1376 +- Location.mkloc s ptype_loc
1377 +- and y =
1378 +- let f y = [%type: [%t y] Deriving_Json.t] in
1379 +- let y = f (Ppx_deriving.core_type_of_type_decl d) in
1380 +- Ppx_deriving.poly_arrow_of_type_decl f d y
1381 +- in
1382 +- Ast_helper.Val.mk s y) |> Ast_helper.Sig.value
1383 +-
1384 +-let sigs_of_decl ({Parsetree.ptype_loc} as d) =
1385 +- Ast_helper.with_default_loc ptype_loc @@ fun () ->
1386 +- let l = [
1387 +- read_sig_of_decl d;
1388 +- write_sig_of_decl d;
1389 +- json_sig_of_decl d
1390 +- ] in
1391 +- match d with
1392 +- | { Parsetree.ptype_manifest =
1393 +- Some {Parsetree.ptyp_desc = Parsetree.Ptyp_variant _}} ->
1394 +- read_with_tag_sig_of_decl d :: recognize_sig_of_decl d :: l
1395 +- | _ ->
1396 +- l
1397 +-
1398 +-let register_for_expr s f =
1399 +- let core_type ({Parsetree.ptyp_loc} as y) =
1400 +- let f () = f y |> sanitize in
1401 +- Ast_helper.with_default_loc ptyp_loc f
1402 +- in
1403 +- Ppx_deriving.(create s ~core_type () |> register)
1404 +-
1405 +-let _ =
1406 +- register_for_expr "of_json" @@ fun y -> [%expr
1407 +- fun s ->
1408 +- [%e read_of_type y]
1409 +- (Deriving_Json_lexer.init_lexer (Lexing.from_string s))]
1410 +-
1411 +-let _ =
1412 +- register_for_expr "to_json" @@ fun y -> [%expr
1413 +- fun x ->
1414 +- let buf = Buffer.create 50 in
1415 +- [%e write_of_type y ~poly:false] buf x;
1416 +- Buffer.contents buf]
1417 +-
1418 +-let _ =
1419 +- let core_type ({Parsetree.ptyp_loc} as y) =
1420 +- let f () = json_of_type y |> sanitize in
1421 +- Ast_helper.with_default_loc ptyp_loc f
1422 +- and type_decl_str ~options ~path l =
1423 +- let lw, lr, lj, lp, lrv =
1424 +- let f d (lw, lr, lj, lp, lrv) =
1425 +- let w, r, j, p, rv = json_str_of_decl d in
1426 +- w :: lw, r :: lr, j :: lj,
1427 +- (match p with Some p -> p :: lp | None -> lp),
1428 +- (match rv with Some rv -> rv :: lrv | None -> lrv)
1429 +- and acc = [], [], [], [], [] in
1430 +- List.fold_right f l acc
1431 +- and f = Ast_helper.Str.value Asttypes.Recursive
1432 +- and f' = Ast_helper.Str.value Asttypes.Nonrecursive in
1433 +- let l = [f (lrv @ lr); f lw; f' lj] in
1434 +- match lp with [] -> l | _ -> f lp :: l
1435 +- and type_decl_sig ~options ~path l =
1436 +- List.map sigs_of_decl l |> List.flatten
1437 +- in
1438 +- Ppx_deriving.
1439 +- (create "json" ~core_type ~type_decl_str ~type_decl_sig ()
1440 +- |> register)
1441
1442 diff --git a/dev-ml/js_of_ocaml/js_of_ocaml-2.7.ebuild b/dev-ml/js_of_ocaml/js_of_ocaml-2.7.ebuild
1443 index 420e7ae..2de89b9 100644
1444 --- a/dev-ml/js_of_ocaml/js_of_ocaml-2.7.ebuild
1445 +++ b/dev-ml/js_of_ocaml/js_of_ocaml-2.7.ebuild
1446 @@ -31,6 +31,10 @@ RDEPEND="
1447 DEPEND="${RDEPEND}
1448 dev-ml/ocamlbuild"
1449
1450 +src_prepare() {
1451 + has_version '>=dev-lang/ocaml-4.03' && epatch "${FILESDIR}/oc43.patch"
1452 +}
1453 +
1454 src_configure() {
1455 printf "\n\n" >> Makefile.conf
1456 use ocamlopt || echo "BEST := byte" >> Makefile.conf