Skip to content

Commit ff41cf1

Browse files
authored
Merge pull request #128 from janestreet/use-parameter-flag
Process the `-parameter` flag
2 parents d0a4a19 + d1f0a06 commit ff41cf1

File tree

19 files changed

+639
-2
lines changed

19 files changed

+639
-2
lines changed

src/kernel/mconfig.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ let dump_ocaml x =
5454
("pp", Json.option (dump_with_workdir Json.string) x.pp);
5555
("warnings", dump_warnings x.warnings);
5656
("cmi_file", Json.option Json.string x.cmi_file);
57+
("parameters", `List (List.map ~f:Json.string x.parameters));
5758
("as_parameter", `Bool x.as_parameter);
5859
( "zero_alloc_check",
5960
`String (Zero_alloc_annotations.to_string x.zero_alloc_check) )

src/kernel/mocaml.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ let setup_reader_config config =
5252
as_parameter := ocaml.as_parameter;
5353
zero_alloc_check := ocaml.zero_alloc_check
5454

55+
let init_params params =
56+
List.iter params ~f:(fun s ->
57+
Env.register_parameter (s |> Global_module.Name.create_no_args))
58+
5559
let setup_typer_config config =
5660
setup_reader_config config;
5761
let visible = Mconfig.build_path config in
5862
let hidden = Mconfig.hidden_build_path config in
59-
Load_path.(init ~auto_include:no_auto_include ~visible ~hidden)
63+
Load_path.(init ~auto_include:no_auto_include ~visible ~hidden);
64+
init_params config.ocaml.parameters
6065

6166
(** Switchable implementation of Oprint *)
6267

src/kernel/mtyper.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,13 @@ let run config parsetree =
289289
(* Resetting the local store will clear the load_path cache.
290290
Save it now, reset the store and then restore the path. *)
291291
let { Load_path.visible; hidden } = Load_path.get_paths () in
292+
(* Same story with the registered parameters. *)
293+
let parameters = Env.parameters () in
292294
Mocaml.flush_caches ();
293295
Local_store.reset ();
294296
Load_path.reset ();
295-
Load_path.(init ~auto_include:no_auto_include ~visible ~hidden));
297+
Load_path.(init ~auto_include:no_auto_include ~visible ~hidden);
298+
List.iter ~f:Env.register_parameter parameters);
296299
let caught = ref [] in
297300
Msupport.catch_errors Mconfig.(config.ocaml.warnings) caught @@ fun () ->
298301
Typecore.reset_delayed_checks ();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type t = P.t
2+
3+
let create () = P.create ()
4+
let wrap t = t
5+
let p t = t
6+
let to_string t = "Basic(" ^ P.to_string t ^ ")"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(** Basic functionality implemented over the [P] parameter. *)
2+
3+
(** A [P.t] with minor enhancements. *)
4+
type t
5+
6+
(** Make a [t] from scratch. *)
7+
val create : unit -> t
8+
9+
(** Make a [t] from a [P.t]. *)
10+
val wrap : P.t -> t
11+
12+
val p : t -> P.t
13+
14+
(** Convert [t] to string. *)
15+
val to_string : t -> string
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type t = Basic.t
2+
3+
let create t = t
4+
let wrap t = Basic.wrap t
5+
let to_string t = "Fancy(" ^ Basic.to_string t ^ ")"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type t
2+
3+
(** Make something fancy out of something basic. *)
4+
val create : Basic.t -> t
5+
val wrap : P.t -> t
6+
val to_string : t -> string
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type t = int
2+
3+
let create () = 0
4+
let frob = succ
5+
let to_string = string_of_int
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type t = int
2+
3+
val create : unit -> t
4+
val frob : t -> t
5+
val to_string : t -> string
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(** A parameter module. *)
2+
3+
(** A thing. *)
4+
type t
5+
6+
(** Make a thing. *)
7+
val create : int -> t
8+
9+
(** Frobnicate the thing. *)
10+
val frob : t -> t
11+
12+
(** Show the thing. *)
13+
val to_string : t -> string

0 commit comments

Comments
 (0)