Use pattern matching when possible

Signed-off-by: Etienne Millon <me@emillon.org>
This commit is contained in:
Etienne Millon 2018-08-06 08:32:59 +00:00
parent 0ec9baf257
commit 27b460c320
3 changed files with 14 additions and 17 deletions

View File

@ -76,25 +76,27 @@ module Linkage = struct
let flags =
match m.kind with
| Exe ->
if wanted_mode = Native && real_mode = Byte then
["-custom"]
else
[]
begin
match wanted_mode, real_mode with
| Native, Byte -> ["-custom"]
| _ -> []
end
| Object -> o_flags
| Shared_object ->
let so_flags =
if ctx.os_type = "Win32" then
if String.equal ctx.os_type "Win32" then
so_flags_windows
else
so_flags_unix
in
if real_mode = Native then
match real_mode with
| Native ->
(* The compiler doesn't pass these flags in native mode. This
looks like a bug in the compiler. *)
List.concat_map ctx.native_c_libraries ~f:(fun flag ->
["-cclib"; flag])
@ so_flags
else
| Byte ->
so_flags
in
{ ext

View File

@ -487,9 +487,10 @@ module Gen(P : Install_rules.Params) = struct
let l =
let has_native = Option.is_some ctx.ocamlopt in
List.filter_map (L.Set.to_list exes.modes) ~f:(fun (mode : L.t) ->
if not has_native && mode.mode = Native then
match has_native, mode.mode with
| false, Native ->
None
else
| _ ->
Some (Exe.Linkage.of_user_config ctx mode))
in
(* If bytecode was requested but not native or best version,

View File

@ -870,15 +870,9 @@ module Mode_conf = struct
let default = of_list [Byte; Best]
let eval t ~has_native =
let best : Mode.t =
if has_native then
Native
else
Byte
in
let has_best = mem t Best in
let byte = mem t Byte || (has_best && best = Byte) in
let native = best = Native && (mem t Native || has_best) in
let byte = mem t Byte || (has_best && (not has_native)) in
let native = has_native && (mem t Native || has_best) in
{ Mode.Dict.byte; native }
end
end