Skip to content

Commit

Permalink
Fix some statement orderings in scalc (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr authored Apr 23, 2024
2 parents 62c9500 + 1412e76 commit 3e2aa54
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 361 deletions.
28 changes: 16 additions & 12 deletions build_system/clerk_driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ module Poll = struct
running from the root of a compiled source tree.@]"
d)

let ocaml_link_flags : string list Lazy.t =
let ocaml_include_and_lib_flags : (string list * string list) Lazy.t =
lazy
(let link_libs = ["zarith"; "dates_calc"] in
let link_libs_flags =
List.concat_map
let includes_libs =
List.map
(fun lib ->
match File.(check_directory (Lazy.force ocaml_libdir / lib)) with
| None ->
Expand All @@ -372,15 +372,19 @@ module Poll = struct
File.(Lazy.force ocaml_libdir / lib)
lib
| Some d ->
[
"-I";
d;
String.map (function '-' -> '_' | c -> c) lib ^ ".cmxa";
])
( ["-I"; d],
String.map (function '-' -> '_' | c -> c) lib ^ ".cmxa" ))
link_libs
in
let runtime_dir = Lazy.force ocaml_runtime_dir in
link_libs_flags @ [File.(runtime_dir / "runtime_ocaml.cmxa")])
let includes, libs = List.split includes_libs in
( List.concat includes @ ["-I"; Lazy.force ocaml_runtime_dir],
libs @ [File.(Lazy.force ocaml_runtime_dir / "runtime_ocaml.cmxa")] ))

let ocaml_include_flags : string list Lazy.t =
lazy (fst (Lazy.force ocaml_include_and_lib_flags))

let ocaml_link_flags : string list Lazy.t =
lazy (snd (Lazy.force ocaml_include_and_lib_flags))

let has_command cmd =
let check_cmd = Printf.sprintf "type %s >/dev/null 2>&1" cmd in
Expand Down Expand Up @@ -471,7 +475,7 @@ let base_bindings catala_exe catala_flags build_dir include_dirs test_flags =
| _ -> false)
test_flags
in
let ocaml_flags = ["-I"; Lazy.force Poll.ocaml_runtime_dir] in
let ocaml_flags = Lazy.force Poll.ocaml_include_flags in
[
Nj.binding Var.ninja_required_version ["1.7"];
(* use of implicit outputs *)
Expand Down Expand Up @@ -528,7 +532,7 @@ let[@ocamlformat "disable"] static_base_rules =

Nj.rule "ocaml-exec"
~command: [
!ocamlopt_exe; !runtime_ocaml_libs; !ocaml_flags;
!ocamlopt_exe; !ocaml_flags; !runtime_ocaml_libs;
shellout [!catala_exe; "depends";
"--prefix="^ !builddir; "--extension=cmx";
!catala_flags; !orig_src];
Expand Down
21 changes: 11 additions & 10 deletions compiler/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,20 @@ module Passes = struct
let avoid_exceptions = avoid_exceptions || closure_conversion in
(* --closure-conversion implies --avoid-exceptions *)
let prg =
match avoid_exceptions, options.trace, typed with
| true, true, _ ->
Message.error
"Option --avoid-exceptions is not compatible with option --trace"
| true, _, Untyped _ ->
if avoid_exceptions && options.trace then
Message.warning
"It is discouraged to use option @{<yellow>--avoid-exceptions@} if \
you@ also@ need@ @{<yellow>--trace@},@ the@ resulting@ trace@ may@ \
be@ unreliable@ at@ the@ moment.";
match avoid_exceptions, typed with
| true, Untyped _ ->
Lcalc.From_dcalc.translate_program_without_exceptions prg
| true, _, Typed _ ->
| true, Typed _ ->
Lcalc.From_dcalc.translate_program_without_exceptions prg
| false, _, Typed _ ->
| false, Typed _ -> Lcalc.From_dcalc.translate_program_with_exceptions prg
| false, Untyped _ ->
Lcalc.From_dcalc.translate_program_with_exceptions prg
| false, _, Untyped _ ->
Lcalc.From_dcalc.translate_program_with_exceptions prg
| _, _, Custom _ -> invalid_arg "Driver.Passes.lcalc"
| _, Custom _ -> invalid_arg "Driver.Passes.lcalc"
in
let prg =
if optimize then begin
Expand Down
6 changes: 3 additions & 3 deletions compiler/plugins/api_web.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ module To_jsoo = struct
(* Tuples are encoded as an javascript polymorphic array. *)
Format.fprintf fmt "Js.Unsafe.any_js_array Js.t "
| TOption t ->
Format.fprintf fmt "@[<hov 2>(%a)@] %a" format_typ_with_parens t
format_enum_name Expr.option_enum
Format.fprintf fmt "@[<hov 2>(%a)@] Js.opt" format_typ_with_parens t
| TDefault t -> format_typ fmt t
| TEnum e -> Format.fprintf fmt "%a Js.t" format_enum_name e
| TArray t1 ->
Expand Down Expand Up @@ -116,7 +115,8 @@ module To_jsoo = struct
elts
| TOption t ->
Format.fprintf fmt
"(function Eoption.ENone -> Js.null | Eoption.ESome x -> %a x)"
"(function Eoption.ENone () -> Js.null | Eoption.ESome x -> Js.some \
(%a x))"
format_to_js t
| TAny -> Format.fprintf fmt "Js.Unsafe.inject"
| TArrow _ | TClosureEnv -> ()
Expand Down
Loading

0 comments on commit 3e2aa54

Please sign in to comment.