refactor(clerk): add Catala backend in the name of the output build

This commit is contained in:
Emile Rolley 2022-02-17 14:56:45 +01:00
parent bbf4b540eb
commit 7a4ef62ebe
14 changed files with 157 additions and 439 deletions

View File

@ -507,12 +507,11 @@ let collect_all_ninja_build (ninja : ninja) (tested_file : string) (reset_test_o
},
test_names ^ " $\n " ^ test_name )
| Cli.Python | Cli.OCaml | Cli.Latex | Cli.Html | Cli.Makefile ->
let tmp_file =
Filename.temp_file "clerk_" ("_" ^ catala_backend_to_string expected_output.backend)
in
let catala_backend = catala_backend_to_string expected_output.backend in
let tmp_file = Filename.temp_file "clerk_" ("_" ^ catala_backend) in
let vars =
[
("catala_cmd", Nj.Expr.Lit (catala_backend_to_string expected_output.backend));
("catala_cmd", Nj.Expr.Lit catala_backend);
("tested_file", Nj.Expr.Lit tested_file);
( "expected_output",
Nj.Expr.Lit (expected_output.output_dir ^ expected_output.complete_filename) );
@ -523,7 +522,7 @@ let collect_all_ninja_build (ninja : ninja) (tested_file : string) (reset_test_o
let test_name, rule, vars =
match expected_output.scope with
| Some scope ->
( Printf.sprintf "%s_%s_%s" output_build_kind scope tested_file
( Printf.sprintf "%s_%s_%s_%s" output_build_kind scope catala_backend tested_file
|> Nj.Build.unpath,
output_build_kind ^ "_with_scope_and_output",
("scope", Nj.Expr.Lit scope) :: vars )

View File

@ -1,22 +0,0 @@
## Article
```catala
declaration scope A:
output x content collection money
scope A:
definition x equals [$0; $4 +$ $5; $8 *$ 0.65]
declaration scope B:
a scope A
output max content money
output min content money
output y content money
output z content integer
scope B:
definition max equals maximum money initial $0 for m in a.x of m *$ 2.0
definition min equals minimum money initial $20 for m in a.x of m +$ $5
definition y equals sum money for m in a.x of (m +$ $1)
definition z equals number for m in a.x of (m >=$ $8.95)
```

View File

@ -1,177 +0,0 @@
(** This file has been generated by the Catala compiler, do not edit! *)
open Runtime
[@@@ocaml.warning "-4-26-27-32-41-42"]
type s = { id : integer; income : money }
type a_out = { x_out : s array }
type a_in = { x_in : unit -> s array }
type b_out = { argmax_out : s; argmin_out : s }
type b_in = unit
let a (a_in : a_in) =
let x_ : unit -> s array = a_in.x_in in
let x_ : s array =
try
handle_default
[| (fun (_ : _) -> x_ ()) |]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
[|
{ id = integer_of_string "0"; income = money_of_cents_string "0" };
{
id = integer_of_string "1";
income =
money_of_cents_string "400" +$ money_of_cents_string "500";
};
{
id = integer_of_string "2";
income = money_of_cents_string "800" *$ decimal_of_string "0.65";
};
|]));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)));
|]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||] (fun (_ : _) -> false) (fun (_ : _) -> raise EmptyError));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)))
with EmptyError ->
raise
(NoValueProvided
{
filename = "tests/test_array/good/aggregation_2.catala_en";
start_line = 9;
start_column = 19;
end_line = 9;
end_column = 20;
law_headings = [ "Article" ];
})
in
{ x_out = x_ }
let b (b_in : b_in) =
let a_dot_x_ : unit -> s array = fun (_ : unit) -> raise EmptyError in
let result_ : a_out = a { x_in = a_dot_x_ } in
let a_dot_x_ : s array = result_.x_out in
let argmin_ : s =
try
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
let predicate_ : _ =
fun (m_ : _) -> m_.income +$ money_of_cents_string "500"
in
Array.fold_left
(fun (acc_ : _) (item_ : _) ->
if predicate_ acc_ <$ predicate_ item_ then acc_ else item_)
{
id = ~-!(integer_of_string "1");
income = money_of_cents_string "2000";
}
a_dot_x_));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)));
|]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||] (fun (_ : _) -> false) (fun (_ : _) -> raise EmptyError));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError))
with EmptyError ->
raise
(NoValueProvided
{
filename = "tests/test_array/good/aggregation_2.catala_en";
start_line = 21;
start_column = 11;
end_line = 21;
end_column = 17;
law_headings = [ "Article" ];
})
in
let argmax_ : s =
try
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
let predicate_ : _ =
fun (m_ : _) -> m_.income *$ decimal_of_string "2."
in
Array.fold_left
(fun (acc_ : _) (item_ : _) ->
if predicate_ acc_ >$ predicate_ item_ then acc_ else item_)
{ id = ~-!(integer_of_string "1"); income = money_of_cents_string "0" }
a_dot_x_));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)));
|]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||] (fun (_ : _) -> false) (fun (_ : _) -> raise EmptyError));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError))
with EmptyError ->
raise
(NoValueProvided
{
filename = "tests/test_array/good/aggregation_2.catala_en";
start_line = 20;
start_column = 11;
end_line = 20;
end_column = 17;
law_headings = [ "Article" ];
})
in
{ argmax_out = argmax_; argmin_out = argmin_ }

View File

@ -1,11 +0,0 @@
## Unit testing for collection concatenation.
```catala
declaration scope A:
output x content collection integer
output y content collection integer
scope A:
definition x equals [0; 1; 2] ++ [3; 4; 5; 6]
definition y equals x ++ ([7; 8; 9] ++ [10])
```

View File

@ -1,18 +0,0 @@
## Article
```catala
declaration scope A:
output x content collection money
scope A:
definition x equals [$0; $4 +$ $5; $8 *$ 0.65]
declaration scope B:
a scope A
output y content collection money
output z content collection boolean
scope B:
definition y equals filter for m in a.x of (m >=$ $4.95)
definition z equals map for m in a.x of (m >=$ $4.95)
```

View File

@ -1,2 +0,0 @@
[RESULT] Computation successful! Results:
[RESULT] x = [$0.00; $9.00; $5.20]

View File

@ -1,5 +0,0 @@
[RESULT] Computation successful! Results:
[RESULT] max = $18.00
[RESULT] min = $5.00
[RESULT] y = $17.20
[RESULT] z = 1

View File

@ -4,174 +4,165 @@ open Runtime
[@@@ocaml.warning "-4-26-27-32-41-42"]
type s = { id : integer; income : money }
type s = {
id: integer;
income: money;
}
type a_out = { x_out : s array }
type a_in = { x_in : unit -> s array }
type b_out = { argmax_out : s; argmin_out : s }
type a_out = {
x_out: s array;
}
type a_in = {
x_in: unit -> (s array);
}
type b_out = {
argmax_out: s;
argmin_out: s;
}
type b_in = unit
let a (a_in : a_in) =
let x_ : unit -> s array = a_in.x_in in
let x_ : s array =
try
handle_default
[| (fun (_ : _) -> x_ ()) |]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
[|
{ id = integer_of_string "0"; income = money_of_cents_string "0" };
{
id = integer_of_string "1";
income =
money_of_cents_string "400" +$ money_of_cents_string "500";
};
{
id = integer_of_string "2";
income = money_of_cents_string "800" *$ decimal_of_string "0.65";
};
|]));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)));
|]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||] (fun (_ : _) -> false) (fun (_ : _) -> raise EmptyError));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)))
with EmptyError ->
raise
(NoValueProvided
{
filename = "build_system/tests/test_array/good/aggregation_2.catala_en";
start_line = 9;
start_column = 19;
end_line = 9;
end_column = 20;
law_headings = [ "Article" ];
})
in
{ x_out = x_ }
let b (b_in : b_in) =
let a_dot_x_ : unit -> s array = fun (_ : unit) -> raise EmptyError in
let result_ : a_out = a { x_in = a_dot_x_ } in
let a_dot_x_ : s array = result_.x_out in
let argmin_ : s =
try
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
let a =
fun (a_in: a_in) -> let x_ : unit -> (s array) = (a_in.x_in)
in
let x_ : s array =
((try
(handle_default ([|(fun (_: _) -> x_ ())|]) (fun (_: _) -> true)
(fun (_: _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
let predicate_ : _ =
fun (m_ : _) -> m_.income +$ money_of_cents_string "500"
in
Array.fold_left
(fun (acc_ : _) (item_ : _) ->
if predicate_ acc_ <$ predicate_ item_ then acc_ else item_)
{
id = ~-!(integer_of_string "1");
income = money_of_cents_string "2000";
}
a_dot_x_));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)));
|]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||] (fun (_ : _) -> false) (fun (_ : _) -> raise EmptyError));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError))
with EmptyError ->
raise
(NoValueProvided
{
filename = "build_system/tests/test_array/good/aggregation_2.catala_en";
start_line = 21;
start_column = 11;
end_line = 21;
end_column = 17;
law_headings = [ "Article" ];
})
in
let argmax_ : s =
try
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> true)
(fun (_: _) ->
handle_default
([|(fun (_: _) ->
handle_default ([||])
(fun (_: _) -> true)
(fun (_: _) ->
[|{id = (integer_of_string "0");
income =
(money_of_cents_string "0")};
{id = (integer_of_string "1");
income =
((money_of_cents_string
"400") +$
(money_of_cents_string
"500"))};
{id = (integer_of_string "2");
income =
((money_of_cents_string
"800") *$
(decimal_of_string "0.65"))}|]))|])
(fun (_: _) -> false)
(fun (_: _) -> raise EmptyError)))|])
(fun (_: _) -> true)
(fun (_: _) ->
handle_default
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> false)
(fun (_: _) -> raise EmptyError))|])
(fun (_: _) -> false) (fun (_: _) -> raise EmptyError))))
with EmptyError -> (raise (NoValueProvided
{filename = "build_system/tests/test_array/good/aggregation_2.catala_en";
start_line=9; start_column=19; end_line=9; end_column=20;
law_headings=["Article"]})))) in
{x_out = x_}
let b =
fun (b_in: b_in) ->
let a_dot_x_ : unit -> (s array) = (fun (_: unit) -> (raise EmptyError))
in
let result_ : a_out = (((a) {x_in = a_dot_x_}))
in
let a_dot_x_ : s array = (result_.x_out)
in
let argmin_ : s =
((try
(handle_default
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> true)
(fun (_: _) ->
handle_default
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> true)
(fun (_: _) ->
let predicate_ : _ =
(fun (m_: _) ->
(m_.income) +$
(money_of_cents_string "500"))
in
(Array.fold_left
(fun (acc_: _) (item_: _) ->
if
((predicate_ acc_) <$
(predicate_ item_)) then
acc_ else item_)
{id = (~-! (integer_of_string "1"));
income = (money_of_cents_string
"2000")} a_dot_x_)))|])
(fun (_: _) -> false)
(fun (_: _) -> raise EmptyError)))|])
(fun (_: _) -> true)
(fun (_: _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||]
(fun (_ : _) -> true)
(fun (_ : _) ->
let predicate_ : _ =
fun (m_ : _) -> m_.income *$ decimal_of_string "2."
in
Array.fold_left
(fun (acc_ : _) (item_ : _) ->
if predicate_ acc_ >$ predicate_ item_ then acc_ else item_)
{ id = ~-!(integer_of_string "1"); income = money_of_cents_string "0" }
a_dot_x_));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError)));
|]
(fun (_ : _) -> true)
(fun (_ : _) ->
handle_default
[|
(fun (_ : _) ->
handle_default [||] (fun (_ : _) -> false) (fun (_ : _) -> raise EmptyError));
|]
(fun (_ : _) -> false)
(fun (_ : _) -> raise EmptyError))
with EmptyError ->
raise
(NoValueProvided
{
filename = "build_system/tests/test_array/good/aggregation_2.catala_en";
start_line = 20;
start_column = 11;
end_line = 20;
end_column = 17;
law_headings = [ "Article" ];
})
in
{ argmax_out = argmax_; argmin_out = argmin_ }
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> false)
(fun (_: _) -> raise EmptyError))|])
(fun (_: _) -> false) (fun (_: _) -> raise EmptyError)))
with EmptyError -> (raise (NoValueProvided
{filename = "build_system/tests/test_array/good/aggregation_2.catala_en";
start_line=21; start_column=11; end_line=21; end_column=17;
law_headings=["Article"]}))))
in
let argmax_ : s =
((try
(handle_default
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> true)
(fun (_: _) ->
handle_default
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> true)
(fun (_: _) ->
let predicate_ : _ =
(fun (m_: _) ->
(m_.income) *$
(decimal_of_string "2."))
in
(Array.fold_left
(fun (acc_: _) (item_: _) ->
if
((predicate_ acc_) >$
(predicate_ item_)) then
acc_ else item_)
{id = (~-! (integer_of_string "1"));
income = (money_of_cents_string
"0")} a_dot_x_)))|])
(fun (_: _) -> false)
(fun (_: _) -> raise EmptyError)))|])
(fun (_: _) -> true)
(fun (_: _) ->
handle_default
([|(fun (_: _) ->
handle_default ([||]) (fun (_: _) -> false)
(fun (_: _) -> raise EmptyError))|])
(fun (_: _) -> false) (fun (_: _) -> raise EmptyError)))
with EmptyError -> (raise (NoValueProvided
{filename = "build_system/tests/test_array/good/aggregation_2.catala_en";
start_line=20; start_column=11; end_line=20; end_column=17;
law_headings=["Article"]}))))
in
{argmax_out = argmax_; argmin_out = argmin_}

View File

@ -1,3 +0,0 @@
[RESULT] Computation successful! Results:
[RESULT] x = [0; 1; 2; 3; 4; 5; 6]
[RESULT] y = [0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10]

View File

@ -1,2 +0,0 @@
[RESULT] Computation successful! Results:
[RESULT] x = [$0.00; $9.00; $5.20]

View File

@ -1,3 +0,0 @@
[RESULT] Computation successful! Results:
[RESULT] y = [$9.00; $5.20]
[RESULT] z = [false; true; true]

View File

@ -1,2 +0,0 @@
[RESULT] Computation successful! Results:
[RESULT] x = [0; 9; 64]

View File

@ -1,5 +0,0 @@
[RESULT] Computation successful! Results:
[RESULT] v = 3
[RESULT] w = true
[RESULT] y = true
[RESULT] z = false

View File

@ -1,22 +0,0 @@
## Article
```catala
declaration scope A:
output x content collection integer
scope A:
definition x equals [0; 4+5; 8*8]
declaration scope B:
a scope A
output v content integer
output w content boolean
output y content boolean
output z content boolean
scope B:
definition v equals number of a.x
definition w equals 64 in a.x
definition y equals exists m in a.x such that m = 9
definition z equals for all m in a.x we have m > 0
```