Skip to content

Commit

Permalink
CR: Config.target
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Sep 22, 2024
1 parent fd0d0b4 commit 9d08e70
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions compiler/bin-js_of_ocaml/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ let run
} =
let include_cmis = toplevel && not no_cmis in
let custom_header = common.Jsoo_cmdline.Arg.custom_header in
Config.set_target `JavaScript;
Jsoo_cmdline.Arg.eval common;
Linker.reset ();
(match output_file with
Expand Down
1 change: 1 addition & 0 deletions compiler/bin-js_of_ocaml/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ let f
; mklib
; toplevel
} =
Config.set_target `JavaScript;
Jsoo_cmdline.Arg.eval common;
Linker.reset ();
let with_output f =
Expand Down
1 change: 1 addition & 0 deletions compiler/lib-dynlink/js_of_ocaml_compiler_dynlink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let normalize_bytecode code =
Bytes.to_string b

let () =
Config.set_target `JavaScript;
let global = J.pure_js_expr "globalThis" in
Config.Flag.set "use-js-string" (Jsoo_runtime.Sys.Config.use_js_string ());
Config.Flag.set "effects" (Jsoo_runtime.Sys.Config.effects ());
Expand Down
1 change: 1 addition & 0 deletions compiler/lib-runtime-files/gen/gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ let rec list_product l =
let bool = [ true; false ]

let () =
Js_of_ocaml_compiler.Config.set_target `JavaScript;
let () = set_binary_mode_out stdout true in
match Array.to_list Sys.argv with
| [] -> assert false
Expand Down
9 changes: 5 additions & 4 deletions compiler/lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ end

(****)

let target_ : [ `JavaScript | `Wasm ] option ref = ref None
let target_ : [ `JavaScript | `Wasm | `None ] ref = ref `None

let target () =
match !target_ with
| Some t -> t
| None -> failwith "target was not set"
| `None -> failwith "target was not set"
| (`JavaScript | `Wasm) as t -> t

let set_target t = target_ := Some t
let set_target (t : [ `JavaScript | `Wasm ]) =
target_ := (t :> [ `JavaScript | `Wasm | `None ])

0 comments on commit 9d08e70

Please sign in to comment.