Skip to content

Commit cc0b118

Browse files
author
Hongbo Zhang
committed
improve ocamlpack
1 parent 8a923e2 commit cc0b118

20 files changed

+401
-378
lines changed

jscomp/bin/bs_ppx.ml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(** Bundled by ocamlpack 08/11-09:12 *)
1+
(** Bundled by ocamlpack 08/11-09:55 *)
22
module String_map : sig
33
#1 "string_map.mli"
44
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -1853,7 +1853,8 @@ module Ext_pervasives : sig
18531853
*)
18541854

18551855
external reraise: exn -> 'a = "%reraise"
1856-
val finally : 'a -> ('a -> 'b) -> ('a -> 'c) -> 'b
1856+
1857+
val finally : 'a -> ('a -> 'c) -> ('a -> 'b) -> 'b
18571858

18581859
val with_file_as_chan : string -> (out_channel -> 'a) -> 'a
18591860

@@ -1905,26 +1906,24 @@ end = struct
19051906

19061907
external reraise: exn -> 'a = "%reraise"
19071908

1908-
let finally v f action =
1909+
let finally v action f =
19091910
match f v with
19101911
| exception e ->
19111912
action v ;
19121913
reraise e
19131914
| e -> action v ; e
19141915

19151916
let with_file_as_chan filename f =
1916-
let chan = open_out filename in
1917-
finally chan f close_out
1917+
finally (open_out filename) close_out f
19181918

19191919
let with_file_as_pp filename f =
1920-
let chan = open_out filename in
1921-
finally chan
1920+
finally (open_out filename) close_out
19221921
(fun chan ->
19231922
let fmt = Format.formatter_of_out_channel chan in
19241923
let v = f fmt in
19251924
Format.pp_print_flush fmt ();
19261925
v
1927-
) close_out
1926+
)
19281927

19291928

19301929
let is_pos_pow n =
@@ -6531,9 +6530,9 @@ let rewrite_implementation : (Parsetree.structure -> Parsetree.structure) ref =
65316530

65326531
end
65336532
module
6534-
Ppx_driver
6533+
Bs_ppx_main
65356534
= struct
6536-
#1 "ppx_driver.ml"
6535+
#1 "bs_ppx_main.ml"
65376536

65386537

65396538

jscomp/bin/bs_ppx.mllib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ include ../syntax/syntax.mllib
1515
../common/js_config
1616
../common/literals
1717

18-
../syntax/ppx_driver
18+
../bs_ppx_main

jscomp/bin/compiler.ml

Lines changed: 85 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(** Bundled by ocamlpack 08/11-09:12 *)
1+
(** Bundled by ocamlpack 08/11-09:55 *)
22
module String_map : sig
33
#1 "string_map.mli"
44
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -1853,7 +1853,8 @@ module Ext_pervasives : sig
18531853
*)
18541854

18551855
external reraise: exn -> 'a = "%reraise"
1856-
val finally : 'a -> ('a -> 'b) -> ('a -> 'c) -> 'b
1856+
1857+
val finally : 'a -> ('a -> 'c) -> ('a -> 'b) -> 'b
18571858

18581859
val with_file_as_chan : string -> (out_channel -> 'a) -> 'a
18591860

@@ -1905,26 +1906,24 @@ end = struct
19051906

19061907
external reraise: exn -> 'a = "%reraise"
19071908

1908-
let finally v f action =
1909+
let finally v action f =
19091910
match f v with
19101911
| exception e ->
19111912
action v ;
19121913
reraise e
19131914
| e -> action v ; e
19141915

19151916
let with_file_as_chan filename f =
1916-
let chan = open_out filename in
1917-
finally chan f close_out
1917+
finally (open_out filename) close_out f
19181918

19191919
let with_file_as_pp filename f =
1920-
let chan = open_out filename in
1921-
finally chan
1920+
finally (open_out filename) close_out
19221921
(fun chan ->
19231922
let fmt = Format.formatter_of_out_channel chan in
19241923
let v = f fmt in
19251924
Format.pp_print_flush fmt ();
19261925
v
1927-
) close_out
1926+
)
19281927

19291928

19301929
let is_pos_pow n =
@@ -8969,6 +8968,83 @@ let reset () =
89698968
let undefined = create_js "undefined"
89708969
let nil = create_js "null"
89718970

8971+
end
8972+
module Ext_io : sig
8973+
#1 "ext_io.mli"
8974+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
8975+
*
8976+
* This program is free software: you can redistribute it and/or modify
8977+
* it under the terms of the GNU Lesser General Public License as published by
8978+
* the Free Software Foundation, either version 3 of the License, or
8979+
* (at your option) any later version.
8980+
*
8981+
* In addition to the permissions granted to you by the LGPL, you may combine
8982+
* or link a "work that uses the Library" with a publicly distributed version
8983+
* of this file to produce a combined library or application, then distribute
8984+
* that combined work under the terms of your choosing, with no requirement
8985+
* to comply with the obligations normally placed on you by section 4 of the
8986+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
8987+
* should you choose to use a later version).
8988+
*
8989+
* This program is distributed in the hope that it will be useful,
8990+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8991+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8992+
* GNU Lesser General Public License for more details.
8993+
*
8994+
* You should have received a copy of the GNU Lesser General Public License
8995+
* along with this program; if not, write to the Free Software
8996+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
8997+
8998+
val load_file : string -> string
8999+
9000+
val rev_lines_of_file : string -> string list
9001+
9002+
end = struct
9003+
#1 "ext_io.ml"
9004+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
9005+
*
9006+
* This program is free software: you can redistribute it and/or modify
9007+
* it under the terms of the GNU Lesser General Public License as published by
9008+
* the Free Software Foundation, either version 3 of the License, or
9009+
* (at your option) any later version.
9010+
*
9011+
* In addition to the permissions granted to you by the LGPL, you may combine
9012+
* or link a "work that uses the Library" with a publicly distributed version
9013+
* of this file to produce a combined library or application, then distribute
9014+
* that combined work under the terms of your choosing, with no requirement
9015+
* to comply with the obligations normally placed on you by section 4 of the
9016+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
9017+
* should you choose to use a later version).
9018+
*
9019+
* This program is distributed in the hope that it will be useful,
9020+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9021+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9022+
* GNU Lesser General Public License for more details.
9023+
*
9024+
* You should have received a copy of the GNU Lesser General Public License
9025+
* along with this program; if not, write to the Free Software
9026+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
9027+
9028+
9029+
(** on 32 bit , there are 16M limitation *)
9030+
let load_file f =
9031+
Ext_pervasives.finally (open_in f) close_in begin fun ic ->
9032+
let n = in_channel_length ic in
9033+
let s = Bytes.create n in
9034+
really_input ic s 0 n;
9035+
Bytes.unsafe_to_string s
9036+
end
9037+
9038+
9039+
let rev_lines_of_file file =
9040+
Ext_pervasives.finally (open_in file) close_in begin fun chan ->
9041+
let rec loop acc =
9042+
match input_line chan with
9043+
| line -> loop (line :: acc)
9044+
| exception End_of_file -> close_in chan ; acc in
9045+
loop []
9046+
end
9047+
89729048
end
89739049
module Ext_map : sig
89749050
#1 "ext_map.mli"
@@ -9400,7 +9476,7 @@ let group t i action =
94009476
else
94019477
let old = t.indent_level in
94029478
t.indent_level <- t.indent_level + i;
9403-
Ext_pervasives.finally () action (fun _ -> t.indent_level <- old)
9479+
Ext_pervasives.finally () (fun _ -> t.indent_level <- old) action
94049480

94059481
let vgroup = group
94069482

@@ -33384,114 +33460,3 @@ let builtin_modules =
3338433460
]
3338533461

3338633462
end
33387-
module Line_process : sig
33388-
#1 "line_process.mli"
33389-
33390-
33391-
(** Given a filename return a list of modules *)
33392-
val read_lines : string -> string -> string list
33393-
val load_file : string -> string
33394-
33395-
end = struct
33396-
#1 "line_process.ml"
33397-
33398-
(* let lexer = Genlex.make_lexer [] (\* poor man *\) *)
33399-
33400-
(* let rec to_list acc stream = *)
33401-
(* match Stream.next stream with *)
33402-
(* | exception _ -> List.rev acc *)
33403-
(* | v -> to_list (v::acc) stream *)
33404-
33405-
33406-
let rev_lines_of_file file =
33407-
let chan = open_in file in
33408-
let rec loop acc =
33409-
match input_line chan with
33410-
| line -> loop (line :: acc)
33411-
| exception End_of_file -> close_in chan ; acc in
33412-
loop []
33413-
33414-
33415-
let rec filter_map (f: 'a -> 'b option) xs =
33416-
match xs with
33417-
| [] -> []
33418-
| y :: ys ->
33419-
begin match f y with
33420-
| None -> filter_map f ys
33421-
| Some z -> z :: filter_map f ys
33422-
end
33423-
33424-
33425-
(** on 32 bit , there are 16M limitation *)
33426-
let load_file f =
33427-
let ic = open_in f in
33428-
let n = in_channel_length ic in
33429-
let s = Bytes.create n in
33430-
really_input ic s 0 n;
33431-
close_in ic;
33432-
Bytes.unsafe_to_string s
33433-
33434-
let (@>) (b, v) acc =
33435-
if b then
33436-
v :: acc
33437-
else
33438-
acc
33439-
33440-
33441-
let (//) = Filename.concat
33442-
33443-
let rec process_line cwd filedir line =
33444-
let line = Ext_string.trim line in
33445-
let len = String.length line in
33446-
if len = 0 then []
33447-
else
33448-
match line.[0] with
33449-
| '#' -> []
33450-
| _ ->
33451-
let segments =
33452-
Ext_string.split_by ~keep_empty:false (fun x -> x = ' ' || x = '\t' ) line
33453-
in
33454-
33455-
begin
33456-
match segments with
33457-
| ["include" ; path ]
33458-
->
33459-
(* prerr_endline path; *)
33460-
read_lines cwd (filedir// path)
33461-
| [ x ] ->
33462-
let ml = filedir // x ^ ".ml" in
33463-
let mli = filedir // x ^ ".mli" in
33464-
let ml_exists, mli_exists = Sys.file_exists ml , Sys.file_exists mli in
33465-
if not ml_exists && not mli_exists then
33466-
begin
33467-
prerr_endline (filedir //x ^ " not exists");
33468-
[]
33469-
end
33470-
else
33471-
(ml_exists, ml) @> (mli_exists , mli) @> []
33472-
33473-
| _
33474-
-> Ext_pervasives.failwithf ~loc:__LOC__ "invalid line %s" line
33475-
end
33476-
33477-
(* example
33478-
{[
33479-
Line_process.read_lines "." "./tools/tools.mllib"
33480-
]}
33481-
33482-
FIXME: we can only concat (dir/file) not (dir/dir)
33483-
{[
33484-
Filename.concat "/bb/x/" "/bb/x/";;
33485-
]}
33486-
*)
33487-
and read_lines cwd file =
33488-
33489-
file
33490-
|> rev_lines_of_file
33491-
|> List.fold_left (fun acc f ->
33492-
let filedir = Filename.dirname file in
33493-
let extras = process_line cwd filedir f in
33494-
extras @ acc
33495-
) []
33496-
33497-
end

0 commit comments

Comments
 (0)