-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathcmjdump_main.ml
75 lines (69 loc) · 2.88 KB
/
cmjdump_main.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
(* start dumping *)
let f fmt = Printf.fprintf stdout fmt
let pp_cmj_case (case : Ext_js_file_kind.case) : unit =
f "%s\n"
("case : "
^
match case with
| Little -> "little"
| Upper -> "upper")
let pp_cmj
({values; pure; package_spec = npm_package_path; case} : Js_cmj_format.t) =
f "package info: %s\n"
(Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path);
pp_cmj_case case;
f "effect: %s\n" (if pure then "pure" else "not pure");
Ext_array.iter values (fun {name; arity; persistent_closed_lambda} ->
(match arity with
| Single arity -> (
f "%s: %s\n" name (Format.asprintf "%a" Lam_arity.print arity);
match persistent_closed_lambda with
| None -> f "%s: not saved\n" name
| Some lam ->
f "%s: ======[start]\n" name;
f "%s\n" (Lam_print.lambda_to_string lam);
f "%s: ======[finish]\n" name)
| Submodule xs ->
(match persistent_closed_lambda with
| None -> f "%s: not saved\n" name
| Some lam ->
f "%s: ======[start]\n" name;
f "%s" (Lam_print.lambda_to_string lam);
f "%s: ======[finish]\n" name);
Array.iteri
(fun i arity ->
f "%s[%i] : %s \n" name i
(Format.asprintf "%a" Lam_arity.print arity))
xs);
f "\n")
let () =
match Sys.argv with
| [|_; file|] ->
let cmj, digest = Js_cmj_format.from_file_with_digest file in
Format.fprintf Format.std_formatter "@[Digest: %s@]@."
(Digest.to_hex digest);
pp_cmj cmj
| _ -> failwith "expect one argument"