Scalc change: switch only on variables

matches can bind, but switches cannot, so we can assume the switch argument
should always be bound to a name ; this allow the intermediate variable to be
better renamed.
This commit is contained in:
Louis Gesbert 2024-08-08 15:06:03 +02:00
parent 14a378a33d
commit e9abbf9bd8
8 changed files with 169 additions and 176 deletions

View File

@ -70,8 +70,8 @@ type stmt =
| SFatalError of Runtime.error | SFatalError of Runtime.error
| SIfThenElse of { if_expr : expr; then_block : block; else_block : block } | SIfThenElse of { if_expr : expr; then_block : block; else_block : block }
| SSwitch of { | SSwitch of {
switch_expr : expr; switch_var : VarName.t;
switch_expr_typ : typ; switch_var_typ : typ;
enum_name : EnumName.t; enum_name : EnumName.t;
switch_cases : switch_case list; switch_cases : switch_case list;
} }

View File

@ -421,7 +421,23 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) : A.block * R
binder_pos ); binder_pos );
], ctxt.ren_ctx ], ctxt.ren_ctx
| EMatch { e = e1; cases; name } -> | EMatch { e = e1; cases; name } ->
let typ = Expr.maybe_ty (Mark.get e1) in
let e1_stmts, new_e1, ren_ctx = translate_expr ctxt e1 in let e1_stmts, new_e1, ren_ctx = translate_expr ctxt e1 in
let ctxt = { ctxt with ren_ctx } in
let e1_stmts, switch_var, ctxt =
match new_e1 with
| A.EVar v, _ -> e1_stmts, v, ctxt
| _ ->
let v, ctxt = fresh_var ctxt ctxt.context_name ~pos:(Expr.pos e1) in
RevBlock.append e1_stmts
( A.SLocalInit
{ name = v, Expr.pos e1;
expr = new_e1;
typ },
Expr.pos e1 ),
v,
ctxt
in
let new_cases = let new_cases =
EnumConstructor.Map.fold EnumConstructor.Map.fold
(fun _ arg new_args -> (fun _ arg new_args ->
@ -443,20 +459,19 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) : A.block * R
| _ -> assert false) | _ -> assert false)
cases [] cases []
in in
let new_args = List.rev new_cases in
RevBlock.rebuild e1_stmts RevBlock.rebuild e1_stmts
~tail: ~tail:
[ [
( A.SSwitch ( A.SSwitch
{ {
switch_expr = new_e1; switch_var;
switch_expr_typ = Expr.maybe_ty (Mark.get e1); switch_var_typ = typ;
enum_name = name; enum_name = name;
switch_cases = new_args; switch_cases = List.rev new_cases;
}, },
Expr.pos block_expr ); Expr.pos block_expr );
], ],
ren_ctx ctxt.ren_ctx
| EIfThenElse { cond; etrue; efalse } -> | EIfThenElse { cond; etrue; efalse } ->
let cond_stmts, s_cond, ren_ctx = translate_expr ctxt cond in let cond_stmts, s_cond, ren_ctx = translate_expr ctxt cond in
let s_e_true, _ = translate_statements ctxt etrue in let s_e_true, _ = translate_statements ctxt etrue in

View File

@ -169,12 +169,12 @@ let rec format_statement
Format.fprintf fmt "@[<hov 2>%a %a@]" Print.keyword "assert" Format.fprintf fmt "@[<hov 2>%a %a@]" Print.keyword "assert"
(format_expr decl_ctx ~debug) (format_expr decl_ctx ~debug)
(naked_expr, Mark.get stmt) (naked_expr, Mark.get stmt)
| SSwitch { switch_expr = e_switch; enum_name = enum; switch_cases = arms; _ } | SSwitch { switch_var = v_switch; enum_name = enum; switch_cases = arms; _ }
-> ->
let cons = EnumName.Map.find enum decl_ctx.ctx_enums in let cons = EnumName.Map.find enum decl_ctx.ctx_enums in
Format.fprintf fmt "@[<v 0>%a @[<hov 2>%a@]%a@,@]%a" Print.keyword "switch" Format.fprintf fmt "@[<v 0>%a @[<hov 2>%a@]%a@,@]%a" Print.keyword "switch"
(format_expr decl_ctx ~debug) format_var_name v_switch
e_switch Print.punctuation ":" Print.punctuation ":"
(Format.pp_print_list (Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n") ~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n")
(fun fmt ((case, _), switch_case_data) -> (fun fmt ((case, _), switch_case_data) ->

View File

@ -389,18 +389,15 @@ let rec format_statement
Format.fprintf fmt Format.fprintf fmt
"@[<hv 2>@[<hov 2>if (%a) {@]@,%a@,@;<1 -2>} else {@,%a@,@;<1 -2>}@]" "@[<hv 2>@[<hov 2>if (%a) {@]@,%a@,@;<1 -2>} else {@,%a@,@;<1 -2>}@]"
(format_expression ctx) cond (format_block ctx) b1 (format_block ctx) b2 (format_expression ctx) cond (format_block ctx) b1 (format_block ctx) b2
| SSwitch { switch_expr = e1; enum_name = e_name; switch_cases = cases; _ } -> | SSwitch { switch_var; enum_name = e_name; switch_cases = cases; _ } ->
let cases = let cases =
List.map2 List.map2
(fun x (cons, _) -> x, cons) (fun x (cons, _) -> x, cons)
cases cases
(EnumConstructor.Map.bindings (EnumName.Map.find e_name ctx.ctx_enums)) (EnumConstructor.Map.bindings (EnumName.Map.find e_name ctx.ctx_enums))
in in
let tmp_var = VarName.fresh ("match_arg", Pos.no_pos) in
Format.fprintf fmt "@[<hov 2>%a %a = %a;@]@," EnumName.format e_name
VarName.format tmp_var (format_expression ctx) e1;
Format.pp_open_vbox fmt 2; Format.pp_open_vbox fmt 2;
Format.fprintf fmt "@[<hov 4>switch (%a.code) {@]@," VarName.format tmp_var; Format.fprintf fmt "@[<hov 4>switch (%a.code) {@]@," VarName.format switch_var;
Format.pp_print_list Format.pp_print_list
(fun fmt ({ case_block; payload_var_name; payload_var_typ }, cons_name) -> (fun fmt ({ case_block; payload_var_name; payload_var_typ }, cons_name) ->
Format.fprintf fmt "@[<hv 2>case %a_%a:@ " EnumName.format e_name Format.fprintf fmt "@[<hv 2>case %a_%a:@ " EnumName.format e_name
@ -408,7 +405,7 @@ let rec format_statement
if not (Type.equal payload_var_typ (TLit TUnit, Pos.no_pos)) then if not (Type.equal payload_var_typ (TLit TUnit, Pos.no_pos)) then
Format.fprintf fmt "%a = %a.payload.%a;@ " Format.fprintf fmt "%a = %a.payload.%a;@ "
(format_typ ctx (fun fmt -> VarName.format fmt payload_var_name)) (format_typ ctx (fun fmt -> VarName.format fmt payload_var_name))
payload_var_typ VarName.format tmp_var EnumConstructor.format payload_var_typ VarName.format switch_var EnumConstructor.format
cons_name; cons_name;
Format.fprintf fmt "%a@ break;@]" (format_block ctx) case_block) Format.fprintf fmt "%a@ break;@]" (format_block ctx) case_block)
fmt cases; fmt cases;

View File

@ -370,7 +370,7 @@ let rec format_statement ctx (fmt : Format.formatter) (s : stmt Mark.pos) : unit
(format_expression ctx) cond (format_block ctx) b1 (format_block ctx) b2 (format_expression ctx) cond (format_block ctx) b1 (format_block ctx) b2
| SSwitch | SSwitch
{ {
switch_expr = e1; switch_var;
enum_name = e_name; enum_name = e_name;
switch_cases = switch_cases =
[ [
@ -381,14 +381,11 @@ let rec format_statement ctx (fmt : Format.formatter) (s : stmt Mark.pos) : unit
} }
when EnumName.equal e_name Expr.option_enum -> when EnumName.equal e_name Expr.option_enum ->
(* We translate the option type with an overloading by Python's [None] *) (* We translate the option type with an overloading by Python's [None] *)
let tmp_var = VarName.fresh ("perhaps_none_arg", Pos.no_pos) in Format.fprintf fmt "@[<v 4>if %a is None:@ %a@]@," VarName.format switch_var
Format.fprintf fmt "@[<hv 4>%a = %a@]@," VarName.format tmp_var
(format_expression ctx) e1;
Format.fprintf fmt "@[<v 4>if %a is None:@ %a@]@," VarName.format tmp_var
(format_block ctx) case_none; (format_block ctx) case_none;
Format.fprintf fmt "@[<v 4>else:@ %a = %a@,%a@]" VarName.format Format.fprintf fmt "@[<v 4>else:@ %a = %a@,%a@]" VarName.format
case_some_var VarName.format tmp_var (format_block ctx) case_some case_some_var VarName.format switch_var (format_block ctx) case_some
| SSwitch { switch_expr = e1; enum_name = e_name; switch_cases = cases; _ } -> | SSwitch { switch_var; enum_name = e_name; switch_cases = cases; _ } ->
let cons_map = EnumName.Map.find e_name ctx.decl_ctx.ctx_enums in let cons_map = EnumName.Map.find e_name ctx.decl_ctx.ctx_enums in
let cases = let cases =
List.map2 List.map2
@ -396,16 +393,14 @@ let rec format_statement ctx (fmt : Format.formatter) (s : stmt Mark.pos) : unit
cases cases
(EnumConstructor.Map.bindings cons_map) (EnumConstructor.Map.bindings cons_map)
in in
let tmp_var = VarName.fresh ("match_arg", Pos.no_pos) in Format.fprintf fmt "@[<hov 4>if %a@]"
Format.fprintf fmt "%a = %a@\n@[<hov 4>if %a@]" VarName.format tmp_var
(format_expression ctx) e1
(Format.pp_print_list (Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@]@\n@[<hov 4>elif ") ~pp_sep:(fun fmt () -> Format.fprintf fmt "@]@\n@[<hov 4>elif ")
(fun fmt ({ case_block; payload_var_name; _ }, cons_name) -> (fun fmt ({ case_block; payload_var_name; _ }, cons_name) ->
Format.fprintf fmt "%a.code == %a_Code.%a:@\n%a = %a.value@\n%a" Format.fprintf fmt "%a.code == %a_Code.%a:@\n%a = %a.value@\n%a"
VarName.format tmp_var EnumName.format e_name VarName.format switch_var EnumName.format e_name
EnumConstructor.format cons_name VarName.format payload_var_name EnumConstructor.format cons_name VarName.format payload_var_name
VarName.format tmp_var (format_block ctx) case_block)) VarName.format switch_var (format_block ctx) case_block))
cases cases
| SReturn e1 -> | SReturn e1 ->
Format.fprintf fmt "@[<hov 4>return %a@]" (format_expression ctx) Format.fprintf fmt "@[<hov 4>return %a@]" (format_expression ctx)

View File

@ -110,8 +110,8 @@ Baz baz(Baz_in baz_in) {
Array_1 a4; Array_1 a4;
a4.content_field = catala_malloc(sizeof(Array_1)); a4.content_field = catala_malloc(sizeof(Array_1));
a4.content_field[0] = code(env, NULL); a4.content_field[0] = code(env, NULL);
Option_1 match_arg = catala_handle_exceptions(a4); Option_1 a3 = catala_handle_exceptions(a4);
switch (match_arg.code) { switch (a3.code) {
case Option_1_None_1: case Option_1_None_1:
if (1 /* TRUE */) { if (1 /* TRUE */) {
Bar a3; Bar a3;
@ -120,8 +120,8 @@ Baz baz(Baz_in baz_in) {
Array_1 a7; Array_1 a7;
a7.content_field = catala_malloc(sizeof(Array_1)); a7.content_field = catala_malloc(sizeof(Array_1));
Option_1 match_arg = catala_handle_exceptions(a7); Option_1 a8 = catala_handle_exceptions(a7);
switch (match_arg.code) { switch (a8.code) {
case Option_1_None_1: case Option_1_None_1:
if (1 /* TRUE */) { if (1 /* TRUE */) {
Bar a6 = {Bar_No, {No: NULL}}; Bar a6 = {Bar_No, {No: NULL}};
@ -133,15 +133,15 @@ Baz baz(Baz_in baz_in) {
} }
break; break;
case Option_1_Some_1: case Option_1_Some_1:
Bar x1 = match_arg.payload.Some_1; Bar x1 = a8.payload.Some_1;
option_1 a6 = {Option_1_Some_1, {Some_1: x1}}; option_1 a6 = {Option_1_Some_1, {Some_1: x1}};
break; break;
} }
Array_1 a5; Array_1 a5;
a5.content_field = catala_malloc(sizeof(Array_1)); a5.content_field = catala_malloc(sizeof(Array_1));
a5.content_field[0] = a6; a5.content_field[0] = a6;
Option_1 match_arg = catala_handle_exceptions(a5); Option_1 a9 = catala_handle_exceptions(a5);
switch (match_arg.code) { switch (a9.code) {
case Option_1_None_1: case Option_1_None_1:
if (0 /* FALSE */) { if (0 /* FALSE */) {
option_1 a4 = {Option_1_None_1, {None_1: NULL}}; option_1 a4 = {Option_1_None_1, {None_1: NULL}};
@ -152,20 +152,16 @@ Baz baz(Baz_in baz_in) {
} }
break; break;
case Option_1_Some_1: case Option_1_Some_1:
Bar x1 = match_arg.payload.Some_1; Bar x1 = a9.payload.Some_1;
option_1 a4 = {Option_1_Some_1, {Some_1: x1}}; option_1 a4 = {Option_1_Some_1, {Some_1: x1}};
break; break;
} }
Option_1 match_arg = a4; switch (a4.code) {
switch (match_arg.code) {
case Option_1_None_1: case Option_1_None_1:
catala_raise_fatal_error (catala_no_value, catala_raise_fatal_error (catala_no_value,
"tests/backends/simple.catala_en", 11, 11, 11, 12); "tests/backends/simple.catala_en", 11, 11, 11, 12);
break; break;
case Option_1_Some_1: case Option_1_Some_1: Bar arg = a4.payload.Some_1; a3 = arg; break;
Bar arg = match_arg.payload.Some_1;
a3 = arg;
break;
} }
option_1 a3 = {Option_1_Some_1, {Some_1: a3}}; option_1 a3 = {Option_1_Some_1, {Some_1: a3}};
@ -175,20 +171,16 @@ Baz baz(Baz_in baz_in) {
} }
break; break;
case Option_1_Some_1: case Option_1_Some_1:
Bar x1 = match_arg.payload.Some_1; Bar x1 = a3.payload.Some_1;
option_1 a3 = {Option_1_Some_1, {Some_1: x1}}; option_1 a3 = {Option_1_Some_1, {Some_1: x1}};
break; break;
} }
Option_1 match_arg = a3; switch (a3.code) {
switch (match_arg.code) {
case Option_1_None_1: case Option_1_None_1:
catala_raise_fatal_error (catala_no_value, catala_raise_fatal_error (catala_no_value,
"tests/backends/simple.catala_en", 11, 11, 11, 12); "tests/backends/simple.catala_en", 11, 11, 11, 12);
break; break;
case Option_1_Some_1: case Option_1_Some_1: Bar arg = a3.payload.Some_1; a2 = arg; break;
Bar arg = match_arg.payload.Some_1;
a2 = arg;
break;
} }
Bar a1; Bar a1;
a1 = a2; a1 = a2;

View File

@ -91,82 +91,80 @@ class BIn:
def some_name(some_name_in:SomeNameIn): def some_name(some_name_in:SomeNameIn):
i = some_name_in.i_in i = some_name_in.i_in
perhaps_none_arg = handle_exceptions([], []) o4 = handle_exceptions([], [])
if perhaps_none_arg is None: if o4 is None:
if True: if True:
o3 = (i + integer_of_string("1")) o3 = (i + integer_of_string("1"))
else: else:
o3 = None o3 = None
else: else:
x = perhaps_none_arg x = o4
o3 = x o3 = x
perhaps_none_arg = handle_exceptions( o5 = handle_exceptions(
[SourcePosition( [SourcePosition(
filename="tests/backends/python_name_clash.catala_en", filename="tests/backends/python_name_clash.catala_en",
start_line=10, start_column=23, start_line=10, start_column=23, end_line=10, end_column=28,
end_line=10, end_column=28, law_headings=[])], law_headings=[])],
[o3] [o3]
) )
if perhaps_none_arg is None: if o5 is None:
if False: if False:
o2 = None o2 = None
else: else:
o2 = None o2 = None
else: else:
x = perhaps_none_arg x = o5
o2 = x o2 = x
perhaps_none_arg = o2 if o2 is None:
if perhaps_none_arg is None:
raise NoValue(SourcePosition( raise NoValue(SourcePosition(
filename="tests/backends/python_name_clash.catala_en", filename="tests/backends/python_name_clash.catala_en",
start_line=7, start_column=10, start_line=7, start_column=10,
end_line=7, end_column=11, law_headings=[])) end_line=7, end_column=11, law_headings=[]))
else: else:
arg = perhaps_none_arg arg = o2
o1 = arg o1 = arg
o = o1 o = o1
return SomeName(o = o) return SomeName(o = o)
def b(b_in:BIn): def b(b_in:BIn):
perhaps_none_arg = handle_exceptions([], []) result4 = handle_exceptions([], [])
if perhaps_none_arg is None: if result4 is None:
if True: if True:
result3 = integer_of_string("1") result3 = integer_of_string("1")
else: else:
result3 = None result3 = None
else: else:
x = perhaps_none_arg x = result4
result3 = x result3 = x
perhaps_none_arg = handle_exceptions( result5 = handle_exceptions(
[SourcePosition( [SourcePosition(
filename="tests/backends/python_name_clash.catala_en", filename="tests/backends/python_name_clash.catala_en",
start_line=16, start_column=33, start_line=16, start_column=33,
end_line=16, end_column=34, law_headings=[])], end_line=16, end_column=34, law_headings=[])],
[result3] [result3]
) )
if perhaps_none_arg is None: if result5 is None:
if False: if False:
result2 = None result2 = None
else: else:
result2 = None result2 = None
else: else:
x = perhaps_none_arg x = result5
result2 = x result2 = x
perhaps_none_arg = result2 if result2 is None:
if perhaps_none_arg is None:
raise NoValue(SourcePosition( raise NoValue(SourcePosition(
filename="tests/backends/python_name_clash.catala_en", filename="tests/backends/python_name_clash.catala_en",
start_line=16, start_column=14, start_line=16, start_column=14,
end_line=16, end_column=25, law_headings=[])) end_line=16, end_column=25, law_headings=[]))
else: else:
arg = perhaps_none_arg arg = result2
result1 = arg result1 = arg
result = some_name(SomeNameIn(i_in = result1)) result = some_name(SomeNameIn(i_in = result1))
result4 = SomeName(o = result.o) result6 = SomeName(o = result.o)
if True: if True:
some_name2 = result4 some_name2 = result6
else: else:
some_name2 = result4 some_name2 = result6
some_name1 = some_name2 some_name1 = some_name2
return B(some_name = some_name1) return B(some_name = some_name1)
``` ```

View File

@ -128,7 +128,8 @@ let S2 (S2_in: S2_in) =
decl a1 : decimal; decl a1 : decimal;
decl a2 : option decimal; decl a2 : option decimal;
decl a3 : option decimal; decl a3 : option decimal;
switch handle_exceptions []: a4 : option decimal = handle_exceptions [];
switch a4:
| ENone _ → | ENone _ →
if true: if true:
a3 = ESome glob3 ¤44.00 + 100. a3 = ESome glob3 ¤44.00 + 100.
@ -136,7 +137,8 @@ let S2 (S2_in: S2_in) =
a3 = ENone () a3 = ENone ()
| ESome x → | ESome x →
a3 = ESome x; a3 = ESome x;
switch handle_exceptions [a3]: a5 : option decimal = handle_exceptions [a3];
switch a5:
| ENone _ → | ENone _ →
if false: if false:
a2 = ENone () a2 = ENone ()
@ -157,7 +159,8 @@ let S3 (S3_in: S3_in) =
decl a1 : decimal; decl a1 : decimal;
decl a2 : option decimal; decl a2 : option decimal;
decl a3 : option decimal; decl a3 : option decimal;
switch handle_exceptions []: a4 : option decimal = handle_exceptions [];
switch a4:
| ENone _ → | ENone _ →
if true: if true:
a3 = ESome 50. + glob4 ¤44.00 55. a3 = ESome 50. + glob4 ¤44.00 55.
@ -165,7 +168,8 @@ let S3 (S3_in: S3_in) =
a3 = ENone () a3 = ENone ()
| ESome x → | ESome x →
a3 = ESome x; a3 = ESome x;
switch handle_exceptions [a3]: a5 : option decimal = handle_exceptions [a3];
switch a5:
| ENone _ → | ENone _ →
if false: if false:
a2 = ENone () a2 = ENone ()
@ -186,7 +190,8 @@ let S4 (S4_in: S4_in) =
decl a1 : decimal; decl a1 : decimal;
decl a2 : option decimal; decl a2 : option decimal;
decl a3 : option decimal; decl a3 : option decimal;
switch handle_exceptions []: a4 : option decimal = handle_exceptions [];
switch a4:
| ENone _ → | ENone _ →
if true: if true:
a3 = ESome glob5 + 1. a3 = ESome glob5 + 1.
@ -194,7 +199,8 @@ let S4 (S4_in: S4_in) =
a3 = ENone () a3 = ENone ()
| ESome x → | ESome x →
a3 = ESome x; a3 = ESome x;
switch handle_exceptions [a3]: a5 : option decimal = handle_exceptions [a3];
switch a5:
| ENone _ → | ENone _ →
if false: if false:
a2 = ENone () a2 = ENone ()
@ -215,7 +221,8 @@ let S (S_in: S_in) =
decl a1 : decimal; decl a1 : decimal;
decl a2 : option decimal; decl a2 : option decimal;
decl a3 : option decimal; decl a3 : option decimal;
switch handle_exceptions []: a4 : option decimal = handle_exceptions [];
switch a4:
| ENone _ → | ENone _ →
if true: if true:
a3 = ESome glob1 * glob1 a3 = ESome glob1 * glob1
@ -223,7 +230,8 @@ let S (S_in: S_in) =
a3 = ENone () a3 = ENone ()
| ESome x → | ESome x →
a3 = ESome x; a3 = ESome x;
switch handle_exceptions [a3]: a5 : option decimal = handle_exceptions [a3];
switch a5:
| ENone _ → | ENone _ →
if false: if false:
a2 = ENone () a2 = ENone ()
@ -241,7 +249,8 @@ let S (S_in: S_in) =
decl b1 : A {y: bool; z: decimal}; decl b1 : A {y: bool; z: decimal};
decl b2 : option A {y: bool; z: decimal}; decl b2 : option A {y: bool; z: decimal};
decl b3 : option A {y: bool; z: decimal}; decl b3 : option A {y: bool; z: decimal};
switch handle_exceptions []: b4 : option A {y: bool; z: decimal} = handle_exceptions [];
switch b4:
| ENone _ → | ENone _ →
if true: if true:
b3 = ESome glob2 b3 = ESome glob2
@ -249,7 +258,8 @@ let S (S_in: S_in) =
b3 = ENone () b3 = ENone ()
| ESome x → | ESome x →
b3 = ESome x; b3 = ESome x;
switch handle_exceptions [b3]: b5 : option A {y: bool; z: decimal} = handle_exceptions [b3];
switch b5:
| ENone _ → | ENone _ →
if false: if false:
b2 = ENone () b2 = ENone ()
@ -446,48 +456,46 @@ glob6 = (
) )
def s2(s2_in:S2In): def s2(s2_in:S2In):
perhaps_none_arg = handle_exceptions([], []) a4 = handle_exceptions([], [])
if perhaps_none_arg is None: if a4 is None:
if True: if True:
a3 = (glob3(money_of_cents_string("4400")) + a3 = (glob3(money_of_cents_string("4400")) +
decimal_of_string("100.")) decimal_of_string("100."))
else: else:
a3 = None a3 = None
else: else:
x = perhaps_none_arg x = a4
a3 = x a3 = x
perhaps_none_arg = handle_exceptions( a5 = handle_exceptions(
[SourcePosition( [SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=53, start_column=24, start_line=53, start_column=24, end_line=53, end_column=43,
end_line=53, end_column=43, law_headings=["Test toplevel function defs"])],
law_headings=["Test toplevel function defs"])], [a3]
[a3] )
) if a5 is None:
if perhaps_none_arg is None:
if False: if False:
a2 = None a2 = None
else: else:
a2 = None a2 = None
else: else:
x = perhaps_none_arg x = a5
a2 = x a2 = x
perhaps_none_arg = a2 if a2 is None:
if perhaps_none_arg is None:
raise NoValue(SourcePosition( raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=50, start_column=10, start_line=50, start_column=10,
end_line=50, end_column=11, end_line=50, end_column=11,
law_headings=["Test toplevel function defs"])) law_headings=["Test toplevel function defs"]))
else: else:
arg = perhaps_none_arg arg = a2
a1 = arg a1 = arg
a = a1 a = a1
return S2(a = a) return S2(a = a)
def s3(s3_in:S3In): def s3(s3_in:S3In):
perhaps_none_arg = handle_exceptions([], []) a4 = handle_exceptions([], [])
if perhaps_none_arg is None: if a4 is None:
if True: if True:
a3 = (decimal_of_string("50.") + a3 = (decimal_of_string("50.") +
glob4(money_of_cents_string("4400"), glob4(money_of_cents_string("4400"),
@ -495,151 +503,139 @@ def s3(s3_in:S3In):
else: else:
a3 = None a3 = None
else: else:
x = perhaps_none_arg x = a4
a3 = x a3 = x
perhaps_none_arg = handle_exceptions( a5 = handle_exceptions(
[SourcePosition( [SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=74, start_column=24, start_line=74, start_column=24, end_line=74, end_column=47,
end_line=74, end_column=47, law_headings=["Test function def with two args"])],
law_headings=["Test function def with two args"] [a3]
)], )
[a3] if a5 is None:
)
if perhaps_none_arg is None:
if False: if False:
a2 = None a2 = None
else: else:
a2 = None a2 = None
else: else:
x = perhaps_none_arg x = a5
a2 = x a2 = x
perhaps_none_arg = a2 if a2 is None:
if perhaps_none_arg is None:
raise NoValue(SourcePosition( raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=71, start_column=10, start_line=71, start_column=10,
end_line=71, end_column=11, end_line=71, end_column=11,
law_headings=["Test function def with two args"])) law_headings=["Test function def with two args"]))
else: else:
arg = perhaps_none_arg arg = a2
a1 = arg a1 = arg
a = a1 a = a1
return S3(a = a) return S3(a = a)
def s4(s4_in:S4In): def s4(s4_in:S4In):
perhaps_none_arg = handle_exceptions([], []) a4 = handle_exceptions([], [])
if perhaps_none_arg is None: if a4 is None:
if True: if True:
a3 = (glob5 + decimal_of_string("1.")) a3 = (glob5 + decimal_of_string("1."))
else: else:
a3 = None a3 = None
else: else:
x = perhaps_none_arg x = a4
a3 = x a3 = x
perhaps_none_arg = handle_exceptions( a5 = handle_exceptions(
[SourcePosition( [SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=98, start_column=24, start_line=98, start_column=24, end_line=98, end_column=34,
end_line=98, end_column=34, law_headings=["Test inline defs in toplevel defs"])],
law_headings=["Test inline defs in toplevel defs"] [a3]
)], )
[a3] if a5 is None:
)
if perhaps_none_arg is None:
if False: if False:
a2 = None a2 = None
else: else:
a2 = None a2 = None
else: else:
x = perhaps_none_arg x = a5
a2 = x a2 = x
perhaps_none_arg = a2 if a2 is None:
if perhaps_none_arg is None:
raise NoValue(SourcePosition( raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=95, start_column=10, start_line=95, start_column=10,
end_line=95, end_column=11, end_line=95, end_column=11,
law_headings=["Test inline defs in toplevel defs"])) law_headings=["Test inline defs in toplevel defs"]))
else: else:
arg = perhaps_none_arg arg = a2
a1 = arg a1 = arg
a = a1 a = a1
return S4(a = a) return S4(a = a)
def s5(s_in:SIn): def s5(s_in:SIn):
perhaps_none_arg = handle_exceptions([], []) a4 = handle_exceptions([], [])
if perhaps_none_arg is None: if a4 is None:
if True: if True:
a3 = (glob1 * glob1) a3 = (glob1 * glob1)
else: else:
a3 = None a3 = None
else: else:
x = perhaps_none_arg x = a4
a3 = x a3 = x
perhaps_none_arg = handle_exceptions( a5 = handle_exceptions(
[SourcePosition( [SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=18, start_column=24, start_line=18, start_column=24, end_line=18, end_column=37,
end_line=18, end_column=37, law_headings=["Test basic toplevel values defs"])],
law_headings=["Test basic toplevel values defs"] [a3]
)], )
[a3] if a5 is None:
)
if perhaps_none_arg is None:
if False: if False:
a2 = None a2 = None
else: else:
a2 = None a2 = None
else: else:
x = perhaps_none_arg x = a5
a2 = x a2 = x
perhaps_none_arg = a2 if a2 is None:
if perhaps_none_arg is None:
raise NoValue(SourcePosition( raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=7, start_column=10, start_line=7, start_column=10,
end_line=7, end_column=11, end_line=7, end_column=11,
law_headings=["Test basic toplevel values defs"])) law_headings=["Test basic toplevel values defs"]))
else: else:
arg = perhaps_none_arg arg = a2
a1 = arg a1 = arg
a = a1 a = a1
perhaps_none_arg = handle_exceptions([], []) b4 = handle_exceptions([], [])
if perhaps_none_arg is None: if b4 is None:
if True: if True:
b3 = glob6 b3 = glob6
else: else:
b3 = None b3 = None
else: else:
x = perhaps_none_arg x = b4
b3 = x b3 = x
perhaps_none_arg = handle_exceptions( b5 = handle_exceptions(
[SourcePosition( [SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=19, start_column=24, start_line=19, start_column=24, end_line=19, end_column=29,
end_line=19, end_column=29, law_headings=["Test basic toplevel values defs"])],
law_headings=["Test basic toplevel values defs"] [b3]
)], )
[b3] if b5 is None:
)
if perhaps_none_arg is None:
if False: if False:
b2 = None b2 = None
else: else:
b2 = None b2 = None
else: else:
x = perhaps_none_arg x = b5
b2 = x b2 = x
perhaps_none_arg = b2 if b2 is None:
if perhaps_none_arg is None:
raise NoValue(SourcePosition( raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en", filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=8, start_column=10, start_line=8, start_column=10,
end_line=8, end_column=11, end_line=8, end_column=11,
law_headings=["Test basic toplevel values defs"])) law_headings=["Test basic toplevel values defs"]))
else: else:
arg = perhaps_none_arg arg = b2
b1 = arg b1 = arg
b = b1 b = b1
return S(a = a, b = b) return S(a = a, b = b)