24
24
25
25
26
26
27
- let build_queue ppf queue (ast_table : _ Ast_extract.t String_map.t ) =
28
- queue |> Queue. iter (fun modname ->
29
- match String_map. find modname ast_table with
30
- | {ast_info = Ml (source_file,ast, opref)}
31
- ->
32
- Js_implementation. after_parsing_impl ppf source_file
33
- opref ast
34
- | {ast_info = Mli (source_file,ast,opref) ; }
35
- ->
36
- Js_implementation. after_parsing_sig ppf source_file
37
- opref ast
38
- | {ast_info = Ml_mli (source_file1,impl,opref1,source_file2,intf,opref2)}
39
- ->
40
- Js_implementation. after_parsing_sig ppf source_file1 opref1 intf ;
41
- Js_implementation. after_parsing_impl ppf source_file2 opref2 impl
42
- | exception Not_found -> assert false
43
- )
44
-
45
- let build_lazy_queue ppf queue (ast_table : _ Ast_extract.t String_map.t ) =
46
- queue |> Queue. iter (fun modname ->
47
- match String_map. find modname ast_table with
48
- | {ast_info = Ml (source_file,lazy ast, opref)}
49
- ->
50
- Js_implementation. after_parsing_impl ppf source_file
51
- opref ast
52
- | {ast_info = Mli (source_file,lazy ast,opref) ; }
53
- ->
54
- Js_implementation. after_parsing_sig ppf source_file
55
- opref ast
56
- | {ast_info = Ml_mli (source_file1,lazy impl,opref1,source_file2,lazy intf,opref2)}
57
- ->
58
- Js_implementation. after_parsing_sig ppf source_file1 opref1 intf ;
59
- Js_implementation. after_parsing_impl ppf source_file2 opref2 impl
60
- | exception Not_found -> assert false
61
- )
62
-
63
-
64
-
65
27
module String_set = Depend. StringSet
66
28
67
-
68
- let handle_main_file ppf main_file =
69
- let dirname = Filename. dirname main_file in
70
- let files =
71
- Sys. readdir dirname
72
- |> Ext_array. to_list_f
73
- (fun source_file ->
74
- if Ext_string. ends_with source_file " .ml" ||
75
- Ext_string. ends_with source_file " .mli" then
76
- Some (Filename. concat dirname source_file)
77
- else None
78
- ) in
79
- let ast_table =
80
- Ast_extract. build ppf files
81
- Ocaml_parse. lazy_parse_implementation
82
- Ocaml_parse. lazy_parse_interface in
83
-
84
- let visited = Hashtbl. create 31 in
85
- let result = Queue. create () in
86
- let next module_name =
87
- match String_map. find module_name ast_table with
88
- | exception _ -> String_set. empty
89
- | {ast_info = Ml (_ , lazy impl , _ )} ->
90
- Ast_extract. read_parse_and_extract Ml_kind impl
91
- | {ast_info = Mli (_ , lazy intf ,_ )} ->
92
- Ast_extract. read_parse_and_extract Mli_kind intf
93
- | {ast_info = Ml_mli (_,lazy impl, _, _, lazy intf, _)}
94
- ->
95
- String_set. union
96
- (Ast_extract. read_parse_and_extract Ml_kind impl)
97
- (Ast_extract. read_parse_and_extract Mli_kind intf)
98
- in
99
- let rec visit visiting path current =
100
- if String_set. mem current visiting then
101
- Bs_exception. error (Bs_cyclic_depends (current::path))
102
- else
103
- if not (Hashtbl. mem visited current)
104
- && String_map. mem current ast_table then
105
- begin
106
- String_set. iter
107
- (visit
108
- (String_set. add current visiting)
109
- (current::path))
110
- (next current) ;
111
- Queue. push current result;
112
- Hashtbl. add visited current () ;
113
- end in
114
- visit (String_set. empty) [] (Ext_filename. module_name_of_file main_file) ;
29
+ let process_result ppf main_file ast_table result =
115
30
if Js_config. get_diagnose () then
116
31
Format. fprintf Format. err_formatter
117
32
" Order: @[%a@]@."
118
33
(Ext_format. pp_print_queue
119
34
~pp_sep: Format. pp_print_space
120
35
Format. pp_print_string)
121
36
result ;
122
- build_lazy_queue ppf result ast_table;
37
+ Ast_extract. build_lazy_queue ppf result ast_table
38
+ Js_implementation. after_parsing_impl
39
+ Js_implementation. after_parsing_sig
40
+ ;
123
41
if not (! Clflags. compile_only) then
124
42
Sys. command
125
43
(" node " ^ Filename. chop_extension main_file ^ " .js" )
126
44
else 0
127
45
128
46
47
+
129
48
let batch_compile ppf files main_file =
130
49
Compenv. readenv ppf Before_compile ;
131
50
Compmisc. init_path false ;
@@ -135,11 +54,20 @@ let batch_compile ppf files main_file =
135
54
Ast_extract. build ppf files
136
55
Ocaml_parse. parse_implementation
137
56
Ocaml_parse. parse_interface in
138
- build_queue ppf (Ast_extract. sort (fun x -> x ) (fun x -> x )ast_table) ast_table
57
+ Ast_extract. build_queue ppf
58
+ (Ast_extract. sort (fun x -> x ) (fun x -> x )ast_table)
59
+ ast_table
60
+ Js_implementation. after_parsing_impl
61
+ Js_implementation. after_parsing_sig
139
62
end
140
63
;
141
64
if String. length main_file <> 0 then
142
- handle_main_file ppf main_file
65
+ let ast_table, result =
66
+ Ast_extract. handle_main_file ppf
67
+ Ocaml_parse. lazy_parse_implementation
68
+ Ocaml_parse. lazy_parse_interface
69
+ main_file in
70
+ process_result ppf main_file ast_table result
143
71
else 0
144
72
145
73
0 commit comments