Skip to content

Commit 4655415

Browse files
committed
support parse flags per file
1 parent 6e84a90 commit 4655415

File tree

8 files changed

+108
-132
lines changed

8 files changed

+108
-132
lines changed

jscomp/main/js_main.ml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ let buckle_script_flags : (string * Arg.spec * string) list =
320320
::
321321
("-bs-no-cross-module-opt",
322322
Arg.Clear Js_config.cross_module_inline,
323-
"enable cross module inlining(experimental), default(false)")
323+
"disable cross module inlining(experimental)")
324324
::
325325
("-bs-diagnose",
326326
Arg.Set Js_config.diagnose,
@@ -354,16 +354,29 @@ let buckle_script_flags : (string * Arg.spec * string) list =
354354

355355

356356

357+
let file_level_flags_handler (e : Parsetree.expression option) =
358+
match e with
359+
| None -> ()
360+
| Some {pexp_desc = Pexp_array args } ->
361+
let args = Array.of_list
362+
(Sys.executable_name :: Ext_list.map args (fun e ->
363+
match e.pexp_desc with
364+
| Pexp_constant (Pconst_string(name,_)) -> name
365+
| _ -> Location.raise_errorf ~loc:e.pexp_loc "string literal expected" )) in
366+
Arg.parse_argv ~current:(ref 0)
367+
args buckle_script_flags ignore usage
368+
;Format.fprintf Format.err_formatter "%a %b@."
369+
Ext_obj.pp_any args !Js_config.cross_module_inline;
370+
| Some e ->
371+
Location.raise_errorf ~loc:e.pexp_loc "string array expected"
357372

358-
let _ =
359-
(* (
360-
print_endline
361-
("BSB_PROJECT_ROOT :" ^
362-
match Sys.getenv_opt "BSB_PROJECT_ROOT" with
363-
| None -> "None"
364-
| Some s -> s
365-
)); *)
373+
let _ : unit =
366374
Bs_conditional_initial.setup_env ();
375+
let flags = "flags" in
376+
Ast_config.structural_config_table := Map_string.add !Ast_config.structural_config_table
377+
flags file_level_flags_handler;
378+
Ast_config.signature_config_table := Map_string.add !Ast_config.signature_config_table
379+
flags file_level_flags_handler;
367380
try
368381
Compenv.readenv ppf Before_args;
369382
Arg.parse buckle_script_flags anonymous usage;

jscomp/stdlib-406/sys.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[@@@bs.config { flags = [|"-bs-no-cross-module-opt"; |]}]
12
#2 "stdlib/sys.mlp"
23
(**************************************************************************)
34
(* *)

jscomp/stdlib-406/unix.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(* special exception on linking described in the file LICENSE. *)
1313
(* *)
1414
(**************************************************************************)
15-
15+
[@@@bs.config { flags = [|"-bs-no-cross-module-opt" |]}]
1616
type error =
1717
E2BIG
1818
| EACCES

jscomp/syntax/ast_config.ml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,21 @@
2525

2626
type action_table =
2727
(Parsetree.expression option -> unit) Map_string.t
28-
(** global configurations below *)
29-
let common_actions_table :
30-
(string * (Parsetree.expression option -> unit)) list =
31-
[
32-
]
3328

3429

35-
let structural_config_table : action_table =
36-
Map_string.of_list
37-
(( "no_export" ,
30+
let structural_config_table : action_table ref =
31+
ref (Map_string.singleton
32+
"no_export"
3833
(fun x ->
3934
Js_config.no_export := (
4035
match x with
4136
|Some e -> Ast_payload.assert_bool_lit e
4237
| None -> true)
4338
))
44-
:: common_actions_table)
39+
4540

46-
let signature_config_table : action_table =
47-
Map_string.of_list common_actions_table
41+
let signature_config_table : action_table ref =
42+
ref Map_string.empty
4843

4944

5045
let rec iter_on_bs_config_stru (x :Parsetree.structure) =
@@ -53,7 +48,7 @@ let rec iter_on_bs_config_stru (x :Parsetree.structure) =
5348
| {pstr_desc = Pstr_attribute (({txt = "bs.config"; loc}, payload) as attr)}::_ ->
5449
Bs_ast_invariant.mark_used_bs_attribute attr;
5550
Ext_list.iter (Ast_payload.ident_or_record_as_config loc payload)
56-
(Ast_payload.table_dispatch structural_config_table)
51+
(Ast_payload.table_dispatch !structural_config_table)
5752
| {pstr_desc = Pstr_attribute _} :: rest ->
5853
iter_on_bs_config_stru rest
5954
| non_attr :: _ -> ()
@@ -64,7 +59,7 @@ let rec iter_on_bs_config_sigi (x :Parsetree.signature) =
6459
| {psig_desc = Psig_attribute (({txt = "bs.config"; loc}, payload) as attr)}::_ ->
6560
Bs_ast_invariant.mark_used_bs_attribute attr;
6661
Ext_list.iter (Ast_payload.ident_or_record_as_config loc payload)
67-
(Ast_payload.table_dispatch signature_config_table)
62+
(Ast_payload.table_dispatch !signature_config_table)
6863
| {psig_desc = Psig_attribute _} :: rest ->
6964
iter_on_bs_config_sigi rest
7065
| non_attr :: _ -> ()

jscomp/syntax/ast_config.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
type action_table =
26+
(Parsetree.expression option -> unit) Map_string.t
2527

2628

27-
29+
val structural_config_table : action_table ref
30+
val signature_config_table : action_table ref
31+
2832
val iter_on_bs_config_stru :
2933
Parsetree.structure ->
3034
unit

jscomp/test/bs_MapInt_test.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[@@@bs.config{flags = [|"-bs-no-cross-module-opt"; |] }]
12
let should b =
23
if not b then Js.Exn.raiseError "IMPOSSIBLE"
34

lib/es6/unix.js

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import * as Sys from "./sys.js";
44
import * as List from "./list.js";
55
import * as $$Array from "./array.js";
66
import * as Block from "./block.js";
7+
import * as Bytes from "./bytes.js";
78
import * as Curry from "./curry.js";
89
import * as Printf from "./printf.js";
910
import * as $$String from "./string.js";
10-
import * as Caml_io from "./caml_io.js";
1111
import * as Hashtbl from "./hashtbl.js";
1212
import * as Callback from "./callback.js";
1313
import * as Caml_sys from "./caml_sys.js";
1414
import * as Filename from "./filename.js";
1515
import * as Printexc from "./printexc.js";
1616
import * as Caml_array from "./caml_array.js";
17-
import * as Caml_bytes from "./caml_bytes.js";
1817
import * as Pervasives from "./pervasives.js";
1918
import * as Caml_format from "./caml_format.js";
2019
import * as Caml_exceptions from "./caml_exceptions.js";
@@ -459,40 +458,34 @@ function execvpe(name, args, env) {
459458

460459
function read(fd, buf, ofs, len) {
461460
if (ofs < 0 || len < 0 || ofs > (buf.length - len | 0)) {
462-
throw [
463-
Caml_builtin_exceptions.invalid_argument,
464-
"Unix.read"
465-
];
461+
return Pervasives.invalid_arg("Unix.read");
462+
} else {
463+
return Caml_external_polyfill.resolve("unix_read")(fd, buf, ofs, len);
466464
}
467-
return Caml_external_polyfill.resolve("unix_read")(fd, buf, ofs, len);
468465
}
469466

470467
function write(fd, buf, ofs, len) {
471468
if (ofs < 0 || len < 0 || ofs > (buf.length - len | 0)) {
472-
throw [
473-
Caml_builtin_exceptions.invalid_argument,
474-
"Unix.write"
475-
];
469+
return Pervasives.invalid_arg("Unix.write");
470+
} else {
471+
return Caml_external_polyfill.resolve("unix_write")(fd, buf, ofs, len);
476472
}
477-
return Caml_external_polyfill.resolve("unix_write")(fd, buf, ofs, len);
478473
}
479474

480475
function single_write(fd, buf, ofs, len) {
481476
if (ofs < 0 || len < 0 || ofs > (buf.length - len | 0)) {
482-
throw [
483-
Caml_builtin_exceptions.invalid_argument,
484-
"Unix.single_write"
485-
];
477+
return Pervasives.invalid_arg("Unix.single_write");
478+
} else {
479+
return Caml_external_polyfill.resolve("unix_single_write")(fd, buf, ofs, len);
486480
}
487-
return Caml_external_polyfill.resolve("unix_single_write")(fd, buf, ofs, len);
488481
}
489482

490483
function write_substring(fd, buf, ofs, len) {
491-
return write(fd, Caml_bytes.bytes_of_string(buf), ofs, len);
484+
return write(fd, Bytes.unsafe_of_string(buf), ofs, len);
492485
}
493486

494487
function single_write_substring(fd, buf, ofs, len) {
495-
return single_write(fd, Caml_bytes.bytes_of_string(buf), ofs, len);
488+
return single_write(fd, Bytes.unsafe_of_string(buf), ofs, len);
496489
}
497490

498491
function map_file(fd, posOpt, kind, layout, shared, dims) {
@@ -557,50 +550,42 @@ function domain_of_sockaddr(param) {
557550

558551
function recv(fd, buf, ofs, len, flags) {
559552
if (ofs < 0 || len < 0 || ofs > (buf.length - len | 0)) {
560-
throw [
561-
Caml_builtin_exceptions.invalid_argument,
562-
"Unix.recv"
563-
];
553+
return Pervasives.invalid_arg("Unix.recv");
554+
} else {
555+
return Caml_external_polyfill.resolve("unix_recv")(fd, buf, ofs, len, flags);
564556
}
565-
return Caml_external_polyfill.resolve("unix_recv")(fd, buf, ofs, len, flags);
566557
}
567558

568559
function recvfrom(fd, buf, ofs, len, flags) {
569560
if (ofs < 0 || len < 0 || ofs > (buf.length - len | 0)) {
570-
throw [
571-
Caml_builtin_exceptions.invalid_argument,
572-
"Unix.recvfrom"
573-
];
561+
return Pervasives.invalid_arg("Unix.recvfrom");
562+
} else {
563+
return Caml_external_polyfill.resolve("unix_recvfrom")(fd, buf, ofs, len, flags);
574564
}
575-
return Caml_external_polyfill.resolve("unix_recvfrom")(fd, buf, ofs, len, flags);
576565
}
577566

578567
function send(fd, buf, ofs, len, flags) {
579568
if (ofs < 0 || len < 0 || ofs > (buf.length - len | 0)) {
580-
throw [
581-
Caml_builtin_exceptions.invalid_argument,
582-
"Unix.send"
583-
];
569+
return Pervasives.invalid_arg("Unix.send");
570+
} else {
571+
return Caml_external_polyfill.resolve("unix_send")(fd, buf, ofs, len, flags);
584572
}
585-
return Caml_external_polyfill.resolve("unix_send")(fd, buf, ofs, len, flags);
586573
}
587574

588575
function sendto(fd, buf, ofs, len, flags, addr) {
589576
if (ofs < 0 || len < 0 || ofs > (buf.length - len | 0)) {
590-
throw [
591-
Caml_builtin_exceptions.invalid_argument,
592-
"Unix.sendto"
593-
];
577+
return Pervasives.invalid_arg("Unix.sendto");
578+
} else {
579+
return Caml_external_polyfill.resolve("unix_sendto")(fd, buf, ofs, len, flags, addr);
594580
}
595-
return Caml_external_polyfill.resolve("unix_sendto")(fd, buf, ofs, len, flags, addr);
596581
}
597582

598583
function send_substring(fd, buf, ofs, len, flags) {
599-
return send(fd, Caml_bytes.bytes_of_string(buf), ofs, len, flags);
584+
return send(fd, Bytes.unsafe_of_string(buf), ofs, len, flags);
600585
}
601586

602587
function sendto_substring(fd, buf, ofs, len, flags, addr) {
603-
return sendto(fd, Caml_bytes.bytes_of_string(buf), ofs, len, flags, addr);
588+
return sendto(fd, Bytes.unsafe_of_string(buf), ofs, len, flags, addr);
604589
}
605590

606591
function SO_get(prim, prim$1, prim$2) {
@@ -1025,7 +1010,7 @@ function open_process_in(cmd) {
10251010
open_proc(cmd, undefined, /* Process_in */Block.__(1, [inchan]), 0, in_write, 2);
10261011
}
10271012
catch (e){
1028-
Caml_external_polyfill.resolve("caml_ml_close_channel")(inchan);
1013+
Pervasives.close_in(inchan);
10291014
Caml_external_polyfill.resolve("unix_close")(in_write);
10301015
throw e;
10311016
}
@@ -1041,8 +1026,7 @@ function open_process_out(cmd) {
10411026
open_proc(cmd, undefined, /* Process_out */Block.__(2, [outchan]), out_read, 1, 2);
10421027
}
10431028
catch (e){
1044-
Caml_io.caml_ml_flush(outchan);
1045-
Caml_external_polyfill.resolve("caml_ml_close_channel")(outchan);
1029+
Pervasives.close_out(outchan);
10461030
Caml_external_polyfill.resolve("unix_close")(out_read);
10471031
throw e;
10481032
}
@@ -1166,15 +1150,14 @@ function find_proc_id(fun_name, proc) {
11661150

11671151
function close_process_in(inchan) {
11681152
var pid = find_proc_id("close_process_in", /* Process_in */Block.__(1, [inchan]));
1169-
Caml_external_polyfill.resolve("caml_ml_close_channel")(inchan);
1153+
Pervasives.close_in(inchan);
11701154
return waitpid_non_intr(pid)[1];
11711155
}
11721156

11731157
function close_process_out(outchan) {
11741158
var pid = find_proc_id("close_process_out", /* Process_out */Block.__(2, [outchan]));
11751159
try {
1176-
Caml_io.caml_ml_flush(outchan);
1177-
Caml_external_polyfill.resolve("caml_ml_close_channel")(outchan);
1160+
Pervasives.close_out(outchan);
11781161
}
11791162
catch (raw_exn){
11801163
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
@@ -1193,10 +1176,9 @@ function close_process(param) {
11931176
inchan,
11941177
outchan
11951178
]));
1196-
Caml_external_polyfill.resolve("caml_ml_close_channel")(inchan);
1179+
Pervasives.close_in(inchan);
11971180
try {
1198-
Caml_io.caml_ml_flush(outchan);
1199-
Caml_external_polyfill.resolve("caml_ml_close_channel")(outchan);
1181+
Pervasives.close_out(outchan);
12001182
}
12011183
catch (raw_exn){
12021184
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
@@ -1217,10 +1199,9 @@ function close_process_full(param) {
12171199
outchan,
12181200
errchan
12191201
]));
1220-
Caml_external_polyfill.resolve("caml_ml_close_channel")(inchan);
1202+
Pervasives.close_in(inchan);
12211203
try {
1222-
Caml_io.caml_ml_flush(outchan);
1223-
Caml_external_polyfill.resolve("caml_ml_close_channel")(outchan);
1204+
Pervasives.close_out(outchan);
12241205
}
12251206
catch (raw_exn){
12261207
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
@@ -1229,7 +1210,7 @@ function close_process_full(param) {
12291210
}
12301211

12311212
}
1232-
Caml_external_polyfill.resolve("caml_ml_close_channel")(errchan);
1213+
Pervasives.close_in(errchan);
12331214
return waitpid_non_intr(pid)[1];
12341215
}
12351216

0 commit comments

Comments
 (0)