From 16b37a9c00115a4e7d635eaa0db1e350cf7e1174 Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Fri, 23 Sep 2022 11:37:53 +0100 Subject: [PATCH] Support OCaml 4.13, 4.14 --- dune-workspace.all | 8 +++++-- src/malfunction_compat.cppo.ml | 44 +++++++++++++++++++++++++--------- src/malfunction_compiler.ml | 15 +++++++++++- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/dune-workspace.all b/dune-workspace.all index fece5e0..7bd1bee 100644 --- a/dune-workspace.all +++ b/dune-workspace.all @@ -19,7 +19,11 @@ (context (opam (switch 4.10.2+flambda))) (context (opam (switch 4.11.0))) (context (opam (switch 4.11.0+flambda))) -(context (opam (switch 4.11.1) (merlin))) +(context (opam (switch 4.11.1))) (context (opam (switch 4.11.1+flambda))) -(context (opam (switch 4.12.0) )) +(context (opam (switch 4.12.0) (merlin))) (context (opam (switch 4.12.0+flambda))) +(context (opam (switch 4.13.1) )) +(context (opam (switch 4.13.1+flambda))) +(context (opam (switch 4.14.0) )) +(context (opam (switch 4.14.0+flambda))) diff --git a/src/malfunction_compat.cppo.ml b/src/malfunction_compat.cppo.ml index 8a3212c..391ee26 100644 --- a/src/malfunction_compat.cppo.ml +++ b/src/malfunction_compat.cppo.ml @@ -39,26 +39,41 @@ let lfunction params body = #if OCAML_VERSION >= (4, 08, 0) let params = List.map (fun x -> x, Pgenval) params in #endif + let attr = { + inline = Default_inline; + specialise = Default_specialise; + is_a_functor = false; +#if OCAML_VERSION >= (4, 05, 0) + stub = false; +#endif +#if OCAML_VERSION >= (4, 08, 0) + local = Default_local; +#endif +#if OCAML_VERSION >= (4, 14, 0) + poll = Default_poll; + tmc_candidate = false; +#endif + } in +#if OCAML_VERSION >= (4, 14, 0) + lfunction + ~kind:Curried + ~params + ~return:Pgenval + ~body + ~attr + ~loc:loc_none +#else Lfunction { kind = Curried; params; body; loc = loc_none; - attr = { - inline = Default_inline; - specialise = Default_specialise; - is_a_functor = false; -#if OCAML_VERSION >= (4, 05, 0) - stub = false; -#endif -#if OCAML_VERSION >= (4, 08, 0) - local = Default_local; -#endif - }; + attr; #if OCAML_VERSION >= (4, 08, 0) return = Pgenval; #endif } +#endif let lapply fn args = Lapply { @@ -241,7 +256,14 @@ let compile_implementation if Config.flambda then Flambda_middle_end.lambda_to_clambda else Closure_middle_end.lambda_to_clambda in +#if OCAML_VERSION >= (4, 13, 0) + ignore filename; + Asmgen.compile_implementation + ?toplevel:None ~backend ~prefixname ~middle_end ~ppf_dump:ppf + program +#else Asmgen.compile_implementation ?toplevel:None ~backend ~filename ~prefixname ~middle_end ~ppf_dump:ppf program #endif +#endif diff --git a/src/malfunction_compiler.ml b/src/malfunction_compiler.ml index 14bc347..e302b37 100644 --- a/src/malfunction_compiler.ml +++ b/src/malfunction_compiler.ml @@ -214,8 +214,21 @@ module IntSwitch = struct let geint = Pintcomp Cge let gtint = Pintcomp Cgt + type arg = Lambda.lambda + type test = Lambda.lambda type act = Lambda.lambda + let make_is_nonzero arg = + (* https://github.com/ocaml/ocaml/pull/10681 *) + Lprim (pintcomp_cne, + [arg; Lconst (Const_base (Const_int 0))], + loc_none) + + let arg_as_test (arg : arg) : test = arg + + (* these are unused on some OCaml versions *) + let _ = make_is_nonzero, arg_as_test + let make_prim p args = lprim p args let make_offset arg n = match n with | 0 -> arg @@ -630,7 +643,7 @@ let setup_options options = (* FIXME: should we use classic_arguments for non-flambda builds? *) (* Hack: disable the "no cmx" warning for zarith *) - Warnings.parse_options false "-58"; + let _ = Warnings.parse_options false "-58" in assert (not (Warnings.is_active (Warnings.No_cmx_file "asdf"))); (options |> List.iter @@ function